home *** CD-ROM | disk | FTP | other *** search
/ Fun Online 1997 April / FOL0497.iso / tvmlsa / apps / maze / mr.tvm < prev    next >
Text File  |  1997-06-26  |  161KB  |  6,421 lines

  1. /**********************************************************************
  2.  *
  3.  * File :     mazerun.tvm
  4.  *
  5.  * Abstract : TVML Maze runner
  6.  *
  7.  **********************************************************************
  8.  *
  9.  * This file is a product of TVML Ltd.
  10.  *
  11.  * This file is provided as is with no warranties of any kind and is
  12.  * provided without any obligation on TVML Ltd.
  13.  *
  14.  * TVML Ltd. will not, under any circumstances, be liable for any
  15.  * lost revenue or other damages arising from the use of this file.
  16.  *
  17.  ************************************************************************/
  18.  
  19. local
  20.     /* Binary /text control flags */
  21.  
  22.     const
  23.         int BadLuckMessage = 0, WellDoneMessage = 2, BonusMessage = 4, ScoreMessage = 6
  24.         int language = 1
  25.  
  26.     var
  27. //        string MazeRemoteRoot = "http://194.80.180.23/web/tvml/apps/maze/"
  28. //        string MazeRemoteRoot = "http://www.tvml.co.uk/tvml/apps/maze/"
  29. //        string MazeRemoteRoot = "http://tvml.simplenet.com/tvml/apps/maze/"
  30.         string MazeRemoteRoot = "http://www.fol.de/tvml/apps/maze/"
  31.         string MazeLocalCDRoot = ""
  32.         filename MazeDir = `tvmlsa\apps\maze\`
  33. //        filename MazeDir = `apps\maze\`
  34.  
  35.         filename TvmlDir
  36.         filename InstallDir
  37.  
  38.         int    start_text,end_text,del_text
  39.  
  40.     const
  41.         string PlayerVersion = "0.89"
  42.  
  43.         int FastScale = 2, SlowScale = 1
  44.  
  45.         CLOSEST  as float=0.1
  46.         NORTH    as int=1
  47.         EAST     as int=2
  48.         SOUTH    as int=4
  49.         WEST     as int=8
  50.         float PickUp = 0.25
  51.  
  52.         int FastTimerTick = 75      //ms
  53.         int SlowTimerTick = 500      //ms
  54.         int bumprepeat = 1000 //ms
  55.  
  56.  
  57.     data Messages:2
  58.         "Bad luck! You didn't succeed this time. Better luck next time!",
  59.         "Schade! Pech gehabt - du hast es leider nicht geschafft.\n Versuch┤s doch nochmal!",
  60.  
  61.         "Congratulations! You have completed the maze successfully!\n",
  62.         "Super! Herzlichen Glⁿckwunsch! Du hast es geschafft!\n",
  63.  
  64.         "Your time bonus is %d\n",
  65.         "Dein Zeitbonus ist %d\n",
  66.  
  67.         "Your final score is %d\n",
  68.         "Dein Endergebnis ist %d\n"
  69.     enddata
  70.  
  71.     data ObjectsPerRoomData
  72.     //    1,2,3,4,5,6,7,8,9,10,11
  73.         2,3,4,4,1,4,4,2,3, 4, 2
  74.     enddata
  75.  
  76.     data DoorsPerRoomData
  77.     //    1,2,3,4,5,6,7,8,9,10,11
  78.         2,3,4,4,1,4,4,2,3, 4, 2
  79.     enddata
  80.  
  81.     data MinRoomSizeData
  82.     //    1,2,3,4,5,6,7,8,9,10,11
  83.         2,2,2,2,2,2,3,2,3, 3, 1
  84.     enddata
  85.  
  86.     data RoomRotateData
  87.         1,0,0,0,
  88.         1,0,0,0,
  89.         1,0,0,0,
  90.         1,0,0,0
  91.     enddata
  92.  
  93.  
  94.     const
  95.         int MapEditMode=1,
  96.             RoomEditMode=2,
  97.             MazeEditMode=3,
  98.             ThreeDEditMode=4,
  99.             TextureEditMode=5
  100.  
  101.         int StretchTexturesBoth=1, TileTexturesBoth=2, StretchAcrossTileDown=3, StretchDownTileAcross=4,
  102.             StretchAndSquareTile=5
  103.  
  104.     const
  105.         int MINUNIT = 10, MAXUNIT = 100, UNITSTEP = 10, DEFAULTMAPUNIT = 30, DEFAULTROOMUNIT = 60
  106.         int DEFAULTPLAYERMAPUNIT=8
  107.         int DRAWNAMEUNIT = 40
  108.         int maxx = 100, maxy  = 100
  109.  
  110.  
  111.         int MapGridX = 60,  MapGridY = 180
  112.         int RoomGridX = 60, RoomGridY = 180
  113.  
  114.         int NROTATES = high(RoomRotateData)+1
  115.         int MaxRoomSize = 10
  116.  
  117.         int DefaultRoomW = 5, DefaultRoomD = 5, DefaultRoomHeight = 2, DefaultLinkHeight = 1
  118.  
  119.     //basic room defs
  120.     const
  121.         float floor = -0.5
  122.         float roomsep = 0.000
  123.         float OBJECTHEIGHT = 0.1
  124.  
  125.         int NROOMS = 7,
  126.             NLINKS = 4,
  127.             NMAPOBJS = NROOMS+NLINKS,
  128.             NOBJECTS = 11
  129.  
  130.         int NITEMS=7
  131.         int MAXINVENTORY=10
  132.  
  133.         int GreenKeyItem=0, BlueKeyItem=1, RedKeyItem=2
  134.         int MapItem=3, TimeBonusItem=4, FreezeTimeItem=5
  135.         int SpeedItem=6
  136.         int EndItem=10
  137.  
  138.         int SPEEDTIMEPERIOD=20
  139.         int FREEZETIMEPERIOD=10
  140.         int TIMEBONUS=10
  141.  
  142.         int MaxObjectsPerRoom = 5
  143.         int MaxObjectsPerLink = 2
  144.  
  145.  
  146.         int DefaultClipping=15
  147.  
  148.     var
  149.         int FarClipping=DefaultClipping
  150.  
  151.         string InitFile
  152.         int bigarray[maxy][maxx]
  153.         int walls[maxy][maxx]
  154.  
  155.         int ObjectsPerRoom[1 to NMAPOBJS]
  156.         int DoorsPerRoom[1 to NMAPOBJS]
  157.  
  158.         string MazeFilenames[0]
  159.  
  160.     var
  161.         int XOriginObj, YOriginObj
  162.  
  163.         //global maze data
  164.  
  165.         string MazeTimeLimit
  166.         string MazeName
  167.         string MazeFilename
  168.         filename SaveFilename
  169.         boolean goodsav
  170.         string TextureDir
  171.         int RoomFloorTexture, RoomWallTexture, RoomCeilingTexture
  172.         int LinkFloorTexture, LinkWallTexture, LinkCeilingTexture
  173.         int RedDoorTexture, GreenDoorTexture, BlueDoorTexture
  174.  
  175.         int SoundEffectFlags
  176.         string FinishSound, OooffSound, CollectSound
  177.         string BackgroundMIDI
  178.  
  179.         string ObjectDir
  180.         string SoundDir
  181.  
  182.         int NextCollectSlot
  183.  
  184.         string Object3dList[0]
  185.         int Object3dUsage[0]
  186.         float Object3dScale[0]
  187. //        float Object3dXRot[0]
  188. //        float Object3dYRot[0]
  189. //        float Object3dZRot[0]
  190.  
  191.         string TextureList[0]
  192.         int TextureUsage[0]
  193.         int NumberOfTextures
  194.  
  195.         int RoomFloorTexturing, RoomWallTexturing, RoomCeilingTexturing
  196.  
  197.         int ThisRoomTexturing=0
  198.         int ThisRoomFloorTexture
  199.         int ThisRoomWallTexture
  200.         int ThisRoomCeilingTexture
  201.  
  202.         string LevelName[0]
  203.         int NextRoomAtLevel[0]
  204.         int NextLinkAtLevel[0]
  205.  
  206.         int Adjacent[0]        //list of adjacent cells for all rooms
  207.         RwClump *DoorClumps[0]//clump for each door in a room
  208.  
  209.         RwClump DoorControlCLump[0]
  210.         int DoorControlCell[0]
  211.  
  212.         int OverlapList[0]    //list of overlapping cells for all rooms
  213.         int ObjectsList[0]    //list of all objects in the maze
  214.         string ObjectsName[0]//special names of objects in a room
  215.         int ObjectsXYH[0]    //position of objects in a room
  216. //        float ObjectsXRot[0], ObjectsYRot[0], ObjectsZRot[0]
  217.  
  218.         RwClump *ObjectsClump[0]//clump for each object in a room
  219.  
  220.         int roomtype[0]        //type of room
  221.         int RoomNumber[0]
  222.         int roomid[0]        //id of first object in room
  223.         int roomNameid[0]    //id of name object for room if any
  224.         int roomx[0]        //x pos of room
  225.         int roomy[0]        //y pos
  226.         int roomw[0]        //width
  227.         int roomd[0]        //depth
  228.         int roomr[0]        //rotation code
  229.         int RoomHeight[0]    //height
  230.         int RoomLevel[0]    //level of room
  231.         string RoomName[0]    //name of room
  232.         int RoomDoors[0]    //number of doors in room
  233.         int RoomAdjacent[0]    //index in AdjacentList of first adjacent cell
  234.         int RoomObjectsCount[0]    //number of objects in room
  235.         int RoomObjectsindex[0]    //index in ObjectsXXXX of first object in room
  236.         int RoomTextureBits[0]
  237.         int RoomVisited[0]    //true if room visited
  238.         RwClump *room_geometry[0]
  239.         RwScene *room_contents[0]
  240.  
  241.         RwClump *PosStr
  242.  
  243.         int TopDownSort[0]
  244.         int BottomUpSort[0]
  245.         int LeftToRightSort[0]
  246.         int RightToLeftSort[0]
  247.  
  248.         int AdjacentRender[0]
  249.  
  250.         int RoomsAtThisLevel[0]
  251.  
  252.         int PlayerMapUnit=DEFAULTPLAYERMAPUNIT
  253.         int MapUnit
  254.         int RoomUnit
  255.         int CurrentPenWidth = 2
  256.         int unit
  257.         int door
  258.  
  259.         int FirstObjectTag, LastObjectTag
  260.  
  261.         int StartX, StartY, StartRoom, StartLevel
  262.         int EndX, EndY, EndRoom, EndLevel
  263.  
  264.         int CheckError
  265.  
  266.         int StartPosObj, EndPosObj
  267.  
  268.         int GridObjectFirst, GridObjectLast
  269.         int DrawOriginX, DrawOriginY
  270.         int GridOriginX, GridOriginY
  271.         boolean RelativeDrawMode
  272.  
  273.         int MapdrawX, MapDrawY
  274.  
  275.         int EditMode = -1
  276.         int MapCreateMode = 1
  277. //        boolean AutoLinkMode
  278.  
  279.         int ActionKey=0
  280.         int ActionType
  281.         int ActionRoom=-1, thesize=2
  282.         int ActionLevel=0
  283.         int ActionX, ActionY
  284. //        string ActionRoomName
  285.         string ActionLevelName
  286.  
  287.         boolean EndReached, OutOfTime, quit
  288.  
  289.     //stock object stuff
  290.  
  291.     int ItemsList[NITEMS]
  292.     RwClump Inventory[NITEMS][1 to MAXINVENTORY]
  293.  
  294.     int score
  295.     int MazeTime
  296.     int TimerTick
  297.     int ticks
  298.     int FrozenTime
  299.     int HighSpeedTime
  300.  
  301.     int FirstScoreSprite=10, ScoreDigits=7
  302.     int FirstTimeSprite=17, TimeDigits=3
  303.     int TimeRingSprite=20
  304.  
  305.     //stock object sprites are numbered 0-7
  306.     int digits=10
  307.     int MaggotSprite=255
  308.     int FirstTimeRingSprite=20
  309.     int TimeRingSprites=10
  310.  
  311.     int WindowX, WindowY, WindowW, WindowH
  312.     int WindowRX, WindowRY
  313.  
  314.     sub printrwerror( str as string )
  315.         print str, " ", RwStrError( RwGetError() ), "\n"
  316.     endsub
  317.  
  318.  
  319.     sub fast_ ShowScore( bonus as int )
  320.         local
  321.             int i, s, dv
  322.             int x=0,y=0
  323.         endlocal
  324.  
  325.         score+=bonus
  326.         s=score
  327.  
  328.         for i = FirstScoreSprite to FirstScoreSprite+ScoreDigits-1 loop
  329.             dv = s % 10
  330.             s/=10
  331.             CreateSprite i, x, y, oneshot, 0, 0, 1, [digits+dv]
  332.             if s = 0 then
  333.                 loopexit
  334.             endif
  335.         end loop
  336.     end sub
  337.  
  338.  
  339.     sub fast_ ShowTime( adjust as int )
  340.         local
  341.             int i, t, dv
  342.             int x=0,y=0
  343.             boolean Leading0=true
  344.             int ring, lastring
  345.             int divby=int(pow(10,TimeDigits-1))
  346.         endlocal
  347.  
  348.         if MazeTimeLimit = "-1" then
  349.             return
  350.         endif
  351.  
  352.         if MazeTimeLimit = "0" then
  353.             //count up
  354.             MazeTime-=adjust
  355.             t = MazeTime
  356.         else
  357.             MazeTime+=adjust
  358.             t = MazeTime
  359.             if t <= 0 then
  360.                 OutOfTime = true
  361.                 t = 0
  362.             endif
  363.  
  364.             ring = (MazeTime)/10
  365.  
  366.             if ring <= 8 then
  367.                 if ring <> lastring then
  368.                     CreateSprite TimeRingSprite, 38*2, 23*2, oneshot, 0, 0, 1, [FirstTimeRingSprite+(8-ring)]
  369.                     SetSpriteFlags TimeRingSprite, enabled|visible, unbound
  370.                     lastring = ring
  371.                 endif
  372.             else
  373.                 ring = 10
  374.                 if ring <> lastring then
  375.                     CreateSprite TimeRingSprite, 38*2, 23*2, oneshot, 0, 0, 1, [FirstTimeRingSprite+8]
  376.                     SetSpriteFlags TimeRingSprite, enabled|visible, unbound
  377.                     lastring=ring
  378.                 endif
  379.             endif
  380.         endif
  381.  
  382.         for i = FirstTimeSprite+TimeDigits-1 to FirstTimeSprite step -1 loop
  383. //            dv = t % 10
  384. //            t/=10
  385.  
  386.             dv = t/divby
  387.             t-=dv*divby
  388.             divby/=10
  389.  
  390.             if dv <> 0 then
  391.                 leading0 = false
  392.             endif
  393.  
  394.             CreateSprite i, x, y, oneshot, 0, 0, 1, [digits+dv]
  395.             if leading0 then
  396.                 SetSpriteFlags i, enabled, unbound
  397.             else
  398.                 SetSpriteFlags i, enabled|visible, unbound
  399.             endif
  400.         end loop
  401.     end sub
  402.  
  403.     function fast_ ValidRoom( n as int ) as boolean
  404.         if n < 0 or n > high(RoomType) then
  405.             return false
  406.         endif
  407.  
  408.         if RoomType[n] = 0/* or RoomID[n] = 0*/ then
  409.             return false
  410.         endif
  411.  
  412.         return true
  413.     end function
  414.  
  415.  
  416.     function fast_ RoomAtLevel( n as int level as int ) as boolean
  417.         return RoomLevel[n] = level
  418.     end function
  419.  
  420.     function fast_ PointInRoom( n as int x as int y as int level as int ) as boolean
  421.         //return true if (x,y) is in room n
  422.  
  423.         local
  424.             int r
  425.             int x1,y1,x2,y2
  426.         endlocal
  427.  
  428.         if not ValidRoom(n) then
  429.             return false
  430.         endif
  431.  
  432.         if not RoomAtLevel( n, level ) then
  433.             return false
  434.         endif
  435.  
  436. //        print using "PointInRoom=%d type=%d (%d,%d)", n, RoomType[n], x, y
  437. //        print using "x=%d y=%d w=%d d=%d", roomx[n], roomy[n], roomw[n], roomd[n] 
  438.  
  439.         if x < roomx[n] or x >= (roomx[n]+roomw[n]) then
  440.             return false
  441.         endif
  442.  
  443.         if y < roomy[n] or y >= (roomy[n]+roomd[n]) then
  444.             return false
  445.         endif
  446.  
  447.         x1 = RoomX[n]
  448.         y1 = RoomY[n]
  449.         x2 = RoomW[n]+x1-1
  450.         y2 = RoomD[n]+y1-1
  451.         r  = RoomR[n]
  452.  
  453.         if RoomType[n] = NROOMS+1 then
  454.             //special cases for the link pieces because these are not rectangular
  455.             if r = 0 then
  456.                 if x = x2 and y = y1 then
  457.                     return false
  458.                 endif
  459.             elsif r = 4 then
  460.                 if x = x2 and y = y2 then
  461.                     return false
  462.                 endif
  463.             elsif r = 8 then
  464.                 if x = x1 and y = y2 then
  465.                     return false
  466.                 endif
  467.             elsif r = 12 then
  468.                 if x = x1 and y = y1 then
  469.                     return false
  470.                 endif
  471.             endif                
  472.         elseif RoomType[n] = NROOMS+2 then
  473.             if r = 0 then
  474.                 if (x = x1 and y = y2) or (x = x2 and y = y2) then
  475.                     return false
  476.                 endif
  477.             elsif r = 4 then
  478.                 if (x = x1 and y = y1) or (x = x1 and y = y2) then
  479.                     return false
  480.                 endif
  481.             elsif r = 8 then
  482.                 if (x = x1 and y = y1) or (x = x2 and y = y1) then
  483.                     return false
  484.                 endif
  485.             elsif r = 12 then
  486.                 if (x = x2 and y = y1) or (x = x2 and y = y2) then
  487.                     return false
  488.                 endif
  489.             endif
  490.         elseif RoomType[n] = NROOMS+3 then
  491.             if (r % 4) = 0 then
  492.                 if (x = x1 and y = y1) or (x = x2 and y = y1) or (x = x1 and y = y2) or (x = x2 and y = y2) then
  493.                     return false
  494.                 endif
  495.             endif
  496.         endif
  497.  
  498.         return true            
  499.     end function
  500.  
  501.     function fast_ FindRoomAtXYL( x as int y as int level as int type inout int ) as int
  502.         //return the number of the room covering xy
  503.         //return 0 if none
  504.         local
  505.             int n=0
  506.         endlocal
  507.  
  508.         while n <= high(RoomType) loop
  509.             if PointInRoom(n, x, y, level) then
  510.                 type = RoomType[n]
  511.                 return n
  512.             endif
  513.              n++
  514.         endloop
  515.  
  516.         return -1
  517.     end function
  518.  
  519.  
  520.     function fast_ XYL( x as int y as int level as int ) as int
  521.         return (level*maxy+y)*maxx+x
  522.     end function
  523.  
  524.  
  525.     sub fast_ fromXYL( XYL as int x inout int y inout int level inout int )
  526.         XYL &= %x00ffffff
  527.         x = XYL % maxx
  528. //        XYL-=x
  529.         XYL/=maxx
  530.         y = XYL % maxy
  531. //        XYL-=y
  532.         level = XYL/maxy
  533.     end sub
  534.  
  535. //    include `\tvml\apps\mazeedit\msgbox.tvm`
  536.     //msg box functions
  537.  
  538.     const
  539.         int  cancel=1, yes=2, no=3
  540.         int YESORNOBOX=1, OKBOX=2, YESNOCANCELBOX=3
  541.  
  542.     function MsgBox( str1 as string str2 as string type as int ) as int
  543.         local
  544.             const
  545.                 int h = 60*3, l = 400, t = 0
  546.             var
  547.                 int id, id1, id2
  548.                 int flag=0
  549.                 int l1=len(str1)
  550.                 int w=max([l1,len(str2)])*10
  551.                 int bwidth, bleft, left
  552.         endlocal
  553.  
  554.         for id = id1 to id2 loop
  555.             DeleteObject id
  556.         endfor
  557.  
  558.         gsave()
  559.         id1 = GetNextObjectID()
  560.  
  561.         if type = OKBOX then
  562.             bwidth = 120+30*2
  563.         elsif type = YESORNOBOX then
  564.             bwidth = 120*2+30*3
  565.         elsif type = YESNOCANCELBOX then
  566.             bwidth = 120*3+30*4
  567.         endif
  568.  
  569.         w = max([bwidth, w])
  570.         left = max([(1280-w)/2,l])
  571.  
  572.         bleft = (w-bwidth)/2+left+30
  573.  
  574.         linestyle solid
  575.         pencolor 0,0,160
  576.         penwidth 2
  577.         SetColourFill 128,128,128
  578.         rectangle left, t+10, w, h-10
  579.         id = 200
  580.         label id, left,  t+10, w, 100, centre, str1+'\n'+str2
  581.  
  582.         if type = OKBOX then
  583.             button    bleft,  t+110, 120, 60, "OK",  enabled, none, { flag = yes }
  584.         elsif type = YESORNOBOX then
  585.             button    bleft,  t+110, 120, 60, "YES", enabled, none, { flag = yes }
  586.             button bleft+150, t+110, 120, 60, "NO",  enabled, none, { flag = no  }
  587.         elsif type = YESNOCANCELBOX then
  588.             button bleft    , t+110, 120, 60, "YES", enabled, none, { flag = yes }
  589.             button bleft+150, t+110, 120, 60, "NO",  enabled, none, { flag = no  }
  590.             button bleft+300, t+110, 120, 60, "CANCEL", enabled, none, { flag = cancel}
  591.         endif
  592.  
  593.         grestore()
  594.         id2 = GetNextObjectID()-1
  595.  
  596.         flag = 0
  597.         while not flag loop
  598.             hold
  599.         endloop
  600.  
  601.         for id = id1 to id2 loop
  602.             DeleteObject id
  603.         endfor
  604.  
  605.         id1 = 0
  606.         id2 = 0
  607.  
  608.         return flag
  609.     end function
  610.  
  611.  
  612. //    include `\tvml\apps\mazeedit\mapstuff.tvm`
  613.     //Bug fix function
  614.  
  615.     sub DelayedUpdate( p as boolean )
  616.         local
  617.             int r
  618.         endlocal
  619.  
  620.         gsave()
  621.         SetDelayedUpdate p
  622.  
  623.         if not p then
  624.             r = GetNextObjectID()
  625.             linestyle 0
  626.             SetNoFill
  627.             rectangle GridOriginX,GridOriginY,1280-GridOriginX,960-GridOriginY
  628.             DeleteObject r
  629.         endif
  630.         grestore()
  631.     end sub
  632.  
  633.  
  634.     sub SetRoomDefaults( num as int )
  635.         if num != -1 and RoomType[num] > NROOMS then
  636.             pencolor 255,0,255
  637.         else
  638.             pencolor 0,0,255
  639.         endif
  640.  
  641.         if unit < 20 then
  642.             CurrentPenWidth = 1
  643.         else
  644.             CurrentPenWidth = 2
  645.         endif
  646.  
  647.         penwidth CurrentPenWidth
  648.         linestyle solid
  649.     end sub
  650.  
  651.  
  652.     sub DrawDoors( num as int x1 as int y1 as int x2 as int y2 as int )
  653.         //draw room num doors
  654.  
  655.         local
  656.             int rx1 = RoomX[num], ry1 = RoomY[num], rx2 = rx1+RoomW[num], ry2 = ry1+RoomD[num]
  657.             int aji = RoomAdjacent[num]
  658.             int nd = RoomDoors[num]
  659.             int i, dt, dx, dy, dl, dp
  660.             int o
  661.         endlocal
  662.  
  663.         gsave()
  664.         linestyle solid
  665.         if CurrentPenWidth = 2 then
  666.             penwidth 3
  667.             o = 3
  668.         else
  669.             penwidth 1
  670.             o = 1
  671.         endif
  672.  
  673.         for i = 0 to nd-1 loop
  674.             dt = Adjacent[aji+i] & %xff000000
  675.  
  676.             if dt then
  677.                 dt>>=24
  678.                 if dt = 1 then
  679.                     pencolor 128+63+32,0,0
  680.                 elseif dt = 2 then
  681.                     pencolor 0,128+63+32,0
  682.                 elseif dt = 3 then
  683.                     pencolor 0,0,128+63+32
  684.                 endif
  685.             else
  686.                 //draw thicker grey line to indicate doorway
  687.                 pencolor 128+64+32,128+64+32,128+64+32
  688.             endif
  689.  
  690.             fromXYL( Adjacent[aji+i], dx, dy, dl )
  691.             if dx = rx1-1 then
  692.                 //left wall door
  693.                 dp = (dy-ry1)*unit+y1
  694.                 line [x1+o,dp, x1+o, dp+unit]
  695.             elseif dx = rx2 then
  696.                 //right wall door
  697.                 dp = (dy-ry1)*unit+y1
  698.                 line [x2-o,dp, x2-o, dp+unit]
  699.             elseif dy = ry1-1 then
  700.                 //top wall door
  701.                 dp = (dx-rx1)*unit+x1
  702.                 line [dp, y1+o, dp+unit, y1+o]
  703.             elseif dy = ry2 then
  704.                 //bottom wall door
  705.                 dp = (dx-rx1)*unit+x1
  706.                 line [dp, y2-o, dp+unit, y2-o]
  707.             endif
  708.         endloop
  709.  
  710.         grestore()
  711.     end sub
  712.  
  713.  
  714.     sub fast_ DrawObjectTags( num as int )
  715.         local
  716.             int max, ObjectIndex, first=RoomObjectsIndex[num]
  717.             int x,y,h, id, offset
  718.             string ObjectTags[1 to NOBJECTS], name
  719.             boolean InitDone
  720.         endlocal
  721.  
  722.         if not InitDone then
  723.             ObjectTags[1] = "g"
  724.             ObjectTags[2] = "b"
  725.             ObjectTags[3] = "r"
  726.             ObjectTags[4] = "m"
  727.             ObjectTags[5] = "t"
  728.             ObjectTags[6] = "h"
  729.             ObjectTags[7] = "f"
  730.             ObjectTags[8] = "p"
  731.             ObjectTags[9] = "p"
  732.             ObjectTags[10] = "p"
  733.             ObjectTags[11] = "e"
  734.             InitDone = true
  735.         endif
  736.  
  737.         gsave()
  738.         font "timesroman", unit/2, unit
  739.  
  740.         if RoomType[num] <= NROOMS then
  741.             max  = MaxObjectsPerRoom
  742.         else
  743.             max  = MaxObjectsPerLink
  744.         endif
  745.  
  746.         for ObjectIndex = 0 to max-1 loop
  747.  
  748.             id = ObjectsList[ObjectIndex+first]
  749.  
  750.             if id != 0 then
  751.                 fromXYL( ObjectsXYH [ObjectIndex+first], x, y, h )
  752.                 x+=RoomX[num]
  753.                 y+=RoomY[num]
  754.  
  755.                 if id = -11 then
  756.                     print using "End in Room %d\n", num
  757.                 endif
  758.  
  759.                 if id != -4 then offset = unit/4 else offset = 0 endif
  760.  
  761.                 if id < 0 then
  762.                     //stock object
  763.                     text (x+DrawOriginX)*unit+GridOriginX+offset, (y+DrawOriginY)*unit+GridOriginY, ObjectTags[-id]
  764.                 else
  765.                     //it's a user object
  766.                     text (x+DrawOriginX)*unit+GridOriginX+offset, (y+DrawOriginY)*unit+GridOriginY, "u"
  767.                 endif
  768.  
  769.             endif
  770.         endfor
  771.  
  772.         grestore()
  773.     end sub
  774.  
  775.  
  776.     sub fast_ DeleteAllObjectTags()
  777.         local
  778.             int id
  779.         endlocal
  780.  
  781.         for id = FirstObjectTag to LastObjectTag loop
  782.             DeleteObject id
  783.         endfor
  784.  
  785.         FirstObjectTag = 0
  786.         LastObjectTag = -1
  787.     endsub
  788.  
  789.  
  790.     sub fast_ DrawAllObjectTags()
  791.         local
  792.             int r
  793.         endlocal
  794.  
  795.         DeleteAllObjectTags()
  796.  
  797.         FirstObjectTag = GetNextObjectID()
  798.         for r = 0 to high(RoomType) loop
  799.             if RoomLevel[r] = ActionLevel then
  800.                 DrawObjectTags( r )
  801.             endif
  802.         endfor
  803.  
  804.         LastObjectTag = GetNextObjectID()-1
  805.     end sub
  806.  
  807.  
  808.     sub fast_ DrawRoom( num as int )
  809.         //draw room number num
  810.  
  811.         local
  812.             int n = RoomType[num]
  813.             int x = RoomX[num], y = RoomY[num], w = RoomW[num], d = RoomD[num], r = RoomR[num]
  814.             int thisx = x, thisy = y
  815.             int x1, y1, x2, y2
  816.             int dw1, dw2, dw3, dw4, dh1, dh2, dh3, dh4
  817.             int id
  818.         endlocal
  819.  
  820.         if ActionLevel != RoomLevel[num] then
  821.             return
  822.         endif
  823.  
  824.         gsave()
  825.         SetRoomDefaults(num)
  826.  
  827.         if EditMode = MapEditMode then
  828.             if num = ActionRoom then
  829.                 pencolor 0,255,0
  830.             endif
  831.         endif
  832.  
  833.         if RoomTextureBits[num] > 0 then
  834.             penwidth 1            //Windows 95 can't draw a broken line any thicker
  835.             linestyle dots
  836.         endif
  837.  
  838.         if RelativeDrawMode then
  839.             thisx = 0
  840.             thisy = 0
  841.         endif
  842.  
  843.         x1 = (thisx+DrawOriginX)*unit+GridOriginX        y1 = (thisy+DrawOriginY)*unit+GridOriginY
  844.  
  845.         if x1 < GridOriginX or y1 < GridOriginY then
  846.             grestore()
  847.             return
  848.         endif
  849.  
  850.         x2 = (thisx+w+DrawOriginX)*unit+GridOriginX
  851.         y2 = (thisy+d+DrawOriginY)*unit+GridOriginY
  852.  
  853.         if CurrentPenWidth = 2 then
  854.             x2-=CurrentPenWidth
  855.             y2-=CurrentPenWidth
  856.         endif
  857.  
  858.         RoomID[num] = GetNextObjectID()
  859.  
  860.         dw1 = ((w-1)/2)
  861.         dw2 =  (w-1-dw1)
  862.         dw3 =  (w-3)/2
  863.         dw4 =  (w-3-dw3)
  864.  
  865.         dh1 = ((d-1)/2)
  866.         dh2 =  (d-1-dh1)
  867.         dh3 =  (d-3)/2
  868.         dh4 =  (d-3-dh3)
  869.  
  870.         dw1*=unit    dw2*=unit    dw3*=unit    dw4*=unit
  871.         dh1*=unit    dh2*=unit    dh3*=unit    dh4*=unit
  872.  
  873.         if n = 1 then
  874.             if r = 0 then
  875.                 line [x1,y1,x2,y1,x2,y2]            //top and right
  876.                 line [x2-door,y2,x1,y2,x1,y1+door]    //bottom and left
  877.             elsif r = 4 then
  878.                 line [x2,y1,x2,y2,x1,y2]        
  879.                 line [x1,y2-door,x1,y1,x2-door,y1]    
  880.             elsif r = 8 then
  881.                 line [x2,y2,x1,y2,x1,y1]        
  882.                 line [x1+door,y1,x2,y1,x2,y2-door]    
  883.             elsif r = 12 then
  884.                 line [x1,y2,x1,y1,x2,y1]        
  885.                 line [x2,y1+door,x2,y2,x1+door,y2]    
  886.             else
  887.                 print "Illegal rotate code room %d %d ", n, r
  888.             endif
  889.         elseif n = 2 then
  890.             if r = 0 then
  891.                 line [x2,y1,x2,y2]
  892.                 line [x2-door,y2,x1,y2,x1,y2-dh2]
  893.                 line [x1,y1+dh1,x1,y1,x2-door,y1]
  894.             elsif r = 4 then
  895.                 line [x2,y2,x1,y2]
  896.                 line [x1,y2-door,x1,y1,x1+dw2,y1]
  897.                 line [x2-dw1,y1,x2,y1,x2,y2-door]
  898.             elsif r = 8 then
  899.                 line [x1,y2,x1,y1]
  900.                 line [x1+door,y1,x2,y1,x2,y1+dh1]
  901.                 line [x2,y2-dh2,x2,y2,x1+door,y2]
  902.             elsif r = 12 then
  903.                 line [x1,y1,x2,y1]
  904.                 line [x2,y1+door,x2,y2,x2-dw2,y2]
  905.                 line [x1+dw1,y2,x1,y2,x1,y1+door]
  906.             else
  907.                 print "Illegal rotate code room %d %d ", n, r
  908.             endif
  909.         elseif n = 3 then
  910.             if (r = 0) or (r = 8) then
  911.                 line [x1,y1+dh1,x1,y1,x2-door,y1]
  912.                 line [x2,y1,x2,y1+dh2]
  913.                 line [x2,y2-dh1,x2,y2,x1+door,y2]
  914.                 line [x1,y2,x1,y2-dh2]
  915.             elsif (r = 4) or (r = 12) then
  916.                 line [x1,y1,x1+dw2,y1]
  917.                 line [x2-dw1,y1,x2,y1,x2,y2-door]
  918.                 line [x2,y2,x2-dw2,y2]
  919.                 line [x1+dw1,y2,x1,y2,x1,y1+door]
  920.             else
  921.                 print "Illegal rotate code room %d %d ", n, r
  922.             endif
  923.         elseif n = 4 then
  924.             if r = 0 or r = 8 then
  925.                 line [x1+door,y1,x2,y1,x2,y1+dh2]
  926.                 line [x2,y2-dh1,x2,y2]
  927.                 line [x2-door,y2,x1,y2,x1,y2-dh2]
  928.                 line [x1,y1+dh1,x1,y1]
  929.             elsif r = 4 or r = 12 then
  930.                 line [x1,y2-door,x1,y1,x1+dw2,y1]
  931.                 line [x2-dw1,y1,x2,y1]
  932.                 line [x2,y1+door,x2,y2,x2-dw2,y2]
  933.                 line [x1+dw1,y2,x1,y2]
  934.             else
  935.                 print "Illegal rotate code room %d %d ", n, r
  936.             endif
  937.         elsif n = 5 then
  938.             if r = 0 then
  939.                 line [x1+dw1,y1, x1,y1,x1,y2,x2,y2,x2,y1,x2-dw2,y1]
  940.             elsif r = 4 then
  941.                 line [x2,y1+dh1, x2,y1,x1,y1,x1,y2,x2,y2,x2,y2-dh2]
  942.             elsif r = 8 then
  943.                 line [x2-dw1,y2, x2,y2,x2,y1,x1,y1,x1,y2,x1+dw2,y2]
  944.             elsif r = 12 then
  945.                 line [x1,y2-dh1, x1,y2,x2,y2,x2,y1,x1,y1,x1,y1+dh2]
  946.             else
  947.                 print "Illegal rotate code room %d %d ", n, r
  948.             endif
  949.         elsif n = 6 then
  950.             if (r % 4) = 0 then
  951.                 line [x1,y1+dh1,x1,y1,x1+dw1,y1]
  952.                 line [x2-dw2,y1,x2,y1,x2,y1+dh2]
  953.                 line [x2,y2-dh1,x2,y2,x2-dw1,y2]
  954.                 line [x1+dw2,y2,x1,y2,x1,y2-dh2]
  955.             else
  956.                 print "Illegal rotate code room %d %d ", n, r
  957.             endif
  958.         elsif n = 7 then
  959.             if r = 0 then
  960.                 line [x1+door,y1,x2,y1,x2,y1+dh1]
  961.                 line [x2,y2-dh2,x2,y2,x2-dw3,y2]
  962.                 line [x2-dw3-door,y2,x2-dw3-2*door,y2]
  963.                 line [x1+dw4,y2,x1,y2,x1,y1]
  964.             elsif r = 4 then
  965.                 line [x1,y1+dh4,x1,y1,x2,y1]
  966.                 line [x2,y1+door,x2,y2,x2-dw1,y2]
  967.                 line [x1+dw2,y2,x1,y2,x1,y2-dh3]
  968.                 line [x1,y2-dh3-door,x1,y2-dh3-2*door]
  969.             elsif r = 8 then
  970.                 line [x1,y1+dh2,x1,y1,x1+dw3,y1]
  971.                 line [x1+dw3+door,y1,x1+dw3+2*door,y1]
  972.                 line [x2-dw4,y1,x2,y1,x2,y2]
  973.                 line [x2-door,y2,x1,y2,x1,y2-dh1]
  974.             elsif r = 12 then
  975.                 line [x1,y2-door,x1,y1,x1+dw1,y1]
  976.                 line [x2-dw2,y1,x2,y1,x2,y1+dh3]
  977.                 line [x2,y1+dh3+door,x2,y1+dh3+2*door]
  978.                 line [x2,y2-dh4,x2,y2,x1,y2]
  979.             else
  980.                 print "Illegal rotate code room %d %d ", n, r
  981.             endif
  982.         elsif n = NROOMS+1 then
  983.             //links
  984.             if r = 0 then
  985.                 line [x1,y1,x1,y2,x2,y2]
  986.                 line [x2-unit,y1,x2-unit,y1+unit,x2,y1+unit]
  987.             elsif r = 4 then
  988.                 line [x1,y2,x1,y1,x2,y1]
  989.                 line [x2-unit,y2,x2-unit,y2-unit,x2,y2-unit]
  990.             elsif r = 8 then
  991.                 line [x1,y1,x2,y1,x2,y2]
  992.                 line [x1,y2-unit,x1+unit,y2-unit,x1+unit,y2]
  993.             elsif r = 12 then
  994.                 line [x1,y1+unit,x1+unit,y1+unit,x1+unit,y1]
  995.                 line [x1,y2,x2,y2,x2,y1]
  996.             endif
  997.         elsif n = NROOMS+2 then
  998.             if r = 0 then
  999.                 line [x1,y1,x2,y1]
  1000.                 line [x1,y2-unit,x1+unit,y2-unit,x1+unit,y2]
  1001.                 line [x2,y2-unit,x2-unit,y2-unit,x2-unit,y2]
  1002.             elsif r = 4 then
  1003.                 line [x2,y1,x2,y2]
  1004.                 line [x1+unit,y1,x1+unit,y1+unit,x1,y1+unit]
  1005.                 line [x1+unit,y2,x1+unit,y2-unit,x1,y2-unit]
  1006.             elsif r = 8 then
  1007.                 line [x1,y2,x2,y2]
  1008.                 line [x1,y1+unit,x1+unit,y1+unit,x1+unit,y1]
  1009.                 line [x2,y1+unit,x2-unit,y1+unit,x2-unit,y1]
  1010.             elsif r = 12 then
  1011.                 line [x1,y1,x1,y2]
  1012.                 line [x2-unit,y1,x2-unit,y1+unit,x2,y1+unit]
  1013.                 line [x2-unit,y2,x2-unit,y2-unit,x2,y2-unit]
  1014.             endif
  1015.         elsif n = NROOMS+3 then
  1016.             if r = 0 or r = 4 or r = 8 or r = 12 then
  1017.                 line [x1,y1+unit,x1+unit,y1+unit,x1+unit,y1]
  1018.                 line [x2-unit,y1,x2-unit,y1+unit,x2,y1+unit]
  1019.                 line [x1,y2-unit,x1+unit,y2-unit,x1+unit,y2]
  1020.                 line [x2-unit,y2,x2-unit,y2-unit,x2,y2-unit]
  1021.             endif
  1022.         elsif n = NROOMS+4 then
  1023.             if r = 0 or r = 8 then
  1024.                 line [x1,y1,x2,y1]
  1025.                 line [x1,y2,x2,y2]
  1026.             elsif r = 4 or r = 12 then
  1027.                 line [x1,y1,x1,y2]
  1028.                 line [x2,y1,x2,y2]
  1029.             endif
  1030.         endif
  1031.  
  1032.         DrawDoors( num, x1, y1, x2, y2 )
  1033.  
  1034.         pencolor 0,0,255
  1035.         if unit >= DRAWNAMEUNIT then
  1036.             RoomNameID[num] = GetNextObjectID()
  1037.             text x1+4, y1, RoomName[num]
  1038.         else
  1039.             RoomNameID[num] = 0
  1040.         endif
  1041.  
  1042.         grestore()
  1043.     end sub
  1044.  
  1045.  
  1046.     sub FindAdjacent( num as int )
  1047.         //find the cells adjacent to the doors of room num
  1048.         local
  1049.             int n = RoomType[num]
  1050. //            int thisx = x, thisy = y
  1051.             int dw1, dw2, dw3, dw4, dh1, dh2, dh3, dh4
  1052. //            int id
  1053.  
  1054.             int l = RoomLevel[num]
  1055.             int aji = RoomAdjacent[num]
  1056.             int w = RoomW[num], d = RoomD[num], r = RoomR[num]
  1057.             int x1 = Roomx[num], y1 = RoomY[num], x2 = x1+RoomW[num], y2=y1+RoomD[num]
  1058.             int nd = RoomDoors[num]
  1059.         endlocal
  1060.  
  1061.  
  1062.         if not ValidRoom(num) then
  1063.             return
  1064.         endif
  1065.  
  1066.         //preserve any door type info
  1067.         for dw1 = 0 to nd-1 loop
  1068.             Adjacent[aji+dw1] &= %xff000000
  1069.         endloop
  1070.  
  1071.         dw1 = ((w-1)/2)
  1072.         dw2 =  (w-1-dw1)
  1073.         dw3 =  (w-3)/2
  1074.         dw4 =  (w-3-dw3)
  1075.  
  1076.         dh1 = ((d-1)/2)
  1077.         dh2 =  (d-1-dh1)
  1078.         dh3 =  (d-3)/2
  1079.         dh4 =  (d-3-dh3)
  1080.  
  1081.  
  1082.         if n = 1 then
  1083. //            print using "Room type 1 (%d,%d)-(%d,%d)", x1,y1,x2,y2
  1084.             if r = 0 then
  1085.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1086.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1087.             elsif r = 4 then
  1088.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1089.                 Adjacent[aji++] |= XYL(x2-1,y1-1,l)
  1090.             elsif r = 8 then
  1091.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1092.                 Adjacent[aji++] |= XYL(x2,y2-1,l)
  1093.             elsif r = 12 then
  1094.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1095.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1096.             endif
  1097.         elsif n = 2 then
  1098.             if r = 0 then
  1099.                 Adjacent[aji++] |= XYL(x2-1,y1-1,l)
  1100.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1101.                 Adjacent[aji++] |= XYL(x1-1,y1+dh1,l)
  1102.             elsif r = 4 then
  1103.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1104.                 Adjacent[aji++] |= XYL(x2,y2-1,l)
  1105.                 Adjacent[aji++] |= XYL(x1+dw2,y1-1,l)
  1106.             elsif r = 8 then
  1107.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1108.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1109.                 Adjacent[aji++] |= XYL(x2,y1+dh1,l)
  1110.             elsif r = 12 then
  1111.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1112.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1113.                 Adjacent[aji++] |= XYL(x1+dw1,y2,l)
  1114.             endif
  1115.         elsif n = 3 then
  1116.             if (r = 0) or (r = 8) then
  1117.                 Adjacent[aji++] |= XYL(x2-1,y1-1,l)
  1118.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1119.                 Adjacent[aji++] |= XYL(x1-1,y1+dh1,l)
  1120.                 Adjacent[aji++] |= XYL(x2,y1+dh2,l)
  1121.             elsif (r = 4) or (r = 12) then
  1122.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1123.                 Adjacent[aji++] |= XYL(x1+dw2,y1-1,l)
  1124.                 Adjacent[aji++] |= XYL(x2,y2-1,l)
  1125.                 Adjacent[aji++] |= XYL(x1+dw1,y2,l)
  1126.             endif
  1127.         elsif n = 4 then
  1128.             if r = 0 or r = 8 then
  1129.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1130.                 Adjacent[aji++] |= XYL(x2,y1+dh2,l)
  1131.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1132.                 Adjacent[aji++] |= XYL(x1-1,y1+dh1,l)
  1133.             elsif r = 4 or r = 12 then
  1134.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1135.                 Adjacent[aji++] |= XYL(x1+dw2,y1-1,l)
  1136.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1137.                 Adjacent[aji++] |= XYL(x1+dw1,y2,l)
  1138.             endif
  1139.         elsif n = 5 then
  1140.             if r = 0 then
  1141.                 Adjacent[aji++] |= XYL(x1+dw1,y1-1,l)
  1142.             elsif r = 4 then
  1143.                 Adjacent[aji++] |= XYL(x2,y1+dh1,l)
  1144.             elsif r = 8 then
  1145.                 Adjacent[aji++] |= XYL(x1+dw2,y2,l)
  1146.             elsif r = 12 then
  1147.                 Adjacent[aji++] |= XYL(x1-1,y1+dh2,l)
  1148.             endif
  1149.         elsif n = 6 then
  1150.             if (r % 4) = 0 then
  1151.                 Adjacent[aji++] |= XYL(x1-1,y1+dh1,l)
  1152.                 Adjacent[aji++] |= XYL(x1+dw1,y1-1,l)
  1153.                 Adjacent[aji++] |= XYL(x2,y1+dh2,l)
  1154.                 Adjacent[aji++] |= XYL(x1+dw2,y2,l)
  1155.             endif
  1156.         elsif n = 7 then
  1157.             if r = 0 then
  1158.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1159.                 Adjacent[aji++] |= XYL(x2,y1+dh1,l)
  1160.                 Adjacent[aji++] |= XYL(x2-dw3-1,y2,l)
  1161.                 Adjacent[aji++] |= XYL(x1+dw4,y2,l)
  1162.             elsif r = 4 then
  1163.                 Adjacent[aji++] |= XYL(x1-1,y1+dh4,l)
  1164.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1165.                 Adjacent[aji++] |= XYL(x1+dw2,y2,l)
  1166.                 Adjacent[aji++] |= XYL(x1-1,y2-dh3-1,l)
  1167.             elsif r = 8 then
  1168.                 Adjacent[aji++] |= XYL(x1-1,y1+dh2,l)
  1169.                 Adjacent[aji++] |= XYL(x1+dw3,y1-1,l)
  1170.                 Adjacent[aji++] |= XYL(x1+dw3+2,y1-1,l)
  1171.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1172.             elsif r = 12 then
  1173.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1174.                 Adjacent[aji++] |= XYL(x1+dw1,y1-1,l)
  1175.                 Adjacent[aji++] |= XYL(x2,y1+dh3,l)
  1176.                 Adjacent[aji++] |= XYL(x2,y1+dh3+2,l)
  1177.             endif
  1178.         elsif n = NROOMS+1 then
  1179.             if r = 0 then
  1180.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1181.                 Adjacent[aji++] |= XYL(x2,y2-1,l)
  1182.             elsif r = 4 then
  1183.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1184.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1185.             elsif r = 8 then
  1186.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1187.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1188.             elsif r = 12 then
  1189.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1190.                 Adjacent[aji++] |= XYL(x2-1,y1-1,l)
  1191.             endif
  1192.         elsif n = NROOMS+2 then
  1193.             if r = 0 then
  1194.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1195.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1196.                 Adjacent[aji++] |= XYL(x1+1,y2,l)
  1197.             elsif r = 4 then
  1198.                 Adjacent[aji++] |= XYL(x2-1,y1-1,l)
  1199.                 Adjacent[aji++] |= XYL(x1-1,y1+1,l)
  1200.                 Adjacent[aji++] |= XYL(x2-1,y2,l)
  1201.             elsif r = 8 then
  1202.                 Adjacent[aji++] |= XYL(x1-1,y2-1,l)
  1203.                 Adjacent[aji++] |= XYL(x1+1,y1-1,l)
  1204.                 Adjacent[aji++] |= XYL(x2,y2-1,l)
  1205.             elsif r = 12 then
  1206.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1207.                 Adjacent[aji++] |= XYL(x2,y1+1,l)
  1208.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1209.             endif
  1210.         elsif n = NROOMS+3 then
  1211.             if (r % 4) = 0 then
  1212.                 Adjacent[aji++] |= XYL(x1+1,y1-1,l)
  1213.                 Adjacent[aji++] |= XYL(x1-1,y1+1,l)
  1214.                 Adjacent[aji++] |= XYL(x2,y1+1,l)
  1215.                 Adjacent[aji++] |= XYL(x1+1,y2,l)
  1216.             endif
  1217.         elsif n = NROOMS+4 then
  1218.             if r = 0 or r = 8 then
  1219.                 Adjacent[aji++] |= XYL(x1-1,y1,l)
  1220.                 Adjacent[aji++] |= XYL(x2,y1,l)
  1221.             elsif r = 4 or r = 12 then
  1222.                 Adjacent[aji++] |= XYL(x1,y1-1,l)
  1223.                 Adjacent[aji++] |= XYL(x1,y2,l)
  1224.             endif
  1225.         endif
  1226.     end sub
  1227.  
  1228.  
  1229.     function CreateLink( n as int x as int y as int r as int height as int name as string ) as int
  1230.         //create a link of type n at(x,y) rotation r
  1231.         //return the link number (0 based)
  1232.  
  1233.         local
  1234.             int num, w, d, i
  1235.             int NameObject = 0
  1236.         endlocal
  1237.  
  1238.         num = NextLinkAtLevel[ActionLevel]++
  1239.  
  1240.         if n = 1 then
  1241.             w = 2
  1242.             d = 2
  1243.         elsif n = 2 then
  1244.             if r = 0 or r = 8 then
  1245.                 w = 3
  1246.                 d = 2
  1247.             else
  1248.                 w = 2
  1249.                 d = 3
  1250.             endif
  1251.         elsif n = 3 then
  1252.             w = 3
  1253.             d = 3
  1254.         elsif n = 4 then
  1255.             w = 1
  1256.             d = 1
  1257.         endif
  1258.  
  1259.         AddElement roomx x
  1260.         AddElement roomy y
  1261.         AddElement roomw w
  1262.         AddElement roomd d
  1263.         AddElement roomr r
  1264.         AddElement RoomHeight height
  1265.  
  1266.         AddElement RoomType n+NROOMS
  1267.         AddElement RoomID 0
  1268.         AddElement RoomNameID 0
  1269.         AddElement RoomDoors DoorsPerRoom[n+NROOMS]
  1270.         AddElement RoomAdjacent high(Adjacent)+1
  1271.         AddElement RoomObjectsCount 0
  1272.         AddElement RoomObjectsIndex high(ObjectsList)+1
  1273.         AddElement RoomTextureBits 0
  1274.  
  1275.         for i = 1 to MaxObjectsPerLink loop
  1276.             AddElement ObjectsList 0
  1277.             AddElement ObjectsName ""
  1278.             AddElement ObjectsXYH 0
  1279.         endfor
  1280.  
  1281.         for i = 1 to DoorsPerRoom[n+NROOMS] loop
  1282.             AddElement Adjacent 0
  1283.         endfor
  1284.  
  1285.         if name == "" then
  1286.             name = print( using "Link %d", Num )
  1287.         endif
  1288.  
  1289.         AddElement RoomNumber num
  1290.         AddElement RoomName name
  1291.         AddElement RoomLevel ActionLevel
  1292.  
  1293.         FindAdjacent( high(RoomType) )
  1294.         DrawRoom( high(RoomType) )
  1295.  
  1296.         return high(RoomType)
  1297.     endfunction
  1298.  
  1299.  
  1300.     function fast_ CreateRoom( n as int x as int y as int w as int d as int r as int height as int name as string ) as int
  1301.         //create a room of type n at(x,y) size(w,d) rotation r
  1302.         //return the room number (0 based)
  1303.  
  1304.         local
  1305.             int num, i
  1306.         endlocal
  1307.  
  1308.         num = NextRoomAtLevel[ActionLevel]++
  1309.  
  1310.         AddElement roomx x
  1311.         AddElement roomy y
  1312.         AddElement roomw w
  1313.         AddElement roomd d
  1314.         AddElement roomr r
  1315.         AddElement RoomHeight height
  1316.  
  1317.         AddElement RoomType n
  1318.         AddElement RoomID 0
  1319.         AddElement RoomNameID 0
  1320.         AddElement RoomDoors DoorsPerRoom[n]
  1321.         AddElement RoomAdjacent high(Adjacent)+1
  1322.         AddElement RoomObjectsCount 0
  1323.         AddElement RoomObjectsIndex high(ObjectsList)+1
  1324.         AddElement RoomTextureBits 0
  1325.  
  1326.         for i = 1 to MaxObjectsPerRoom loop
  1327.             AddElement ObjectsList 0
  1328.             AddElement ObjectsName ""
  1329.             AddElement ObjectsXYH 0
  1330.         endfor
  1331.  
  1332.         for i = 1 to DoorsPerRoom[n] loop
  1333.             AddElement Adjacent 0
  1334.         endfor
  1335.  
  1336.         if name == "" then
  1337.             name = print( using "Room %d", num )
  1338.         endif
  1339.  
  1340.         AddElement RoomNumber num
  1341.         AddElement RoomName name
  1342.         AddElement RoomLevel ActionLevel
  1343.  
  1344.         FindAdjacent( high(RoomType) )
  1345.         DrawRoom( high(RoomType) )
  1346.  
  1347.         return high(RoomType)
  1348.     endfunction
  1349.  
  1350.  
  1351.  
  1352.     sub fast_ DrawGrid()
  1353.         local
  1354.             int sx, sy, n
  1355.             int w, d
  1356.         endlocal
  1357.  
  1358.         GridObjectFirst = GetNextObjectID()
  1359.         gsave()
  1360.  
  1361.         DelayedUpdate (true)
  1362.         pencolor 128+64+32,128+64+32,128+64+32
  1363.         penwidth 1
  1364.         linestyle solid
  1365.  
  1366.         SetNoFill
  1367.  
  1368.         if EditMode = MapEditMode then
  1369.             w = 100*unit-(GridOriginX-DrawOriginX*unit)
  1370.             d = 100*unit-(GridOriginY-DrawOriginY*unit)
  1371.             w=100*unit
  1372.             d=100*unit
  1373.         else
  1374.             w = 12*unit-(GridOriginX-DrawOriginX*unit)
  1375.             d = 12*unit-(GridOriginY-DrawOriginY*unit)
  1376.             w = 12*unit
  1377.             d = 12*unit
  1378.         endif
  1379.  
  1380.         if w > 1280-GridOriginX then
  1381.             w = 1280-GridOriginX
  1382.         endif
  1383.  
  1384.         if d > 960-GridOriginY then
  1385.             d = 960-GridOriginY
  1386.         endif
  1387.  
  1388.         rectangle GridOriginX, GridOriginY, w, d
  1389.  
  1390.         n=0
  1391.         for sx = GridOriginX to w+GridOriginX step unit loop
  1392.             line [ sx,GridOriginY,sx,d+GridOriginY ]
  1393.             if ++n >= 100 then
  1394.                 loopexit
  1395.             endif
  1396.         endloop
  1397.  
  1398.         n=0
  1399.         for sy = GridOriginY to d+GridOriginY step unit loop
  1400.             line [ GridOriginX,sy,w+GridOriginX,sy ]
  1401.             if ++n >= 100 then
  1402.                 loopexit
  1403.             endif
  1404.         endloop
  1405.  
  1406.         GridObjectLast = GetNextObjectID()-1
  1407.         DelayedUpdate (false)
  1408.         grestore()
  1409.  
  1410.         if XOriginObj then
  1411.             SetStringProperty XOriginObj, "Text", itostr(-DrawOriginX)
  1412.         endif
  1413.  
  1414.         if YOriginObj then
  1415.             SetStringProperty YOriginObj, "Text", itostr(-DrawOriginY)
  1416.         endif
  1417.     end sub
  1418.  
  1419.     sub fast_ DeleteGrid()
  1420.         local
  1421.             int id
  1422.         endlocal
  1423.  
  1424.         DelayedUpdate (true)
  1425.         for id = GridObjectFirst to GridObjectLast loop
  1426.             DeleteObject id
  1427.         endfor
  1428.  
  1429.         GridObjectFirst = 0
  1430.         GridObjectLast = 0
  1431.  
  1432.         DelayedUpdate (false)
  1433.     end sub
  1434.  
  1435.  
  1436.     sub fast_ SetRoomLineColour( n as int r as rgbvalue g as rgbvalue b as rgbvalue )
  1437.         // set the colour of the lines making this room
  1438.         local
  1439.             int i, id
  1440.         endlocal
  1441.  
  1442.         if not ValidRoom(n) then
  1443.             return
  1444.         endif
  1445.  
  1446.         id = RoomId[n]
  1447.         if id then
  1448.             for i = 1 to ObjectsPerRoom[RoomType[n]] loop
  1449.                 SetRGBProperty id++, "PenColour", r,g,b
  1450.             endfor
  1451.         endif
  1452.     end sub
  1453.  
  1454.     sub fast_ ResetRoomLineColour( n as int )
  1455.         // set the default colour of the lines making this room
  1456.         local
  1457.             int i, id
  1458.             rgbvalue r=0,g=0,b=255
  1459.         endlocal
  1460.  
  1461.         if not ValidRoom(n) then
  1462.             return
  1463.         endif
  1464.  
  1465.         if RoomType[n] > NROOMS then
  1466.             r=255
  1467.         endif
  1468.  
  1469.         id = RoomId[n]
  1470.         if id then
  1471.             for i = 1 to ObjectsPerRoom[RoomType[n]] loop
  1472.                 SetRGBProperty id++, "PenColour", r,g,b
  1473.             endfor
  1474.         endif
  1475.     end sub
  1476.  
  1477.     sub DrawStartPos( relative as int )
  1478.         local
  1479.             int w, h
  1480.             string name
  1481.         endlocal
  1482.  
  1483.         if StartPosObj then
  1484.             DeleteObject StartPosObj
  1485.         endif
  1486.  
  1487.         if StartX >= DrawOriginX and StartY >= DrawOriginY and ActionLevel = StartLevel then
  1488.             gsave()
  1489.             pencolor 0,255/2,0
  1490.  
  1491.             font "timesroman.bold", unit, unit
  1492.  
  1493.             StartPosObj = GetNextObjectID()
  1494.             if relative then
  1495.                 text (StartX-RoomX[StartRoom])*unit+GridOriginX,(StartY-RoomY[StartRoom])*unit+GridOriginY, "S"
  1496.             else
  1497.                 text (StartX+DrawOriginX)*unit+GridOriginX,(StartY+DrawOriginY)*unit+GridOriginY, "S"
  1498.             endif
  1499.             grestore()
  1500.         endif
  1501.     end sub
  1502.  
  1503.     sub fast_ DeleteRoom( n as int )
  1504.         //delete room number n
  1505.         local
  1506.             int i, id, aji
  1507.         endlocal
  1508.  
  1509.         if not ValidRoom(n) then
  1510.             return
  1511.         endif
  1512.  
  1513.         id = RoomId[n]
  1514.         if id then
  1515.             for i = 1 to ObjectsPerRoom[RoomType[n]] + DoorsPerRoom[RoomType[n]] loop
  1516.                 DeleteObject id++
  1517.             endfor
  1518.             RoomID[n] = 0
  1519.         endif
  1520.  
  1521.         aji = RoomAdjacent[n]
  1522.         for i = 1 to DoorsPerRoom[RoomType[n]] loop
  1523.             adjacent[aji++] = -1
  1524.         endfor
  1525.  
  1526.         if RoomNameID[n] then
  1527.             DeleteObject RoomNameID[n]
  1528.             RoomNameID[n] = 0
  1529.         endif
  1530.  
  1531.         if n = StartRoom then
  1532.             StartX = -1
  1533.             StartY = -1
  1534.             StartRoom = -1
  1535.             DrawStartPos(0)
  1536.         endif
  1537.  
  1538.         RoomType[n] = 0
  1539.     end sub
  1540.  
  1541.  
  1542.     sub fast_ HideRoom( n as int )
  1543.         //delete objects for room number n but leave roomtype
  1544.         local
  1545.             int i, id
  1546.         endlocal
  1547.  
  1548.         if not ValidRoom(n) then
  1549.             return
  1550.         endif
  1551.  
  1552.         id = RoomId[n]
  1553.         if id then
  1554.             for i = 1 to ObjectsPerRoom[RoomType[n]] + DoorsPerRoom[RoomType[n]] loop
  1555.                 DeleteObject id++
  1556.             endfor
  1557.             RoomID[n] = 0
  1558.         endif
  1559.  
  1560.         if RoomNameID[n] then
  1561.             DeleteObject RoomNameID[n]
  1562.             RoomNameID[n] = 0
  1563.         endif
  1564.     end sub
  1565.  
  1566.     sub fast_ RedrawRoom( n as int )
  1567.         //delete objects for room number n and then redraw it
  1568.         local
  1569.             int i, id
  1570.         endlocal
  1571.  
  1572.         if RoomType[n] = 0 then
  1573.             return
  1574.         endif
  1575.  
  1576.         id = RoomId[n]
  1577.         if id then
  1578.             for i = 1 to ObjectsPerRoom[RoomType[n]] + DoorsPerRoom[RoomType[n]] loop
  1579.                 DeleteObject id++
  1580.             endfor
  1581.         endif
  1582.  
  1583.         if RoomNameID[n] then
  1584.             DeleteObject RoomNameID[n]
  1585.         endif
  1586.  
  1587.         DrawRoom( n )
  1588.     end sub
  1589.  
  1590.     sub fast_ HideAllRooms()
  1591.         local
  1592.             int i
  1593.         endlocal
  1594.  
  1595.         DelayedUpdate( true)
  1596.         for i = 0 to high(RoomType) loop
  1597.             HideRoom(i)
  1598.         end for
  1599.         DelayedUpdate( false)
  1600.     end sub
  1601.  
  1602.     sub fast_ RedrawAllRooms()
  1603.         local
  1604.             int i
  1605.         endlocal
  1606.  
  1607.         DelayedUpdate (true)
  1608.         for i = 0 to high(RoomType) loop
  1609.             RedrawRoom(i)
  1610.         end for
  1611.  
  1612.         DelayedUpdate (false)
  1613.     end sub
  1614.  
  1615.  
  1616.  
  1617. //maze load code
  1618.  
  1619.     sub fast_ ClearMaze() 
  1620.         Mazename = "NewMaze"
  1621. //        MazeRemoteRoot = "no remote root"
  1622. //        MazeLocalCDRoot = "no local CD root"
  1623.         MazeTimeLimit= "60"
  1624.         MazeFilename = ""
  1625.         TextureDir = "textures"
  1626.         SoundDir = "sounds"
  1627.         ObjectDir = "objects"
  1628.         RoomFloorTexture = 0
  1629.         RoomWallTexture = 0
  1630.         RoomCeilingTexture = 0
  1631.         LinkFloorTexture = 0
  1632.         LinkWallTexture = 0
  1633.         LinkCeilingTexture = 0
  1634.         RedDoorTexture = -1
  1635.         GreenDoorTexture = -1
  1636.         BlueDoorTexture = -1
  1637.  
  1638.         DeleteElements LevelName,    high(LevelName)+1
  1639.         DeleteElements NextRoomAtLevel,    high(NextRoomAtLevel)+1
  1640.         DeleteElements NextLinkAtLevel,    high(NextLinkAtLevel)+1
  1641.         DeleteElements Adjacent,    high(Adjacent)+1
  1642.         DeleteElements OverlapList,    high(OverlapList)+1
  1643.         DeleteElements roomtype,    high(roomtype)+1
  1644.         DeleteElements RoomNumber,    high(RoomNumber)+1
  1645.         DeleteElements roomid ,        high(roomid)+1
  1646.         DeleteElements roomx ,        high(roomx)+1
  1647.         DeleteElements roomy ,        high(roomy)+1
  1648.         DeleteElements roomw ,        high(roomw)+1
  1649.         DeleteElements roomd ,        high(roomd)+1
  1650.         DeleteElements roomr ,        high(roomr)+1
  1651.         DeleteElements roomheight ,    high(roomheight)+1
  1652.         DeleteElements roomlevel,    high(roomlevel)+1
  1653.         DeleteElements roomname,    high(roomname)+1
  1654.         DeleteElements roomdoors,    high(roomdoors)+1
  1655.         DeleteElements roomadjacent,high(roomadjacent)+1
  1656.         DeleteElements RoomTextureBits, high(RoomTextureBits)+1
  1657.         DeleteElements roomvisited, high(roomvisited)+1
  1658.  
  1659.         DeleteElements RoomObjectsCount, high(RoomObjectsCount)+1
  1660.         DeleteElements RoomObjectsIndex, high(RoomObjectsIndex)+1
  1661.         DeleteElements Room_Contents, high(Room_Contents)+1
  1662.         DeleteElements Room_geometry, high(Room_geometry)+1
  1663.  
  1664.         DeleteElements object3dList,high(object3dList)+1
  1665.         DeleteElements object3dScale,high(object3dScale)+1
  1666.         DeleteElements Object3dUsage, high(Object3dUsage)+1
  1667.  
  1668.         DeleteElements ObjectsList, high(ObjectsList)+1
  1669.         DeleteElements ObjectsName, high(ObjectsName)+1
  1670.         DeleteElements ObjectsClump, high(ObjectsClump)+1
  1671.         DeleteElements DoorClumps,  high(DoorClumps)+1
  1672.         DeleteElements ObjectsXYH,  high(ObjectsXYH)+1
  1673.         DeleteElements TextureList, high(TextureList)+1
  1674.         DeleteElements TextureUsage, high(TextureUsage)+1
  1675.     end sub
  1676.  
  1677.  
  1678.     function LoadDoors( f as int r as int ) as int
  1679.         local
  1680.             int i, nd
  1681.             string str
  1682.         endlocal
  1683.  
  1684.         input #f, nd
  1685.         RoomDoors[r] = nd
  1686.  
  1687.         for i = 1 to nd loop
  1688.             str = input$(8,#f)
  1689.             AddElement Adjacent bstrtoi(str, 16)
  1690.             AddElement DoorClumps null
  1691.             input$(1,#f)
  1692.         endloop
  1693.  
  1694.         return 1
  1695.     end function
  1696.  
  1697.     function LoadObjects( f as int r as int index as int version as string) as int
  1698.         local
  1699.             int i, x, y, h, ONumber
  1700.             string name
  1701.             int ocount
  1702.         endlocal
  1703.  
  1704.         input #f, ocount
  1705.         RoomObjectsCount[r] = ocount
  1706.  
  1707.         for i = 1 to ocount loop
  1708.             input #f, ONumber, x, y, h
  1709.             ObjectsList[index] = ONumber
  1710.             ObjectsXYH[index] = XYL( x, y, h )
  1711.             ObjectsClump[index] = null
  1712.             index++
  1713.         endloop
  1714.  
  1715.         name = ""
  1716.         return 1
  1717.     end function
  1718.  
  1719.     function LoadRoom( f as int level as int version as string) as int
  1720.         local
  1721.             int d, doors, x, y, l, i, t
  1722.             int r=high(RoomType)+1
  1723.             int max
  1724.         endlocal
  1725.  
  1726.         AddElement roomx 0
  1727.         AddElement roomy 0
  1728.         AddElement roomw 0
  1729.         AddElement roomd 0
  1730.         AddElement roomr 0
  1731.         AddElement RoomHeight 0
  1732.  
  1733.         AddElement RoomType 0
  1734.         AddElement RoomID 0
  1735.         AddElement RoomNameID 0
  1736.         AddElement RoomDoors 0
  1737.         AddElement RoomAdjacent high(Adjacent)+1
  1738.         AddElement RoomObjectsCount 0
  1739.         AddElement RoomObjectsIndex high(ObjectsList)+1
  1740.         AddElement Room_Contents null
  1741.         AddElement Room_geometry null
  1742.         AddElement RoomVisited 0
  1743.  
  1744.         AddElement RoomNumber 0
  1745.         AddElement RoomName ""
  1746.         AddElement RoomLevel level
  1747.         AddElement RoomTextureBits 0
  1748.         AddElement RoomVisited 0
  1749.  
  1750.         input #f, RoomNumber[r]
  1751.         RoomName[r] = inputline$(#f)
  1752.  
  1753.         input #f, RoomType[r], roomx[r], roomy[r], roomw[r], roomd[r], roomr[r], RoomHeight[r]
  1754.         RoomDoors[r] = DoorsPerRoom[RoomType[r]]
  1755.  
  1756.         if RoomType[r] <= NROOMS then
  1757.             max = MaxObjectsPerRoom
  1758.         else
  1759.             max = MaxObjectsPerLink
  1760.         endif
  1761.  
  1762.         for i = 1 to max loop
  1763.             AddElement ObjectsList 0
  1764.             AddElement ObjectsName ""
  1765.             AddElement ObjectsXYH 0
  1766.             AddElement ObjectsClump null
  1767.         endfor
  1768.  
  1769.         if version >= "0.81" then
  1770.             RoomTextureBits[r] = bstrtoi( inputline$(#f), 16 )
  1771.         endif
  1772.  
  1773.         LoadObjects( f, r, RoomObjectsIndex[high(RoomObjectsIndex)], version )
  1774.  
  1775.         if version >= "0.83" then
  1776.             LoadDoors( f, r )
  1777.         endif
  1778.  
  1779.         return 1
  1780.     end function
  1781.  
  1782.  
  1783.     function fast_ LoadMaze( fname as string, mode as int ) as boolean
  1784.         local
  1785.             int bl    //base level of maze we are loading
  1786.             boolean status=false
  1787.             filename thefile, thebakfile
  1788.             string lfile
  1789.             int index
  1790.             string VersionStr, str
  1791.             int levels, rooms, links
  1792.             int l, r
  1793.             int OriginalLevel
  1794.             int f=1
  1795.             int type
  1796.             float scale
  1797.             string objectname
  1798.             int NumberOfObjects
  1799.             string spare
  1800.  
  1801.             boolean FoundStart=false, FoundEnd=false, FoundAction=false
  1802.         endlocal
  1803.  
  1804.         goodsav = false
  1805.  
  1806.         thefile = filename(fname)
  1807.  
  1808.         if !checkfile( thefile, readable ) then
  1809.             thefile = InstallDir + thefile
  1810.  
  1811.             if !checkfile( thefile, readable ) then
  1812.                 MsgBox( "Can't load", string(thefile), OKBOX )
  1813.                 return false
  1814.             endif
  1815.         endif
  1816.  
  1817.         lfile = tidy$( string(thefile), lower )
  1818.         index = instr( lfile, ".maz", 0 )
  1819.  
  1820.         if index >=1 then
  1821.             thebakfile = filename(left$( string(thefile), index )) + `.bak`
  1822.             SaveFilename = filename(left$( string(thefile), index )) + `.sav`
  1823.             goodsav = true
  1824.         endif
  1825.  
  1826.         if mode = 0 then
  1827.             ClearMaze()
  1828.             bl = 0
  1829.         else
  1830.             bl = high(LevelName)+1
  1831.         endif
  1832.  
  1833.         open thefile for read as #f
  1834.         print using "Loading %s\n", thefile
  1835.  
  1836.         VersionStr = inputline$(#f)
  1837.  
  1838.         if PlayerVersion < VersionStr then
  1839.             MsgBox( "Can't load", "Your editor is out of date!", OKBOX )
  1840.             return false
  1841.         endif
  1842.  
  1843.         MazeName = inputline$(#f)
  1844.         print using "Loading Maze %s\n", MazeName
  1845.  
  1846.         if VersionStr >= "0.87" then
  1847. //            MazeRemoteRoot = inputline$(#f)
  1848. //            MazeLocalCDRoot = inputline$(#f)
  1849.             spare = inputline$(#f)
  1850.             spare = inputline$(#f)
  1851.         endif
  1852.  
  1853.         if VersionStr > "0.84" then
  1854.             MazeTimeLimit = inputline$(#f)
  1855.         else
  1856.             MazeTimeLimit = "60"
  1857.         endif
  1858.  
  1859.         input #f, ActionRoom, ActionLevel
  1860.         input #f, DrawOriginX, DrawOriginY, MapUnit, RoomUnit
  1861.         input #f, CheckError
  1862.  
  1863.         DrawOriginX = 0
  1864.         DrawOriginY = 0
  1865.  
  1866.         if VersionStr < "0.84" then
  1867.             input #f, StartX, StartY, StartLevel, EndX, EndY, EndLevel
  1868.         else
  1869.             input #f, StartX, StartY, StartLevel
  1870.         endif
  1871.  
  1872.         if VersionStr >= "0.81" then
  1873.             TextureDir = inputline$(#f)
  1874.  
  1875.             input #f, NumberOfTextures
  1876.             if NumberOfTextures then
  1877.                 for l = 1 to NumberOfTextures loop
  1878.                     AddElement TextureUsage 1
  1879.                     if VersionStr >= "0.89" then
  1880.                         input #f, TextureUsage[l-1]
  1881.                     endif
  1882.                     AddElement TextureList inputline$(#f)
  1883.                 endfor
  1884.             else
  1885.                 AddElement TextureList "none"
  1886.             endif
  1887.  
  1888.             input #f, RoomFloorTexture, RoomWallTexture, RoomCeilingTexture
  1889.             input #f, LinkFloorTexture, LinkWallTexture, LinkCeilingTexture
  1890.             if VersionStr >= "0.84" then
  1891.                 input #f, RedDoorTexture, GreenDoorTexture, BlueDoorTexture
  1892.             else
  1893.                 RedDoorTexture = -1
  1894.                 GreenDoorTexture = -1
  1895.                 BlueDoorTexture = -1
  1896.             endif
  1897.             input #f, RoomFloorTexturing, RoomWallTexturing, RoomCeilingTexturing
  1898.         else
  1899.             TextureDir = inputline$(#f)
  1900.  
  1901.             AddElement TextureList inputline$(#f)
  1902.             AddElement TextureList inputline$(#f)
  1903.             AddElement TextureList inputline$(#f)
  1904.             AddElement TextureList inputline$(#f)
  1905.             AddElement TextureList inputline$(#f)
  1906.             AddElement TextureList inputline$(#f)
  1907.  
  1908.             RoomFloorTexture = 0
  1909.             RoomWallTexture = 1
  1910.             RoomCeilingTexture = 2
  1911.             LinkFloorTexture = 3
  1912.             LinkWallTexture = 4
  1913.             LinkCeilingTexture = 5
  1914.             RedDoorTexture = -1
  1915.             GreenDoorTexture = -1
  1916.             BlueDoorTexture = -1
  1917.  
  1918.             input #f, RoomFloorTexturing
  1919.             if RoomFloorTexturing = 0 then
  1920.                 RoomFloorTexturing = StretchTexturesBoth
  1921.             else
  1922.                 RoomFloorTexturing = TileTexturesBoth
  1923.             endif
  1924.  
  1925.             RoomWallTexturing = RoomFloorTexturing
  1926.             RoomCeilingTexturing = RoomFloorTexturing
  1927.         endif
  1928.  
  1929.         if versionStr >= "0.88" then
  1930.             SoundDir = inputline$(#f)
  1931.         endif
  1932.  
  1933.         if versionStr >= "0.80" then
  1934.             input #f, SoundEffectFlags
  1935.  
  1936.             if SoundEffectFlags & 1 then
  1937.                 OooffSound = inputline$(#f)
  1938.             endif
  1939.  
  1940.             if SoundEffectFlags & 2 then
  1941.                 BackgroundMIDI = inputline$(#f)
  1942.             endif
  1943.  
  1944.             if SoundEffectFlags & 4 then
  1945.                 CollectSound = inputline$(#f)
  1946.             endif
  1947.  
  1948.             if SoundEffectFlags & 8 then
  1949.                 FinishSound = inputline$(#f)
  1950.             endif
  1951.         endif
  1952.  
  1953.         if VersionStr >= "0.77" then
  1954.             ObjectDir = inputline$(#f)
  1955.  
  1956.             input #f, NumberOfObjects
  1957.  
  1958.             for r = 1 to NumberOfObjects loop
  1959.                 AddElement Object3dUsage 1
  1960.                 if VersionStr >= "0.89" then
  1961.                     input #f, Object3dUsage[r-1]
  1962.                 endif
  1963.  
  1964.                 input #f, scale
  1965.                 AddElement Object3dScale scale
  1966.                 Objectname = inputline$(#f)
  1967.                 AddElement Object3dList objectname
  1968.             endloop
  1969.         endif
  1970.  
  1971.         input #f, levels
  1972.         print using "Loading %d levels\n", levels
  1973.  
  1974.         for l = bl to bl+levels-1 loop
  1975.             print using "Loading level %d\n", l
  1976.             AddElement LevelName ""
  1977.             AddElement NextRoomAtLevel 0
  1978.             AddElement NextLinkAtLevel 0
  1979.  
  1980.             input #f, OriginalLevel
  1981.  
  1982.             LevelName[l] = inputline$(#f)
  1983.  
  1984.             input #f, rooms, NextRoomAtLevel[l]
  1985.             input #f, links, NextLinkAtLevel[l]
  1986.  
  1987.             for r = 0 to rooms+links-1 loop
  1988.                 print using "Loading room %d\n", r
  1989.                 LoadRoom(f, l, VersionStr)
  1990.             endloop
  1991.         endloop
  1992.  
  1993.         close #f
  1994.  
  1995.         StartRoom = FindRoomAtXYL( StartX, StartY, StartLevel, type )
  1996.  
  1997.         for r = 0 to high(RoomNumber) loop
  1998.             if RoomNumber[r] = ActionRoom then
  1999.                 ActionRoom = r
  2000.                 loopexit
  2001.             endif
  2002.         endfor
  2003.  
  2004.         status = true
  2005.         return status
  2006.     end function
  2007.  
  2008.     sub fast_ LoadEditorData() 
  2009.         local
  2010.             int i
  2011.             string str
  2012.             int f=1
  2013.         endlocal
  2014.  
  2015.         // load list of previous maze files
  2016.  
  2017.         str=global_select
  2018.             //only add files to list if they exist
  2019.             if len(str) > 0 and checkfile( InstallDir + filename(str), readable ) then
  2020.                 AddElement MazeFilenames str
  2021.             endif
  2022.     end sub
  2023.  
  2024.     sub BuildWalls( num as int )
  2025.         //find the cells adjacent to the doors of room num
  2026.         local
  2027.             int n = RoomType[num]
  2028.             int dw1, dw2, dw3, dw4, dh1, dh2, dh3, dh4
  2029.  
  2030.             int l = RoomLevel[num]
  2031.             int w = RoomW[num], d = RoomD[num], r = RoomR[num]
  2032.             int x1 = Roomx[num], y1 = RoomY[num], x2 = x1+RoomW[num]-1, y2=y1+RoomD[num]-1
  2033.             int x,y
  2034.         endlocal
  2035.  
  2036.  
  2037.         if not ValidRoom(num) then
  2038.             return
  2039.         endif
  2040.  
  2041.         if n <= NROOMS then
  2042.             //build complete walls for rooms
  2043.  
  2044.             for x = x1 to x2 loop
  2045.                 walls[y1][x] |= NORTH
  2046.                 walls[y2][x] |= SOUTH
  2047.             endloop
  2048.  
  2049.             for y = y1 to y2 loop
  2050.                 walls[y][x1] |= WEST
  2051.                 walls[y][x2] |= EAST
  2052.             endloop
  2053.         endif
  2054.  
  2055.         dw1 = ((w-1)/2)
  2056.         dw2 =  (w-1-dw1)
  2057.         dw3 =  (w-3)/2
  2058.         dw4 =  (w-3-dw3)
  2059.  
  2060.         dh1 = ((d-1)/2)
  2061.         dh2 =  (d-1-dh1)
  2062.         dh3 =  (d-3)/2
  2063.         dh4 =  (d-3-dh3)
  2064.  
  2065.  
  2066.         if n = 1 then
  2067. //            print using "Room type 1 (%d,%d)-(%d,%d)", x1,y1,x2,y2
  2068.             if r = 0 then
  2069.                 walls[y1][x1] &= ~WEST
  2070.                 walls[y2][x2] &= ~SOUTH
  2071.             elsif r = 4 then
  2072.                 walls[y2][x1] &= ~WEST
  2073.                 walls[y1][x2] &= ~NORTH
  2074.             elsif r = 8 then
  2075.                 walls[y1][x1] &= ~NORTH
  2076.                 walls[y2][x2] &= ~EAST
  2077.             elsif r = 12 then
  2078.                 walls[y2][x1] &= ~SOUTH
  2079.                 walls[y1][x2] &= ~EAST
  2080.             endif
  2081.         elsif n = 2 then
  2082.             if r = 0 then
  2083.                 walls[y1][x2] &= ~NORTH
  2084.                 walls[y2][x2] &= ~SOUTH
  2085.                 walls[y1+dh1][x1] &= ~WEST
  2086.             elsif r = 4 then
  2087.                 walls[y2][x1] &= ~WEST
  2088.                 walls[y2][x2] &= ~EAST
  2089.                 walls[y1][x1+dw1] &= ~NORTH
  2090.             elsif r = 8 then
  2091.                 walls[y1][x1] &= ~NORTH
  2092.                 walls[y2][x1] &= ~SOUTH
  2093.                 walls[y1+dh1][x2] &= ~EAST
  2094.             elsif r = 12 then
  2095.                 walls[y1][x1] &= ~WEST
  2096.                 walls[y1][x2] &= ~EAST
  2097.                 walls[y2][x1+dw1] &= ~SOUTH
  2098.             endif
  2099.         elsif n = 3 then
  2100.             if r = 0 or r = 8 then
  2101.                 walls[y1][x2] &= ~NORTH
  2102.                 walls[y2][x1] &= ~SOUTH
  2103.                 walls[y1+dh1][x1] &= ~WEST
  2104.                 walls[y1+dh2][x2] &= ~EAST
  2105.             elsif r = 4 or r = 12 then
  2106.                 walls[y1][x1] &= ~WEST
  2107.                 walls[y1][x1+dw2] &= ~NORTH
  2108.                 walls[y2][x2] &= ~EAST
  2109.                 walls[y2][x1+dw1] &= ~SOUTH
  2110.             endif
  2111.         elsif n = 4 then
  2112.             if r = 0 or r = 8 then
  2113.                 walls[y1][x1] &= ~NORTH
  2114.                 walls[y1+dh2][x2] &= ~EAST
  2115.                 walls[y2][x2] &= ~SOUTH
  2116.                 walls[y1+dh1][x1] &= ~WEST
  2117.             elsif r = 4 or r = 12 then
  2118.                 walls[y2][x1] &= ~WEST
  2119.                 walls[y1][x1+dw2] &= ~NORTH
  2120.                 walls[y1][x2] &= ~EAST
  2121.                 walls[y2][x1+dw1] &= ~SOUTH
  2122.             endif
  2123.         elsif n = 5 then
  2124.             if r = 0 then
  2125.                 walls[y1][x1+dw1] &= ~NORTH
  2126.             elsif r = 4 then
  2127.                 walls[y1+dh1][x2] &= ~EAST
  2128.             elsif r = 8 then
  2129.                 walls[y2][x1+dw2] &= ~SOUTH
  2130.             elsif r = 12 then
  2131.                 walls[y1+dh2][x1] &= ~WEST
  2132.             endif
  2133.         elsif n = 6 then
  2134.             if (r % 4) = 0 then
  2135.                 walls[y1+dh1][x1] &= ~WEST
  2136.                 walls[y1][x1+dw1] &= ~NORTH
  2137.                 walls[y1+dh2][x2] &= ~EAST
  2138.                 walls[y2][x1+dw2] &= ~SOUTH
  2139.             endif
  2140.         elsif n = 7 then
  2141.             if r = 0 then
  2142.                 walls[y1][x1] &= ~NORTH
  2143.                 walls[y1+dh1][x2] &= ~EAST
  2144.                 walls[y2][x1+dw4] &= ~SOUTH
  2145.                 walls[y2][x1+dw4+2] &= ~SOUTH
  2146.             elsif r = 4 then
  2147.                 walls[y1+dh4][x1] &= ~WEST
  2148.                 walls[y1][x2] &= ~EAST
  2149.                 walls[y2][x1+dw2] &= ~SOUTH
  2150.                 walls[y1+dh4+2][x1] &= ~WEST
  2151.             elsif r = 8 then
  2152.                 walls[y1+dh2][x1] &= ~WEST
  2153.                 walls[y1][x1+dw3] &= ~NORTH
  2154.                 walls[y1][x1+dw3+2] &= ~NORTH
  2155.                 walls[y2][x2] &= ~SOUTH
  2156.             elsif r = 12 then
  2157.                 walls[y2][x1] &= ~WEST
  2158.                 walls[y1][x1+dw1] &= ~NORTH
  2159.                 walls[y1+dh3][x2] &= ~EAST
  2160.                 walls[y1+dh3+2][x2] &= ~EAST
  2161.             endif
  2162.         elsif n = NROOMS+1 then
  2163.             if r = 0 then
  2164.                 walls[y1][x1] |= EAST|WEST
  2165.                 walls[y2][x1] |= SOUTH|WEST
  2166.                 walls[y2][x2] |= NORTH|SOUTH
  2167.             elsif r = 4 then
  2168.                 walls[y1][x1] |= WEST|NORTH
  2169.                 walls[y1][x2] |= NORTH|SOUTH
  2170.                 walls[y2][x1] |= EAST|WEST
  2171.             elsif r = 8 then
  2172.                 walls[y1][x1] |= NORTH|SOUTH
  2173.                 walls[y1][x2] |= NORTH|EAST
  2174.                 walls[y2][x2] |= EAST|WEST
  2175.             elsif r = 12 then
  2176.                 walls[y2][x1] |= NORTH|SOUTH
  2177.                 walls[y2][x2] |= SOUTH|EAST
  2178.                 walls[y1][x2] |= EAST|WEST
  2179.             endif
  2180.         elsif n = NROOMS+2 then
  2181.             if r = 0 then
  2182.                 walls[y1][x1] |= NORTH|SOUTH
  2183.                 walls[y1][x1+1] |= NORTH
  2184.                 walls[y1][x2] |= NORTH|SOUTH
  2185.                 walls[y2][x1+1] |= EAST|WEST
  2186.             elsif r = 4 then
  2187.                 walls[y1][x2] |= EAST|WEST
  2188.                 walls[y1+1][x1] |= NORTH|SOUTH
  2189.                 walls[y1+1][x2] |= EAST
  2190.                 walls[y2][x2] |= EAST|WEST
  2191.             elsif r = 8 then
  2192.                 walls[y2][x1] |= NORTH|SOUTH
  2193.                 walls[y1][x1+1] |= EAST|WEST
  2194.                 walls[y2][x1+1] |= SOUTH
  2195.                 walls[y2][x2] |= NORTH|SOUTH
  2196.             elsif r = 12 then
  2197.                 walls[y1][x1] |= EAST|WEST
  2198.                 walls[y1+1][x1] |= WEST
  2199.                 walls[y1+1][x2] |= NORTH|SOUTH
  2200.                 walls[y2][x1] |= EAST|WEST
  2201.             endif
  2202.         elsif n = NROOMS+3 then
  2203.             if (r % 4) = 0 then
  2204.                 walls[y1][x1+1] |= EAST|WEST
  2205.                 walls[y1+1][x1] |= NORTH|SOUTH
  2206.                 walls[y1+1][x2] |= NORTH|SOUTH
  2207.                 walls[y2][x1+1] |= EAST|WEST
  2208.             endif
  2209.         elsif n = NROOMS+4 then
  2210.             if r = 0 or r = 8 then
  2211.                 for x = x1 to x2 loop
  2212.                     walls[y1][x] |= NORTH
  2213.                     walls[y2][x] |= SOUTH
  2214.                 endfor
  2215.             elsif r = 4 or r = 12 then
  2216.                 for y = y1 to y2 loop
  2217.                     walls[y][x1] |= WEST
  2218.                     walls[y][x2] |= EAST
  2219.                 endfor
  2220.             endif
  2221.         endif
  2222.     end sub
  2223.  
  2224.     function fast_ BuildRoom( num as int FTexturing as int WTexturing as int CTexturing as int ) as RwClump
  2225.         //build room number num
  2226.  
  2227.         local
  2228.             int n = RoomType[num]
  2229.             int x = RoomX[num], y = RoomY[num],  r = RoomR[num]
  2230.             int w = RoomW[num]
  2231.             int d = RoomD[num]
  2232.             int h = RoomHeight[num]
  2233.             int thisx = x, thisy = y
  2234.             float x1, y1, x2, y2
  2235.             int dw1, dw2, dw3, dw4, dh1, dh2, dh3, dh4
  2236.             int id
  2237.             RwClump clump
  2238.             int temp, temp2
  2239.             rwClumpHints hint = rwHS
  2240.             float twf,tdf
  2241.             float tww,tdw,th
  2242.             float twc,tdc
  2243.         endlocal
  2244.  
  2245.         if ActionLevel != RoomLevel[num] then
  2246.             return null
  2247.         endif
  2248.  
  2249.         x1 = 0
  2250.         y1 = 0
  2251.  
  2252.         if r = 0 then
  2253.             x2 = x1+w-roomsep
  2254.             y2 = y1+d-roomsep
  2255.         elsif r = 4 then
  2256.             x2 = x1+d-roomsep
  2257.             y2 = y1+w-roomsep
  2258.         elsif r = 8 then
  2259.             x2 = x1+w-roomsep
  2260.             y2 = y1+d-roomsep
  2261.         elsif r = 12 then
  2262.             x2 = x1+d-roomsep
  2263.             y2 = y1+w-roomsep
  2264.         endif
  2265.  
  2266.  
  2267.         dw1 = ((w-1)/2)
  2268.         dw2 =  (w-1-dw1)
  2269.         dw3 =  (w-3)/2
  2270.         dw4 =  (w-3-dw3)
  2271.  
  2272.         dh1 = ((d-1)/2)
  2273.         dh2 =  (d-1-dh1)
  2274.         dh3 =  (d-3)/2
  2275.         dh4 =  (d-3-dh3)
  2276.  
  2277.         dw1*=unit    dw2*=unit    dw3*=unit    dw4*=unit
  2278.         dh1*=unit    dh2*=unit    dh3*=unit    dh4*=unit
  2279.  
  2280.         if r = 0 then
  2281.             null
  2282.         elsif r = 4 then
  2283.             temp = w
  2284.             w = d
  2285.             d = temp
  2286.         elsif r = 8 then
  2287.             null
  2288.         elsif r = 12 then
  2289.             temp = w
  2290.             w = d
  2291.             d = temp
  2292.         endif
  2293.  
  2294.  
  2295.         if FTexturing = TileTexturesBoth then
  2296.             twf = 1 tdf = 1
  2297.         elseif FTexturing = StretchTexturesBoth then
  2298.             twf = w tdf = d
  2299.         elseif FTexturing = StretchAcrossTileDown then
  2300.             twf = w tdf = 1
  2301.         elseif FTexturing = StretchDownTileAcross then
  2302.             twf = 1 tdf = d
  2303.         elseif FTexturing = StretchAndSquareTile then
  2304.             twf = min([w,d]) tdf = min([w,d]) 
  2305.         endif
  2306.  
  2307.         if WTexturing = TileTexturesBoth then
  2308.             tww = 1 tdw = 1 th = 1
  2309.         elseif WTexturing = StretchTexturesBoth then
  2310.             tww = w tdw = d th = h
  2311.         elseif WTexturing = StretchAcrossTileDown then
  2312.             tww = w tdw = d th = 1
  2313.         elseif WTexturing = StretchDownTileAcross then
  2314.             tww = 1 tdw = 1 th = h
  2315.         elseif WTexturing = StretchAndSquareTile then
  2316.             tww = h tdw = h th = h
  2317.         endif
  2318.  
  2319.         if CTexturing = TileTexturesBoth then
  2320.             twc = 1 tdc = 1
  2321.         elseif CTexturing = StretchTexturesBoth then
  2322.             twc = w tdc = d
  2323.         elseif CTexturing = StretchAcrossTileDown then
  2324.             twc = w tdc = 1
  2325.         elseif CTexturing = StretchDownTileAcross then
  2326.             twc = 1 tdc = d
  2327.         elseif CTexturing = StretchAndSquareTile then
  2328.             twc = min([w,d]) tdc = min([w,d])
  2329.         endif
  2330.  
  2331.  
  2332.         RwModelBegin()
  2333.  
  2334.         if n = 1 then
  2335.             RwIdentityCTM()
  2336.             if r = 0 then
  2337.                 RwTranslateCTM( thisx, 0, thisy)
  2338.                 RwRotateCTM( 0,1,0,0 )
  2339.             elsif r = 4 then
  2340.                 RwTranslateCTM( thisx+d, 0, thisy)
  2341.                 RwRotateCTM( 0,1,0,-90)
  2342.             elsif r = 8 then
  2343.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  2344.                 RwRotateCTM( 0,1,0,180)
  2345.             elsif r = 12 then
  2346.                 RwTranslateCTM( thisx, 0, thisy+w)
  2347.                 RwRotateCTM( 0,1,0,90)
  2348.             else
  2349.                 print "Illegal rotate code room %d %d ", n, r
  2350.             endif
  2351.  
  2352.             RwClumpBegin()
  2353.  
  2354.             RwSetSurface( 0.75, 0.65, 0.0)
  2355.             RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2356.             RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2357.             RwSetSurfaceTextureModes( rwFORESHORTEN )
  2358.  
  2359.             //floor points
  2360.             RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2361.             RwVertexUV( x2,floor, y1, w/twf, 0 )
  2362.             RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2363.             RwVertexUV( x1,floor, y2, 0, d/tdf )
  2364.             RwQuad( 4 3 2 1 )        //floor
  2365.  
  2366.             //ceiling points
  2367.             RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2368.             RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2369.             RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2370.             RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2371.  
  2372.             RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2373.             RwSetSurfaceTextureModes( rwFORESHORTEN )
  2374.             RwQuad( 5 6 7 8 )        //ceiling
  2375.  
  2376.             RwVertexUV( x1, floor,      y2, 0, h/th )
  2377.             RwVertexUV( x2-door, floor, y2, (w-door)/tww, h/th )
  2378.             RwVertexUV( x2-door, floor+door, y2, (w-door)/tww, (h-door)/th )
  2379.             RwVertexUV( x2, floor+door,      y2, w/tww, (h-door)/th )
  2380.             RwVertexUV( x2, floor+h, y2, w/tww, 0 )
  2381.             RwVertexUV( x1, floor+h, y2, 0, 0 )
  2382.  
  2383.             RwVertexUV( x1, floor,   y2, 0, h/th )
  2384.             RwVertexUV( x1, floor,   y1+door, (d-door)/tdw, h/th )
  2385.             RwVertexUV( x1, floor+door, y1+door, (d-door)/tdw, (h-door)/th )
  2386.             RwVertexUV( x1, floor+door, y1, d/tdw, (h-door)/th )
  2387.             RwVertexUV( x1, floor+h, y1,    d/tdw, 0 )
  2388.             RwVertexUV( x1, floor+h, y2,    0, 0 )
  2389.  
  2390.             RwVertexUV( x2, floor,   y2, 0, h/th )
  2391.             RwVertexUV( x2, floor,   y1, w/tww, h/th )
  2392.             RwVertexUV( x2, floor+h, y1, w/tww, 0 )
  2393.             RwVertexUV( x2, floor+h, y2, 0, 0 )
  2394.  
  2395.             RwVertexUV( x1, floor,   y1, 0, h/th )
  2396.             RwVertexUV( x2, floor,   y1, w/tww, h/th )
  2397.             RwVertexUV( x2, floor+h, y1, w/tww, 0 )
  2398.             RwVertexUV( x1, floor+h, y1, 0, 0 )
  2399.  
  2400.             RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2401.             RwSetSurfaceTextureModes( rwFORESHORTEN )
  2402.             RwPolygon( [14, 13, 12, 11, 10, 9] )
  2403.             RwQuad( 24 23 22 21 )
  2404.             RwPolygon( [15,16,17,18,19,20] )
  2405.             RwQuad( 25 26 27 28 )
  2406.  
  2407.         elseif n = 2 then
  2408.             if r = 0 then
  2409.                 temp = dh1
  2410.             elsif r = 4 then
  2411.                 temp = dw1
  2412.             elsif r = 8 then
  2413.                 temp = dh2
  2414.             elsif r = 12 then
  2415.                 temp = dw1
  2416.             endif
  2417.  
  2418.             RwProtoBegin("floor")
  2419.                 RwSetSurface( 0.75, 0.65, 0.0)
  2420.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2421.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2422.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2423.  
  2424.                 //floor points
  2425.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2426.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2427.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2428.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2429.                 RwQuad( 4 3 2 1 )        //floor
  2430.             RwProtoEnd()
  2431.  
  2432.             RwProtoBegin("ceiling")
  2433.                 RwSetSurface( 0.75, 0.65, 0.0)
  2434.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2435.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2436.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2437.  
  2438.                 //ceiling points
  2439.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2440.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2441.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2442.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2443.  
  2444.                 RwQuad( 1 2 3 4 )        //ceiling
  2445.             RwProtoEnd()
  2446.  
  2447.             RwProtoBegin("walls")
  2448.                 RwSetSurface( 0.75, 0.65, 0.0)
  2449.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2450.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2451.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2452.  
  2453.                 RwVertexUV( x1,      floor,        y1, 0, h/th )
  2454.                 RwVertexUV( x2-door, floor,        y1, (w-door)/tww, h/th )
  2455.                 RwVertexUV( x2-door, floor+door,   y1, (w-door)/tww, (h-door)/th )
  2456.                 RwVertexUV( x2,      floor+door,   y1, w/tww, (h-door)/th )
  2457.                 RwVertexUV( x2,      floor+h,      y1, w/tww, 0 )
  2458.                 RwVertexUV( x1,      floor+h,      y1, 0, 0 )
  2459.  
  2460.                 RwVertexUV( x2,      floor,   y1, 0, h/th )
  2461.                 RwVertexUV( x2,      floor,   y2, d/tdw, h/th )
  2462.                 RwVertexUV( x2,      floor+h, y1, 0, 0 )
  2463.                 RwVertexUV( x2,      floor+h, y2, d/tdw, 0 )
  2464.  
  2465.                 RwVertexUV( x2-door, floor,   y2, door/tww, h/th )
  2466.                 RwVertexUV( x1,      floor,   y2, w/tww, h/th )
  2467.                 RwVertexUV( x1,      floor+h, y2, w/tww, 0 )
  2468.                 RwVertexUV( x2,      floor+h, y2, 0, 0 )
  2469.                 RwVertexUV( x2,      floor+door, y2, 0, (h-door)/th )
  2470.                 RwVertexUV( x2-door, floor+door, y2, door/tww, (h-door)/th )
  2471.  
  2472.                 RwVertexUV( x1,      floor,   y1, 0, h/th )
  2473.                 RwVertexUV( x1,      floor,   y1+temp, temp/tdw, h/th )
  2474.                 RwVertexUV( x1,      floor+door, y1+temp, temp/tdw, (h-door)/th )
  2475.                 RwVertexUV( x1,      floor+door, y1+temp+door, (temp+door)/tdw, (h-door)/th )
  2476.                 RwVertexUV( x1,      floor,   y1+temp+door, (temp+door)/tdw, h/th )
  2477.                 RwVertexUV( x1,      floor,   y2, d/tdw, h/th )
  2478.                 RwVertexUV( x1,      floor+h, y2, d/tdw, 0 )
  2479.                 RwVertexUV( x1,      floor+h, y1, 0, 0 )
  2480.  
  2481.                 RwPolygon( [1, 2, 3, 4, 5, 6] )
  2482.                 RwQuad( 7 8 10 9 )
  2483.                 RwPolygon( [11,12,13,14,15,16] )
  2484.                 RwPolygon( [24,23,22,21,20,19,18,17 ] )
  2485.             RwProtoEnd()
  2486.  
  2487.             RwIdentityCTM()
  2488.             if r = 0 then
  2489.                 RwTranslateCTM( thisx, 0, thisy)
  2490.                 RwRotateCTM( 0,1,0,0 )
  2491.             elsif r = 4 then
  2492.                 RwTranslateCTM( thisx+d, 0, thisy)
  2493.                 RwRotateCTM( 0,1,0,-90)
  2494.             elsif r = 8 then
  2495.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  2496.                 RwRotateCTM( 0,1,0,180)
  2497.             elsif r = 12 then
  2498.                 RwTranslateCTM( thisx, 0, thisy+w)
  2499.                 RwRotateCTM( 0,1,0,+90)
  2500.             else
  2501.                 print "Illegal rotate code room %d %d ", n, r
  2502.             endif
  2503.  
  2504.             RwClumpBegin()
  2505.                 RwSetHints( hint )
  2506.                 RwProtoInstance( "floor" )
  2507.                 RwProtoInstance( "ceiling" )
  2508.                 RwProtoInstance( "walls" )
  2509.  
  2510.         elseif n = 3 then
  2511.             if r = 0 then
  2512.                 temp = dh1
  2513.             elsif r = 4 then
  2514.                 temp = dw1
  2515.             elsif r = 8 then
  2516.                 temp = dh1
  2517.             elsif r = 12 then
  2518.                 temp = dw1
  2519.             endif
  2520.  
  2521.             RwProtoBegin("floor")
  2522.                 RwSetSurface( 0.75, 0.65, 0.0)
  2523.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2524.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2525.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2526.  
  2527.                 //floor points
  2528.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2529.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2530.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2531.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2532.                 RwQuad( 4 3 2 1 )        //floor
  2533.             RwProtoEnd()
  2534.  
  2535.             RwProtoBegin("ceiling")
  2536.                 RwSetSurface( 0.75, 0.65, 0.0)
  2537.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2538.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2539.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2540.  
  2541.                 //ceiling points
  2542.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2543.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2544.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2545.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2546.  
  2547.                 RwQuad( 1 2 3 4 )        //ceiling
  2548.             RwProtoEnd()
  2549.  
  2550.             RwProtoBegin("walls")
  2551.                 RwSetSurface( 0.75, 0.65, 0.0)
  2552.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2553.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2554.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2555.  
  2556.                 RwVertexUV( x1,      floor,        y1, 0, h/th )
  2557.                 RwVertexUV( x2-door, floor,        y1, (w-door)/tww, h/th )
  2558.                 RwVertexUV( x2-door, floor+door,   y1, (w-door)/tww, (h-door)/th )
  2559.                 RwVertexUV( x2,      floor+door,   y1, w/tww, (h-door)/th )
  2560.                 RwVertexUV( x2,      floor+h,      y1, w/tww, 0 )
  2561.                 RwVertexUV( x1,      floor+h,      y1, 0, 0 )
  2562.  
  2563.                 RwVertexUV( x2,      floor,        y2, 0, h/th )
  2564.                 RwVertexUV( x1+door, floor,        y2, (w-door)/tww, h/th )
  2565.                 RwVertexUV( x1+door, floor+door,   y2, (w-door)/tww, (h-door)/th )
  2566.                 RwVertexUV( x1,      floor+door,   y2, w/tww, (h-door)/th )
  2567.                 RwVertexUV( x1,      floor+h,      y2, w/tww, 0 )
  2568.                 RwVertexUV( x2,      floor+h,      y2, 0, 0 )
  2569.  
  2570.                 RwVertexUV( x1,      floor,   y1, 0, h/th )
  2571.                 RwVertexUV( x1,      floor,   y1+temp, temp/tdw, h/th )
  2572.                 RwVertexUV( x1,      floor+door, y1+temp, temp/tdw, (h-door)/th )
  2573.                 RwVertexUV( x1,      floor+door, y1+temp+door, (temp+door)/tdw, (h-door)/th )
  2574.                 RwVertexUV( x1,      floor,   y1+temp+door, (temp+door)/tdw, h/th )
  2575.                 RwVertexUV( x1,      floor,   y2, d/tdw, h/th )
  2576.                 RwVertexUV( x1,      floor+h, y2, d/tdw, 0 )
  2577.                 RwVertexUV( x1,      floor+h, y1, 0, 0 )
  2578.  
  2579.                 RwVertexUV( x2,      floor,   y2, 0, h/th )
  2580.                 RwVertexUV( x2,      floor,   y2-temp, temp/tdw, h/th )
  2581.                 RwVertexUV( x2,      floor+door, y2-temp, temp/tdw, (h-door)/th )
  2582.                 RwVertexUV( x2,      floor+door, y2-temp-door, (temp+door)/tdw, (h-door)/th )
  2583.                 RwVertexUV( x2,      floor,   y2-temp-door, (temp+door)/tdw, h/th )
  2584.                 RwVertexUV( x2,      floor,   y1, d/tdw, h/th )
  2585.                 RwVertexUV( x2,      floor+h, y1, d/tdw, 0 )
  2586.                 RwVertexUV( x2,      floor+h, y2, 0, 0 )
  2587.  
  2588.                 RwPolygon( [1,2,3,4,5,6] )
  2589.                 RwPolygon( [7,8,9,10,11,12] )
  2590.                 RwPolygon( [20,19,18,17,16,15,14,13] )
  2591.                 RwPolygon( [28,27,26,25,24,23,22,21] )
  2592.             RwProtoEnd()
  2593.  
  2594.             RwIdentityCTM()
  2595.             if r = 0 then
  2596.                 RwTranslateCTM( thisx, 0, thisy)
  2597.                 RwRotateCTM( 0,1,0,0 )
  2598.             elsif r = 4 then
  2599.                 RwTranslateCTM( thisx+d, 0, thisy)
  2600.                 RwRotateCTM( 0,1,0,-90)
  2601.             elsif r = 8 then
  2602.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  2603.                 RwRotateCTM( 0,1,0,180)
  2604.             elsif r = 12 then
  2605.                 RwTranslateCTM( thisx, 0, thisy+w)
  2606.                 RwRotateCTM( 0,1,0,+90)
  2607.             else
  2608.                 print "Illegal rotate code room %d %d ", n, r
  2609.             endif
  2610.  
  2611.             RwClumpBegin()
  2612.                 RwSetHints( hint )
  2613.                 RwProtoInstance( "floor" )
  2614.                 RwProtoInstance( "ceiling" )
  2615.                 RwProtoInstance( "walls" )
  2616.  
  2617.         elseif n = 4 then
  2618.             if r = 0 then
  2619.                 temp = dh1
  2620.             elsif r = 4 then
  2621.                 temp = dw1
  2622.             elsif r = 8 then
  2623.                 temp = dh1
  2624.             elsif r = 12 then
  2625.                 temp = dw1
  2626.             endif
  2627.  
  2628.             RwProtoBegin("floor")
  2629.                 RwSetSurface( 0.75, 0.65, 0.0)
  2630.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2631.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2632.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2633.  
  2634.                 //floor points
  2635.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2636.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2637.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2638.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2639.                 RwQuad( 4 3 2 1 )        //floor
  2640.             RwProtoEnd()
  2641.  
  2642.             RwProtoBegin("ceiling")
  2643.                 RwSetSurface( 0.75, 0.65, 0.0)
  2644.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2645.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2646.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2647.  
  2648.                 //ceiling points
  2649.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2650.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2651.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2652.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2653.  
  2654.                 RwQuad( 1 2 3 4 )        //ceiling
  2655.             RwProtoEnd()
  2656.  
  2657.             RwProtoBegin("walls")
  2658.                 RwSetSurface( 0.75, 0.65, 0.0)
  2659.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2660.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2661.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2662.  
  2663.                 RwVertexUV( x1,      floor+door, y1, 0, (h-door)/th )
  2664.                 RwVertexUV( x1,      floor+h,    y1, 0, 0 )
  2665.                 RwVertexUV( x2,      floor+h,    y1, w/tww, 0 )
  2666.                 RwVertexUV( x2,      floor,      y1, w/tww, h/th )
  2667.                 RwVertexUV( x1+door, floor,      y1, door/tww, h/th )
  2668.                 RwVertexUV( x1+door, floor+door, y1, door/tww, (h-door)/th )
  2669.  
  2670.                 RwVertexUV( x1,      floor,      y2, 0, h/th )
  2671.                 RwVertexUV( x2-door, floor,      y2, (w-door)/tww, h/th )
  2672.                 RwVertexUV( x2-door, floor+door, y2, (w-door)/tww, (h-door)/th )
  2673.                 RwVertexUV( x2,      floor+door, y2, w/tww, (h-door)/th )
  2674.                 RwVertexUV( x2,      floor+h,    y2, w/tww, 0 )
  2675.                 RwVertexUV( x1,      floor+h,    y2, 0, 0 )
  2676.  
  2677.                 RwVertexUV( x1,      floor,      y1, 0, h/th )
  2678.                 RwVertexUV( x1,      floor,      y1+temp, temp/tdw, h/th )
  2679.                 RwVertexUV( x1,      floor+door, y1+temp, temp/tdw, (h-door)/th )
  2680.                 RwVertexUV( x1,      floor+door, y1+temp+door, (temp+door)/tdw, (h-door)/th )
  2681.                 RwVertexUV( x1,      floor,      y1+temp+door, (temp+door)/tdw, h/th )
  2682.                 RwVertexUV( x1,      floor,      y2, d/tdw, h/th )
  2683.                 RwVertexUV( x1,      floor+h,    y2, d/tdw, 0 )
  2684.                 RwVertexUV( x1,      floor+h,    y1, 0, 0 )
  2685.  
  2686.                 RwVertexUV( x2,      floor,      y2, 0, h/th )
  2687.                 RwVertexUV( x2,      floor,      y2-temp, temp/tdw, h/th )
  2688.                 RwVertexUV( x2,      floor+door, y2-temp, temp/tdw, (h-door)/th )
  2689.                 RwVertexUV( x2,      floor+door, y2-temp-door, (temp+door)/tdw, (h-door)/th )
  2690.                 RwVertexUV( x2,      floor,      y2-temp-door, (temp+door)/tdw, h/th )
  2691.                 RwVertexUV( x2,      floor,      y1, d/tdw, h/th )
  2692.                 RwVertexUV( x2,      floor+h,    y1, d/tdw, 0 )
  2693.                 RwVertexUV( x2,      floor+h,    y2, 0, 0 )
  2694.  
  2695.                 RwPolygon( [6,5,4,3,2,1] )
  2696.                 RwPolygon( [12,11,10,9,8,7] )
  2697.                 RwPolygon( [20,19,18,17,16,15,14,13] )
  2698.                 RwPolygon( [28,27,26,25,24,23,22,21] )
  2699.             RwProtoEnd()
  2700.  
  2701.             RwIdentityCTM()
  2702.             if r = 0 then
  2703.                 RwTranslateCTM( thisx, 0, thisy)
  2704.                 RwRotateCTM( 0,1,0,0 )
  2705.             elsif r = 4 then
  2706.                 RwTranslateCTM( thisx+d, 0, thisy)
  2707.                 RwRotateCTM( 0,1,0,-90)
  2708.             elsif r = 8 then
  2709.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  2710.                 RwRotateCTM( 0,1,0,180)
  2711.             elsif r = 12 then
  2712.                 RwTranslateCTM( thisx, 0, thisy+w)
  2713.                 RwRotateCTM( 0,1,0,+90)
  2714.             else
  2715.                 print "Illegal rotate code room %d %d ", n, r
  2716.             endif
  2717.  
  2718.             RwClumpBegin()
  2719.                 RwSetHints( hint )
  2720.                 RwProtoInstance( "floor" )
  2721.                 RwProtoInstance( "ceiling" )
  2722.                 RwProtoInstance( "walls" )
  2723.  
  2724.         elsif n = 5 then
  2725.             if r = 0 then
  2726.                 temp = dw1
  2727.             elsif r = 4 then
  2728.                 temp = dh1
  2729.             elsif r = 8 then
  2730.                 temp = dw1
  2731.             elsif r = 12 then
  2732.                 temp = dh1
  2733.             endif
  2734.  
  2735.             RwProtoBegin("floor")
  2736.                 RwSetSurface( 0.75, 0.65, 0.0)
  2737.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2738.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2739.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2740.  
  2741.                 //floor points
  2742.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2743.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2744.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2745.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2746.                 RwQuad( 4 3 2 1 )        //floor
  2747.             RwProtoEnd()
  2748.  
  2749.             RwProtoBegin("ceiling")
  2750.                 RwSetSurface( 0.75, 0.65, 0.0)
  2751.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2752.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2753.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2754.  
  2755.                 //ceiling points
  2756.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2757.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2758.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2759.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2760.  
  2761.                 RwQuad( 1 2 3 4 )        //ceiling
  2762.             RwProtoEnd()
  2763.  
  2764.             RwProtoBegin("walls")
  2765.                 RwSetSurface( 0.75, 0.65, 0.0)
  2766.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2767.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2768.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2769.  
  2770.                 RwVertexUV( x2,      floor,   y1, 0, h/th )
  2771.                 RwVertexUV( x2,      floor,   y2, d/tdw, h/th )
  2772.                 RwVertexUV( x2,      floor+h, y1, 0, 0 )
  2773.                 RwVertexUV( x2,      floor+h, y2, d/tdw, 0 )
  2774.  
  2775.                 RwVertexUV( x1,      floor,   y1, 0, h/th )
  2776.                 RwVertexUV( x1,      floor,   y2, d/tdw, h/th )
  2777.                 RwVertexUV( x1,      floor+h, y1, 0, 0 )
  2778.                 RwVertexUV( x1,      floor+h, y2, d/tdw, 0 )
  2779.  
  2780.                 RwVertexUV( x1,      floor,   y2, 0, h/th )
  2781.                 RwVertexUV( x2,      floor,   y2, w/tww, h/th )
  2782.                 RwVertexUV( x1,      floor+h, y2, 0, 0 )
  2783.                 RwVertexUV( x2,      floor+h, y2, w/tww, 0 )
  2784.  
  2785.                 RwVertexUV( x1,           floor,      y1, 0, h/th )
  2786.                 RwVertexUV( x1+temp,      floor,      y1, temp/tww, h/th )
  2787.                 RwVertexUV( x1+temp,      floor+door, y1, temp/tww, (h-door)/th )
  2788.                 RwVertexUV( x1+temp+door, floor+door, y1, (temp+door)/tww, (h-door)/th )
  2789.                 RwVertexUV( x1+temp+door, floor,      y1, (temp+door)/tww, h/th )
  2790.                 RwVertexUV( x2,           floor,      y1, w/tww, h/th )
  2791.                 RwVertexUV( x2,           floor+h,    y1, w/tww, 0 )
  2792.                 RwVertexUV( x1,           floor+h,    y1, 0, 0 )
  2793.  
  2794.                 RwQuad( 1 2 4 3)
  2795.                 RwQuad( 5 7 8 6)
  2796.                 RwQuad( 9 11 12 10)
  2797.                 RwPolygon( [13,14,15,16,17,18,19,20 ] )
  2798.             RwProtoEnd()
  2799.  
  2800.             RwIdentityCTM()
  2801.             if r = 0 then
  2802.                 RwTranslateCTM( thisx, 0, thisy)
  2803.                 RwRotateCTM( 0,1,0,0 )
  2804.             elsif r = 4 then
  2805.                 RwTranslateCTM( thisx+d, 0, thisy)
  2806.                 RwRotateCTM( 0,1,0,-90)
  2807.             elsif r = 8 then
  2808.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  2809.                 RwRotateCTM( 0,1,0,180)
  2810.             elsif r = 12 then
  2811.                 RwTranslateCTM( thisx, 0, thisy+w)
  2812.                 RwRotateCTM( 0,1,0,+90)
  2813.             else
  2814.                 print "Illegal rotate code room %d %d ", n, r
  2815.             endif
  2816.  
  2817.             RwClumpBegin()
  2818.                 RwSetHints( hint )
  2819.                 RwProtoInstance( "floor" )
  2820.                 RwProtoInstance( "ceiling" )
  2821.                 RwProtoInstance( "walls" )
  2822.  
  2823.         elsif n = 6 then
  2824.                 temp = dw1
  2825.                 temp2 = dh2
  2826.  
  2827.             RwProtoBegin("floor")
  2828.                 RwSetSurface( 0.75, 0.65, 0.0)
  2829.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2830.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2831.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2832.  
  2833.                 //floor points
  2834.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2835.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2836.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2837.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2838.                 RwQuad( 4 3 2 1 )        //floor
  2839.             RwProtoEnd()
  2840.  
  2841.             RwProtoBegin("ceiling")
  2842.                 RwSetSurface( 0.75, 0.65, 0.0)
  2843.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2844.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2845.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2846.  
  2847.                 //ceiling points
  2848.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //5
  2849.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2850.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2851.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2852.  
  2853.                 RwQuad( 1 2 3 4 )        //ceiling
  2854.             RwProtoEnd()
  2855.  
  2856.  
  2857.             RwProtoBegin( "walls")
  2858.                 RwSetSurface( 0.75, 0.65, 0.0)
  2859.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2860.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2861.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2862.  
  2863.                 RwVertexUV( x1,           floor,      y1, 0, h/th )
  2864.                 RwVertexUV( x1+temp,      floor,      y1, temp/tww, h/th )
  2865.                 RwVertexUV( x1+temp,      floor+door, y1, temp/tww, (h-door)/th )
  2866.                 RwVertexUV( x1+temp+door, floor+door, y1, (temp+door)/tww, (h-door)/th )
  2867.                 RwVertexUV( x1+temp+door, floor,      y1, (temp+door)/tww, h/th )
  2868.                 RwVertexUV( x2,           floor,      y1, w/tww, h/th )
  2869.                 RwVertexUV( x2,           floor+h,    y1, w/tww, 0 )
  2870.                 RwVertexUV( x1,           floor+h,    y1, 0, 0 )
  2871.  
  2872.                 RwVertexUV( x1,           floor,      y2, 0, h/th )
  2873.                 RwVertexUV( x2-temp-door, floor,      y2, (w-temp-door)/tww, h/th )
  2874.                 RwVertexUV( x2-temp-door, floor+door, y2, (w-temp-door)/tww, (h-door)/th )
  2875.                 RwVertexUV( x2-temp,      floor+door, y2, (w-temp)/tww, (h-door)/th )
  2876.                 RwVertexUV( x2-temp,      floor,      y2, (w-temp)/tww, h/th )
  2877.                 RwVertexUV( x2,           floor,      y2, w/tww, h/th )
  2878.                 RwVertexUV( x2,           floor+h,    y2, w/tww, 0 )
  2879.                 RwVertexUV( x1,           floor+h,    y2, 0, 0 )
  2880.  
  2881.                 RwVertexUV( x1, floor,      y1, 0, h/th )
  2882.                 RwVertexUV( x1, floor,      y2-temp2-door, (d-temp2-door)/tdw, h/th )
  2883.                 RwVertexUV( x1, floor+door, y2-temp2-door, (d-temp2-door)/tdw, (h-door)/th )
  2884.                 RwVertexUV( x1, floor+door, y2-temp2, (d-temp2)/tdw, (h-door)/th )
  2885.                 RwVertexUV( x1, floor,      y2-temp2, (d-temp2)/tdw, h/th )
  2886.                 RwVertexUV( x1, floor,      y2, d/tdw, h/th )
  2887.                 RwVertexUV( x1, floor+h,    y2, d/tdw, 0 )
  2888.                 RwVertexUV( x1, floor+h,    y1, 0, 0 )
  2889.  
  2890.                 RwVertexUV( x2, floor,      y1, 0, h/th )
  2891.                 RwVertexUV( x2, floor,      y1+temp2, temp2/tdw, h/th )
  2892.                 RwVertexUV( x2, floor+door, y1+temp2, temp2/tdw, (h-door)/th )
  2893.                 RwVertexUV( x2, floor+door, y1+temp2+door, (temp2+door)/tdw, (h-door)/th )
  2894.                 RwVertexUV( x2, floor,      y1+temp2+door, (temp2+door)/tdw, h/th )
  2895.                 RwVertexUV( x2, floor,      y2, d/tdw, h/th )
  2896.                 RwVertexUV( x2, floor+h,    y2, d/tdw, 0 )
  2897.                 RwVertexUV( x2, floor+h,    y1, 0, 0 )
  2898.  
  2899.                 RwPolygon( [ 1,2,3,4,5,6,7,8] )
  2900.                 RwPolygon( [ 16,15,14,13,12,11,10,9] )
  2901.                 RwPolygon( [ 24,23,22,21,20,19,18,17] )
  2902.                 RwPolygon( [ 25,26,27,28,29,30,31,32] )
  2903.  
  2904.             RwProtoEnd()
  2905.  
  2906.             RwIdentityCTM()
  2907.                 RwTranslateCTM( thisx, 0, thisy)
  2908.                 RwRotateCTM( 0,1,0,0 )
  2909.  
  2910.             RwClumpBegin()
  2911.                 RwSetHints( hint )
  2912.                 RwProtoInstance( "floor" )
  2913.                 RwProtoInstance( "ceiling" )
  2914.                 RwProtoInstance( "walls" )
  2915.  
  2916.         elsif n = 7 then
  2917.             if r = 0 then
  2918.                 temp = dh1
  2919.                 temp2 = dw3
  2920.             elsif r = 4 then
  2921.                 temp = dw1
  2922.                 temp2 = dh3
  2923.             elsif r = 8 then
  2924.                 temp = dh1
  2925.                 temp2 = dw3
  2926.             elsif r = 12 then
  2927.                 temp = dw1
  2928.                 temp2 = dh3
  2929.             endif
  2930.  
  2931.             RwProtoBegin("floor")
  2932.                 RwSetSurface( 0.75, 0.65, 0.0)
  2933.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2934.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  2935.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2936.  
  2937.                 //floor points
  2938.                 RwVertexUV( x1,floor, y1, 0, 0 ) //1
  2939.                 RwVertexUV( x2,floor, y1, w/twf, 0 )
  2940.                 RwVertexUV( x2,floor, y2, w/twf, d/tdf )
  2941.                 RwVertexUV( x1,floor, y2, 0, d/tdf )
  2942.                 RwQuad( 4 3 2 1 )        //floor
  2943.             RwProtoEnd()
  2944.  
  2945.             RwProtoBegin("ceiling")
  2946.                 RwSetSurface( 0.75, 0.65, 0.0)
  2947.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2948.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  2949.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2950.  
  2951.                 //ceiling points
  2952.                 RwVertexUV( x1,floor+h,y1, 0, 0 ) //1
  2953.                 RwVertexUV( x2,floor+h,y1, w/twc, 0 )
  2954.                 RwVertexUV( x2,floor+h,y2, w/twc, d/tdc )
  2955.                 RwVertexUV( x1,floor+h,y2, 0, d/tdc )
  2956.  
  2957.                 RwQuad( 1 2 3 4 )        //ceiling
  2958.             RwProtoEnd()
  2959.  
  2960.  
  2961.             RwProtoBegin( "walls")
  2962.                 RwSetSurface( 0.75, 0.65, 0.0)
  2963.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  2964.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  2965.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  2966.  
  2967.                 RwVertexUV( x1,      floor+door, y1, 0, (h-door)/th )
  2968.                 RwVertexUV( x1,      floor+h,    y1, 0, 0 )
  2969.                 RwVertexUV( x2,      floor+h,    y1, w/tww, 0 )
  2970.                 RwVertexUV( x2,      floor,      y1, w/tww, h/th )
  2971.                 RwVertexUV( x1+door, floor,      y1, door/tww, h/th )
  2972.                 RwVertexUV( x1+door, floor+door, y1, door/tww, (h-door)/th )
  2973.  
  2974.                 RwVertexUV( x1,      floor,   y1, 0, h/th )
  2975.                 RwVertexUV( x1,      floor,   y2, d/tdw, h/th )
  2976.                 RwVertexUV( x1,      floor+h, y2, d/tdw, 0 )
  2977.                 RwVertexUV( x1,      floor+h, y1, 0, 0 )
  2978.  
  2979.                 RwVertexUV( x2,      floor,   y2, 0, h/th )
  2980.                 RwVertexUV( x2,      floor,   y1+temp+door, (d-temp-door)/tdw, h/th )
  2981.                 RwVertexUV( x2,      floor+door, y1+temp+door, (d-temp-door)/tdw, (h-door)/th )
  2982.                 RwVertexUV( x2,      floor+door, y1+temp, (d-temp)/tdw, (h-door)/th )
  2983.                 RwVertexUV( x2,      floor,   y1+temp, (d-temp)/tdw, h/th )
  2984.                 RwVertexUV( x2,      floor,   y1, d/tdw, h/th )
  2985.                 RwVertexUV( x2,      floor+h, y1, d/tdw, 0 )
  2986.                 RwVertexUV( x2,      floor+h, y2, 0, 0 )
  2987.  
  2988.                 RwVertexUV( x1, floor,   y2,   0, h/th )
  2989.                 RwVertexUV( x1, floor+h, y2,   0,    0 )
  2990.                 RwVertexUV( x2, floor+h, y2, w/tww,   0 )
  2991.                 RwVertexUV( x2, floor,   y2, w/tww, h/th)
  2992.                 RwVertexUV( x2-temp2,        floor,      y2, (w-temp2)/tww , h/th )
  2993.                 RwVertexUV( x2-temp2,        floor+door, y2, (w-temp2)/tww , (h-door)/th )
  2994.                 RwVertexUV( x2-temp2-door,   floor+door, y2, (w-temp2-door)/tww , (h-door)/th )
  2995.                 RwVertexUV( x2-temp2-door,   floor,      y2, (w-temp2-door)/tww , h/th )
  2996.                 RwVertexUV( x2-temp2-2*door, floor,      y2, (w-temp2-2*door)/tww , h/th )
  2997.                 RwVertexUV( x2-temp2-2*door, floor+door, y2, (w-temp2-2*door)/tww , (h-door)/th )
  2998.                 RwVertexUV( x2-temp2-3*door, floor+door, y2, (w-temp2-3*door)/tww , (h-door)/th )
  2999.                 RwVertexUV( x2-temp2-3*door, floor,      y2, (w-temp2-3*door)/tww , h/th )
  3000.  
  3001.                 RwPolygon( [6,5,4,3,2,1] )
  3002.                 RwPolygon( [10,9,8,7] )
  3003.                 RwPolygon( [18,17,16,15,14,13,12,11] )
  3004.                 RwPolygon( [19,20,21,22,23,24,25,26,27,28,29,30] )
  3005.             RwProtoEnd()
  3006.  
  3007.             RwIdentityCTM()
  3008.             if r = 0 then
  3009.                 RwTranslateCTM( thisx, 0, thisy)
  3010.                 RwRotateCTM( 0,1,0,0 )
  3011.             elsif r = 4 then
  3012.                 RwTranslateCTM( thisx+d, 0, thisy)
  3013.                 RwRotateCTM( 0,1,0,-90)
  3014.             elsif r = 8 then
  3015.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  3016.                 RwRotateCTM( 0,1,0,180)
  3017.             elsif r = 12 then
  3018.                 RwTranslateCTM( thisx, 0, thisy+w)
  3019.                 RwRotateCTM( 0,1,0,+90)
  3020.             else
  3021.                 print "Illegal rotate code room %d %d ", n, r
  3022.             endif
  3023.  
  3024.             RwClumpBegin()
  3025.                 RwSetHints( hint )
  3026.                 RwProtoInstance( "floor" )
  3027.                 RwProtoInstance( "ceiling" )
  3028.                 RwProtoInstance( "walls" )
  3029.  
  3030.         elsif n = NROOMS+1 then
  3031.             //corner
  3032.             RwProtoBegin("floor1")
  3033.                 RwSetSurface( 0.05, 0.65, 0.0)
  3034.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3035.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3036.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3037.                 RwSetSurfaceLightSampling( rwVERTEX )
  3038.  
  3039.                 RwVertexUV( x1,  floor,y2-1,1,0 )
  3040.                 RwVertexUV( x2-1,floor,y2-1,1,1 )
  3041.                 RwVertexUV( x1,  floor,y2,  0,0 )
  3042.                 RwVertexUV( x2-1,floor,y2,  0,1 )
  3043.  
  3044.                 RwPolygon( [1,3,4,2] )
  3045.  
  3046.                 RwVertexUV( x2-1,floor,y1,  0,0 )
  3047.                 RwVertexUV( x2,  floor,y1,  1,0 )
  3048.                 RwVertexUV( x2-1,floor,y2-1,0,1 )
  3049.                 RwVertexUV( x2,  floor,y2-1,1,1 )
  3050.  
  3051.                 RwPolygon( [5,7,8,6] )
  3052.             RwProtoEnd()
  3053.  
  3054.             RwProtoBegin("floor2")
  3055.                 RwSetSurface( 0.05, 0.65, 0.0)
  3056.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3057.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3058.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3059.                 RwSetSurfaceLightSampling( rwVERTEX )
  3060.  
  3061.                 RwVertexUV( x1,  floor,y1,  0,0 )
  3062.                 RwVertexUV( x2-1,floor,y1,  1,0 )
  3063.                 RwVertexUV( x1,  floor,y2-1,0,1 )
  3064.                 RwVertexUV( x2-1,floor,y2-1,1,1 )
  3065.  
  3066.                 RwPolygon( [1,3,4,2] )
  3067.             RwProtoEnd()
  3068.  
  3069.             RwProtoBegin("ceiling1")
  3070.                 RwSetSurface( 0.05, 0.65, 0.0)
  3071.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3072.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3073.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3074.                 RwSetSurfaceLightSampling( rwVERTEX )
  3075.  
  3076.                 RwVertexUV( x1,  floor+h,y2-1,1,0 )
  3077.                 RwVertexUV( x2-1,floor+h,y2-1,1,1 )
  3078.                 RwVertexUV( x1,  floor+h,y2,  0,0 )
  3079.                 RwVertexUV( x2-1,floor+h,y2,  0,1 )
  3080.  
  3081.                 RwPolygon( [2,4,3,1] )
  3082.  
  3083.                 RwVertexUV( x2-1,floor+h,y1,  0,0 )
  3084.                 RwVertexUV( x2,  floor+h,y1,  1,0 )
  3085.                 RwVertexUV( x2-1,floor+h,y2-1,0,1 )
  3086.                 RwVertexUV( x2,  floor+h,y2-1,1,1 )
  3087.  
  3088.                 RwPolygon( [6,8,7,5] )
  3089.             RwProtoEnd()
  3090.  
  3091.             RwProtoBegin("ceiling2")
  3092.                 RwSetSurface( 0.05, 0.65, 0.0)
  3093.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3094.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3095.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3096.                 RwSetSurfaceLightSampling( rwVERTEX )
  3097.  
  3098.                 RwVertexUV( x1,  floor+h,y1,  0,0 )
  3099.                 RwVertexUV( x2-1,floor+h,y1,  1,0 )
  3100.                 RwVertexUV( x1,  floor+h,y2-1,0,1 )
  3101.                 RwVertexUV( x2-1,floor+h,y2-1,1,1 )
  3102.  
  3103.                 RwPolygon( [2,4,3,1] )
  3104.             RwProtoEnd()
  3105.  
  3106.             RwProtoBegin("walls")
  3107.                 RwSetSurface( 0.05, 0.65, 0.0)
  3108.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3109.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  3110.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3111.                 RwSetSurfaceLightSampling( rwVERTEX )
  3112.  
  3113.                 RwVertexUV( x1,  floor,y2,  d,h )//1
  3114.                 RwVertexUV( x1,  floor,y1,  0,h )
  3115.                 RwVertexUV( x2,  floor,y1,  w,h )
  3116.                 RwVertexUV( x2-1,floor,y2,  1,h )
  3117.                 RwVertexUV( x2-1,floor,y2-1,0,h )
  3118.                 RwVertexUV( x2,  floor,y2-1,1,h )
  3119.  
  3120.                 RwVertexUV( x1,  floor+h,y2,  d,0 )//1
  3121.                 RwVertexUV( x1,  floor+h,y1,  0,0 )
  3122.                 RwVertexUV( x2,  floor+h,y1,  w,0 )
  3123.                 RwVertexUV( x2-1,floor+h,y2,  1,0 )
  3124.                 RwVertexUV( x2-1,floor+h,y2-1,0,0 )
  3125.                 RwVertexUV( x2,  floor+h,y2-1,1,0 )
  3126.  
  3127.                 RwQuad( 1 2 8 7 )
  3128.                 RwQuad( 2 3 9 8 )
  3129.                 RwQuad( 6 5 11 12)
  3130.                 RwQuad( 5 4 10 11)
  3131.  
  3132.             RwProtoEnd()
  3133.  
  3134.             RwIdentityCTM()
  3135.             if r = 0 then
  3136.                 RwTranslateCTM( thisx, 0, thisy+d)
  3137.                 RwRotateCTM( 0,1,0,90 )
  3138.             elsif r = 4 then
  3139.                 RwTranslateCTM( thisx, 0, thisy)
  3140.                 RwRotateCTM( 0,1,0,0)
  3141.             elsif r = 8 then
  3142.                 RwTranslateCTM( thisx+w, 0, thisy)
  3143.                 RwRotateCTM( 0,1,0,-90)
  3144.             elsif r = 12 then
  3145.                 RwTranslateCTM( thisx+w, 0, thisy+d)
  3146.                 RwRotateCTM( 0,1,0,180)
  3147.             else
  3148.                 print "Illegal rotate code room %d %d ", n, r
  3149.             endif
  3150.  
  3151.             RwClumpBegin()
  3152.                 RwSetHints( hint )
  3153.                 RwProtoInstance( "floor1" )
  3154.                 RwProtoInstance( "floor2" )
  3155.                 RwProtoInstance( "ceiling1" )
  3156.                 RwProtoInstance( "ceiling2" )
  3157.                 RwProtoInstance( "walls" )
  3158.         elsif n = NROOMS+2 then
  3159.             // T junction
  3160.  
  3161.             RwProtoBegin("walls")
  3162.                 RwSetSurface( 0.05, 0.65, 0.0)
  3163.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3164.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  3165.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3166.                 RwSetSurfaceLightSampling( rwVERTEX )
  3167.  
  3168.                 RwVertexUV( x1,   floor, y1,      0, h) //1
  3169.                 RwVertexUV( x2,   floor, y1,      w, h)
  3170.                 RwVertexUV( x1,   floor, y1+door, 0, h)
  3171.                 RwVertexUV( x1+1, floor, y1+door, 1, h)
  3172.                 RwVertexUV( x1+1, floor, y2,      0, h)
  3173.                 RwVertexUV( x2-1, floor, y2,      w-1, h)
  3174.                 RwVertexUV( x2-1, floor, y1+door, 0, h)
  3175.                 RwVertexUV( x2,   floor, y1+door, w, h)
  3176.  
  3177.                 RwVertexUV( x1,   floor+h, y1,      0, 0) //9
  3178.                 RwVertexUV( x2,   floor+h, y1,      w, 0)
  3179.                 RwVertexUV( x1,   floor+h, y1+door, 0, 0)
  3180.                 RwVertexUV( x1+1, floor+h, y1+door, 1, 0)
  3181.                 RwVertexUV( x1+1, floor+h, y2,      0, 0)
  3182.                 RwVertexUV( x2-1, floor+h, y2,      w-1, 0)
  3183.                 RwVertexUV( x2-1, floor+h, y1+door, 0, 0)
  3184.                 RwVertexUV( x2,   floor+h, y1+door, w, 0)
  3185.  
  3186.  
  3187.                 RwQuad( 1 2 10  9 )
  3188.                 RwQuad( 4 3 11 12 )
  3189.                 RwQuad( 5 4 12 13 )
  3190.                 RwQuad( 7 6 14 15 )
  3191.                 RwQuad( 8 7 15 16 )
  3192.             RwProtoEnd()
  3193.  
  3194.             RwProtoBegin("floor1")
  3195.                 RwSetSurface( 0.05, 0.65, 0.0)
  3196.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3197.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3198.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3199.                 RwSetSurfaceLightSampling( rwVERTEX )
  3200.  
  3201.                 RwVertexUV( x1,   floor, y1,      0, 0) //1
  3202.                 RwVertexUV( x1+1, floor, y1,      1, 0)
  3203.                 RwVertexUV( x1,   floor, y1+door, 0, 1)
  3204.                 RwVertexUV( x1+1, floor, y1+door, 1, 1)
  3205.  
  3206.                 RwVertexUV( x2-1, floor, y1,      0, 0)
  3207.                 RwVertexUV( x2,   floor, y1,      1, 0)
  3208.                 RwVertexUV( x2-1, floor, y1+door, 0, 1)
  3209.                 RwVertexUV( x2,   floor, y1+door, 1, 1)
  3210.  
  3211.                 RwVertexUV( x1+1, floor, y1+door, 1, 0)
  3212.                 RwVertexUV( x1+1, floor, y2,      0, 0)
  3213.                 RwVertexUV( x2-1, floor, y2,      0, 1)
  3214.                 RwVertexUV( x2-1, floor, y1+door, 1, 1)
  3215.  
  3216.                 RwQuad( 1 3 4 2 )
  3217.                 RwQuad( 5 7 8 6 )
  3218.                 RwQuad( 9 10 11 12 )
  3219.             RwProtoEnd()
  3220.  
  3221.             RwProtoBegin("floor2")
  3222.                 RwSetSurface( 0.05, 0.65, 0.0)
  3223.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3224.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3225.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3226.                 RwSetSurfaceLightSampling( rwVERTEX )
  3227.  
  3228.                 RwVertexUV( x1+1, floor, y1,      0, 0)
  3229.                 RwVertexUV( x2-1, floor, y1,      1, 0) //1
  3230.                 RwVertexUV( x2-1, floor, y1+door, 1, 1)
  3231.                 RwVertexUV( x1+1, floor, y1+door, 0, 1)
  3232.  
  3233.                 RwQuad( 4 3 2 1 )
  3234.             RwProtoEnd()
  3235.  
  3236.             RwProtoBegin("ceiling1")
  3237.                 RwSetSurface( 0.05, 0.65, 0.0)
  3238.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3239.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3240.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3241.                 RwSetSurfaceLightSampling( rwVERTEX )
  3242.  
  3243.                 RwVertexUV( x1,   floor+h, y1,      0, 0) //1
  3244.                 RwVertexUV( x1+1, floor+h, y1,      1, 0)
  3245.                 RwVertexUV( x1,   floor+h, y1+door, 0, 1)
  3246.                 RwVertexUV( x1+1, floor+h, y1+door, 1, 1)
  3247.  
  3248.                 RwVertexUV( x2-1, floor+h, y1,      0, 0)
  3249.                 RwVertexUV( x2,   floor+h, y1,      1, 0)
  3250.                 RwVertexUV( x2-1, floor+h, y1+door, 0, 1)
  3251.                 RwVertexUV( x2,   floor+h, y1+door, 1, 1)
  3252.  
  3253.                 RwVertexUV( x1+1, floor+h, y1+door, 1, 0)
  3254.                 RwVertexUV( x1+1, floor+h, y2,      0, 0)
  3255.                 RwVertexUV( x2-1, floor+h, y2,      0, 1)
  3256.                 RwVertexUV( x2-1, floor+h, y1+door, 1, 1)
  3257.  
  3258.                 RwQuad( 2 4 3 1 )
  3259.                 RwQuad( 6 8 7 5 )
  3260.                 RwQuad( 12 11 10 9 )
  3261.             RwProtoEnd()
  3262.  
  3263.             RwProtoBegin("ceiling2")
  3264.                 RwSetSurface( 0.05, 0.65, 0.0)
  3265.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3266.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3267.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3268.                 RwSetSurfaceLightSampling( rwVERTEX )
  3269.  
  3270.                 RwVertexUV( x1+1, floor+h, y1,      0, 0)
  3271.                 RwVertexUV( x2-1, floor+h, y1,      1, 0) //1
  3272.                 RwVertexUV( x2-1, floor+h, y1+door, 1, 1)
  3273.                 RwVertexUV( x1+1, floor+h, y1+door, 0, 1)
  3274.  
  3275.                 RwQuad( 1 2 3 4 )
  3276.             RwProtoEnd()
  3277.  
  3278.             RwIdentityCTM()
  3279.             if r = 0 then
  3280.                 RwTranslateCTM( thisx, 0, thisy)
  3281.                 RwRotateCTM( 0,1,0,0)
  3282.             elsif r = 4 then
  3283.                 RwTranslateCTM( thisx+2, 0, thisy)
  3284.                 RwRotateCTM( 0,1,0,-90)
  3285.             elsif r = 8 then
  3286.                 RwTranslateCTM( thisx+3, 0, thisy+2)
  3287.                 RwRotateCTM( 0,1,0,180)
  3288.             elsif r = 12 then
  3289.                 RwTranslateCTM( thisx, 0, thisy+3)
  3290.                 RwRotateCTM( 0,1,0,90 )
  3291.             else
  3292.                 print "Illegal rotate code room %d %d ", n, r
  3293.             endif
  3294.  
  3295.             RwClumpBegin()
  3296.                 RwSetHints( rwHS )
  3297.                 RwProtoInstance( "floor1" )
  3298.                 RwProtoInstance( "floor2" )
  3299.                 RwProtoInstance( "walls" )
  3300.                 RwProtoInstance( "ceiling1" )
  3301.                 RwProtoInstance( "ceiling2" )
  3302.         elsif n = NROOMS+3 then
  3303.             if r = 0 or r = 4 or r = 8 or r = 12 then
  3304.             // cross junction
  3305.  
  3306.             RwProtoBegin("walls")
  3307.                 RwSetSurface( 0.05, 0.65, 0.0)
  3308.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3309.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  3310.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3311.                 RwSetSurfaceLightSampling( rwVERTEX )
  3312.  
  3313.                 RwVertexUV( x1,      floor, y1+door, 0, h)
  3314.                 RwVertexUV( x1+door, floor, y1+door, 1, h)
  3315.                 RwVertexUV( x1+door, floor, y1,      0, h)
  3316.                 RwVertexUV( x2-door, floor, y1,      0, h)
  3317.                 RwVertexUV( x2-door, floor, y1+door, 1, h)
  3318.                 RwVertexUV( x2,      floor, y1+door, 0, h)
  3319.  
  3320.                 RwVertexUV( x1,      floor, y2-door, 0, h) //7
  3321.                 RwVertexUV( x1+door, floor, y2-door, 1, h)
  3322.                 RwVertexUV( x1+door, floor, y2,      0, h)
  3323.                 RwVertexUV( x2-door, floor, y2,      0, h)
  3324.                 RwVertexUV( x2-door, floor, y2-door, 1, h)
  3325.                 RwVertexUV( x2,      floor, y2-door, 0, h)
  3326.  
  3327.                 RwVertexUV( x1,      floor+h, y1+door, 0, 0) //13
  3328.                 RwVertexUV( x1+door, floor+h, y1+door, 1, 0)
  3329.                 RwVertexUV( x1+door, floor+h, y1,      0, 0)
  3330.                 RwVertexUV( x2-door, floor+h, y1,      0, 0)
  3331.                 RwVertexUV( x2-door, floor+h, y1+door, 1, 0)
  3332.                 RwVertexUV( x2,      floor+h, y1+door, 0, 0)
  3333.  
  3334.                 RwVertexUV( x1,      floor+h, y2-door, 0, 0) //19
  3335.                 RwVertexUV( x1+door, floor+h, y2-door, 1, 0)
  3336.                 RwVertexUV( x1+door, floor+h, y2,      0, 0)
  3337.                 RwVertexUV( x2-door, floor+h, y2,      0, 0)
  3338.                 RwVertexUV( x2-door, floor+h, y2-door, 1, 0)
  3339.                 RwVertexUV( x2,      floor+h, y2-door, 0, 0)
  3340.  
  3341.                 RwQuad( 1 2 14 13 )
  3342.                 RwQuad( 2 3 15 14 )
  3343.                 RwQuad( 4 5 17 16 )
  3344.                 RwQuad( 5 6 18 17 )
  3345.                 RwQuad( 8 7 19 20 )
  3346.                 RwQuad( 9 8 20 21 )
  3347.                 RwQuad( 11 10 22 23)
  3348.                 RwQuad( 12 11 23 24)
  3349.             RwProtoEnd()
  3350.  
  3351.             RwProtoBegin("floor1")
  3352.                 RwSetSurface( 0.05, 0.65, 0.0)
  3353.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3354.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3355.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3356.                 RwSetSurfaceLightSampling( rwVERTEX )
  3357.  
  3358.                 RwVertexUV( x1+door, floor, y1+door, 0, 0)
  3359.                 RwVertexUV( x2-door, floor, y1+door, 0, 1)
  3360.                 RwVertexUV( x2-door, floor, y1,      1, 1)
  3361.                 RwVertexUV( x1+door, floor, y1,      1, 0)
  3362.  
  3363.                 RwVertexUV( x1+door, floor, y2,      0, 0)
  3364.                 RwVertexUV( x2-door, floor, y2,      0, 1)
  3365.                 RwVertexUV( x2-door, floor, y2-door, 1, 1)
  3366.                 RwVertexUV( x1+door, floor, y2-door, 1, 0)
  3367.  
  3368.                 RwQuad( 1 2 3 4 )
  3369.                 RwQuad( 5 6 7 8 )
  3370.  
  3371.                 RwVertexUV( x1,      floor, y1+door, 0, 0 )
  3372.                 RwVertexUV( x1,      floor, y2-door, 0, 1 )
  3373.                 RwVertexUV( x1+door, floor, y2-door, 1, 1 )
  3374.                 RwVertexUV( x1+door, floor, y1+door, 1, 0 )
  3375.  
  3376.                 RwVertexUV( x2,      floor, y1+door, 0, 0 )
  3377.                 RwVertexUV( x2,      floor, y2-door, 0, 1 )
  3378.                 RwVertexUV( x2-door, floor, y2-door, 1, 1 )
  3379.                 RwVertexUV( x2-door, floor, y1+door, 1, 0 )
  3380.  
  3381.                 RwQuad(  9 10 11 12 )
  3382.                 RwQuad( 16 15 14 13 )
  3383.             RwProtoEnd()
  3384.  
  3385.             RwProtoBegin("floor2")
  3386.                 RwSetSurface( 0.05, 0.65, 0.0)
  3387.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3388.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3389.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3390.                 RwSetSurfaceLightSampling( rwVERTEX )
  3391.  
  3392.                 RwVertexUV( x1+door, floor, y1+door, 0, 0)
  3393.                 RwVertexUV( x1+door, floor, y2-door, 0, 1)
  3394.                 RwVertexUV( x2-door, floor, y2-door, 1, 1)
  3395.                 RwVertexUV( x2-door, floor, y1+door, 1, 0)
  3396.  
  3397.                 RwQuad( 1 2 3 4 )
  3398.             RwProtoEnd()
  3399.  
  3400.             RwProtoBegin("ceiling1")
  3401.                 RwSetSurface( 0.05, 0.65, 0.0)
  3402.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3403.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3404.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3405.                 RwSetSurfaceLightSampling( rwVERTEX )
  3406.  
  3407.                 RwVertexUV( x1+door, floor+h, y1+door, 0, 0)
  3408.                 RwVertexUV( x2-door, floor+h, y1+door, 0, 1)
  3409.                 RwVertexUV( x2-door, floor+h, y1,      1, 1)
  3410.                 RwVertexUV( x1+door, floor+h, y1,      1, 0)
  3411.  
  3412.                 RwVertexUV( x1+door, floor+h, y2,      0, 0)
  3413.                 RwVertexUV( x2-door, floor+h, y2,      0, 1)
  3414.                 RwVertexUV( x2-door, floor+h, y2-door, 1, 1)
  3415.                 RwVertexUV( x1+door, floor+h, y2-door, 1, 0)
  3416.  
  3417.                 RwQuad( 4 3 2 1 )
  3418.                 RwQuad( 8 7 6 5 )
  3419.  
  3420.                 RwVertexUV( x1,      floor+h, y1+door, 0, 0 )
  3421.                 RwVertexUV( x1,      floor+h, y2-door, 0, 1 )
  3422.                 RwVertexUV( x1+door, floor+h, y2-door, 1, 1 )
  3423.                 RwVertexUV( x1+door, floor+h, y1+door, 1, 0 )
  3424.  
  3425.                 RwVertexUV( x2,      floor+h, y1+door, 0, 0 )
  3426.                 RwVertexUV( x2,      floor+h, y2-door, 0, 1 )
  3427.                 RwVertexUV( x2-door, floor+h, y2-door, 1, 1 )
  3428.                 RwVertexUV( x2-door, floor+h, y1+door, 1, 0 )
  3429.  
  3430.                 RwQuad( 12 11 10  9 )
  3431.                 RwQuad( 13 14 15 16 )
  3432.             RwProtoEnd()
  3433.  
  3434.             RwProtoBegin("ceiling2")
  3435.                 RwSetSurface( 0.05, 0.65, 0.0)
  3436.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3437.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3438.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3439.                 RwSetSurfaceLightSampling( rwVERTEX )
  3440.  
  3441.                 RwVertexUV( x1+door, floor+h, y1+door, 0, 0)
  3442.                 RwVertexUV( x1+door, floor+h, y2-door, 0, 1)
  3443.                 RwVertexUV( x2-door, floor+h, y2-door, 1, 1)
  3444.                 RwVertexUV( x2-door, floor+h, y1+door, 1, 0)
  3445.  
  3446.                 RwQuad( 4 3 2 1 )
  3447.             RwProtoEnd()
  3448.  
  3449.             RwIdentityCTM()
  3450.             if (r %4) = 0 then
  3451.                 RwTranslateCTM( thisx, 0, thisy)
  3452.             else
  3453.                 print "Illegal rotate code room %d %d ", n, r
  3454.             endif
  3455.  
  3456.             RwClumpBegin()
  3457.                 RwSetHints( hint )
  3458.                 RwProtoInstance( "floor1" )
  3459.                 RwProtoInstance( "floor2" )
  3460.                 RwProtoInstance( "walls" )
  3461.                 RwProtoInstance( "ceiling1" )
  3462.                 RwProtoInstance( "ceiling2" )
  3463.             endif
  3464.         elsif n = NROOMS+4 then
  3465.             //straight corridor
  3466.             if r = 0 or r = 8 then
  3467.             RwProtoBegin("floor")
  3468.                 RwSetSurface( 0.05, 0.65, 0.0)
  3469.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3470.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3471.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3472.                 RwSetSurfaceLightSampling( rwVERTEX )
  3473.  
  3474.                 RwVertexUV( x1,  floor,y1,0,0 )
  3475.                 RwVertexUV( x2,  floor,y1,w,0 )
  3476.                 RwVertexUV( x1,  floor,y2,0,d )
  3477.                 RwVertexUV( x2,  floor,y2,w,d )
  3478.  
  3479.                 RwPolygon( [1,3,4,2] )
  3480.             RwProtoEnd()
  3481.  
  3482.             RwProtoBegin("ceiling")
  3483.                 RwSetSurface( 0.05, 0.65, 0.0)
  3484.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3485.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3486.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3487.                 RwSetSurfaceLightSampling( rwVERTEX )
  3488.  
  3489.                 RwVertexUV( x1,  floor+h,y1,0,0 )
  3490.                 RwVertexUV( x2,  floor+h,y1,w,0 )
  3491.                 RwVertexUV( x1,  floor+h,y2,0,d )
  3492.                 RwVertexUV( x2,  floor+h,y2,w,d )
  3493.  
  3494.                 RwPolygon( [1,2,4,3] )
  3495.             RwProtoEnd()
  3496.  
  3497.             RwProtoBegin("walls")
  3498.                 RwSetSurface( 0.05, 0.65, 0.0)
  3499.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3500.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  3501.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3502.                 RwSetSurfaceLightSampling( rwVERTEX )
  3503.  
  3504.                 RwVertexUV( x1,  floor,  y1,0,h )//1
  3505.                 RwVertexUV( x2,  floor,  y1,w,h )
  3506.                 RwVertexUV( x1,  floor+h,y1,0,0 )
  3507.                 RwVertexUV( x2,  floor+h,y1,w,0 )
  3508.  
  3509.                 RwVertexUV( x1,  floor,  y2,0,h )//1
  3510.                 RwVertexUV( x2,  floor,  y2,w,h )
  3511.                 RwVertexUV( x1,  floor+h,y2,0,0 )
  3512.                 RwVertexUV( x2,  floor+h,y2,w,0 )
  3513.  
  3514.                 RwQuad( 1 2 4 3 )
  3515.                 RwQuad( 6 5 7 8 )
  3516.             RwProtoEnd()
  3517.  
  3518.             RwIdentityCTM()
  3519.             RwTranslateCTM( thisx, 0, thisy)
  3520.  
  3521.             RwClumpBegin()
  3522.                 RwSetHints( hint )
  3523.                 RwProtoInstance( "floor" )
  3524.                 RwProtoInstance( "ceiling" )
  3525.                 RwProtoInstance( "walls" )
  3526.             elsif r = 4 or r = 12 then
  3527.  
  3528.                 //swap these back
  3529.                 temp = d
  3530.                 d = w
  3531.                 w = temp
  3532.                 x2 = x1+w-roomsep
  3533.                 y2 = y1+d-roomsep
  3534.  
  3535.             RwProtoBegin("floor")
  3536.                 RwSetSurface( 0.05, 0.65, 0.0)
  3537.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3538.                 RwSetSurfaceTexture( TextureList[ThisRoomFloorTexture] )
  3539.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3540.                 RwSetSurfaceLightSampling( rwVERTEX )
  3541.  
  3542.                 RwVertexUV( x1,  floor,y1,d,0 )
  3543.                 RwVertexUV( x2,  floor,y1,d,w )
  3544.                 RwVertexUV( x1,  floor,y2,0,0 )
  3545.                 RwVertexUV( x2,  floor,y2,0,w )
  3546.  
  3547.                 RwPolygon( [1,3,4,2] )
  3548.             RwProtoEnd()
  3549.  
  3550.             RwProtoBegin("ceiling")
  3551.                 RwSetSurface( 0.05, 0.65, 0.0)
  3552.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3553.                 RwSetSurfaceTexture( TextureList[ThisRoomCeilingTexture] )
  3554.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3555.                 RwSetSurfaceLightSampling( rwVERTEX )
  3556.  
  3557.                 RwVertexUV( x1,  floor+h,y1,d,0 )
  3558.                 RwVertexUV( x2,  floor+h,y1,d,w )
  3559.                 RwVertexUV( x1,  floor+h,y2,0,0 )
  3560.                 RwVertexUV( x2,  floor+h,y2,0,w )
  3561.  
  3562.                 RwPolygon( [1,2,4,3] )
  3563.             RwProtoEnd()
  3564.  
  3565.             RwProtoBegin("walls")
  3566.                 RwSetSurface( 0.05, 0.65, 0.0)
  3567.                 RwSetSurfaceColor( 0.8, 0.5, 0.0 )
  3568.                 RwSetSurfaceTexture( TextureList[ThisRoomWallTexture] )
  3569.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3570.                 RwSetSurfaceLightSampling( rwVERTEX )
  3571.  
  3572.                 RwVertexUV( x1,  floor,  y1,0,h )//1
  3573.                 RwVertexUV( x1,  floor,  y2,d,h )
  3574.                 RwVertexUV( x1,  floor+h,y1,0,0 )
  3575.                 RwVertexUV( x1,  floor+h,y2,d,0 )
  3576.  
  3577.                 RwVertexUV( x2,  floor,  y1,0,h )//1
  3578.                 RwVertexUV( x2,  floor,  y2,d,h )
  3579.                 RwVertexUV( x2,  floor+h,y1,0,0 )
  3580.                 RwVertexUV( x2,  floor+h,y2,d,0 )
  3581.  
  3582.                 RwQuad( 1 3 4 2)
  3583.                 RwQuad( 5 6 8 7 )
  3584.             RwProtoEnd()
  3585.  
  3586.             RwIdentityCTM()
  3587.             RwTranslateCTM( thisx, 0, thisy)
  3588.  
  3589.             RwClumpBegin()
  3590.                 RwSetHints( hint )
  3591.                 RwProtoInstance( "floor" )
  3592.                 RwProtoInstance( "ceiling" )
  3593.                 RwProtoInstance( "walls" )
  3594.             endif
  3595.         endif
  3596.  
  3597.         clump = RwRootClumpEnd( clump )
  3598.         RwModelEnd()
  3599.         return clump
  3600.     end function
  3601.  
  3602.     boolean TimerActive, destroyed
  3603.  
  3604.     sub printmat( name as string, mat as RwMatrix4d )
  3605.         local
  3606.             int i
  3607.             RwReal elem[4][4]
  3608.         endlocal
  3609.  
  3610.         RwGetMatrixElements( mat, elem )
  3611.         print name, "\n"
  3612.         for i = 0 to 3 loop
  3613.             print using "(%s, %s, %s, %s)\n", ftostr( elem[i][0], "%f" ), ftostr( elem[i][1], "%f" ), ftostr( elem[i][2], "%f" ), ftostr( elem[i][3], "%f" )
  3614.         endloop
  3615.     endsub
  3616.  
  3617.  
  3618.     function RANDOM_REAL (lmin as RwReal, lmax as RwReal ) as RwReal
  3619.         return lmin + (float(RwRandom()&%x7fff) * 1.0/32768.0) * (lmax - lmin)
  3620.     endfunction
  3621.  
  3622.     function RANDOM_INT(lmin as int, lmax as int) as int
  3623.         return (lmin + (16383 + (RwRandom() & %x7fff) * (lmax - lmin))) >> 15
  3624.     endfunction
  3625.  
  3626.     var
  3627.         dfile as int=1
  3628.     const
  3629.  
  3630.     /* Default size of the viewer's window. */
  3631.     DEFAULT_WINDOW_WIDTH    as int=419//322
  3632.     DEFAULT_WINDOW_HEIGHT   as int=372//246
  3633.  
  3634.     /* Maximum size of the viewer's window. */
  3635.     MAXIMUM_WINDOW_WIDTH    as int=419//640
  3636.     MAXIMUM_WINDOW_HEIGHT   as int=372//480
  3637.  
  3638.     /* What kind of action to take on mouse events. */
  3639.     int MMNoAction=0, MMPanAndZoomCamera =1, MMTiltCamera =2, MMRotateClump=3, MMMoveClump=4
  3640.  
  3641.  
  3642.     var
  3643.         boolean ThreeDInitialized 
  3644.  
  3645.         boolean Shrink
  3646.         boolean Fast=false
  3647.         int VScale = SlowScale
  3648.         boolean MapOn= false
  3649.  
  3650. /* Global RenderWare object pointers. */
  3651.         RwScene *Scene, *AdjacentRenderScene
  3652.         RwCamera *Camera
  3653.         RwLight *RoomLight1, *RoomLight2
  3654.         RwClump *DragClump
  3655.  
  3656.         RwClump *RedDoorClump, *GreenDoorClump, *BlueDoorClump
  3657.  
  3658.         fforward as RwReal
  3659.         pan as RwReal
  3660.  
  3661.         MouseMoveMode as int = MMNoAction;
  3662.  
  3663.     var
  3664.  
  3665.         FirstX as int
  3666.         FirstY as int
  3667.         SX as int
  3668.         SY as int
  3669.         LastX as int
  3670.         LastY as int
  3671.  
  3672.  
  3673. sub SetViewport( vscale as int )
  3674. local
  3675.     int w, h
  3676. endlocal
  3677.  
  3678.     WinGetClientRect w, h;
  3679.     RwSetCameraViewport(Camera, 0, 0, w/vscale, h/vscale );
  3680.     RwSetCameraBackdropViewportRect(Camera, 0, 0, w/vscale, h/vscale );
  3681. endsub
  3682.  
  3683.  
  3684. sub fast_ ClearMap( )
  3685.     local
  3686.         int x, y
  3687.     endlocal
  3688.  
  3689.     for x = 0 to maxx-1 loop
  3690.         for y = 0 to maxy-1 loop
  3691.             bigarray[y][x] = -1
  3692.             walls[y][x] = 0
  3693.         endfor
  3694.     endfor
  3695. end sub
  3696.  
  3697. sub fast_ MakeMap( level as int )
  3698.     local
  3699.         int r, x, y
  3700.     endlocal
  3701.  
  3702.     for r = 0 to high(RoomType) loop
  3703.         if RoomLevel[r] = level then
  3704.             for x = roomx[r] to roomx[r]+roomw[r]-1 loop
  3705.                 for y = roomy[r] to roomy[r]+roomd[r]-1 loop
  3706. //                    bigarray[99-y][x] = r
  3707.                     bigarray[y][x] = r
  3708.                 endfor
  3709.             endfor
  3710.         endif
  3711.     end for
  3712. end sub
  3713.  
  3714.  
  3715. function SetPolygonColour( poly as RwPolygon3d r as int g as int b as int ) as RwPolygon3d
  3716.     RwSetPolygonColor( poly, r, g, b )
  3717.     return poly
  3718. end function
  3719.  
  3720. function fast_ BuildRoomScene( r as int ) as RwScene
  3721.     local
  3722.         RwConvertOptions opts = optPROTOTYPE|optCOMMENTS|optCENTRE|optCOMBINE
  3723.         int rx1 = RoomX[r], ry1 = RoomY[r], rx2 = rx1+RoomW[r], ry2 = ry1+RoomD[r]
  3724.         int i, index=RoomObjectsIndex[r]
  3725.         int aji = RoomAdjacent[r]
  3726.         int onum, dt
  3727.         int dx, dy, h
  3728.         RwClump *clump
  3729.         RwScene *scene
  3730.         RwClump *DoorClump
  3731.         float scale
  3732.     endlocal
  3733.  
  3734.     Set3dsConvertOptions opts|optNORMALIZE, optTEXTUREEXT|optTEXTURE|optFORESHORTEN, optHS, 1.0, 1.0, 0.3, 0.59, 0.11, 0.5
  3735.  
  3736.     scene = RwCreateScene()
  3737.  
  3738.     for i = 0 to RoomObjectsCount[r]-1 loop
  3739.         onum = ObjectsList[index+i]
  3740.         fromXYL( ObjectsXYH[index+i], dx, dy, h )
  3741.  
  3742.         clump = null
  3743.         if onum < 0 then
  3744.             //stock object
  3745.             clump = RwCreateSprite( RwGetNamedTexture("stock" + itostr(-onum-1) ) )
  3746.             scale = 0.25
  3747.         elseif onum > 0 and onum <= high(Object3dList)+1 then
  3748.             clump = Rw3dsReadShape(InstallDir + filename(ObjectDir) + `/` +  filename(Object3dList[onum-1]) +`.3ds`)
  3749.             scale = Object3dScale[onum-1]
  3750.         endif
  3751.  
  3752.         RwScaleMatrix( RwScratchMatrix(), scale, scale, scale, rwREPLACE)
  3753.         RwTranslateMatrix( RwScratchMatrix(), RoomX[r]+dx+0.5, floor+h+OBJECTHEIGHT+scale/2, RoomY[r]+dy+0.5, rwPOSTCONCAT )
  3754.  
  3755.         if clump != null then
  3756.             if onum > 0 then
  3757.                 RwSetClumpTag(clump, 2)
  3758.             endif
  3759.  
  3760.             ObjectsClump[index+i] = clump
  3761.             RwTransformClump( clump, RwScratchMatrix(), rwREPLACE )
  3762.             RwAddClumpToScene( scene, clump )
  3763.         endif
  3764.     endfor
  3765.  
  3766.     for i = 0 to RoomDoors[r]-1 loop
  3767.         dt = Adjacent[aji+i] & %xff000000
  3768.         dt>>=24
  3769.  
  3770.         if dt then
  3771.             fromXYL( Adjacent[aji+i], dx, dy, h )
  3772.  
  3773.             //get colour and change code to match ***KEY+1
  3774.             if dt = 1 then
  3775.                 dt = 3
  3776.                 DoorClump = RedDoorClump
  3777.             elseif dt = 2 then
  3778.                 dt = 1
  3779.                 DoorClump = GreenDoorClump
  3780.             elseif dt = 3 then
  3781.                 dt = 2
  3782.                 DoorClump = BlueDoorClump
  3783.             endif
  3784.  
  3785.             clump = RwDuplicateClump( DoorClump )
  3786.             if clump != null then
  3787.                 DoorClumps[aji+i] = clump
  3788.             endif
  3789.  
  3790.             RwIdentityMatrix( RwScratchMatrix() )
  3791.             if dx = rx1-1 then
  3792.                 //left wall door
  3793.                 RwRotateMatrix( RwScratchMatrix(), 0,1,0, 90, rwPOSTCONCAT)
  3794.                 RwTranslateMatrix( RwScratchMatrix(), rx1, floor, dy+1,  rwPOSTCONCAT )
  3795.                 walls[dy][rx1] |= (dt<<13)
  3796.                 walls[dy][rx1-1] |= (dt<<7)
  3797.                 AddElement DoorControlCell (dy*256+rx1)*4+dt-1
  3798.                 AddElement DoorControlCell (dy*256+(rx1-1))*4+dt-1
  3799.                 AddElement DoorControlClump clump
  3800.                 AddElement DoorControlClump clump
  3801.             elseif dx = rx2 then
  3802.                 //right wall door
  3803.                 RwRotateMatrix( RwScratchMatrix(), 0,1,0, -90, rwPOSTCONCAT)
  3804.                 RwTranslateMatrix( RwScratchMatrix(), rx2, floor, dy,  rwPOSTCONCAT )
  3805.                 walls[dy][rx2-1] |= (dt<<7)
  3806.                 walls[dy][rx2] |= (dt<<13)
  3807.                 AddElement DoorControlCell (dy*256+rx2)*4+dt-1
  3808.                 AddElement DoorControlCell (dy*256+(rx2-1))*4+dt-1
  3809.                 AddElement DoorControlClump clump
  3810.                 AddElement DoorControlClump clump
  3811.             elseif dy = ry1-1 then
  3812.                 //top wall door
  3813.                 RwTranslateMatrix( RwScratchMatrix(), dx, floor, ry1,  rwPOSTCONCAT )
  3814.                 walls[ry1][dx] |= (dt<<4)
  3815.                 walls[ry1-1][dx] |= (dt<<10)
  3816.                 AddElement DoorControlCell (ry1*256+dx)*4+dt-1
  3817.                 AddElement DoorControlCell ((ry1-1)*256+dx)*4+dt-1
  3818.                 AddElement DoorControlClump clump
  3819.                 AddElement DoorControlClump clump
  3820.             elseif dy = ry2 then
  3821.                 //bottom wall door
  3822.                 RwRotateMatrix( RwScratchMatrix(), 0,1,0, 180, rwPOSTCONCAT)
  3823.                 RwTranslateMatrix( RwScratchMatrix(), dx+1, floor, ry2,  rwPOSTCONCAT )
  3824.                 walls[ry2-1][dx] |= (dt<<10)
  3825.                 walls[ry2][dx] |= (dt<<4)
  3826.                 AddElement DoorControlCell ((ry2-1)*256+dx)*4+dt-1
  3827.                 AddElement DoorControlCell (ry2*256+dx)*4+dt-1
  3828.                 AddElement DoorControlClump clump
  3829.                 AddElement DoorControlClump clump
  3830.             endif
  3831.  
  3832.             if clump <> null then
  3833.                 RwTransformClump( clump, RwScratchMatrix(), rwREPLACE )
  3834.             endif
  3835.         endif
  3836.     endfor
  3837.  
  3838.     return scene
  3839. end function
  3840.  
  3841.  
  3842. sub fast_ BuildRooms( level as int )
  3843.     local
  3844.         int x, y, r, type
  3845.         RwClump clump
  3846.         int w, f, c, tf, tw, tc, index
  3847.     endlocal
  3848.  
  3849.     for r = 0 to high(RoomType) loop
  3850.         if RoomLevel[r] = level then
  3851.  
  3852.             AddElement RoomsAtThisLevel r
  3853.             type = RoomType[r]
  3854.             BuildWalls( r )
  3855.  
  3856.             index = RoomTextureBits[r]
  3857.             tc = index & 7
  3858.             index>>=3
  3859.             tw = index & 7
  3860.             index>>=3
  3861.             tf = index & 7
  3862.             index>>=3
  3863.             c = index & 127
  3864.             index>>=7
  3865.             w = index & 127
  3866.             index>>=7
  3867.             f = index & 127
  3868.  
  3869.  
  3870.             if tf = 0 then
  3871.                 tf = RoomFloorTexturing
  3872.             endif
  3873.  
  3874.             if tw = 0 then
  3875.                 tw = RoomWallTexturing
  3876.             endif
  3877.  
  3878.             if tc = 0 then
  3879.                 tc = RoomCeilingTexturing
  3880.             endif
  3881.  
  3882. //            print using "tf=%d tw=%d tc=%d\n" , tf, tw, tc
  3883.  
  3884.             if w = 0 then
  3885.                 if type <= NROOMS then
  3886.                     ThisRoomWallTexture = RoomWallTexture
  3887.                 else
  3888.                     ThisRoomWallTexture = LinkWallTexture
  3889.                 endif
  3890.             else
  3891.                 ThisRoomWallTexture = w-1
  3892.             endif
  3893.  
  3894.             if f = 0 then
  3895.                 if type <= NROOMS then
  3896.                     ThisRoomFloorTexture = RoomFloorTexture
  3897.                 else
  3898.                     ThisRoomFloorTexture = LinkFloorTexture
  3899.                 endif
  3900.             else
  3901.                 ThisRoomFloorTexture = f-1
  3902.             endif
  3903.  
  3904.             if c = 0 then
  3905.                 if type <= NROOMS then
  3906.                     ThisRoomCeilingTexture = RoomCeilingTexture
  3907.                 else
  3908.                     ThisRoomCeilingTexture = LinkCeilingTexture
  3909.                 endif
  3910.             else
  3911.                 ThisRoomCeilingTexture = c-1
  3912.             endif
  3913.  
  3914.             clump = BuildRoom( r, tf, tw, tc )
  3915.             room_geometry[r] = clump
  3916.             room_contents[r] = BuildRoomScene( r )
  3917.             if clump = null then
  3918.                 print "Room ", r, " failed\n"
  3919.             else
  3920.                 if RoomType[r] > NROOMS then
  3921.                     RwAddClumpToScene( room_contents[r], clump )
  3922.                 endif
  3923.             endif
  3924.         endif
  3925.     end for
  3926. end sub
  3927.  
  3928.  
  3929. function CreateDoorClump( type as int ) as RwClump
  3930.     local
  3931.         RwClump clump
  3932.         float r=0,g=0,b=0
  3933.         int texi
  3934.     endlocal
  3935.  
  3936.     if type = 0 then
  3937.         r=1
  3938.         texi = RedDoorTexture
  3939.     elseif type = 1 then
  3940.         g=1
  3941.         texi = GreenDoorTexture
  3942.     else
  3943.         b=1
  3944.         texi = BlueDoorTexture
  3945.     endif
  3946.  
  3947.     RwModelBegin()
  3948.         RwClumpBegin()
  3949.             RwSetSurface( 0.75, 0.65, 0.0)
  3950.             RwSetSurfaceColor( r, g, b )
  3951.             RwSetSurfaceMaterialModes( rwDOUBLE )
  3952.             if texi <> -1 then
  3953.                 RwSetSurfaceTexture( TextureList[texi] )
  3954.                 RwSetSurfaceTextureModes( rwFORESHORTEN )
  3955.  
  3956.                 RwVertexUV( 0 0 0, 0 1 )
  3957.                 RwVertexUV( 1 0 0, 1 1 )
  3958.                 RwVertexUV( 1 1 0, 1 0 )
  3959.                 RwVertexUV( 0 1 0, 0 0 )
  3960.             else
  3961.  
  3962.                 RwVertex( 0 0 0 )
  3963.                 RwVertex( 1 0 0 )
  3964.                 RwVertex( 1 1 0 )
  3965.                 RwVertex( 0 1 0 )
  3966.             endif
  3967.  
  3968.             RwQuad( 1 2 3 4 )
  3969.         clump = RwRootClumpEnd( clump )
  3970.     RwModelEnd()
  3971.  
  3972.     return clump
  3973. end function
  3974.  
  3975.  
  3976. sub fast_ MakeObjectSpritesDragable( flag as boolean )
  3977. local
  3978.     int id
  3979.     SpriteFlagBits flags
  3980. endlocal
  3981.  
  3982.     if flag then
  3983.         flags = enabled|visible|dragable
  3984.     else
  3985.         flags = enabled|visible
  3986.     endif
  3987.  
  3988.     for id = GreenKeyItem to MapItem loop
  3989.         if ItemsList[id] then
  3990.             SetSpriteFlags id, flags, unbound
  3991.         endif
  3992.     end loop
  3993. end sub
  3994.  
  3995.  
  3996. sub fast_ HandleSpriteDrop( id as int x as int y as int )
  3997.     local
  3998.         int i, max, onum
  3999.         int index=RoomObjectsIndex[ActionRoom]
  4000.         boolean dropped=false
  4001.         boolean DeleteReqd=false
  4002.         at as RwReal[3]
  4003.     endlocal
  4004.  
  4005.     if x >= WindowRX and x < WindowRX+WindowW*2 and y >= WindowRY and y < WindowRY + WindowH*2 then
  4006.         //drop it on the window
  4007.  
  4008.         if RoomType[ActionRoom] <= NROOMS then
  4009.             max = MaxObjectsPerRoom
  4010.         else
  4011.             max = MaxObjectsPerLink
  4012.         endif
  4013.  
  4014.         for i = 0 to max-1 loop
  4015.             onum = ObjectsList[index+i]
  4016.             if onum = 0 then
  4017.                 //slot empty, can drop here
  4018.  
  4019.                 onum = -id-1
  4020.  
  4021.                 RwGetCameraPosition(Camera, at)
  4022.                 x = INT(at[0])
  4023.                 y = INT(at[2])
  4024.  
  4025.                 RwScaleMatrix( RwScratchMatrix(), 0.25,0.25,0.25, rwREPLACE)
  4026.                 RwTranslateMatrix( RwScratchMatrix(), x+0.5, floor+OBJECTHEIGHT, y+0.5, rwPOSTCONCAT )
  4027.                 ObjectsXYH [index+i] = XYL( x-RoomX[ActionRoom], y-RoomY[ActionRoom], 0 )
  4028.                 ObjectsClump[index+i] = Inventory[id][ItemsList[id]]
  4029.  
  4030.                 ObjectsList[index+i] = onum
  4031.                 RwTransformClump( ObjectsClump[index+i], RwScratchMatrix(), rwREPLACE )
  4032.                 RwAddClumpToScene( room_contents[ActionRoom], ObjectsClump[index+i] )
  4033.                 dropped = true
  4034.                 loopexit
  4035.             endif
  4036.         end for
  4037.     endif
  4038.  
  4039.     if dropped then
  4040.         if --ItemsList[id] = 0 then
  4041.             DeleteReqd = true
  4042.         endif
  4043.     endif
  4044.  
  4045.     if DeleteReqd then
  4046.         DeleteSprite id
  4047.     else
  4048.         //put it back in the interface correctly
  4049.         MoveSpriteTo id, (id*54+36)*2, 422*2
  4050.     endif
  4051. end sub
  4052.  
  4053.  
  4054. sub fast_ PrintArr( a inout int[] )
  4055.     local
  4056.         int i
  4057.     endlocal
  4058.  
  4059.     print "Array \n"
  4060.     for i = 0 to high(a) loop
  4061.         print a[i], '\n'
  4062.     endfor
  4063. end sub
  4064.  
  4065. function fast_ InAdjacentRender( r as int ) as boolean
  4066.     local
  4067.         i as int
  4068.     endlocal
  4069.  
  4070.     for i = 0 to high(AdjacentRender) loop
  4071.         if AdjacentRender[i] = r then
  4072.             return true
  4073.         endif
  4074.     endfor
  4075.  
  4076.     return false
  4077. end function
  4078.  
  4079.  
  4080. function fast_ Local3DInit ( rootpath as filename ) as boolean
  4081. local
  4082.     clump as RwClump
  4083.     cbclump as RwClump
  4084.     cbreal as float
  4085.  
  4086.     x  as int
  4087.     y  as int
  4088.     i  as int
  4089.     int id, dw, r, max, index
  4090.  
  4091.     rectbottom as int
  4092.     rectright as int
  4093.  
  4094.     thiscell as string
  4095.  
  4096.     CType as int
  4097.     BOOL ok, err
  4098.     string str
  4099.  
  4100.     int depth
  4101.  
  4102. endlocal
  4103.  
  4104.  
  4105.     /* set search path so we pick up textures */
  4106.  
  4107.     RwSetShapePath(rootpath + filename(TextureDir), rwREPLACE)
  4108.     RwSetShapePath(rootpath + filename(ObjectDir), rwPOSTCONCAT)
  4109.     RwSetShapePath(`.`, rwPOSTCONCAT)
  4110.  
  4111.     ActionX = StartX
  4112.     ActionY = StartY
  4113.     ActionLevel = StartLevel
  4114.     unit = 1
  4115.     door = unit
  4116.  
  4117.     Scene = RwCreateScene()
  4118.     if (Scene == NULL) then
  4119.         print "Error creating the RenderWare scene\n"
  4120.         return FALSE
  4121.     endif
  4122.     AdjacentRenderScene = RwCreateScene()
  4123.  
  4124.     RoomLight1 = RwCreateLight(rwDIRECTIONAL, -0.5, -1.0, 0.5, 0.5)
  4125.     RoomLight2 = RwCreateLight(rwDIRECTIONAL, -0.5, -1.0, 0.5, 0.5)
  4126.  
  4127.     RedDoorClump = CreateDoorClump(0)
  4128.     GreenDoorClump = CreateDoorClump(1)
  4129.     BlueDoorClump = CreateDoorClump(2)
  4130.  
  4131.     MakeMap(ActionLevel)
  4132.     DeleteElements RoomsAtThisLevel, high(RoomsAtThisLevel)+1
  4133.     BuildRooms( ActionLevel )
  4134.  
  4135.     ActionRoom = bigarray[ActionY][ActionX]
  4136.     RoomVisited[ActionRoom] = 1
  4137.     unit=PlayerMapUnit
  4138.     unit=1
  4139.  
  4140.     DeleteElements AdjacentRender, high(AdjacentRender)+1
  4141.     RwForAllClumpsInScene( AdjacentRenderScene, RwRemoveClumpFromScene(clump), clump )
  4142.  
  4143.     dw = RoomAdjacent[ActionRoom]
  4144.     for i = 1 to RoomDoors[ActionRoom] loop
  4145.         fromXYL( adjacent[dw++] & %x00ffffff, x, y, id )
  4146.         r = FindRoomAtXYL( x, y, ActionLevel, id )
  4147.         AddElement AdjacentRender, r
  4148.  
  4149.         if RoomType[r] <= NROOMS then
  4150.             max = MaxObjectsPerRoom
  4151.         else
  4152.             max = MaxObjectsPerLink
  4153.         endif
  4154.  
  4155.         if Room_Geometry[r] != null then
  4156.             RwAddClumpToScene( AdjacentRenderScene Room_Geometry[r])
  4157.         endif
  4158.  
  4159.         index=RoomObjectsIndex[r]
  4160.         for i = 1 to max loop
  4161.             clump = ObjectsClump[index++]
  4162.             if clump <> null then
  4163.                 RwAddClumpToScene( AdjacentRenderScene clump)
  4164.             endif
  4165.         endfor
  4166.  
  4167.         index=RoomAdjacent[r]
  4168.         for i = 1 to RoomDoors[r] loop
  4169.             clump = DoorClumps[index++]
  4170.             if clump <> null then
  4171.                 RwAddClumpToScene( AdjacentRenderScene clump)
  4172.             endif
  4173.         endfor
  4174.     end for
  4175.  
  4176.     //add the actionroom
  4177.     if ActionRoom >= 0 and ActionRoom <= high(room_geometry) then
  4178.         AddElement AdjacentRender, ActionRoom
  4179.         if Room_Geometry[ActionRoom] != null then
  4180.             RwAddClumpToScene( AdjacentRenderScene Room_Geometry[ActionRoom])
  4181.         endif
  4182.  
  4183.         if RoomType[ActionRoom] <= NROOMS then
  4184.             max = MaxObjectsPerRoom
  4185.         else
  4186.             max = MaxObjectsPerLink
  4187.         endif
  4188.  
  4189.         index=RoomObjectsIndex[ActionRoom]
  4190.         for i = 1 to max loop
  4191.             clump = ObjectsClump[index++]
  4192.             if clump <> null then
  4193.                 RwAddClumpToScene( AdjacentRenderScene clump)
  4194.             endif
  4195.         endfor
  4196.  
  4197.         index=RoomAdjacent[ActionRoom]
  4198.         for i = 1 to RoomDoors[ActionRoom] loop
  4199.             clump = DoorClumps[index++]
  4200.             if clump <> null then
  4201.                 RwAddClumpToScene( AdjacentRenderScene clump)
  4202.             endif
  4203.         endfor
  4204.     endif
  4205.  
  4206.     RwAddLightToScene( AdjacentRenderScene, RoomLight1 )
  4207.  
  4208.     for r = 0 to high(room_geometry) loop
  4209.         if not InAdjacentRender(r) then
  4210.             if room_geometry[r] != null then
  4211.                 if RoomType[r] <= NROOMS then
  4212.                     max = MaxObjectsPerRoom
  4213.                 else
  4214.                     max = MaxObjectsPerLink
  4215.                 endif
  4216.  
  4217.                 RwAddClumpToScene( room_contents[r] Room_Geometry[r])
  4218.  
  4219.                 index=RoomObjectsIndex[r]
  4220.                 for i = 1 to max loop
  4221.                     clump = ObjectsClump[index++]
  4222.                     if clump <> null then
  4223.                         RwAddClumpToScene( room_contents[r] clump)
  4224.                     endif
  4225.                 endfor
  4226.  
  4227.                 index=RoomAdjacent[r]
  4228.                 for i = 1 to RoomDoors[r] loop
  4229.                     clump = DoorClumps[index++]
  4230.                     if clump <> null then
  4231.                         RwAddClumpToScene( room_contents[r] clump)
  4232.                     endif
  4233.                 endfor
  4234.             endif
  4235.         endif
  4236.     endfor
  4237.  
  4238.  
  4239.     SetConvertErrorLevel enabled, rwCONVERTWARN 
  4240.     Camera = RwCreateCamera( MAXIMUM_WINDOW_WIDTH, MAXIMUM_WINDOW_HEIGHT )
  4241.  
  4242.     if Camera == NULL then
  4243.         if RwGetError() == RwErrorCode'E_RW_NOMEM then
  4244.             print "Insufficient memory to create the RenderWare camera\n"
  4245.         else
  4246.             print "Error creating the RenderWare camera\n"
  4247.         endif
  4248.         return FALSE
  4249.     endif
  4250.  
  4251.     RwSetCameraPosition(Camera, ActionX, 0, ActionY )
  4252.  
  4253.     RwSetCameraBackColor(Camera, 0.0, 0.0, 0.0)
  4254.     RwSetCameraBackdropOffset(Camera, 0,0)
  4255.  
  4256.     RwSetCameraViewwindow(Camera, 1.0, 1.0)
  4257.  
  4258.     WinGetClientRect rectright, rectbottom 
  4259.     RwDeviceControl(rwWINSETOUTPUTSIZE, Camera, rectright, rectbottom)
  4260.     RwSetCameraViewport(Camera, 0, 0, rectright/VScale , rectbottom/VScale )
  4261.     RwSetCameraBackdropViewportRect(Camera, 0, 0, rectright/VScale , rectbottom/VScale )
  4262.  
  4263.     RwSetCameraFarClipping( Camera, FarClipping )
  4264.  
  4265.     ThreeDInitialized = TRUE
  4266.  
  4267.     return TRUE
  4268. endfunction
  4269.  
  4270.     sub fast_ TidyUp3D()
  4271.         local
  4272.             int i
  4273.         endlocal
  4274.  
  4275.         for i = 0 to high(room_geometry) loop
  4276.             if room_geometry[i] != null then
  4277.                 RwDestroyClump(room_geometry[i])
  4278.             endif
  4279.         endfor
  4280.  
  4281.         for i = 0 to high(room_contents) loop
  4282.             if room_contents[i] != null then
  4283.                 RwDestroyScene(room_contents[i] )
  4284.             endif
  4285.         endfor
  4286.  
  4287.         RwDestroyCamera(Camera)
  4288.         RwDestroyScene(Scene)
  4289.         RwDestroyScene(AdjacentRenderScene)
  4290.         RwClose
  4291.     endsub
  4292.  
  4293.  
  4294. sub DoRender( drawlist inout int[] )
  4295.     local
  4296.         int r, i, max, index
  4297.         RwClump clump
  4298.     endlocal
  4299.  
  4300.     RwBeginCameraUpdate(Camera)
  4301.  
  4302.     for i = 0 to high(drawlist) loop
  4303.         r = drawlist[i]
  4304.         if not InAdjacentRender(r) then
  4305.             if RoomType[r] <= NROOMS then
  4306.                 RwAddLightToScene( room_contents[r], RoomLight2 )
  4307.                 RwRenderClump( room_geometry[r] )
  4308.                 RwRenderScene( room_contents[r] )
  4309.             else
  4310.                 RwAddLightToScene( room_contents[r], RoomLight2 )
  4311.                 RwRenderScene( room_contents[r] )
  4312.             endif
  4313.         endif
  4314.     endfor
  4315.  
  4316.     RwRenderScene(AdjacentRenderScene)
  4317.     RwEndCameraUpdate(Camera)
  4318.     RwShowCameraImage(Camera)
  4319. endsub
  4320.  
  4321.  
  4322.  
  4323. //sort stuff
  4324. const 
  4325.     int xAxis=0, zAxis=2
  4326. var
  4327.     int FirstAxis, SecondAxis
  4328.  
  4329. function FMaxSMax(r1 as int r2 as int vec inout RwReal[3] ) as int
  4330.     local
  4331.         int nVal1, nVal2
  4332.     endlocal
  4333.  
  4334.     if FirstAxis = xAxis then
  4335.         nVal1 = (RoomX[r2]) - (RoomX[r1]+RoomW[r1])
  4336.         nVal2 = (RoomX[r2]+RoomW[r2]) - (RoomX[r1])
  4337.  
  4338.         if nVal1 >= 0 then
  4339.             return 1
  4340.         elseif nVal2 <= 0 then
  4341.             return -1
  4342.         else
  4343.             return ((RoomY[r2]) - (RoomY[r1]))
  4344.         endif
  4345.     else
  4346.         nVal1 = (RoomY[r1]) - (RoomY[r2]+RoomD[r2])
  4347.         nVal2 = (RoomY[r1]+RoomD[r1]) - (RoomY[r2])
  4348.  
  4349.         if nVal1 >= 0 then
  4350.             return -1
  4351.         elseif nVal2 <= 0 then
  4352.             return 1
  4353.         else
  4354.             return -((RoomX[r1]) - (RoomX[r2]))
  4355.         endif
  4356.     endif
  4357. end function
  4358.  
  4359.  
  4360. function FMinSMax(r1 as int r2 as int vec inout RwReal[3]) as int
  4361.     local
  4362.         int nVal1, nVal2
  4363.     endlocal
  4364.  
  4365.     if FirstAxis = xAxis then
  4366.         nVal1 = (RoomX[r2]) - (RoomX[r1]+RoomW[r1])
  4367.         nVal2 = (RoomX[r2]+RoomW[r2]) - (RoomX[r1])
  4368.  
  4369.         if nVal1 >= 0 then
  4370.             return -1
  4371.         elseif nVal2 <= 0 then
  4372.             return 1
  4373.         else
  4374.             return ((RoomY[r2]) - (RoomY[r1]))
  4375.         endif
  4376.     else
  4377.         nVal1 = (RoomY[r1]) - (RoomY[r2]+RoomD[r2])
  4378.         nVal2 = (RoomY[r1]+RoomD[r1]) - (RoomY[r2])
  4379.  
  4380.         if nVal1 >= 0 then
  4381.             return -1
  4382.         elseif nVal2 <= 0 then
  4383.             return 1
  4384.         else
  4385.             return ((RoomX[r1]+RoomW[r1]) - (RoomX[r2]+RoomW[r2]))
  4386.         endif
  4387.     endif
  4388. end function
  4389.  
  4390.  
  4391. function FMinSMin(r1 as int r2 as int vec inout RwReal[3]) as int
  4392.     local
  4393.         int nVal1, nVal2
  4394.     endlocal
  4395.  
  4396.     if FirstAxis = xAxis then
  4397.         nVal1 = (RoomX[r2]) - (RoomX[r1]+RoomW[r1])
  4398.         nVal2 = (RoomX[r2]+RoomW[r2]) - (RoomX[r1])
  4399.  
  4400.         if nVal1 >= 0 then
  4401.             return -1
  4402.         elseif nVal2 <= 0 then
  4403.             return 1
  4404.         else
  4405.             return -((RoomY[r2]+RoomD[r2]) - (RoomY[r1]+RoomD[r1]))
  4406.         endif
  4407.     else
  4408.         nVal1 = (RoomY[r2]) - (RoomY[r1]+RoomD[r1])
  4409.         nVal2 = (RoomY[r2]+RoomD[r2]) - (RoomY[r1])
  4410.  
  4411.         if nVal1 >= 0 then
  4412.             return -1
  4413.         elseif nVal2 <= 0 then
  4414.             return 1
  4415.         else
  4416.             return -((RoomX[r2]+RoomW[r2]) - (RoomX[r1]+RoomW[r2]))
  4417.         endif
  4418.     endif
  4419. end function
  4420.  
  4421.  
  4422. function FMaxSMin(r1 as int r2 as int vec inout RwReal[3]) as int
  4423.     local
  4424.         int nVal1,nVal2
  4425.     endlocal
  4426.  
  4427.     if FirstAxis = xAxis then
  4428.         nVal1 = (RoomX[r2]) - (RoomX[r1]+RoomW[r1])
  4429.         nVal2 = (RoomX[r2]+RoomW[r2]) - (RoomX[r1])
  4430.  
  4431.         if nVal1 >= 0 then
  4432.             return 1
  4433.         elseif nVal2 <= 0 then
  4434.             return -1
  4435.         else
  4436.             return ((RoomY[r1]+RoomD[r1]) - (RoomY[r2]+RoomD[r2]))
  4437.         endif
  4438.     else
  4439.         nVal1 = (RoomY[r2]) - (RoomY[r1]+RoomD[r1])
  4440.         nVal2 = (RoomY[r2]+RoomD[r2]) - (RoomY[r1])
  4441.  
  4442.         if nVal1 >= 0 then
  4443.             return -1
  4444.         elseif nVal2 <= 0 then
  4445.             return 1
  4446.         else
  4447.             return ((RoomX[r2]) - (RoomX[r1]))
  4448.         endif
  4449.     endif
  4450. end function
  4451.  
  4452.  
  4453. sub fast_ render()
  4454. local
  4455.     pos as RwReal[3]
  4456.     at as RwReal[3]
  4457.     x as int
  4458.     y as int
  4459.     int r1, r2
  4460.  
  4461.     RwClump cbclump
  4462.  
  4463.     int r
  4464. endlocal
  4465.  
  4466.     RwGetCameraPosition(Camera, pos)
  4467.     x = INT(pos[0])
  4468.     y = INT(pos[2])
  4469.     ActionRoom = bigarray[y][x]
  4470.  
  4471.     RwGetCameraLookAt(Camera, at)
  4472.  
  4473.     if fabs(at[0]) > fabs(at[2]) then
  4474.         FirstAxis = xAxis
  4475.         SecondAxis = zAxis
  4476.     else
  4477.         FirstAxis = zAxis
  4478.         SecondAxis = xAxis
  4479.     endif
  4480.  
  4481.     if at[0] < 0 then
  4482.         if at[2] < 0 then
  4483.             sortintuser RoomsAtThisLevel, r1, r2, FMinSMin(r1, r2, pos)
  4484.         else
  4485.             sortintuser RoomsAtThisLevel, r1, r2, FMinSMax(r1, r2, pos)
  4486.         endif
  4487.     else
  4488.         if at[2] < 0 then
  4489.             sortintuser RoomsAtThisLevel, r1, r2, FMaxSMin(r1, r2, pos)
  4490.         else
  4491.             sortintuser RoomsAtThisLevel, r1, r2, FMaxSMax(r1, r2, pos)
  4492.         endif
  4493.     endif
  4494.  
  4495.     DoRender( RoomsAtThisLevel )
  4496. end sub
  4497.  
  4498.  
  4499. sub OpenDoors( x as int y as int )
  4500. local
  4501.     int i, thiscell, dcell
  4502.     RwClump *clump=null
  4503. endlocal
  4504.  
  4505.     thiscell = (y*256+x)*4
  4506.  
  4507.     for i = 0 to high(DoorControlCell) loop
  4508.         dcell = DoorControlCell[i]
  4509.  
  4510.         if (dcell & (~3)) = thiscell and ItemsList[(dcell & 3)] then
  4511.             clump = DoorControlClump[i]
  4512.             if clump != null then
  4513.                 RwSetClumpState( clump, rwOFF )
  4514.             endif
  4515.         endif
  4516.     endfor
  4517. end sub
  4518.  
  4519. sub CloseDoors( x as int y as int )
  4520. local
  4521.     int i, thiscell, dcell
  4522.     RwClump *clump=null
  4523. endlocal
  4524.  
  4525.     thiscell = (y*256+x)*4
  4526.  
  4527.     for i = 0 to high(DoorControlCell) loop
  4528.         dcell = DoorControlCell[i]
  4529.  
  4530.         if (dcell & (~3)) = thiscell then
  4531.             clump = DoorControlClump[i]
  4532.             if clump != null then
  4533.                 RwSetClumpState( clump, rwON )
  4534.             endif
  4535.         endif
  4536.     endfor
  4537. end sub
  4538.  
  4539.  
  4540. sub moveforward(fforward as RwReal)
  4541. local
  4542.     pos1 as RwReal[3]
  4543.     pos2 as RwReal[3]
  4544.     at   as RwReal[3]
  4545.  
  4546.     x1 as int
  4547.     y1 as int
  4548.     x2 as int
  4549.     y2 as int
  4550.     dbounce as int
  4551.     dbp as RwReal
  4552.     boolean bump=false
  4553.     int timesincebump
  4554.  
  4555.     RwClump *clump
  4556.  
  4557.     int oldroom, type
  4558.     int i, index, count
  4559.     int onum, max
  4560.     int x, y, h, dcol, r
  4561.     filename res
  4562.     int dw, id, bonus
  4563.     int CellWalls
  4564.  
  4565.     string pos
  4566.     float angle
  4567. endlocal
  4568.  
  4569.     RwGetCameraPosition(Camera, pos1)
  4570.     x1 = INT(pos1[0])
  4571.     y1 = INT(pos1[2])
  4572.     RwGetCameraLookAt(Camera, at)
  4573.  
  4574.     oldroom = ActionRoom
  4575.  
  4576.     //attempt to move
  4577.     if (fforward != 0) then
  4578.         RwWCMoveCamera(Camera, (at[0]*fforward), dbp, (at[2]*fforward))
  4579.     endif
  4580.  
  4581.     RwGetCameraPosition(Camera, pos2)
  4582.     x2 = INT(pos2[0])
  4583.     y2 = INT(pos2[2])
  4584.  
  4585.  
  4586.     //check for doors present first
  4587.     CellWalls = walls[y1][x1]
  4588.     dw = CellWalls>>4
  4589.  
  4590.     if dw then
  4591.         //we have at least one door in this cell
  4592.         count = 1
  4593.         for i = 0 to 3 loop
  4594.             dcol = dw & 7
  4595.             if dcol-- then
  4596.                 //this is a door, 1=g,2=b,3=r
  4597.                 if not ItemsList[dcol] then
  4598.                     CellWalls |= count
  4599.                 endif
  4600.             endif
  4601.  
  4602.             dw>>=3
  4603.             count<<=1
  4604.         endfor
  4605.     endif
  4606.  
  4607.  
  4608.     // constrain movement based upon cell walls 
  4609.     if (INT(pos2[0] - CLOSEST) < x1 && (CellWalls/*walls[y1][x1]*/ & WEST)) then
  4610.         pos2[0] = float(INT(pos1[0]))
  4611.         pos2[0] += CLOSEST
  4612.         bump = true
  4613.     endif
  4614.  
  4615.     if (INT(pos2[0] + CLOSEST) > x1 && (CellWalls/*walls[y1][x1]*/ & EAST)) then    
  4616.         pos2[0] = float(INT(pos1[0]) + 1)
  4617.         pos2[0] -= CLOSEST
  4618.         bump = true
  4619.     endif
  4620.  
  4621.     if (INT(pos2[2] - CLOSEST) < y1 && (CellWalls/*walls[y1][x1]*/ & NORTH)) then
  4622.         pos2[2] = float(INT(pos1[2]))
  4623.         pos2[2] += CLOSEST
  4624.         bump = true
  4625.     endif
  4626.  
  4627.     if (INT(pos2[2] + CLOSEST) > y1 && (CellWalls/*walls[y1][x1]*/ & SOUTH)) then
  4628.         pos2[2] = float(INT(pos1[2]) + 1)
  4629.         pos2[2] -= CLOSEST
  4630.         bump = true
  4631.     endif
  4632.  
  4633.     // special case diagonal move which causes problems 
  4634.     if ((x1 != x2) && (y1 != y2)) then
  4635.         if (y2 > y1) then
  4636.             if (walls[y2-1][x2] & SOUTH) then
  4637.                 pos2[2] = float(INT(pos1[2]) + 1)
  4638.                 pos2[2] -= CLOSEST
  4639.                 bump = true
  4640.             endif
  4641.         else
  4642.             if (walls[y2+1][x2] & NORTH) then
  4643.                 pos2[2] = float(INT(pos1[2]))
  4644.                 pos2[2] += CLOSEST
  4645.                 bump = true
  4646.             endif
  4647.         endif
  4648.     endif
  4649.  
  4650.     timesincebump+=TimerTick
  4651.     if bump and timesincebump > bumprepeat then
  4652.         if SoundEffectFlags & 1 then
  4653.             audio wav, filename(OooffSound)
  4654.         endif
  4655.         timesincebump = 0
  4656.     endif
  4657.  
  4658.     ifc ( pos2[0] < 0 )
  4659.         pos2[0] = 0
  4660.  
  4661.     ifc ( pos2[0] > maxx )
  4662.         pos2[0] = maxx
  4663.  
  4664.     ifc ( pos2[2] < 0 )
  4665.         pos2[2] = 0
  4666.  
  4667.     ifc ( pos2[2] > maxy )
  4668.         pos2[2] = maxy
  4669.  
  4670.  
  4671.     RwSetCameraPosition(Camera, pos2[0], pos2[1], pos2[2] )
  4672.  
  4673.     x2 = INT(pos2[0])
  4674.     y2 = INT(pos2[2])
  4675.     ActionRoom = bigarray[y2][x2]
  4676.  
  4677.     if x1 <> x2 or y1 <> y2 then
  4678.         //new cell stuff
  4679.  
  4680.         CloseDoors( x1, y1 )
  4681.         OpenDoors( x2, y2 )
  4682.         index=RoomObjectsIndex[ActionRoom]
  4683.  
  4684.         if RoomType[ActionRoom] <= NROOMS then
  4685.             max = MaxObjectsPerRoom
  4686.         else
  4687.             max = MaxObjectsPerLink
  4688.         endif
  4689.  
  4690.         for i = 0 to max-1 loop
  4691.             onum = ObjectsList[index+i]
  4692.             if onum < 0 then
  4693.                 //can collect, so do special processing
  4694.  
  4695.                 onum = -onum-1
  4696.  
  4697.                 fromXYL( ObjectsXYH[index+i], x, y, h )
  4698.                 x+=RoomX[ActionRoom]
  4699.                 y+=RoomY[ActionRoom]
  4700.  
  4701.                 if x2 = x and y2 = y then
  4702.                     id = onum    //+1 until we have a green key
  4703.  
  4704.                     if id = EndItem then
  4705.                         EndReached = true
  4706.                     elsif id > SpeedItem then
  4707.                         ObjectsList[index+i] = 0
  4708.                         RwSetClumpState( ObjectsClump[index+i], rwOFF )
  4709.                         // this is a score bonus
  4710.                         bonus = 10000
  4711.                         while id > SpeedItem loop
  4712.                             id--
  4713.                             bonus/=10
  4714.                         endwhile
  4715.  
  4716.                         ShowScore(bonus)
  4717.                     elseif id = TimeBonusItem then
  4718.                         ObjectsList[index+i] = 0
  4719.                         RwSetClumpState( ObjectsClump[index+i], rwOFF )
  4720.                         ShowTime( +TIMEBONUS )
  4721.                     else
  4722.                         if ++ItemsList[id] <= MAXINVENTORY then
  4723.                             Inventory[id][ItemsList[id]] = ObjectsClump[index+i]
  4724.  
  4725.                             ObjectsList[index+i] = 0
  4726.                             RwSetClumpState( ObjectsClump[index+i], rwOFF )
  4727.                             if ItemsList[id] = 1 then
  4728.                                 CreateSprite id, (id*53+36)*2, 422*2, oneshot, 0, 0, 1, [onum]
  4729.                                 if id <= MapItem then
  4730.                                     SetSpriteFlags id, enabled|visible|dragable, unbound
  4731.                                 else
  4732.                                     SetSpriteFlags id, enabled|visible, unbound
  4733.                                 endif
  4734.                             endif
  4735.                         else
  4736.                             --ItemsList[id]
  4737.                         endif
  4738.                     endif
  4739.  
  4740.                     if SoundEffectFlags & 4 and id <> EndItem then
  4741.                         mci ( `close trev`, res )
  4742.                         mci ( `open waveaudio!`+filename(CollectSound)+` alias trev wait`, res )
  4743.                         mci ( `play trev`, res )
  4744.                     endif
  4745.                 endif    
  4746.             endif
  4747.         endfor
  4748.     endif
  4749.  
  4750.     if oldroom <> ActionRoom then
  4751.         //new room
  4752.  
  4753.         DeleteElements AdjacentRender, high(AdjacentRender)+1
  4754.         RwForAllClumpsInScene( AdjacentRenderScene, RwRemoveClumpFromScene(clump), clump )
  4755.  
  4756.         dw = RoomAdjacent[ActionRoom]
  4757.         for i = 1 to RoomDoors[ActionRoom] loop
  4758.             fromXYL( adjacent[dw++] & %x00ffffff, x, y, id )
  4759.             r = FindRoomAtXYL( x, y, ActionLevel, id )
  4760.             AddElement AdjacentRender, r
  4761.  
  4762.             if RoomType[r] <= NROOMS then
  4763.                 max = MaxObjectsPerRoom
  4764.             else
  4765.                 max = MaxObjectsPerLink
  4766.             endif
  4767.  
  4768.             if Room_Geometry[r] != null then
  4769.                 RwAddClumpToScene( AdjacentRenderScene Room_Geometry[r])
  4770.             endif
  4771.  
  4772.             index=RoomObjectsIndex[r]
  4773.             for i = 1 to max loop
  4774.                 clump = ObjectsClump[index++]
  4775.                 if clump <> null then
  4776.                     RwAddClumpToScene( AdjacentRenderScene clump)
  4777.                 endif
  4778.             endfor
  4779.  
  4780.             index=RoomAdjacent[r]
  4781.             for i = 1 to RoomDoors[r] loop
  4782.                 clump = DoorClumps[index++]
  4783.                 if clump <> null then
  4784.                     RwAddClumpToScene( AdjacentRenderScene clump)
  4785.                 endif
  4786.             endfor
  4787.         end for
  4788.  
  4789.         //add the actionroom
  4790.         if ActionRoom >= 0 and ActionRoom <= high(room_geometry) then
  4791.             AddElement AdjacentRender, ActionRoom
  4792.             if Room_Geometry[ActionRoom] != null then
  4793.                 RwAddClumpToScene( AdjacentRenderScene Room_Geometry[ActionRoom])
  4794.             endif
  4795.  
  4796.             if RoomType[ActionRoom] <= NROOMS then
  4797.                 max = MaxObjectsPerRoom
  4798.             else
  4799.                 max = MaxObjectsPerLink
  4800.             endif
  4801.  
  4802.             index=RoomObjectsIndex[ActionRoom]
  4803.             for i = 1 to max loop
  4804.                 clump = ObjectsClump[index++]
  4805.                 if clump <> null then
  4806.                     RwAddClumpToScene( AdjacentRenderScene clump)
  4807.                 endif
  4808.             endfor
  4809.  
  4810.             index=RoomAdjacent[ActionRoom]
  4811.             for i = 1 to RoomDoors[ActionRoom] loop
  4812.                 clump = DoorClumps[index++]
  4813.                 if clump <> null then
  4814.                     RwAddClumpToScene( AdjacentRenderScene clump)
  4815.                 endif
  4816.             endfor
  4817.         endif
  4818.  
  4819.         RwAddLightToScene( AdjacentRenderScene, RoomLight1 )
  4820.  
  4821.  
  4822.         for r = 0 to high(room_geometry) loop
  4823.             if not InAdjacentRender(r) then
  4824.                 if room_geometry[r] != null then
  4825.                     if RoomType[r] <= NROOMS then
  4826.                         max = MaxObjectsPerRoom
  4827.                     else
  4828.                         max = MaxObjectsPerLink
  4829.                         RwAddClumpToScene( room_contents[r] Room_Geometry[r])
  4830.                     endif
  4831.  
  4832.                     index=RoomObjectsIndex[r]
  4833.                     for i = 1 to max loop
  4834.                         clump = ObjectsClump[index++]
  4835.                         if clump <> null then
  4836.                             RwAddClumpToScene( room_contents[r] clump)
  4837.                         endif
  4838.                     endfor
  4839.  
  4840.                     index=RoomAdjacent[r]
  4841.                     for i = 1 to RoomDoors[r] loop
  4842.                         clump = DoorClumps[index++]
  4843.                         if clump <> null then
  4844.                             RwAddClumpToScene( room_contents[r] clump)
  4845.                         endif
  4846.                     endfor
  4847.  
  4848.                     RwAddLightToScene( room_contents[r], RoomLight2 )
  4849.                 endif
  4850.             endif
  4851.         endfor
  4852.  
  4853.  
  4854.  
  4855.         if not RoomVisited[ActionRoom] then
  4856.             RoomVisited[ActionRoom] = 1
  4857.             unit=PlayerMapUnit
  4858.             unit=1
  4859.         endif
  4860.  
  4861.         ResetRoomLineColour(oldroom)
  4862.         SetRoomLineColour( ActionRoom, 0, 255, 0 )
  4863.     endif
  4864.  
  4865. endsub
  4866.  
  4867. sub fast_ DoHandleSize(width as int, height as int)
  4868.     RwDeviceControl(rwWINSETOUTPUTSIZE, Camera, width, height)
  4869.     RwSetCameraViewport(Camera, 0, 0, width/VScale, height/VScale)
  4870.     RwSetCameraBackdropViewportRect(Camera, 0,0, width/VScale, height/VScale)
  4871.  
  4872.     /* viewwindow aspect ratio of 1:1 regardless of viewport aspect ratio */
  4873.     if ((width != 0) && (height != 0)) then
  4874.         if (width >= height) then
  4875.             RwSetCameraViewwindow(Camera, 1.0, 1.0*( float(height)/float(width) ) )
  4876.         else
  4877.             RwSetCameraViewwindow(Camera, 1.0*( float(width)/float(height) ), 1.0 )
  4878.         endif
  4879.     endif
  4880.  
  4881.     WinInvalidateRect
  4882. endsub
  4883.     
  4884. function HandleLeftButtonDown(x as int, y as int , vKeys as int ) as BOOL
  4885.     if not ThreeDInitialized then
  4886.         return 1
  4887.     endif
  4888.  
  4889. //    print "LMOUSEDOWN\n"
  4890.  
  4891.     if (vKeys & MK_DEFS'MK_SHIFT) then
  4892.         MouseMoveMode = MMTiltCamera
  4893.     else
  4894.         MouseMoveMode = MMPanAndZoomCamera
  4895.         fforward = 0.0
  4896.         pan = 0.0
  4897.  
  4898.         if !Fast then
  4899.             Vscale = SlowScale
  4900.         endif
  4901.     endif
  4902.  
  4903.     if (MouseMoveMode != MMNoAction) then
  4904.         WinSetCapture
  4905.         LastX = x
  4906.         LastY = y
  4907.         WinClientToScreen LastX, LastY
  4908.  
  4909.         SX = x
  4910.         SY = y
  4911.         WinClientToScreen SX, SY
  4912.     endif
  4913.     return 0
  4914. endfunction
  4915.  
  4916. function HandleRightButtonDown2(x as int, y as int, vkeys as int) as BOOL
  4917. local
  4918.     vx as int
  4919.     vy as int
  4920.     vw as int
  4921.     vh as int
  4922.  
  4923.     XDelta as RwReal
  4924.     YDelta as RwReal
  4925.  
  4926. //pickrecord
  4927.     picktype as RwPickObject
  4928.     pickclump as RwClump
  4929.     pickpolygon as RwPolygon3d
  4930.     vindex as int
  4931.     d2 as int
  4932.     pickx as RwReal
  4933.     picky as RwReal
  4934.     pickz as RwReal
  4935.     tag as int
  4936.     RwScene Scene
  4937. endlocal
  4938.  
  4939.     if not ThreeDInitialized then
  4940.         return 1
  4941.     endif
  4942.  
  4943.     MouseMoveMode = MMNoAction
  4944.  
  4945.     if room_contents[ActionRoom] != null then
  4946.         Scene = room_contents[ActionRoom]
  4947. //    if (Scene != NULL) then
  4948.         RwGetCameraViewport(Camera, vx, vy, vw, vh)
  4949.         x-=vx
  4950.         y-=vy
  4951.  
  4952.         if RwPickScene(Scene, x, y, Camera, picktype, pickclump, pickpolygon, vindex, d2, pickx, picky, pickz) != Scene then
  4953.             return 0
  4954.         endif
  4955.  
  4956.         if (Picktype == RwPickObject'rwPICKCLUMP) then
  4957.             // The objects in the scene which are manipulatable are tagged with 2.
  4958.  
  4959.             tag = RwGetClumpTag(Pickclump)
  4960.             if (tag) then
  4961.                 DragClump = Pickclump
  4962.  
  4963.                 if (tag = 1) then
  4964.                     MouseMoveMode = MMRotateClump
  4965.                 elseif tag = 2 then
  4966.                     MouseMoveMode = MMMoveClump
  4967.                 endif
  4968.             endif
  4969.         endif
  4970.     endif
  4971.  
  4972.     if (MouseMoveMode != MMNoAction) then
  4973.         RwGetCameraViewport(Camera, vx, vy, vw, vh)
  4974.         FirstX = vx + (vw >> 1)
  4975.         FirstY = vy + (vh >> 1)
  4976.         WinClientToScreen FirstX, FirstY
  4977.         LastX = x+vx
  4978.         LastY = y+vy
  4979.         WinClientToScreen LastX, LastY
  4980.         WinSetCapture
  4981.     endif
  4982.  
  4983.     return 0
  4984. endfunction
  4985.  
  4986. function HandleMouseMove(x as int, y as int) as BOOL
  4987. local
  4988.     centrex as int
  4989.     centrey as int
  4990.  
  4991.     foffx as float
  4992.     foffy as float
  4993.     width as int
  4994.     height as int
  4995.     offx as int
  4996.     offy as int
  4997.     boolean DummyBool
  4998.     at as RwReal[3]
  4999.     RwReal hyp, cosangle
  5000.     RwMatrix4d mat, matr
  5001.     RwReal tlate[3]
  5002.     int OldVScale = VScale
  5003.  
  5004.     int dx, dy
  5005.     string tag
  5006.  
  5007. endlocal
  5008.     
  5009.     if not ThreeDInitialized then
  5010.         return 1
  5011.     endif
  5012.  
  5013. //    print "MOUSEMOVE\n"
  5014.  
  5015.     WinClientToScreen x, y
  5016.  
  5017.     RwGetCameraViewport(Camera, DummyBool, DummyBool, width, height)
  5018.     if MouseMoveMode ==  MMNoAction then
  5019.         null
  5020.  
  5021.     elsif MouseMoveMode == MMPanAndZoomCamera then
  5022.         RwGetCameraPosition(Camera, at)
  5023.         dx = INT(at[0])
  5024.         dy = INT(at[2])
  5025.  
  5026.         pan = float(Sx - x) / 20.0
  5027.         fforward = float(Sy - y)/800.0
  5028.  
  5029.         if fforward > WindowH/(1*800.0) then
  5030.             fforward = WindowH/(1*800.0)
  5031.         endif
  5032.  
  5033.         if ItemsList[SpeedItem] > 0 then
  5034.             fforward*=2
  5035.         endif
  5036.  
  5037.     elsif MouseMoveMode == MMTiltCamera then
  5038.         RwRotateMatrix(RwScratchMatrix(), 0.0, 1.0, 0.0, float(LastX - x), rwREPLACE)
  5039.         RwTransformCameraOrientation(Camera, RwScratchMatrix())
  5040.         RwTiltCamera(Camera, float(y - LastY))
  5041.  
  5042.         RwGetCameraBackdropOffset(Camera, offx, offy)
  5043.         RwGetCameraPosition( Camera, at )
  5044.  
  5045.     elsif MouseMoveMode == MMRotateClump then
  5046.         foffx = float(x - LastX)/ float(width)
  5047.         RwPushScratchMatrix()
  5048.         RwRotateMatrix(RwScratchMatrix(), (0.0), (1.0), (0.0), foffx * (180.0), rwREPLACE)
  5049.         RwTransformClumpJoint(DragClump, RwScratchMatrix(), rwPOSTCONCAT)
  5050.         RwPopScratchMatrix()
  5051.     elsif MouseMoveMode == MMMoveClump then
  5052.         foffx = float(x - LastX)/ float(width)
  5053.         foffy = float(y - LastY)/ float(height)
  5054.         RwGetCameraLookAt( Camera, at )
  5055.         hyp = sqrt( at[0]*at[0] + at[2]*at[2] )
  5056.         cosangle = at[2]/hyp
  5057.  
  5058.         if Shrink then
  5059.             tlate[0] = -foffx*16
  5060.             tlate[1] = 0
  5061.             tlate[2] = -foffy*16
  5062.         else
  5063.             tlate[0] = -foffx*4
  5064.             tlate[1] = 0
  5065.             tlate[2] = -foffy*4
  5066.         endif
  5067.             
  5068.         RwPushScratchMatrix()
  5069.         RwRotateMatrixCos( RwScratchMatrix(), 0,1,0, cosangle, at[0], rwREPLACE )
  5070.         RwTransformVector( tlate, RwScratchMatrix() )
  5071.  
  5072.         RwTranslateMatrix( RwScratchMatrix(), tlate[0], 0.0, tlate[2], rwREPLACE)
  5073.         RwTransformClumpJoint(DragClump, RwScratchMatrix(), rwPOSTCONCAT)
  5074.         RwPopScratchMatrix()
  5075.     endif
  5076.  
  5077.     LastX = x
  5078.     LastY = y
  5079.     return 0
  5080. endfunction
  5081.  
  5082. function HandleLeftButtonUp( ) as BOOL
  5083.     if not ThreeDInitialized then
  5084.         return 1
  5085.     endif
  5086.     if (MouseMoveMode != MMNoAction) then
  5087.         MouseMoveMode = MMNoAction
  5088.         fforward = 0.0
  5089.         pan = 0.0
  5090.  
  5091.         if !Fast then
  5092.             Vscale = SlowScale
  5093.         endif
  5094.  
  5095.         WinReleaseCapture
  5096.     endif
  5097.     return 0
  5098. endfunction
  5099.  
  5100.  
  5101. function HandleRightButtonUp( ) as BOOL
  5102.     if not ThreeDInitialized then
  5103.         return 1
  5104.     endif
  5105.     RwSetCameraLookUp(Camera, 0.0, 1.0, 0.0);
  5106.  
  5107.     if (MouseMoveMode != MMNoAction) then
  5108.         MouseMoveMode = MMNoAction
  5109.         fforward = 0.0
  5110.         pan = 0.0
  5111.  
  5112.         if !Fast then
  5113.             Vscale = SlowScale
  5114.         endif
  5115.         WinReleaseCapture
  5116.     endif
  5117.     return 0
  5118. endfunction
  5119.  
  5120. function HandlePaint() as BOOL
  5121. local
  5122.     int w, h
  5123. endlocal
  5124.  
  5125.     if not ThreeDInitialized then
  5126.         return 1
  5127.     endif
  5128.  
  5129.     WinGetClientRect w, h
  5130.     DoHandleSize( w, h )
  5131.  
  5132.     WinBeginPaint
  5133.     RwInvalidateCameraViewport(Camera)
  5134.     render()
  5135.     WinEndPaint
  5136.     return 0
  5137. endfunction
  5138.  
  5139. function fast_ HandleTimer() as BOOL
  5140. local
  5141.     int dx =0, dy =0, tempx, tempy 
  5142.  
  5143.     at as RwReal[3]
  5144.  
  5145.     cbclump as RwClump
  5146.     cbtexture as RwTexture
  5147.     int h,m,s,c
  5148.     int sold
  5149. endlocal
  5150.  
  5151.     if not ThreeDInitialized then
  5152.         return 1
  5153.     endif
  5154.  
  5155.     gettime h,m,s,c
  5156.     if s <> sold then
  5157.         sold = s
  5158.  
  5159.         if ItemsList[SpeedItem] then
  5160.             if ++HighSpeedTime > SPEEDTIMEPERIOD then
  5161.                 HighSpeedTime = 0
  5162.                 if --ItemsList[SpeedItem] = 0 then
  5163.                     DeleteSprite SpeedItem
  5164.                 endif
  5165.             endif
  5166.         endif
  5167.  
  5168.         if ItemsList[FreezeTimeItem] then
  5169.             if ++FrozenTime > FREEZETIMEPERIOD then
  5170.                 FrozenTime = 0
  5171.                 if --ItemsList[FreezeTimeItem] = 0 then
  5172.                     DeleteSprite FreezeTimeItem
  5173.                 endif
  5174.             endif
  5175.         else
  5176.             ShowTime( -1 )
  5177.         endif
  5178.     endif
  5179.  
  5180.     RwGetCameraPosition(Camera, at)
  5181.     dx = INT(at[0])
  5182.     dy = INT(at[2])
  5183.  
  5184.     /* Perform any "momentum" camera moves. */
  5185.     if ( (pan != 0.0) || (fforward != 0.0) ) then
  5186.         RwRotateMatrix(RwScratchMatrix(), 0.0, 1.0, 0.0, pan, rwREPLACE)
  5187.         RwTransformCameraOrientation(Camera, RwScratchMatrix())
  5188.         moveforward(fforward);
  5189.         RwGetCameraBackdropOffset(Camera, dx, dy);
  5190.  
  5191.         // artificially wrap dx to avoid overflow present in original program
  5192.         if ( (dx > 16383) || (dx < -16384) ) then
  5193.             dx = -dx
  5194.         endif
  5195.  
  5196.         RwSetCameraBackdropOffset(Camera, dx-INT(pan)*2, dy)
  5197.     endif
  5198.  
  5199.     render()
  5200.  
  5201.     if MouseMoveMode = MMNoAction then
  5202.         if TimerTick = FastTimerTick then
  5203.             WinKillTimer 1
  5204.             TimerTick = SlowTimerTick
  5205.             WinSetTimer 1, TimerTick
  5206.         endif
  5207.     else
  5208.         if TimerTick = SlowTimerTick then
  5209.             WinKillTimer 1
  5210.             TimerTick = FastTimerTick
  5211.             WinSetTimer 1, TimerTick
  5212.         endif
  5213.     endif
  5214.  
  5215.     return 0
  5216. endfunction
  5217.  
  5218.  
  5219.  
  5220. function HandleChar( char as int ) as BOOL
  5221. local
  5222.     RwReal pos[3]
  5223. endlocal
  5224.  
  5225.     if not ThreeDInitialized then
  5226.         return 1
  5227.     endif
  5228.  
  5229.     break on
  5230. //    print using "CHAR %s\n", chr$(char)
  5231.  
  5232.     if(char == asc('s') || char == asc('S')) then
  5233.         Shrink = !Shrink
  5234.  
  5235.         RwGetCameraPosition(Camera, pos )
  5236.         if Shrink then
  5237.             pos[1]/=4
  5238.             RwSetCameraViewWindow( Camera, 0.25, 0.25 )
  5239.         else
  5240.             pos[1]*=4
  5241.             RwSetCameraViewWindow( Camera, 1.0, 1.0 )
  5242.         endif
  5243.  
  5244.         RwSetCameraPosition(Camera, pos[0], pos[1], pos[2] )
  5245.  
  5246.     elsif(char == asc('f') || char == asc('F')) then
  5247.         Fast = !Fast
  5248.  
  5249.         if Fast then
  5250.             VScale = FastScale
  5251.         else
  5252.             Vscale = SlowScale
  5253.         endif
  5254.  
  5255.         SetViewport( VScale )
  5256.     endif
  5257.     return 0
  5258. end function
  5259.  
  5260.  
  5261. function HandleSize( Reason as int NewSize as int ) as BOOL
  5262. local
  5263.     NewWidth as int
  5264.     NewHeight as int
  5265. end local
  5266.  
  5267.     if not ThreeDInitialized then
  5268.         return 1
  5269.     endif
  5270.  
  5271.     break on
  5272. //    print "SIZE\n"
  5273.     if (ThreeDInitialized) then
  5274.         NewWidth = NewSize & %xffff
  5275.         NewHeight = NewSize >> 16
  5276.  
  5277.         if Reason = SIZE_REASON'SIZE_MINIMIZED then
  5278.             if TimerActive then
  5279.                 WinKillTimer 1
  5280.                 TimerActive = false
  5281.             endif
  5282.         else
  5283.             if !TimerActive then
  5284.                 WinSetTimer 1, TimerTick
  5285.                 TimerActive = true
  5286.             endif
  5287.  
  5288.             DoHandleSize( NewWidth, NewHeight)
  5289.         endif
  5290.     endif
  5291. end function
  5292.  
  5293.  
  5294. sub fast_ RemoveEventHandlers( )
  5295.     OffWinEvent2   0, WM_CHAR
  5296.     OffWinEvent2   0, WM_CREATE
  5297.     OffWinEvent2   0, WM_SIZE
  5298.     OffWinEvent2   0, WM_PAINT
  5299.     OffWinEvent2   0, WM_TIMER
  5300.     OffWinEvent2   0, WM_DESTROY
  5301.  
  5302.     OffMouseEvent2 0, LBUTTONDOWN
  5303.     OffMouseEvent2 0, RBUTTONDOWN
  5304.     OffMouseEvent2 0, MOUSEMOVE
  5305.     OffMouseEvent2 0, LBUTTONUP
  5306.     OffMouseEvent2 0, RBUTTONUP
  5307.  
  5308. //    off_event timer
  5309. endsub
  5310.  
  5311. function fast_ HandleCreate() as BOOL
  5312.     break on
  5313. //    print "CREATE\n"
  5314.     return 0
  5315. end function
  5316.  
  5317. function fast_ HandleDestroy() as BOOL
  5318.     break on
  5319. //    print "DESTROY\n"
  5320.  
  5321.     WinKillTimer 1
  5322.     TimerActive = false
  5323.  
  5324.     TidyUp3D()
  5325.     DeinitRw()
  5326.     RemoveEventHandlers()
  5327.     destroyed = true
  5328.     return 0
  5329. end function
  5330.  
  5331.  
  5332. sub fast_ SetupEventHandlers( )
  5333. local
  5334.     int Mkey=77
  5335.     int NewSize, Reason
  5336.     MouseXPos as int
  5337.     MouseYPos as int
  5338.     keys as int
  5339.     dummy as int = 0
  5340.     timercount as int
  5341.     char as int
  5342.     RwReal pos[3]
  5343. endlocal
  5344.  
  5345.     OnWinEvent2 0, WM_CHAR,    char,   dummy,   HandleChar( char )
  5346.     OnWinEvent2 0, WM_CREATE,  dummy,  dummy,   HandleCreate()
  5347.     OnWinEvent2 0, WM_SIZE,    Reason, NewSize, HandleSize( Reason, NewSize )
  5348.     OnWinEvent2 0, WM_PAINT,   dummy,  dummy,   HandlePaint()
  5349.     OnWinEvent2 0, WM_TIMER,   dummy,  dummy,   HandleTimer()
  5350.     OnWinEvent2 0, WM_DESTROY, dummy,  dummy,   HandleDestroy()
  5351.  
  5352.     OnMouseEvent2 0, LBUTTONDOWN, MouseXPos, MouseYPos, keys, HandleLeftButtonDown(MouseXPos/VScale, MouseYPos/VScale, keys)
  5353.     OnMouseEvent2 0, RBUTTONDOWN, MouseXPos, MouseYPos, keys, HandleRightButtonDown2(MouseXPos/VScale, MouseYPos/VScale, keys)
  5354.     OnMouseEvent2 0, MOUSEMOVE,   MouseXPos, MouseYPos, keys, HandleMouseMove(MouseXPos/VScale, MouseYPos/VScale)
  5355.     OnMouseEvent2 0, LBUTTONUP,   MouseXPos, MouseYPos, keys, HandleLeftButtonUp()
  5356.     OnMouseEvent2 0, RBUTTONUP,   MouseXPos, MouseYPos, keys, HandleRightButtonUp()
  5357.  
  5358. endsub
  5359.  
  5360.  
  5361.  
  5362. sub fast_ DefineScoreAndTimeSprites()
  5363.     local
  5364.         int i
  5365.         int x=(36+8+(ScoreDigits-1)*16)*2
  5366.         int w= 16*2
  5367.         int y=332*2
  5368.         int bx
  5369.         int h
  5370.     endlocal
  5371.  
  5372.     //stock object sprites images
  5373.     SpriteBank 1
  5374.     transparentcolour 221,0,147,255
  5375.  
  5376.     for bx = 0 to 5 loop
  5377.         DefineSprite bx+1, bx*53*2,384*2,53*2,32*2
  5378.     endfor
  5379.  
  5380.     //green key is separate
  5381.     bx=9
  5382.     DefineSprite 0, bx*53*2,384*2,53*2,32*2
  5383.  
  5384.     //digit sprites images
  5385.     for i = 1 to 9 loop
  5386.         DefineSprite digits+i, (8+20*(i-1))*2, 350*2, 16*2, (32-4)*2
  5387.     endloop
  5388.  
  5389.     DefineSprite digits+0, (8+20*i)*2, 350*2, 16*2, (32-4)*2
  5390.  
  5391.     //score sprites
  5392.     x= (38+(ScoreDigits-1)*16)*2
  5393.     y= 334*2
  5394.     w= 16*2
  5395.     for i = FirstScoreSprite to FirstScoreSprite+ScoreDigits-1 loop
  5396.         CreateSprite i, x, y, oneshot, 0, 0, 1, [digits+0]
  5397.         SetSpriteFlags i, enabled|visible, unbound
  5398.         x-=w
  5399.     end loop 
  5400.  
  5401.     x=0*2
  5402.     y=0*2
  5403.     w=116*2
  5404.     h=115*2
  5405.  
  5406.     //time ring sprite images
  5407.     for i = 0 to 3 loop
  5408.         DefineSprite FirstTimeRingSprite+i, x, y, w, h
  5409.         x+=w-1
  5410.     endfor
  5411.  
  5412.     y+=h
  5413.     for i = 4 to 7 loop
  5414.         x-=w-1
  5415.         DefineSprite FirstTimeRingSprite+i, x, y, w, h
  5416.     endfor
  5417.  
  5418.     x = 4*w
  5419.     y+=h
  5420.     for i = 8 to 9 loop
  5421.         x-=w
  5422.         DefineSprite FirstTimeRingSprite+i, x, y, w, h
  5423.     endfor
  5424.  
  5425.     //time sprites
  5426.     MazeTime = strtoi(MazeTimeLimit)
  5427.  
  5428.     if MazeTime >= 0 then
  5429.         CreateSprite TimeRingSprite, 39*2, 25*2, oneshot, 0, 0, 1, [FirstTimeRingSprite+8]
  5430.         SetSpriteFlags TimeRingSprite, enabled|visible, unbound
  5431.     endif
  5432.  
  5433.     if MazeTime >= 0 then
  5434.  
  5435.         x = (38 + (116/2))*2
  5436.         y = (23 + (116/2)-(28/2))*2
  5437.         w= 16*2
  5438.  
  5439.         if MazeTime = 0 then
  5440.             x+=2*w
  5441.         endif
  5442.  
  5443.         for i = FirstTimeSprite to FirstTimeSprite+TimeDigits-1 loop
  5444.             CreateSprite i, x, y, oneshot, 0, 0, 1, [digits+0]
  5445.             SetSpriteFlags i, enabled|visible, unbound
  5446.             x-=w
  5447.         end loop
  5448.     endif
  5449. end sub
  5450.  
  5451.  
  5452.  
  5453. sub fast_ init()
  5454. local
  5455.     int i, id, x, y
  5456. endlocal
  5457.  
  5458.     PlayerMapUnit = DEFAULTPLAYERMAPUNIT
  5459.     MapUnit = DEFAULTMAPUNIT
  5460.     RoomUnit = DEFAULTROOMUNIT
  5461.     unit = 1
  5462.     door = unit
  5463.     TimerTick = SlowTimerTick
  5464.  
  5465.     GridOriginX = MapGridX
  5466.     DrawOriginX = 0
  5467.     GridOriginY = MapGridY
  5468.     DrawOriginY = 0
  5469.  
  5470.     StartX = -1 StartY = -1 StartRoom = -1 StartLevel = 0
  5471.  
  5472.     for i = 1 to NMAPOBJS loop
  5473.         input data ObjectsPerRoomData, ObjectsPerRoom[i]
  5474.         input data DoorsPerRoomData, DoorsPerRoom[i]
  5475.     endfor
  5476.  
  5477.     on_sprite_drop id, x, y, { HandleSpriteDrop(id, x, y ) }
  5478. end sub
  5479.  
  5480.  
  5481. //maggot stuff
  5482.  
  5483.         const
  5484.             int v=50
  5485.             int astep=100
  5486.             int MaggotStart=1
  5487.  
  5488.         const
  5489.             int MaggotW=10
  5490.             int MaggotL=40
  5491.             int downup=-1, updown=-2, rightleft=-3, leftright=-4
  5492.             int left=0, right=8, down=16, up=24
  5493.             int leftup=32, leftdown=38,rightup=44,rightdown=50
  5494.             int upright=56,upleft=62,downright=68,downleft=74
  5495.             int MaggotBank=2
  5496.  
  5497.         data MaggotLL
  5498.             34,32,28,28,26,32,38,36
  5499.         enddata
  5500.  
  5501.         data MaggotOffsetL
  5502.              0,36,34,28,28,26,34,38
  5503.         enddata
  5504.  
  5505.         data MaggotOffsetR
  5506.              0,34,38,34,26,28,32,32
  5507.         enddata
  5508.  
  5509.         data MaggotRL
  5510.             36,36,34,28,26,32,34,34
  5511.         enddata
  5512.  
  5513.         data MaggotOffsetD
  5514.              0,34,40,34,26,28,32,32
  5515.         enddata
  5516.  
  5517.         data MaggotDL
  5518.             36,38,34,28,28,32,30,36
  5519.         enddata
  5520.  
  5521.         data MaggotOffsetU
  5522.              0,36,36,28,26,28,34,36
  5523.         enddata
  5524.  
  5525.         data MaggotUL
  5526.             36,34,28,28,28,32,38,38
  5527.         enddata
  5528.  
  5529.         data MaggotXY:2
  5530.             212,350,
  5531.             212,364,
  5532.             484,0,
  5533.             508,0
  5534.         enddata
  5535.  
  5536.         data BBoxXY:6
  5537.              14,  8, 38,290,down,downup,    //A-Y
  5538.              14,  8, 38,290,up,upright,        //A-Y
  5539.              14,  8,178, 20,right,rightdown,//A-q
  5540.             166,  8,178,157,down,downleft,    //B-L
  5541.  
  5542.              99,150,178,164,left,leftright,    //H-L
  5543.              99,150,131,164,right,rightdown,//H-J
  5544.             116,150,131,184,down,downleft,    //I-
  5545.              62,170,131,184,left,leftdown,    //K-
  5546.              62,170, 76,294,down,downright,    //K-
  5547.              62,282,134,296,right,rightup,    //-U
  5548.             120,218,134,296,up,updown,        //V-U
  5549.             120,218,134,296,down,downleft,    //V-U
  5550.              87,282,134,296,left,leftup,    //S-U
  5551.              87,194,105,296,up,upright,        //R-T
  5552.              87,194,156,208,right,rightdown,//R-P
  5553.             142,194,156,320,down,downleft,    //Q-W
  5554.              38,306,156,320,left,leftup,    //Y-W
  5555.              38,150, 52,320,up,upright,        //F-X
  5556.              38,150, 86,164,right,rightleft,//F-G
  5557.              38,150, 86,164,left,leftdown,    //F-G
  5558.              38,150, 52,320,down,downleft,    //F-X
  5559.              14,306, 52,320,left,leftdown,    //z-X
  5560.              14,306, 38,479,down,downright,    //z-b
  5561.              14,465,634,479,right,rightup,
  5562.             620,438,634,479,up,updown,
  5563.             620,438,634,479,down,downleft,
  5564.             576,465,634,479,left,leftup,
  5565.  
  5566.             576,450,594,479,up,upright,
  5567.             576,450,608,464,right,rightup,
  5568.             594,420,608,464,up,upleft,
  5569.             576,420,608,434,left,leftup,
  5570.             576,402,594,434,up,upright,
  5571.  
  5572.             576,402,634,416,right,rightdown,
  5573.  
  5574.             620,398,634,440,down,downup,
  5575.             620,  8,634,440,up,upleft,
  5576.  
  5577.             578,  8,634, 20,left,leftright,
  5578.             578,  8,634, 20,right,rightdown,
  5579.             620,  8,634,416,down,downleft,
  5580.             139,402,634,416,left,leftright,
  5581.             139,402,594,416,right,rightdown,
  5582.  
  5583.             576,402,594,434,down,downright,
  5584.             576,420,608,434,right,rightdown,
  5585.             594,420,608,464,down,downleft,
  5586.             576,450,608,464,left,leftdown,
  5587.             576,450,594,479,down,downleft,
  5588.  
  5589.              14,465,594,479,left,leftup,
  5590.              14,402, 38,479,up,upright,
  5591.              14,402,128,416,right,rightleft,
  5592.              14,402,128,416,left,leftup,
  5593.              14,378, 38,416,up,upright,
  5594.              14,378, 61,392,right,rightleft,
  5595.              14,378, 61,392,left,leftup,
  5596.              14,306, 38,392,up,upright,
  5597.              14,306,156,320,right,rightup,
  5598.             142,250,156,320,up,upright,
  5599.             142,250,178,266,right,rightdown,
  5600.             166,250,178,392,down,downleft,
  5601.              74,378,178,392,left,leftright,
  5602.              74,378,178,392,right,rightup,
  5603.             166,252,178,392,up,upleft,
  5604.             142,252,178,266,left,leftup,
  5605.             142,170,156,266,up,updown,
  5606.             142,170,156,208,down,downleft,
  5607.              87,194,156,208,left,leftdown,
  5608.              87,194,105,296,down,downleft,
  5609.              62,282,105,296,left,leftup,
  5610.              62,170,105,296,up,upright,
  5611.              62,170,131,184,right,rightup,
  5612.             116,150,131,184,up,upright,
  5613.             116,150,178,157,right,rightdown,
  5614.             166,150,178,234,down,downup,
  5615.             166,  8,178,234,up,upright,
  5616.             166,  8,567, 20,right,rightleft,
  5617.              14,  8,567, 20,left,leftdown
  5618.  
  5619.  
  5620.         enddata
  5621.  
  5622.  
  5623.         int mx, my, mw, mh, mvx, mvy, mx2, my2
  5624.         int olddir, dir
  5625.         int turndir
  5626.  
  5627.  
  5628.     sub fast_ HandleCorner( turndir as int )
  5629.         SetSpriteFlags MaggotSprite, enabled|visible, unbound
  5630.         SpriteMechanics MaggotSprite,0,0,0,0,0
  5631.  
  5632.         if turndir > 0 then
  5633.             CreateSprite MaggotSprite, mx*2, my*2, oneshot, 0, astep, MaggotBank, [turndir+5,turndir+4,turndir+3,turndir+2,turndir+1,turndir+0]
  5634.         elseif turndir = updown then
  5635.             CreateSprite MaggotSprite, mx*2, my*2, oneshot, 0, astep, MaggotBank, [up+3,up+3,up+3]
  5636.         elseif turndir = downup then
  5637.             CreateSprite MaggotSprite, mx*2, my*2, oneshot, 0, astep, MaggotBank, [down,down,down]
  5638.         elseif turndir = leftright then
  5639.             CreateSprite MaggotSprite, mx*2, my*2, oneshot, 0, astep, MaggotBank, [left+3,left+3,left+3]
  5640.         elseif turndir = rightleft then
  5641.             CreateSprite MaggotSprite, mx*2, my*2, oneshot, 0, astep, MaggotBank, [right,right,right]
  5642.         endif
  5643.  
  5644.  
  5645.         if olddir=left and dir=down then
  5646.             MoveSpriteTo MaggotSprite, mx*2, (my-4)*2
  5647.         elsif olddir=left and dir=up then
  5648.             MoveSpriteTo MaggotSprite, mx*2, (my2-29)*2
  5649.  
  5650.         elsif olddir=right and dir=down then
  5651.             MoveSpriteTo MaggotSprite, (mx2-25)*2, (my-4)*2
  5652.         elsif olddir=right and dir=up then
  5653.             MoveSpriteTo MaggotSprite, (mx2-25)*2, (my2-29)*2
  5654.  
  5655.         elsif olddir=up and dir=right then
  5656.             MoveSpriteTo MaggotSprite, mx*2, (my-4)*2
  5657.         elsif olddir=up and dir=left then
  5658.             MoveSpriteTo MaggotSprite, (mx2-25)*2, (my-4)*2
  5659.  
  5660.         elsif olddir=down and dir=right then
  5661.             MoveSpriteTo MaggotSprite, mx*2, (my2-29)*2
  5662.         elsif olddir=down and dir=left then
  5663.             MoveSpriteTo MaggotSprite, (mx2-25)*2, (my2-29)*2
  5664.         endif
  5665.     end sub
  5666.  
  5667.     sub fast_ HandleDirChange( )
  5668. //        print using "Bump LI=%d\n", ListIndex
  5669.  
  5670.         CreateSprite MaggotSprite, mx*2, my*2, looped, 0, astep, MaggotBank, [dir+0,dir+1,dir+2,dir+3,dir+4,dir+5,dir+6,dir+7]
  5671.  
  5672.         if    olddir=left and dir=down then
  5673.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5674.         elsif olddir=left and dir=up then
  5675.             MoveSpriteTo MaggotSprite, mx*2, (my2-40)*2
  5676.  
  5677.         elsif olddir=down and dir=up then
  5678.             MoveSpriteTo MaggotSprite, mx*2, (my2-40)*2
  5679.         elsif olddir=up and dir=down then
  5680.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5681.  
  5682.         elsif olddir=right and dir=left then
  5683.             MoveSpriteTo MaggotSprite, (mx2-40)*2, my*2
  5684.         elsif olddir=left and dir=right then
  5685.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5686.  
  5687.         elsif olddir=right and dir=down then
  5688.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5689.         elsif olddir=right and dir=up then
  5690.             MoveSpriteTo MaggotSprite, mx*2, (my2-40)*2
  5691.  
  5692.         elsif olddir=up and dir=right then
  5693.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5694.         elsif olddir=up and dir=left then
  5695.             MoveSpriteTo MaggotSprite, (mx2-40)*2, my*2
  5696.  
  5697.         elsif olddir=down and dir=right then
  5698.             MoveSpriteTo MaggotSprite, mx*2, my*2
  5699.         elsif olddir=down and dir=left then
  5700.             MoveSpriteTo MaggotSprite, (mx2-40)*2, my*2
  5701.         endif
  5702.  
  5703.         SpriteBBox MaggotSprite, mx*2, my*2, (mx2-mx)*2, (my2-my)*2
  5704.         SetSpriteFlags MaggotSprite, enabled|visible, bound
  5705.         SpriteMechanics MaggotSprite,mvx,mvy,0,0,0
  5706.     end sub
  5707.  
  5708.  
  5709.     sub fast_ LoadMaggots()
  5710.         local
  5711.             int x, y, w, h, id, offset
  5712.         endlocal
  5713.  
  5714.         spritebank MaggotBank
  5715.         transparentcolour 221,0,147,255
  5716.         spritefile gif, InstallDir + `sprites.gif`
  5717.  
  5718.  
  5719.         //left going maggot
  5720.         input data MaggotXY, x, y
  5721.         restoredata MaggotLL
  5722.         restoredata MaggotOffsetL
  5723.         h=MaggotW
  5724.  
  5725.         for id = 0 to 7 loop
  5726.             input data MaggotLL, w
  5727.             input data MaggotOffsetL, offset
  5728.             x+=offset
  5729.             defsprite id+left, x*2, y*2, w*2, h*2
  5730.         endfor
  5731.  
  5732.  
  5733.         //right going maggot
  5734.         input data MaggotXY, x, y
  5735.         restoredata MaggotRL
  5736.         restoredata MaggotOffsetR
  5737.         h=MaggotW
  5738.  
  5739.         for id = 0 to 7 loop
  5740.             input data MaggotRL, w
  5741.             input data MaggotOffsetR, offset
  5742.             x+=offset
  5743.             defsprite id+right, x*2, y*2, w*2, h*2
  5744.         endfor
  5745.  
  5746.  
  5747.         //down going maggot
  5748.         input data MaggotXY, x, y
  5749.         restoredata MaggotDL
  5750.         restoredata MaggotOffsetD
  5751.         w=MaggotW
  5752.  
  5753.         for id = 0 to 7 loop
  5754.             input data MaggotDL, h
  5755.             input data MaggotOffsetD, offset
  5756.             y+=offset
  5757.             defsprite id+down, x*2, y*2, w*2, h*2
  5758.         endfor
  5759.  
  5760.  
  5761.         //up going maggot
  5762.         input data MaggotXY, x, y
  5763.         restoredata MaggotUL
  5764.         restoredata MaggotOffsetU
  5765.         w=MaggotW
  5766.  
  5767.         for id = 0 to 7 loop
  5768.             input data MaggotUL, h
  5769.             input data MaggotOffsetU, offset
  5770.             y+=offset
  5771.             defsprite id+up, x*2, y*2, w*2, h*2
  5772.         endfor
  5773.  
  5774.  
  5775.         //leftup going maggot
  5776.         offset=40
  5777.         w=25
  5778.         h=25
  5779.         x=10+(5*offset)
  5780.         y=416
  5781.         for id = 0 to 5 loop
  5782.             defsprite id+leftup, x*2, y*2, w*2, h*2
  5783.             x-=offset
  5784.         endfor
  5785.  
  5786.  
  5787.         //leftdown going maggot
  5788.         offset=40
  5789.         w=25
  5790.         h=25
  5791.         x=10+(5*offset)
  5792.         //x=290-offset
  5793.         y=452
  5794.         for id = 0 to 5 loop
  5795.             defsprite id+leftdown, x*2, y*2, w*2, h*2
  5796.             x-=offset
  5797.         endfor
  5798.  
  5799.  
  5800.         //rightup going maggot
  5801.         offset=40
  5802.         w=25
  5803.         h=25
  5804.         x=290-offset
  5805.         y=416
  5806.         for id = 0 to 5 loop
  5807.             defsprite id+rightup, x*2, y*2, w*2, h*2
  5808.             x+=offset
  5809.         endfor
  5810.  
  5811.  
  5812.         //rightdown going maggot
  5813.         offset=40
  5814.         w=25
  5815.         h=25
  5816.         x=290-offset
  5817.         y=452
  5818.         for id = 0 to 5 loop
  5819.             defsprite id+rightdown, x*2, y*2, w*2, h*2
  5820.             x+=offset
  5821.         endfor
  5822.  
  5823.  
  5824.         //upleft going maggot
  5825.         offset=40
  5826.         w=25
  5827.         h=25
  5828.         x=538
  5829.         y=4+(5*offset)
  5830.         for id = 0 to 5 loop
  5831.             defsprite id+upleft, x*2, y*2, w*2, h*2
  5832.             y-=offset
  5833.         endfor
  5834.  
  5835.  
  5836.         //upright going maggot
  5837.         offset=40
  5838.         w=25
  5839.         h=25
  5840.         x=538+42
  5841.         y=4+(5*offset)
  5842.         for id = 0 to 5 loop
  5843.             defsprite id+upright, x*2, y*2, w*2, h*2
  5844.             y-=offset
  5845.         endfor
  5846.  
  5847.  
  5848.         //downleft going maggot
  5849.         offset=40
  5850.         w=25
  5851.         h=25
  5852.         x=538
  5853.         y=4+(6*offset)
  5854.         for id = 0 to 5 loop
  5855.             defsprite id+downleft, x*2, y*2, w*2, h*2
  5856.             y+=offset
  5857.         endfor
  5858.  
  5859.  
  5860.         //downright going maggot
  5861.         offset=40
  5862.         w=25
  5863.         h=25
  5864.         x=538+offset
  5865.         y=4+(6*offset)
  5866.         for id = 0 to 5 loop
  5867.             defsprite id+downright, x*2, y*2, w*2, h*2
  5868.             y+=offset
  5869.         endfor
  5870.     end sub
  5871.  
  5872.  
  5873.     sub fast_ HandleCollision( )
  5874.         olddir = dir
  5875.         input data BBoxXY, turndir
  5876.  
  5877.         if endofdata( BBoxXY ) then
  5878.             RestoreData BBoxXY
  5879.         endif
  5880.  
  5881.         input data BBoxXY, mx, my, mx2, my2, dir
  5882.         if dir = left then
  5883.             mvx = -v    mvy = 0
  5884.         elsif dir = right then
  5885.             mvx = v        mvy = 0
  5886.         elsif dir = up then
  5887.             mvx = 0        mvy = -v
  5888.         elsif dir = down then
  5889.             mvx = 0        mvy = v
  5890.         endif
  5891.  
  5892.         HandleCorner(turndir)
  5893.     end sub
  5894.  
  5895.  
  5896.     sub fast_ HandleStop()
  5897.         if dir=left or dir=right then
  5898.             if abs(mx-mx2) <= MaggotL then
  5899.                 olddir = dir
  5900.                 input data BBoxXY, turndir
  5901.  
  5902.                 if endofdata( BBoxXY ) then
  5903.                     RestoreData BBoxXY
  5904.                 endif
  5905.  
  5906.                 input data BBoxXY, mx, my, mx2, my2, dir
  5907.                 if dir = left then
  5908.                     mvx = -v    mvy = 0
  5909.                 elsif dir = right then
  5910.                     mvx = v        mvy = 0
  5911.                 elsif dir = up then
  5912.                     mvx = 0        mvy = -v
  5913.                 elsif dir = down then
  5914.                     mvx = 0        mvy = v
  5915.                 endif
  5916.  
  5917.                 HandleCorner(turndir)
  5918.             else
  5919.                 HandleDirChange()
  5920.             endif
  5921.         elseif dir=up or dir=down then
  5922.             if abs(my-my2) <= MaggotL then
  5923.                 olddir = dir
  5924.                 input data BBoxXY, turndir
  5925.  
  5926.                 if endofdata( BBoxXY ) then
  5927.                     RestoreData BBoxXY
  5928.                 endif
  5929.  
  5930.                 input data BBoxXY, mx, my, mx2, my2, dir
  5931.                 if dir = left then
  5932.                     mvx = -v    mvy = 0
  5933.                 elsif dir = right then
  5934.                     mvx = v        mvy = 0
  5935.                 elsif dir = up then
  5936.                     mvx = 0        mvy = -v
  5937.                 elsif dir = down then
  5938.                     mvx = 0        mvy = v
  5939.                 endif
  5940.  
  5941.                 HandleCorner(turndir)
  5942.             else
  5943.                 HandleDirChange()
  5944.             endif
  5945.  
  5946.         endif
  5947.     end sub
  5948.  
  5949.     sub fast_ StartMaggots()
  5950.         local
  5951.             int id, id2
  5952.         endlocal
  5953.  
  5954.         restoredata BBoxXY
  5955.         for id = 1 to MaggotStart loop
  5956.             input data BBoxXY, mx, my, mx2, my2, dir
  5957.             if id <> MaggotStart then
  5958.                 input data BBoxXY, turndir
  5959.             endif
  5960.         endfor
  5961.  
  5962.         if dir = left then
  5963.             mvx = -v    mvy = 0
  5964.         elsif dir = right then
  5965.             mvx = v        mvy = 0
  5966.         elsif dir = up then
  5967.             mvx = 0        mvy = -v
  5968.         elsif dir = down then
  5969.             mvx = 0        mvy = v
  5970.         endif
  5971.  
  5972.         Timeline_Timer 100,100
  5973.  
  5974.         CreateSprite MaggotSprite, mx*2, my*2, looped, 0, astep, MaggotBank, [dir+0,dir+1,dir+2,dir+3,dir+4,dir+5,dir+6,dir+7]
  5975.         SetSpriteFlags MaggotSprite, enabled|visible, bound
  5976.         SpriteBBox MaggotSprite, mx*2, my*2, (mx2-mx)*2, (my2-my)*2
  5977.         SpriteMechanics MaggotSprite, mvx,mvy,0,0,0
  5978.         SpriteCollision MaggotSprite, 0, 0, [31], []
  5979.  
  5980.         on_sprite_collision id, id2, { HandleCollision() }
  5981.         on_sprite_animstop id, { HandleStop() }
  5982.     endsub
  5983.  
  5984.     int TextureLoadCount
  5985.  
  5986.     sub GetTexture( f as filename )
  5987.         local
  5988.             int dummy
  5989.         endlocal
  5990.  
  5991.         print "GetTexture ", f, '\n'
  5992.  
  5993.         if MazeRemoteRoot == "no remote root" then
  5994.             TextureLoadCount++
  5995.         else
  5996.             saveimage 1280,960,0,0, jpg, filename(MazeRemoteRoot) + f + `.jpg`, InstallDir + f + `.bmp`, dummy, {
  5997.                 TextureLoadCount++
  5998.             }
  5999.         endif
  6000.     end sub
  6001.  
  6002.  
  6003.     function GetFile( f as filename ) as boolean
  6004.         print "GetFile ", f, '\n'
  6005.         if MazeRemoteRoot == "no remote root" then
  6006.             return false
  6007.         else
  6008.             return FileCopy ( filename(MazeRemoteRoot) + f, InstallDir + f ) = 0
  6009.         endif
  6010.     end function
  6011.  
  6012.  
  6013.     sub CheckAndLoadFiles()
  6014.         local
  6015.             int i, TextureNeedCount
  6016.             filename f
  6017.             string l
  6018.             boolean b
  6019.             filename sd
  6020.         end local
  6021.  
  6022.         TextureLoadCount=0
  6023.         TextureNeedCount=0
  6024.  
  6025.         //ensure sub-directories exist
  6026.         sd = InstallDir + filename("/" + SoundDir)
  6027.         mkdir( sd )
  6028.         mkdir( InstallDir + filename("/" + TextureDir) )
  6029.         mkdir( InstallDir + filename("/" + ObjectDir) )
  6030.  
  6031.         //ensure sound sub-directories exist
  6032.         mkdir( sd + `\circuit` )
  6033.         mkdir( sd + `\iceage` )
  6034.         mkdir( sd + `\medieval` )
  6035.         mkdir( sd + `\metallic` )
  6036.         mkdir( sd + `\organic` )
  6037.  
  6038.         //ensure we have stock objects
  6039.         for i = 0 to 10 loop
  6040.             f = filename(ObjectDir + '/' + "stock" + itostr(i) )
  6041.             if not checkfile ( InstallDir + f + `.bmp`, exists ) then
  6042.                 TextureNeedCount++
  6043.                 GetTexture( f )
  6044.             else
  6045.                 print "Have ", f, '\n'
  6046.             end if
  6047.         end for
  6048.  
  6049.         // get maze textures
  6050.         for i = 0 to high(TextureList) loop
  6051.             //chop off .bmp extension
  6052.             TextureList[i] = left$(TextureList[i], len(TextureList[i])-4)
  6053.             f = filename(TextureDir + '/' + TextureList[i])
  6054.             if TextureUsage[i] then
  6055.                 if not checkfile ( InstallDir + f + `.bmp`, exists ) then
  6056.                     TextureNeedCount++
  6057.                     GetTexture( f )
  6058.                 else
  6059.                     print "Have texture ", f, '\n'
  6060.                 end if
  6061.             endif
  6062.         end for
  6063.  
  6064.         //get maze objects and textures
  6065.         for i = 0 to high(Object3dList) loop
  6066.             if Object3dUsage[i] then
  6067.                 f = filename(ObjectDir + "/" + Object3dList[i] + ".txt")
  6068.  
  6069.                 if checkfile ( InstallDir + f, exists ) then
  6070.                     b = true
  6071.                     print "Have object texture list ", f, '\n'
  6072.                 else
  6073.                     b = GetFile( f )
  6074.                 end if
  6075.  
  6076.                 if b then
  6077.                     open InstallDir + f for read as #1
  6078.  
  6079.                     while not feof(#1) loop
  6080.                         l = inputline$(#1)
  6081.                         if len(l) > 2 then
  6082.                             if l <> "notextures" then
  6083.                                 l = left$( l, len(l)-4 ) //lose the .bmp
  6084.                                 f = filename(ObjectDir + "/" + l)
  6085.  
  6086.                                 if not checkfile ( InstallDir + f + `.bmp`, exists ) then
  6087.                                     TextureNeedCount++
  6088.                                     GetTexture( f )
  6089.                                 else
  6090.                                     print "Have object texture ", f, '\n'
  6091.                                 end if
  6092.                             end if
  6093.                         end if
  6094.                     end while
  6095.  
  6096.                     close #1
  6097.                 endif
  6098.  
  6099.                 f = filename(ObjectDir + "/" + Object3dList[i] + ".3ds")
  6100.                 if not checkfile ( InstallDir + f, exists ) then
  6101.                      GetFile( f )
  6102.                 else
  6103.                     print "Have object ", f, '\n'
  6104.                 end if
  6105.             endif
  6106.         end for
  6107.  
  6108.         //get specific sounds
  6109.         if SoundEffectFlags & 1 then
  6110.             f = filename(SoundDir + "/" + OooffSound)
  6111.             if not checkfile ( InstallDir + f, exists ) then
  6112.                 if not GetFile( f ) then
  6113.                     SoundEffectFlags &= ~1
  6114.                 endif
  6115.             else
  6116.                 print "Have sound ", f, '\n'
  6117.             endif
  6118.             OooffSound = string(InstallDir + f)
  6119.         endif
  6120.  
  6121.         if SoundEffectFlags & 2 then
  6122.             f = filename(SoundDir + '/' + BackgroundMIDI)
  6123.             if not checkfile ( InstallDir + f, exists ) then
  6124.                 if not GetFile( f ) then
  6125.                     SoundEffectFlags &= ~2
  6126.                 endif
  6127.             else
  6128.                 print "Have sound ", f, '\n'
  6129.             endif
  6130.             BackgroundMIDI = string(InstallDir + f)
  6131.         endif
  6132.  
  6133.         if SoundEffectFlags & 4 then
  6134.             f = filename(SoundDir + '/' + CollectSound)
  6135.             if not checkfile ( InstallDir + f, exists ) then
  6136.                 if not GetFile( f ) then
  6137.                     SoundEffectFlags &= ~4
  6138.                 endif
  6139.             else
  6140.                 print "Have sound ", f, '\n'
  6141.             endif
  6142.             CollectSound = string(InstallDir + f)
  6143.         endif
  6144.  
  6145.         if SoundEffectFlags & 8 then
  6146.             f = filename(SoundDir + '/' + FinishSound)
  6147.             if not checkfile ( InstallDir + f, exists ) then
  6148.                 if not GetFile( f ) then
  6149.                     SoundEffectFlags &= ~8
  6150.                 endif
  6151.             else
  6152.                 print "Have sound ", f, '\n'
  6153.             endif
  6154.             FinishSound = string(InstallDir + f)
  6155.         endif
  6156.  
  6157.         while TextureLoadCount <> TextureNeedCount loop
  6158.             print TextureNeedCount - TextureLoadCount, '\n'
  6159.             wait 100
  6160.         endwhile
  6161.     end sub
  6162.  
  6163.  
  6164.  
  6165. initcode as int
  6166.  
  6167. int dummy, flag
  6168. int SCX, SCY
  6169. int id
  6170. int bx
  6171. string bonusstr, message
  6172. string cddrives
  6173.  
  6174. endlocal
  6175.  
  6176. BrowserSetCursorBusy true
  6177. wait 100
  6178. ShowBrowserWindow FULLSCREEN
  6179.  
  6180. //TvmlDir = filename( GetInfo(InstallDir) )
  6181. //InstallDir = TvmlDir + MazeDir
  6182.  
  6183. //check for cd-rom drive
  6184.  
  6185. cddrives = GetInfo( CDROMS )
  6186. if len(cddrives) > 0 then
  6187.     //check for more than 1 cd-rom drive
  6188.     if len(cddrives) > 3 then
  6189.         cddrives = left$(cddrives, 3)
  6190.     endif
  6191.  
  6192.     if MazeLocalCDRoot <> "no local CD root" then
  6193. //        SetReadOnlyCache enabled, filename(cddrives+MazeLocalCDRoot), `/web/`
  6194. //        SetReadOnlyCache enabled, filename(cddrives+MazeLocalCDRoot), `/`
  6195.         SetReadOnlyCache disabled, ``, ``
  6196.     else
  6197.         SetReadOnlyCache disabled, ``, ``
  6198.     end if
  6199. else
  6200.     SetReadOnlyCache disabled, ``, ``
  6201. end if
  6202.  
  6203.  
  6204. //TvmlDir = filename( GetInfo(InstallDir) )
  6205. //InstallDir = TvmlDir + MazeDir
  6206.  
  6207. InstallDir = filename(cddrives) + MazeDir
  6208.  
  6209. init()
  6210.  
  6211. SCX = GetSystemMetrics(SM_CXSCREEN)
  6212. SCY = GetSystemMetrics(SM_CYSCREEN)
  6213.  
  6214. WindowX = ((SCX-640)/2 + 188)
  6215. WindowY = ((SCY-480)/2 + 22)
  6216. WindowW = (608-188)
  6217. WindowH = (393-22)
  6218. WindowRX = 188*2
  6219. WindowRY = 22*2
  6220.  
  6221. print "Maze start\n"
  6222.  
  6223.  
  6224. activepage 1
  6225. if not checkfile( InstallDir + `int2.jpg`, exists ) then
  6226.     GetFile ( `int2.jpg` )
  6227. endif
  6228. loadimage 0,0,1280,960, jpg,  InstallDir + `int2.jpg`
  6229. flag = 1
  6230.  
  6231. spritebank 1
  6232. if not checkfile( InstallDir + `sprites.gif`, exists ) then
  6233.     GetFile ( `sprites.gif` )
  6234. endif
  6235. spritefile gif, InstallDir + `sprites.gif`
  6236.  
  6237.  
  6238. activepage 0
  6239. clearscreen 0,0,1280,960, standard, 1, 255
  6240.  
  6241.  
  6242.  
  6243. start_text = GetNextObjectID()
  6244. pencolor 0,0,0
  6245. text 640,380,"Bitte habt etwas Geduld!"
  6246. text 640,480,"Das Spiel wird geladen."
  6247.  
  6248. end_text = GetNextObjectID()
  6249.  
  6250.  
  6251.  
  6252.  
  6253.  
  6254. InitFile = GetInfo( CommandLine )
  6255. InitFile = tidy$(InitFile, ltrim|rtrim)
  6256.  
  6257. if len(InitFile) > 0 then
  6258.     if not LoadMaze( InitFile, 0 ) then
  6259.         print "Failed to load maze\n"
  6260.         BrowserExit
  6261.     endif
  6262.  
  6263.     if CheckError != 0 then
  6264.         print "Warning: Maze has errors\n"
  6265. //            return false
  6266.     endif
  6267.  
  6268.     MazeFilename = InitFile
  6269.     while flag = 0 loop
  6270.         wait 50
  6271.     end loop
  6272. elseif checkfile( InstallDir + `mazerun.ini`, readable ) then
  6273.     open InstallDir + `mazerun.ini` for read as #1
  6274.     InitFile = inputline$(#1)
  6275.     close #1
  6276.  
  6277.     InitFile = global_select
  6278.     if InitFile = "" or not LoadMaze( InitFile, 0 ) then
  6279.         while flag = 0 loop
  6280.             wait 50
  6281.         end loop
  6282.  
  6283.         BrowserSetCursorBusy false
  6284.         flag = 0
  6285.         InitFile = ".maz"
  6286.         id = GetNextObjectID()
  6287.         editbox 0,0,400,60, enabled, InitFile, {
  6288.             BrowserSetCursorBusy true
  6289.             if LoadMaze( InitFile, 0 ) then flag = 1 endif
  6290.         }
  6291.  
  6292.         button 400,0,60,60,"Quit", enabled, none, { BrowserExit }
  6293.         SetProperty id, "SetFocus"
  6294.  
  6295.         while flag = 0 loop
  6296.             hold
  6297.         end loop
  6298.         DeleteObject id
  6299.         DeleteObject id+1
  6300.     else
  6301.         while flag = 0 loop
  6302.             wait 50
  6303.         end loop
  6304.     endif
  6305. endif
  6306.  
  6307.  
  6308. CheckAndLoadFiles()
  6309.  
  6310. DefineScoreAndTimeSprites()
  6311.  
  6312. SetupEventHandlers()
  6313. LoadMaggots()
  6314.  
  6315. initcode = InitRw("My Window", WS_popup,
  6316.         WindowX, WindowY, WindowW, WindowH, WindowW, WindowH )
  6317.  
  6318. GridOriginX = 190*2
  6319. GridOriginY = 22*2
  6320.  
  6321.  
  6322. if initcode > 0 then
  6323.     print "InitRw() failure code ", initcode, "\n"
  6324. else
  6325.     if initcode = -1 then
  6326.         print "Display not running in a native RenderWare depth of 8 or 16 bits\n"
  6327.     endif
  6328.  
  6329.     LocalInitDoneRw
  6330.  
  6331.     if ! Local3DInit( InstallDir ) then
  6332.         print "Local3DInit() failed\n"
  6333.         WinClose
  6334.     else
  6335.         BrowserSetCursorBusy false
  6336.         WinSetTimer 1, TimerTick
  6337.         TimerActive = true
  6338.  
  6339.         if SoundEffectFlags & 2 then
  6340.             audio mid, filename(BackgroundMIDI)
  6341.         endif
  6342.  
  6343.         hotspot 0,0,40,40,enabled, { quit = true }
  6344.         hotspot 56,30,274,268,enabled, { quit = true }
  6345.  
  6346.         StartMaggots()
  6347.         /* That's it ! */
  6348.  
  6349.         forc(del_text=start_text;del_text<end_text;del_text++)
  6350.             deleteobject del_text
  6351.  
  6352. print "start the maze now"
  6353.  
  6354.  
  6355.         EndReached = false
  6356.         quit = false
  6357.         OutOfTime = false
  6358.  
  6359.         // Windows messages get lost without this
  6360.         loop
  6361.             if EndReached or OutOfTime or quit then
  6362.                 WinClose
  6363.             endif
  6364.  
  6365.             if TimerActive then
  6366.                 null
  6367.             else
  6368.                 wait 100
  6369.             endif
  6370.  
  6371.         until destroyed
  6372.     endif
  6373. endif
  6374.  
  6375. off_sprite_drop
  6376.  
  6377. pencolor 0 160 220
  6378. SetColourFill 0 160 220
  6379. rectangle WindowRX WindowRY WindowW*2 WindowH*2
  6380.  
  6381. if EndReached then
  6382.     pencolor 0,0,0
  6383.  
  6384.     if MazeTime > 0 then
  6385.         input data Messages[BonusMessage+language], message
  6386.         bonusstr = print ( using message, MazeTime*10 )
  6387.         ShowScore( MazeTime*10 )
  6388.     else
  6389.         bonusstr = ""
  6390.     endif
  6391.  
  6392.     input data Messages[ScoreMessage+language], message
  6393.     bonusstr += print ( using message, score )
  6394.  
  6395.     input data Messages[WellDoneMessage+language], message
  6396.     label 0, WindowRX, WindowH+WindowRY, WindowW*2, 300, center, message + bonusstr
  6397.  
  6398.     if SoundEffectFlags & 8 then
  6399.         audio wav, filename(FinishSound)
  6400.     endif
  6401.     wait 4000
  6402. elsif OutOfTime then
  6403.     pencolor 0,0,0
  6404.     input data Messages[BadLuckMessage+language], message
  6405.     label 0, WindowRX, WindowH+WindowRY, WindowW*2, 300, center, message
  6406.     wait 4000
  6407. endif
  6408.  
  6409. if not quit then
  6410.     on_event keyup, scx, scy, { quit = true }
  6411.     on_event mouseclick, scx, scy, { quit = true }
  6412.  
  6413.     while not quit loop
  6414.         hold
  6415.     endwhile
  6416. endif
  6417.  
  6418. pencolor 0,0,0
  6419. script InstallDir + `frontend.tvm`
  6420.  
  6421.