Advertisement
ZoriaRPG

Subscreen7.zs

Jan 1st, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 55.27 KB | None | 0 0
  1. //Cursor on the screen is caused byt he cursor not moving with the pan. We need to make it invisible whenever we pan.
  2.  
  3. import "std.zh"
  4.  
  5. //Debug Settings
  6. const int SUBSCREEN_TEST_MODE = 0;
  7. const int SUBSCREEN_DRAW_TEST = 1;
  8.  
  9. //Global arrays
  10. int GRAM[214747];
  11. int OwnsItems[256];
  12.  
  13. //Global array indices:
  14. const int EXITING_SUBSCREEN     = 500;
  15. const int SUBSCREEN         = 501; //THe subscreen pointer.
  16. const int ENABLEITEMS_PTR   = 502; //The subscreen equipment items (equipable, not inventory) pointer.
  17.  
  18.  
  19. ////////////////////////////////////////
  20. /// Scripted Subscreen Demonstration ///
  21. /// for ZC 2.54 - Beta 46 and Higher ///
  22. /// v0.4, 30-Dec-2016 - By: ZoriaRPG ///
  23. ////////////////////////////////////////
  24.  
  25.  
  26. //Tile pages 114 to 117
  27. //Global Arrays
  28. int ButtonItems[3]; //Merge into another, if desired. Function pointers will be useful for this.
  29.  
  30. //ButtonItems[] array indices:
  31. const int BUTTONITEM_A      = 0;
  32. const int BUTTONITEM_B      = 1;
  33. const int BUTTONITEM_SUBSCREEN  = 2; /* This determines of the subscreen is active, so that functions that 
  34.                     change inventory (e.g. for warping) do not interfere with setting
  35.                     the item in the subscreen. */
  36.  
  37.  
  38. //Generic Item to manipulate with itemdata
  39. const int I_GENERIC         = 123;
  40. const int I_SUBSCREEN_BLANK     = 124;
  41.  
  42. //! Subscreen Settings
  43.  
  44. //Base
  45. const int SUBSC_FFC_INDEX   = 32; //The FFC ID that we reserve for the subscreen ffc.
  46. const int SUBSC_FFC_DATA    = 882; //THe FFC Data for the Subscreen FFC. (Freeze all except FFCs).
  47.  
  48. //Visual Effects & Fades
  49. const int SUBSC_FADE_IN     = 0;    //0 == None, 1 == ZAPIN, 2 == ZAPOUT,
  50. const int SUBSC_FADE_OUT    = 0;
  51. const int SUBSC_PAN_SPEED   = 4; //pixels per frame. MUST BE A POWER OF 2!
  52.  
  53. //Sounds
  54. const int SUBSC_CURSOR_SFX  = 6;  //Cursor movement.
  55. const int SUBSC_SELECTED_SFX    = 44; //Select an item.
  56. const int SUBSC_OPEN_SFX    = 37; //Open the subscreen
  57. const int SUBSC_CLOSE_SFX   = 46; //Close the subscreen.
  58. const int SUBSC_SFX_EQUIP   = 35; //Sound for items that can be equipped/unequipped.
  59.  
  60. //General Settings
  61. const int SUBSC_MAX_ITEMS   = 24; //How many items are on the subscreen?
  62. const int SUBSC_NUM_ROWS    = 4; //Items grid forms this many (horizontal) rows
  63. const int SUBSC_NUM_COLUMNS     = 6; //Items grid forms this many (vertical) columns.
  64. const int SUBSC_LINK_INVISIBLE = 1; //Is Link invisible when the subscreen is active?
  65. const int SUBSC_LAST        = 24; //Last item in the array.
  66.  
  67. //Item Misc Flags
  68. const int MISC_SUBSC_OBJ    = 18; //The index if i->Misc[] to use for marking as a subscreen object.
  69. const int IS_SUBSCREEN_OBJECT   = 1; //! This is used as =, but we should do it bitwise.
  70. const int IS_INVENTORY_A    = 2; //Unused, deprecated.
  71. const int IS_INVENTORY_B    = 4; //Unused, deprecated.
  72.  
  73. //Layout
  74. const int SUBSC_INITIAL_X =     118; //The starting X-position to draw items.
  75. const int SUBSC_INITIAL_Y =     20; //The starting Y-position to draw items.
  76. const int SUBSC_X_SPACING =     18; //Pixels between items
  77. const int SUBSC_Y_SPACING =     18;
  78. const int SUBSC_EQUIP_A_X   = 39; //X-Position of the current A-Item
  79. const int SUBSC_EQUIP_A_Y   = -16; //Y-Position of the current A-Item
  80. const int SUBSC_EQUIP_B_X   = 13; //X-Position of the current B-Item
  81. const int SUBSC_EQUIP_B_Y   = -16; //Y-Position of the current B-Item
  82.  
  83. //Rows, Columns, Wrapping
  84. const int SUBSC_WRAP_ROW =      18; //Wrap from the bottom row to the top, or top to the bottom.
  85. const int SUBSC_WRAP_COLUMS =       6; //Wrap from the left to the right, or riht to the left column.
  86. const int SUBSC_ITEMS_PER_ROW =     6; //Number of items per row. Used for wrapping.
  87. const int SUBSC_ITEMS_PER_COLUMN =  4; //Number of items per column; also used for wrapping.
  88.  
  89. //Pane IDs
  90. const int PANE_LEFT         = 0; //Arbitrary values for each pane of the subscreen.
  91. const int PANE_CENTRE       = 1;
  92. const int PANE_RIGHT        = 2;
  93.  
  94. //Graphical Settings
  95. const int SUBSC_BG_LAYER    = 7; //Layer to draw backgrounds.
  96. const int SUBSC_OBJ_LAYER   = 7; //Layer to draw objects.
  97.  
  98. //Colours
  99. const int SUBSC_COLOUR_WHITE = 0x01; //Are either of these every used?
  100. const int SUBSC_COLOUR_BLACK = 0x0F; //Possibly in the text drawing routines?
  101.  
  102. //Bitmap Settings ->To be deprecated, except that we use some of these as sizes for tile draws, and panning!
  103. const int BG_IS_BITMAP          = -1; /*
  104.                         If set to 0 or higher, drawing will use bitmaps, and draw them
  105.                         to layer-N, where N is this value. This feature is deprecated,
  106.                         and slated for removal. Bitmaps are fine and dandy, but they
  107.                         are also limited in umber at present, and wasting three to
  108.                         create a subscreen, where DrawTile is perfectly usable, is silly.
  109.                         */
  110. const int RT_SUBSCREEN          = 0;    //Render target ID
  111. const int SUBSC_BITMAP_X        = 0;    //! We use some of these values for sizing other things.
  112. const int SUBSC_BITMAP_WIDTH        = 256;  //! Be very careful when deprecating them. !!
  113. const int SUBSC_BITMAP_Y        = 0;
  114. const int SUBSC_BITMAP_HEIGHT       = 232;
  115. const int SUBSC_BITMAP_DRAW_TO_X    = 0;
  116. const int SUBSC_BITMAP_DRAW_TO_Y    = -56;
  117. const int SUBSC_BITMAP_DRAW_MODE    = 0; //0 = Normal, Trans = 1
  118.  
  119. //Tiles
  120. const int SUBSC_TILE_BLANK      = 5; //A blank tile.
  121. const int SUBSC_FIRST_TILE      = 29640; //Main central pane
  122. const int SUBSC_TILE_LPANE      = 30680; //First tile of the left pane
  123. const int SUBSC_TILE_RPANE      = 30680; //First tile of the right pane.
  124.  
  125. const int SUBSC_NUMBER_OF_TILES     = 0; //Unused
  126.  
  127. const int SUBSC_TILE_INITIAL_X      = 0; //Upper-left corner X-coordinate
  128. const int SUBSC_TILE_INITIAL_Y      = -56; //Upper-left corner Y-coordinate.
  129. const int SUBSC_TILE_LAYER      = 7; //Layer to draw tiles. Do we not use SUBSC_BG_LAYER?
  130. const int SUBSC_TILE_WIDTH      = 20; //Width of the screen.
  131. const int SUBSC_TILE_HEIGHT         = 16; //Height of the screen and passive subscreen.
  132. const int SUBSC_TILE_CSET       = 11; //Drawing CSet
  133.  
  134. const int SUBSC_TILE_XSCALE         = -1; //Scale factors: -1 or none, otherwise N%.
  135. const int SUBSC_TILE_YSCALE         = -1;  
  136. const int SUBSC_TILE_RX         = 0; //Rotation. This is normally going to be 0, but...
  137. const int SUBSC_TILE_RY         = 0; //..you know...
  138. const int SUBSC_TILE_RANGLE         = 0; //...
  139. const int SUBSC_TILE_FLIP       = 0; //Flip the entire image. This may cause undesirable effects, if set.
  140. const int SUBSC_TILE_OPACITY        = 128; //Opaque
  141.  
  142. //Cursor Item Appearance
  143. const int CURSOR_TILE       = 20140; //The tile, used by the cursor.
  144. const int CURSOR_CSET       = 6; //Its CSet
  145. const int CURSOR_AFRAMES    = 15; //Would be nice.
  146. const int CURSOR_ASPEED     = 7; //Would also be nice. Requires additional work, and possibly a later beta.
  147. const int CURSOR_LAYER      = 7; /* Layer onto which the cursor is drawn. This should now automatically
  148.                     occur onthe same layer as the other objects, as the last draw.
  149.                     */
  150.  
  151. //Text
  152. const int SUBSC_TEXT_INV_FONT       = 2; //z3 Small
  153. const int SUBSC_TEXT_INV_FONT_SIZE  = 16;
  154. const int SUBSC_TEXT_Y_INVENTORY    = -48; //Poistions for all the textual subscreen objects.
  155. const int SUBSC_TEXT_X_KEYS1        = 8;
  156. const int SUBSC_TEXT_X_KEYS2        = 24;
  157. const int SUBSC_TEXT_X_KEYS3        = 40;
  158. const int SUBSC_TEXT_X_BOMBS        = 96;
  159. const int SUBSC_TEXT_X_SBOMBS       = 112;
  160. const int SUBSC_TEXT_X_ARROWS       = 144;
  161. const int SUBSC_TEXT_X_LIFE         = 160;
  162. const int SUBSC_TEXT_X_MAGIC        = 192;
  163. const int SUBSC_TEXT_X_MONEY        = 224;
  164. const int SUBSC_TEXT_LAYER      = 7;
  165. const int SUBSC_TEXT_INV_FG_COLOUR  = 0x01; //Foreground colour for text.
  166. const int SUBSC_TEXT_INV_BG_COLOUR  = 0x0F; //Shadow colour for text.
  167. const int SUBSC_TEXT_BACKDROP       = -1; //Will draw a solid backgrop behind it if set to 1 or higher.
  168. const int SUBSC_TEXT_INV_OPACITY    = 128; //Opaque
  169. const int SUBSC_TEXT_INV_SHADOW_OFFSET  = 1; //X-Y offset of the shadow effect.
  170.                    
  171.  
  172. //! Subscreen 'q[]' array indices:
  173. //Operating Conditions
  174. const int SUBSC_ACTIVE      = 0; //Array index of GRAM[]: Is it active?
  175.  
  176. //1 to 9 reserved for expansion.
  177.  
  178. //Internal Variables
  179. const int SUBSC_SELECTED    = 10;   //THe selected item
  180. const int SUBSC_LAST_SELECTED   = 11;   //Holds the ID of the previous selected item.
  181.                     //We do not yet use this, but it could be used later.
  182. const int SUBSC_POSX        = 12;   //Holds the X value for where to draw the next object.
  183. const int SUBSC_POSY        = 13;   //Holds the Y value for where to draw the next object.
  184. //14 to 39 reserved for expansion.
  185.  
  186. //Loops
  187. const int SUBSC_FOR_LOOP    = 40;   //The main for loop. Sets the current object ID.
  188. const int SUBSC_SLOTCHECK_LOOP  = 41;   //The loop used to check what items are in slots, and assign the initial cursor position.
  189. const int SUBSC_OBJDRAW_LOOP    = 42;   //The loop used to copy objects to a higher layer.  
  190. const int SUBSC_CLEANUP_LOOP    = 43;   //The loop used to clean up everything.
  191. const int SUBSC_OBJ_PAN_DRAW_LOOP = 44; //Loop for drawing objects during the pan-in.
  192. const int SUBSC_EXIT_CLEANUP_LOOP = 45; //Loop for drawing objects during the pan-in.
  193.  
  194. //Pane Info
  195. const int PANE_ID       = 100; //Holds the ID of the present Subscreen Pane
  196. const int PANE_LEFT_DRAWN   = 101; //Registers to store if drawing events have, or should occur.
  197. const int PANE_RIGHT_DRAWN  = 103;
  198. const int PANE_CENTRE_DRAWN     = 104;
  199.  
  200. //Bitmap Panning registers
  201. const int PANE_CENTRE_X     = 120;  //Registers to store temporary coordinates when panning.
  202. const int PANE_CENTRE_Y     = 121;
  203. const int PANE_LEFT_X       = 122;
  204. const int PANE_LEFT_Y       = 123;
  205. const int PANE_RIGHT_X      = 124; //! These start at a value that draws offscreen,
  206. const int PANE_RIGHT_Y      = 125; //! and reduces to 0 to pan into view.
  207.  
  208. //(None of these are used at present. Reserved for background tiles, and objects.)
  209. const int SUBSC_TILE_BASE   = 200;
  210. const int SUBSC_CSET_BASE   = 201;
  211. const int SUBSC_FLASH_BASE  = 202;
  212. const int SUBSC_AFRAMES_BASE    = 203;
  213. const int SUBSC_ASPEED_BASE     = 204;
  214. const int SUBSC_FRAME_BASE  = 205;
  215. const int SUBSC_DELAY_BASE  = 206;
  216. const int SUBSC_SCRIPT_BASE     = 207; /*   These bases were for using tiles instead of items, to place objects
  217.                         as the base index of an array containing datum on object tiles, csets,
  218.                         and so forth. */
  219. //Item and Itemdata Registers
  220. const int SUBSC_IDATA_SCRATCH   = 29; //Used as scratch space for itemdata loading.
  221. const int SUBSC_ITEM_SCRATCH    = 25; //Not implemented.
  222.  
  223.  
  224. ////////////////////////////////////
  225. /// FFC Script for the Subscreen ///
  226. ////////////////////////////////////
  227.  
  228. //Subscreen FFC
  229. ffc script SubscreenScript{
  230.     void run(){
  231.         SSTest(1); bool pan_in = true;;
  232.         int q[265]; itemdata id[30]; item i[25]; item equip[2];
  233.         AssignSubscreenPointer(q); //Pute the pointer into GRAM[] so that global accessors work.
  234.         q[SUBSC_ACTIVE] = 1;
  235.         q[SUBSC_SELECTED] = 0; q[SUBSC_LAST_SELECTED] = 0;
  236.         q[SUBSC_POSX] = SUBSC_INITIAL_X; q[SUBSC_POSY] = SUBSC_INITIAL_Y;
  237.         q[PANE_CENTRE_DRAWN] = 1;
  238.         q[PANE_ID] = PANE_CENTRE;
  239.         SubPaneX(PANE_CENTRE,0);
  240.         SubPaneY(PANE_CENTRE,-SUBSC_BITMAP_HEIGHT);
  241.         SubPaneX(PANE_LEFT,-SUBSC_BITMAP_WIDTH);
  242.         SubPaneY(PANE_LEFT,0);
  243.         SubPaneX(PANE_RIGHT,SUBSC_BITMAP_WIDTH);
  244.         SubPaneY(PANE_LEFT,0);
  245.        
  246.         //Populate with the IDs of items to place in the inventory selection box.
  247.         int subscreenitems[240]={I_SWORD1, I_SWORD2, I_SWORD3, I_SWORD4, I_BRANG1, I_BRANG2,
  248.                     I_CANDLE1, I_CANDLE2, I_BOMB, I_SBOMB, I_HAMMER, I_CBYRNA,
  249.                     I_BOOTS, I_BOW2, I_FLIPPERS, I_LADDER1, I_HOOKSHOT1, I_POTION1,
  250.                     I_POTION2, I_SHIELD1, I_WAND, I_WHISTLE, I_MAP, I_BAIT};
  251.             //put the items on the screen.
  252.        
  253.         int EnableDisable[]={I_SHIELD1, I_LADDER1, I_FLIPPERS, I_BOOTS};
  254.         StoreEnableItemsPtr(EnableDisable);
  255.  
  256.         id[SUBSC_LAST] = Game->LoadItemData(I_GENERIC);
  257.         id[SUBSC_LAST]->Tile = CURSOR_TILE;
  258.         id[SUBSC_LAST]->CSet = CURSOR_CSET;
  259.         id[SUBSC_LAST]->AFrames = CURSOR_AFRAMES;
  260.         id[SUBSC_LAST]->ASpeed = CURSOR_ASPEED;
  261.        
  262.         equip[0] = Screen->CreateItem(I_GENERIC);
  263.         equip[0]->X = SUBSC_EQUIP_B_X; equip[0]->Y = SUBSC_EQUIP_B_Y;
  264.         equip[0]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  265.         equip[0]->DrawYOffset = -1000;
  266.         equip[0]->Pickup = IP_DUMMY;
  267.         id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemB);
  268.         equip[0]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  269.         equip[0]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  270.        
  271.        
  272.         equip[1] = Screen->CreateItem(I_GENERIC);
  273.         equip[1]->X = SUBSC_EQUIP_A_X; equip[1]->Y = SUBSC_EQUIP_A_Y;
  274.         equip[1]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  275.         equip[1]->DrawYOffset = -1000;
  276.         equip[1]->Pickup = IP_DUMMY;
  277.         id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemA);
  278.         equip[1]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  279.         equip[1]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  280.        
  281.         if ( SUBSC_FADE_IN == 1 ) Screen->ZapIn();
  282.         if ( SUBSC_FADE_IN == 2 ) Screen->ZapOut();
  283.        
  284.         for ( q[SUBSC_FOR_LOOP] = 0; q[SUBSC_FOR_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_FOR_LOOP]++ ) {
  285.            
  286.             i[ q[SUBSC_FOR_LOOP] ] = Screen->CreateItem( subscreenitems[ q[SUBSC_FOR_LOOP] ]);
  287.             i[ q[SUBSC_FOR_LOOP] ]->X = q[SUBSC_POSX];
  288.             i[ q[SUBSC_FOR_LOOP] ]->Y = q[SUBSC_POSY];
  289.             i[ q[SUBSC_FOR_LOOP] ]->Pickup = IP_DUMMY;
  290.             i[ q[SUBSC_FOR_LOOP] ]->DrawYOffset =   SubPaneY(PANE_CENTRE)*-1;  
  291.             i[ q[SUBSC_FOR_LOOP] ]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  292.            
  293.             if ( !Link->Item[ subscreenitems[q[SUBSC_FOR_LOOP] ] ] && !OwnsItems[ subscreenitems[q[SUBSC_FOR_LOOP] ] ] ) {
  294.                 i[ q[SUBSC_FOR_LOOP] ]->ID = I_SUBSCREEN_BLANK;
  295.                 i[ q[SUBSC_FOR_LOOP] ]->Tile = SUBSC_TILE_BLANK;
  296.             }
  297.            
  298.             if ( q[SUBSC_POSX] < ( SUBSC_INITIAL_X + ( SUBSC_X_SPACING * (SUBSC_NUM_COLUMNS-1) ) ) )  {
  299.                 q[SUBSC_POSX] += SUBSC_X_SPACING;
  300.             }
  301.                
  302.             else {
  303.                 q[SUBSC_POSX] = SUBSC_INITIAL_X;
  304.                 if ( q[SUBSC_POSY] < ( SUBSC_INITIAL_Y + (SUBSC_Y_SPACING * (SUBSC_NUM_ROWS-1) ) ) ) q[SUBSC_POSY] += SUBSC_Y_SPACING;
  305.             }
  306.         }
  307.        
  308.         //Pan in the initial tiles.
  309.         do{ //Initial pan in.
  310.             pan_in = PanUpToDown(PANE_CENTRE,true);
  311.             for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  312.                         DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE); 
  313.             WaitNoAction();
  314.         } while(pan_in);
  315.          
  316.        
  317.         //Find out what is in Link's B slot.
  318.         for ( q[SUBSC_SLOTCHECK_LOOP] = 0; q[SUBSC_SLOTCHECK_LOOP] < 24; q[SUBSC_SLOTCHECK_LOOP]++ ) {
  319.             if ( subscreenitems[ q[SUBSC_FOR_LOOP] ] == Link->ItemB ) { q[SUBSC_LAST_SELECTED] = subscreenitems[ q[SUBSC_FOR_LOOP] ]; q[SUBSC_SELECTED] =  subscreenitems[ q[SUBSC_FOR_LOOP] ]; break; }
  320.         }
  321.         //if nothing matches, check the A slot
  322.         for ( q[SUBSC_SLOTCHECK_LOOP] = 0; q[SUBSC_SLOTCHECK_LOOP] < 24; q[SUBSC_SLOTCHECK_LOOP]++ ) {
  323.             if ( q[SUBSC_SELECTED] != 0 ) break; //If we found a B item, skip this step.
  324.             if ( subscreenitems[ q[SUBSC_FOR_LOOP] ] == Link->ItemA )  { q[SUBSC_LAST_SELECTED] = subscreenitems[ q[SUBSC_FOR_LOOP] ]; q[SUBSC_SELECTED] =  subscreenitems[ q[SUBSC_FOR_LOOP] ]; break; }
  325.         }
  326.         i[SUBSC_LAST] = Screen->CreateItem(I_GENERIC);
  327.         i[SUBSC_LAST]->Pickup = IP_DUMMY;
  328.         i[SUBSC_LAST]->X = i[q[SUBSC_SELECTED]]->X;
  329.         i[SUBSC_LAST]->Y = i[q[SUBSC_SELECTED]]->Y;
  330.         i[SUBSC_LAST]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  331.        
  332.         /*
  333.         //Draw the tiles to a bitmap?
  334.         if ( BG_IS_BITMAP > -1 && BG_IS_BITMAP < 7 ) {
  335.             //Set up the bitmap.
  336.             SetupSubscreenBitmap();
  337.         }
  338.         */
  339.        
  340.         //Bitmaps are deprecated.
  341.        
  342.        
  343.         Game->PlaySound(SUBSC_OPEN_SFX);
  344.         while( q[SUBSC_ACTIVE] ){
  345.             SSTest(2);
  346.             if ( !pan_in ) {
  347.                 if ( BG_IS_BITMAP > -1 && BG_IS_BITMAP < 8 ) {
  348.                     Screen->SetRenderTarget(RT_SCREEN);
  349.                     Screen->DrawBitmapEx(BG_IS_BITMAP, RT_SUBSCREEN, SUBSC_BITMAP_X, SUBSC_BITMAP_Y, SUBSC_BITMAP_WIDTH,
  350.                     SUBSC_BITMAP_HEIGHT, SUBSC_BITMAP_X, SUBSC_BITMAP_Y, SUBSC_BITMAP_WIDTH, SUBSC_BITMAP_HEIGHT, 0, 0,0,
  351.                     SUBSC_BITMAP_DRAW_MODE, 0, true);
  352.                 }
  353.                 else {
  354.                     DrawSubscreenTiles(q[PANE_ID]);
  355.                 }
  356.                 DrawSubscreenInventoryText();
  357.             }
  358.            
  359.             if ( q[PANE_ID] == PANE_CENTRE && !q[PANE_CENTRE_DRAWN] ) {
  360.                 q[SUBSC_POSX] = SUBSC_INITIAL_X; q[SUBSC_POSY] = SUBSC_INITIAL_Y;
  361.                 for ( q[SUBSC_FOR_LOOP] = 0; q[SUBSC_FOR_LOOP] <= SUBSC_MAX_ITEMS; q[SUBSC_FOR_LOOP]++ ) {
  362.                     i[ q[SUBSC_FOR_LOOP] ] = Screen->CreateItem( subscreenitems[ q[SUBSC_FOR_LOOP] ]);
  363.                     i[ q[SUBSC_FOR_LOOP] ]->X = q[SUBSC_POSX];
  364.                     i[ q[SUBSC_FOR_LOOP] ]->Y = q[SUBSC_POSY];
  365.                     i[ q[SUBSC_FOR_LOOP] ]->Pickup = IP_DUMMY;
  366.                     i[ q[SUBSC_FOR_LOOP] ]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  367.                     i[ q[SUBSC_FOR_LOOP] ]->DrawYOffset = -1000;
  368.                    
  369.                     if ( !Link->Item[ subscreenitems[q[SUBSC_FOR_LOOP] ] ] && !OwnsItems[ subscreenitems[q[SUBSC_FOR_LOOP] ] ] ) {
  370.                         i[ q[SUBSC_FOR_LOOP] ]->ID = I_SUBSCREEN_BLANK;
  371.                         i[ q[SUBSC_FOR_LOOP] ]->Tile = SUBSC_TILE_BLANK;
  372.                     }
  373.                    
  374.                     if ( q[SUBSC_POSX] < ( SUBSC_INITIAL_X + ( SUBSC_X_SPACING * (SUBSC_NUM_COLUMNS-1) ) ) )  {
  375.                         q[SUBSC_POSX] += SUBSC_X_SPACING;
  376.                     }
  377.                        
  378.                     else {
  379.                         q[SUBSC_POSX] = SUBSC_INITIAL_X;
  380.                         if ( q[SUBSC_POSY] < ( SUBSC_INITIAL_Y + (SUBSC_Y_SPACING * (SUBSC_NUM_ROWS-1) ) ) ) q[SUBSC_POSY] += SUBSC_Y_SPACING;
  381.                     }
  382.                 }
  383.                 //Find out what is in Link's B slot.
  384.                 for ( q[SUBSC_SLOTCHECK_LOOP] = 0; q[SUBSC_SLOTCHECK_LOOP] < 24; q[SUBSC_SLOTCHECK_LOOP]++ ) {
  385.                     if ( subscreenitems[ q[SUBSC_FOR_LOOP] ] == Link->ItemB ) { q[SUBSC_LAST_SELECTED] = subscreenitems[ q[SUBSC_FOR_LOOP] ]; q[SUBSC_SELECTED] =  subscreenitems[ q[SUBSC_FOR_LOOP] ]; break; }
  386.                 }
  387.                 //if nothing matches, check the A slot
  388.                 for ( q[SUBSC_SLOTCHECK_LOOP] = 0; q[SUBSC_SLOTCHECK_LOOP] < 24; q[SUBSC_SLOTCHECK_LOOP]++ ) {
  389.                     if ( q[SUBSC_SELECTED] != 0 ) break; //If we found a B item, skip this step.
  390.                     if ( subscreenitems[ q[SUBSC_FOR_LOOP] ] == Link->ItemA )  { q[SUBSC_LAST_SELECTED] = subscreenitems[ q[SUBSC_FOR_LOOP] ]; q[SUBSC_SELECTED] =  subscreenitems[ q[SUBSC_FOR_LOOP] ]; break; }
  391.                 }
  392.                 i[SUBSC_LAST] = Screen->CreateItem(I_GENERIC);
  393.                 i[SUBSC_LAST]->Pickup = IP_DUMMY;
  394.                 i[SUBSC_LAST]->Misc[MISC_SUBSC_OBJ] = IS_SUBSCREEN_OBJECT;
  395.                
  396.                 i[SUBSC_LAST]->X = i[q[SUBSC_SELECTED]]->X;
  397.                 i[SUBSC_LAST]->Y = i[q[SUBSC_SELECTED]]->Y;
  398.                 i[SUBSC_LAST]->DrawYOffset = 0; //Show the cursor.
  399.  
  400.                 //Draw the tiles to a bitmap?
  401.                
  402.                 /*
  403.                 if ( BG_IS_BITMAP > -1 && BG_IS_BITMAP < 7 ) {
  404.                     //Set up the bitmap.
  405.                     SetupSubscreenBitmap();
  406.                 }
  407.                 */
  408.                 //Bitmaps are deprecated, for now. Would anyone do this, when it wastes three RTs?
  409.                
  410.                 q[PANE_CENTRE_DRAWN] = 1; //mark drawing done.
  411.             }
  412.    
  413.            
  414.             if ( q[PANE_ID] == PANE_CENTRE ) {
  415.                 i[SUBSC_LAST]->X = i[q[SUBSC_SELECTED]]->X;
  416.                 i[SUBSC_LAST]->Y = i[q[SUBSC_SELECTED]]->Y;
  417.                 if ( SUBSC_OBJ_LAYER ) {
  418.                     for ( q[SUBSC_OBJDRAW_LOOP] = 0; q[SUBSC_OBJDRAW_LOOP] <= SUBSC_MAX_ITEMS; q[SUBSC_OBJDRAW_LOOP]++ )
  419.                         DrawItemToLayer(i[q[SUBSC_OBJDRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  420.                 }
  421.                 /*
  422.                 if ( CURSOR_LAYER ) {
  423.                     DrawItemToLayer(i[SUBSC_LAST],CURSOR_LAYER, OP_OPAQUE);
  424.                 }
  425.                 */
  426.                     //Handled another way now.
  427.                 if ( Link->PressRight ) {
  428.                     if ( q[SUBSC_SELECTED] < ( SUBSC_MAX_ITEMS -1 ) ) {
  429.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  430.                         q[SUBSC_SELECTED]++;
  431.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  432.                     }
  433.                     else {
  434.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  435.                         q[SUBSC_SELECTED] = 0;
  436.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  437.                     }
  438.                 }
  439.                 if ( Link->PressLeft ) {
  440.                     if ( q[SUBSC_SELECTED] > 0 ) {
  441.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  442.                         q[SUBSC_SELECTED]--;
  443.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  444.                     }
  445.                     else {
  446.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  447.                         q[SUBSC_SELECTED] = ( SUBSC_MAX_ITEMS -1 );
  448.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  449.                     }
  450.                 }
  451.                 if ( Link->PressDown ) {
  452.                     if ( q[SUBSC_SELECTED] < ( SUBSC_MAX_ITEMS - SUBSC_ITEMS_PER_ROW ) ) { //18
  453.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  454.                         q[SUBSC_SELECTED] += SUBSC_ITEMS_PER_ROW; //6
  455.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  456.                     }
  457.                     else { //on bottom row
  458.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  459.                         q[SUBSC_SELECTED] -= (SUBSC_MAX_ITEMS - SUBSC_ITEMS_PER_ROW); //18
  460.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  461.                     }
  462.                 }
  463.                 if ( Link->PressUp ) {
  464.                    
  465.                     if ( q[SUBSC_SELECTED] > ( SUBSC_ITEMS_PER_ROW -1 )  ) {  //5
  466.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  467.                         q[SUBSC_SELECTED] -= SUBSC_ITEMS_PER_ROW; //6
  468.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  469.                     }
  470.                     else {
  471.                         q[SUBSC_LAST_SELECTED] = q[SUBSC_SELECTED];
  472.                         q[SUBSC_SELECTED] += (SUBSC_MAX_ITEMS - SUBSC_ITEMS_PER_ROW); //18
  473.                         Game->PlaySound(SUBSC_CURSOR_SFX);
  474.                     }
  475.                 }
  476.                 if ( Link->PressA ) {
  477.                     if ( i[q[SUBSC_SELECTED]]->ID != I_SUBSCREEN_BLANK ) {
  478.                         //If the item is not usable, and only something to equip or
  479.                         //to unequip, such as shields, or flippers...
  480.                         if ( IsEnableDisableItem( i[q[SUBSC_SELECTED]]->ID ) ) {
  481.                             Game->PlaySound(SUBSC_SFX_EQUIP);
  482.                             //Be sure to set that Link owns it...
  483.                             OwnsItems[i[q[SUBSC_SELECTED]]->ID] = 1;
  484.                             //equip[0]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  485.                             //Equip/Unequip that item.
  486.                             DoEnableDisable( i[q[SUBSC_SELECTED]]->ID );
  487.                         }                              
  488.                         else{
  489.                             //Set Link's A-slot item
  490.                             Link->ItemA = i[q[SUBSC_SELECTED]]->ID;
  491.                            
  492.                             //Set the array index, so tha it is properly updated.
  493.                             ButtonItems[BUTTONITEM_A] = i[q[SUBSC_SELECTED]]->ID;
  494.                             //Load the itemdata so that we can set the tile for the
  495.                             //subscreen-A-Slot icon.
  496.                             id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemA);
  497.                             //Set the A-Slot icon on the subscreen with the proper tile
  498.                             //and cset.
  499.                             equip[1]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  500.                             equip[1]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  501.                             Game->PlaySound(SUBSC_SELECTED_SFX);
  502.                         }
  503.                     }
  504.                 }
  505.                 if ( Link->PressB ) {
  506.                     if ( i[q[SUBSC_SELECTED]]->ID != I_SUBSCREEN_BLANK ) {
  507.                         if ( IsEnableDisableItem( i[q[SUBSC_SELECTED]]->ID ) ) {
  508.                             Game->PlaySound(SUBSC_SFX_EQUIP);
  509.                             OwnsItems[i[q[SUBSC_SELECTED]]->ID] = 1;
  510.                             DoEnableDisable( i[q[SUBSC_SELECTED]]->ID );
  511.                         }
  512.                         else {
  513.                            
  514.                             Link->ItemB = i[q[SUBSC_SELECTED]]->ID;
  515.                             ButtonItems[BUTTONITEM_B] = i[q[SUBSC_SELECTED]]->ID;  
  516.                             id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemB);
  517.                            
  518.                             equip[0]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  519.                             equip[0]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  520.                             Game->PlaySound(SUBSC_SELECTED_SFX);
  521.                         }
  522.                     }
  523.                 }
  524.                
  525.                 if ( Link->PressR ) {}  //pan to right page
  526.                 if ( Link->PressL ) {
  527.                    
  528.                     Game->PlaySound(SUBSC_SELECTED_SFX);
  529.                     pan_in = true;
  530.                     i[SUBSC_LAST]->DrawYOffset = -1000; //Hide the cursor.
  531.                     do{
  532.                         PanLeftToRight(PANE_CENTRE,false);
  533.                         pan_in = PanLeftToRight(PANE_LEFT,true);
  534.                         for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  535.                             DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  536.                         WaitNoAction();
  537.                     } while(pan_in);
  538.                    
  539.                    
  540.                     q[PANE_ID] = PANE_LEFT;  //pan to left page
  541.                     q[PANE_CENTRE_DRAWN] = 0;
  542.                 }
  543.                 if ( Link->PressStart ) {
  544.                     Link->PressStart = false;
  545.                     i[SUBSC_LAST]->DrawYOffset = -1000; //Hide the cursor.
  546.                     pan_in = true;
  547.                     Game->PlaySound(SUBSC_CLOSE_SFX);
  548.                     do{
  549.                         pan_in = PanExit(PANE_CENTRE,false,i);
  550.                         for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  551.                             DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  552.                             /*Doing this causes graphical glitches:
  553.                             DrawItemToLayer(equip[0], SUBSC_OBJ_LAYER, OP_OPAQUE);
  554.                             DrawItemToLayer(equip[1], SUBSC_OBJ_LAYER, OP_OPAQUE);
  555.                             */
  556.                         WaitNoAction();
  557.                     } while(pan_in);
  558.                     if ( SUBSC_FADE_OUT == 1 ) Screen->ZapIn();
  559.                     if ( SUBSC_FADE_OUT == 2 ) Screen->ZapOut();
  560.                     q[SUBSC_ACTIVE] = 0; //Mark that we should draw.
  561.                    
  562.                     for ( q[SUBSC_EXIT_CLEANUP_LOOP] = Screen->NumItems(); q[SUBSC_EXIT_CLEANUP_LOOP] > 0; q[SUBSC_EXIT_CLEANUP_LOOP]--) {
  563.                         i[SUBSC_LAST] = Screen->LoadItem(q[SUBSC_EXIT_CLEANUP_LOOP]);
  564.                         if ( i[SUBSC_LAST]->Misc[MISC_SUBSC_OBJ] == IS_SUBSCREEN_OBJECT ) Remove(i[SUBSC_LAST]);
  565.                     }
  566.                     Remove(equip[0]); Remove(equip[1]);
  567.                     GRAM[EXITING_SUBSCREEN] = 1;
  568.                     ButtonItems[BUTTONITEM_SUBSCREEN] = 0;
  569.                     if ( SUBSC_LINK_INVISIBLE ) Link->Invisible = false;
  570.                     this->Data = 0; this->Script = 0; Quit();
  571.                 }
  572.                 i[SUBSC_LAST]->X = i[q[SUBSC_SELECTED]]->X;
  573.                 i[SUBSC_LAST]->Y = i[q[SUBSC_SELECTED]]->Y;
  574.             }
  575.             if ( q[PANE_ID] == PANE_LEFT ) {
  576.                 if ( Link->PressR ) {
  577.                     i[SUBSC_LAST]->DrawYOffset = -1000; //Hide the cursor.
  578.                    
  579.                     Game->PlaySound(SUBSC_SELECTED_SFX);
  580.                     pan_in = true;
  581.                     do{
  582.                         PanRightToLeft(PANE_LEFT,false);
  583.                         pan_in = PanRightToLeft(PANE_CENTRE,true);
  584.                         for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  585.                             DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  586.                             /*Doing this causes graphical glitches:
  587.                             //DrawItemToLayer(equip[0], SUBSC_OBJ_LAYER, OP_OPAQUE);
  588.                             //DrawItemToLayer(equip[1], SUBSC_OBJ_LAYER, OP_OPAQUE);
  589.                             */
  590.                         WaitNoAction();
  591.                     } while(pan_in);
  592.                    
  593.                    
  594.                     q[PANE_ID] = PANE_CENTRE;  //pan to left page
  595.                     q[PANE_CENTRE_DRAWN] = 0;
  596.                    
  597.                 }
  598.                 if ( Link->PressStart ) {
  599.                     Link->PressStart = false;
  600.                     i[SUBSC_LAST]->DrawYOffset = -1000; //Hide the cursor.
  601.                     Game->PlaySound(SUBSC_CLOSE_SFX);
  602.                     pan_in = true;
  603.                     do{
  604.                         pan_in = PanExit(PANE_LEFT,false,i);
  605.                         for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] < SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  606.                             DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  607.                        
  608.                         WaitNoAction();
  609.                     } while(pan_in);
  610.  
  611.                     for ( q[SUBSC_EXIT_CLEANUP_LOOP] = Screen->NumItems(); q[SUBSC_EXIT_CLEANUP_LOOP] > 0; q[SUBSC_EXIT_CLEANUP_LOOP]--) {
  612.                         i[SUBSC_LAST] = Screen->LoadItem(q[SUBSC_EXIT_CLEANUP_LOOP]);
  613.                         if ( i[SUBSC_LAST]->Misc[MISC_SUBSC_OBJ] == IS_SUBSCREEN_OBJECT ) Remove(i[SUBSC_LAST]);
  614.                     }
  615.                     Remove(equip[0]); Remove(equip[1]);
  616.                     GRAM[EXITING_SUBSCREEN] = 1;
  617.                     ButtonItems[BUTTONITEM_SUBSCREEN] = 0;
  618.                     if ( SUBSC_LINK_INVISIBLE ) Link->Invisible = false;
  619.                     if ( SUBSC_FADE_OUT == 1 ) Screen->ZapIn();
  620.                     if ( SUBSC_FADE_OUT == 2 ) Screen->ZapOut();
  621.                    
  622.                     q[SUBSC_ACTIVE] = 0;
  623.                     this->Data = 0; this->Script = 0; Quit();
  624.                 }
  625.             }
  626.             if ( !pan_in ) { //Prevent flicker of background.
  627.                 DrawSubscreenTiles(q[PANE_ID]);
  628.                 if ( q[PANE_ID] == PANE_CENTRE ){
  629.                     for ( q[SUBSC_OBJ_PAN_DRAW_LOOP] = 0; q[SUBSC_OBJ_PAN_DRAW_LOOP] <= SUBSC_MAX_ITEMS; q[SUBSC_OBJ_PAN_DRAW_LOOP]++ )
  630.                             DrawItemToLayer(i[q[SUBSC_OBJ_PAN_DRAW_LOOP]],SUBSC_OBJ_LAYER, OP_OPAQUE);
  631.  
  632.                     DrawItemToLayer(equip[0], SUBSC_OBJ_LAYER, OP_OPAQUE);
  633.                     DrawItemToLayer(equip[1], SUBSC_OBJ_LAYER, OP_OPAQUE);
  634.                 }
  635.                 DrawSubscreenInventoryText();
  636.             }
  637.             Waitframe();
  638.         }
  639.         for ( q[SUBSC_EXIT_CLEANUP_LOOP] = Screen->NumItems(); q[SUBSC_EXIT_CLEANUP_LOOP] > 0; q[SUBSC_EXIT_CLEANUP_LOOP]--) {
  640.             i[SUBSC_LAST] = Screen->LoadItem(q[SUBSC_EXIT_CLEANUP_LOOP]);
  641.             if ( i[SUBSC_LAST]->Misc[MISC_SUBSC_OBJ] == IS_SUBSCREEN_OBJECT ) Remove(i[SUBSC_LAST]);
  642.         }
  643.         Remove(equip[0]); Remove(equip[1]);
  644.         GRAM[EXITING_SUBSCREEN] = 1;
  645.         ButtonItems[BUTTONITEM_SUBSCREEN] = 0;
  646.         if ( SUBSC_LINK_INVISIBLE ) Link->Invisible = false;
  647.         //Resume Ghost.zh here.
  648.  
  649.         this->Data = 0; this->Script = 0; Quit();
  650.     }
  651. }
  652.  
  653. ////////////////////////////////
  654. /// Test and Utility Scripts ///
  655. ////////////////////////////////
  656.  
  657. item script test{
  658.     void run(){
  659.         int s[]="Using item: ";
  660.         TraceS(s); Trace(Link->UsingItem);
  661.         int ss[]="Tracing this->ID: ";
  662.         TraceS(ss); Trace(this->ID);
  663.     }
  664. }
  665.  
  666. item script map{
  667.     void run(){
  668.         Link->InputMap = true;
  669.         Link->PressMap = true;
  670.     }
  671. }
  672.  
  673. global script Init{
  674.     void run(){
  675.         SetDefaultItems();
  676.     }
  677. }
  678.  
  679. item script Equip{
  680.     void run(){
  681.         if ( Link->Item[this->ID] && OwnsItems[this->ID] ){ OwnsItems[this->ID] = 1; Link->Item[this->ID] = false; }
  682.         if ( !Link->Item[this->ID] && OwnsItems[this->ID] ) Link->Item[this->ID] = true;
  683.     }
  684. }
  685.        
  686.  
  687. ////////////////////////
  688. /// Global Functions ///
  689. ////////////////////////
  690.  
  691.  
  692. //! Global Array Accessors
  693.  
  694. //Returns the pointer for the global array index that controls subscreen values.
  695. int GetSubscreenPtr(){ return GRAM[SUBSCREEN]; }
  696.  
  697. //Called from the ffc to store the array pointer in GRAM[]
  698. void AssignSubscreenPointer(int ptr){
  699.     GRAM[SUBSCREEN]=ptr;
  700. }
  701.  
  702. //Get the pointer for the internal ffc array from anywhere.
  703. int GetEnableDisablePtr(){ return GRAM[ENABLEITEMS_PTR]; }
  704.  
  705.  
  706. //Call to run the subscreen ffc.
  707. void DoSubscreen(){
  708.     if ( SUBSC_LINK_INVISIBLE ) Link->Invisible = true;
  709.     //Suspend ghost.zh
  710.     ButtonItems[BUTTONITEM_SUBSCREEN] = 1;
  711.     int s[]="SubscreenScript";
  712.     int ff = Game->GetFFCScript(s);
  713.     ffc f = Screen->LoadFFC(SUBSC_FFC_INDEX);
  714.     f->Data = SUBSC_FFC_DATA;
  715.     f->Script = ff;
  716. }
  717.  
  718. //Store the pointer of the internal ffc array into GRAM[]
  719. void StoreEnableItemsPtr(int arr){
  720.     GRAM[ENABLEITEMS_PTR] = arr;
  721. }
  722.  
  723. //Returns if an item is an equippable item.
  724. bool IsEnableDisableItem(int itm){
  725.     int it_ptr = GetEnableDisablePtr();
  726.     for ( int q = (SizeOfArray(it_ptr)-1); q >= 0; q-- ) {
  727.         if ( it_ptr[q] == itm ) return true;
  728.     }
  729.     return false;
  730. }
  731.  
  732. //Equip or unequip an item.
  733. void DoEnableDisable(int itm){
  734.     if ( Link->Item[ itm ] ) Link->Item[itm] = false;
  735.     else Link->Item[itm] = true;
  736. }
  737.  
  738. //Sets some base items.
  739. void SetDefaultItems(){
  740.     Link->Item[I_SHIELD1] = true;
  741.     Link->Item[I_SWORD1] = true;
  742.     Link->Item[I_SWORD2] = true;
  743.     Link->Item[I_WAND] = true;
  744.     Link->Item[I_WHISTLE] = true;
  745.     Link->Item[I_BAIT] = true;
  746.     Link->Item[I_HOOKSHOT1] = true;
  747.     Link->Item[I_MAP] = true;
  748.     OwnsItems[I_MAP] = 1;
  749.     //for ( int q = 0; q < 256; q++ ) TraceB(Link->Item[q]);
  750. }
  751.  
  752.  
  753. //! Drawing Routines : 18 draws here.
  754. void DrawSubscreenInventoryText(){
  755.     //Keys 1
  756.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS1+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  757.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  758.         Game->Counter[CR_KEYS], 0, SUBSC_TEXT_INV_OPACITY);
  759.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS1, SUBSC_TEXT_Y_INVENTORY,
  760.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  761.         Game->Counter[CR_KEYS], 0, SUBSC_TEXT_INV_OPACITY);
  762.     //Keys 2
  763.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS2+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  764.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  765.         Game->LKeys[Game->GetCurLevel()], 0, SUBSC_TEXT_INV_OPACITY);
  766.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS2, SUBSC_TEXT_Y_INVENTORY,
  767.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  768.         Game->LKeys[Game->GetCurLevel()], 0, SUBSC_TEXT_INV_OPACITY);
  769.     //Keys 3
  770.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS3+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  771.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  772.         Game->Counter[CR_SCRIPT5], 0, SUBSC_TEXT_INV_OPACITY);
  773.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_KEYS3, SUBSC_TEXT_Y_INVENTORY,
  774.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  775.         Game->Counter[CR_SCRIPT5], 0, SUBSC_TEXT_INV_OPACITY);
  776.     //Bombs
  777.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_BOMBS+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  778.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  779.         Game->Counter[CR_BOMBS], 0, SUBSC_TEXT_INV_OPACITY);
  780.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_BOMBS, SUBSC_TEXT_Y_INVENTORY,
  781.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  782.         Game->Counter[CR_BOMBS], 0, SUBSC_TEXT_INV_OPACITY);
  783.     //Super Bombs
  784.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_SBOMBS+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  785.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  786.         Game->Counter[CR_SBOMBS], 0, SUBSC_TEXT_INV_OPACITY);
  787.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_SBOMBS, SUBSC_TEXT_Y_INVENTORY,
  788.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  789.         Game->Counter[CR_SBOMBS], 0, SUBSC_TEXT_INV_OPACITY);
  790.     //Arrows
  791.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_ARROWS+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  792.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  793.         Game->Counter[CR_ARROWS], 0, SUBSC_TEXT_INV_OPACITY);
  794.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_ARROWS, SUBSC_TEXT_Y_INVENTORY,
  795.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  796.         Game->Counter[CR_ARROWS], 0, SUBSC_TEXT_INV_OPACITY);
  797.     //Life
  798.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_LIFE+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  799.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  800.         Game->Counter[CR_LIFE], 0, SUBSC_TEXT_INV_OPACITY);
  801.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_LIFE, SUBSC_TEXT_Y_INVENTORY,
  802.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  803.         Game->Counter[CR_LIFE], 0, SUBSC_TEXT_INV_OPACITY);
  804.     //Magic
  805.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_MAGIC+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  806.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  807.         Game->Counter[CR_MAGIC], 0, SUBSC_TEXT_INV_OPACITY);
  808.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_MAGIC, SUBSC_TEXT_Y_INVENTORY,
  809.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  810.         Game->Counter[CR_MAGIC], 0, SUBSC_TEXT_INV_OPACITY);
  811.     //Money
  812.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_MONEY+SUBSC_TEXT_INV_SHADOW_OFFSET, SUBSC_TEXT_Y_INVENTORY,
  813.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_BG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  814.         Game->Counter[CR_RUPEES], 0, SUBSC_TEXT_INV_OPACITY);
  815.     Screen->DrawInteger(SUBSC_TEXT_LAYER, SUBSC_TEXT_X_MONEY, SUBSC_TEXT_Y_INVENTORY,
  816.         SUBSC_TEXT_INV_FONT, SUBSC_TEXT_INV_FG_COLOUR, SUBSC_TEXT_BACKDROP, SUBSC_TEXT_INV_FONT_SIZE, SUBSC_TEXT_INV_FONT_SIZE,
  817.         Game->Counter[CR_RUPEES], 0, SUBSC_TEXT_INV_OPACITY);
  818. }
  819.  
  820. //Store the subscreen panes into bitmaps. (Effectively deprecated.)
  821. void SetupSubscreenBitmap(){
  822.     Screen->SetRenderTarget(RT_BITMAP0);
  823.     //Centre pane
  824.     Screen->DrawTile( SUBSC_TILE_LAYER, SUBSC_TILE_INITIAL_X, SUBSC_TILE_INITIAL_Y,
  825.                         SUBSC_FIRST_TILE, SUBSC_TILE_WIDTH, SUBSC_TILE_HEIGHT,
  826.                         SUBSC_TILE_CSET, SUBSC_TILE_XSCALE, SUBSC_TILE_YSCALE,
  827.                         SUBSC_TILE_RX, SUBSC_TILE_RY, SUBSC_TILE_RANGLE,
  828.                         SUBSC_TILE_FLIP, true, SUBSC_TILE_OPACITY);
  829.     Screen->SetRenderTarget(RT_BITMAP1);
  830.     //Left pane
  831.     Screen->DrawTile( SUBSC_TILE_LAYER, SUBSC_TILE_INITIAL_X, SUBSC_TILE_INITIAL_Y,
  832.                         SUBSC_TILE_LPANE, SUBSC_TILE_WIDTH, SUBSC_TILE_HEIGHT,
  833.                         SUBSC_TILE_CSET, SUBSC_TILE_XSCALE, SUBSC_TILE_YSCALE,
  834.                         SUBSC_TILE_RX, SUBSC_TILE_RY, SUBSC_TILE_RANGLE,
  835.                         SUBSC_TILE_FLIP, true, SUBSC_TILE_OPACITY);
  836.     Screen->SetRenderTarget(RT_BITMAP2);
  837.     //Right pane
  838.     Screen->DrawTile( SUBSC_TILE_LAYER, SUBSC_TILE_INITIAL_X, SUBSC_TILE_INITIAL_Y,
  839.                         SUBSC_TILE_LPANE, SUBSC_TILE_WIDTH, SUBSC_TILE_HEIGHT,
  840.                         SUBSC_TILE_CSET, SUBSC_TILE_XSCALE, SUBSC_TILE_YSCALE,
  841.                         SUBSC_TILE_RX, SUBSC_TILE_RY, SUBSC_TILE_RANGLE,
  842.                         SUBSC_TILE_FLIP, true, SUBSC_TILE_OPACITY);
  843.    
  844. }
  845.  
  846. //Draws an item to a given layer
  847. void DrawItemToLayer(item i, int layer, int opacity){
  848.     Screen->DrawTile(layer,i->X+SubPaneX(PANE_CENTRE),i->Y+SubPaneY(PANE_CENTRE),i->Tile+i->Frame,i->TileWidth,i->TileHeight,i->CSet,-1,-1,0,0,0,0,true,opacity);
  849.     //Trace(i->Frame);
  850. }
  851.  
  852.  
  853. //Draws an item to a layer at x, y
  854. void DrawItemToLayer(item i, int layer, int x, int y, int opacity){
  855.     Screen->DrawTile(layer,x,y,i->Tile+i->Frame,i->TileWidth,i->TileHeight,i->CSet,-1,-1,0,0,0,0,true,opacity);
  856. }
  857.  
  858.  
  859. //Returns the present subscreen base tile.
  860. int GetPaneTile(int pane){
  861.     if ( pane == PANE_LEFT ) return SUBSC_TILE_LPANE;
  862.     else if ( pane == PANE_RIGHT ) return SUBSC_TILE_RPANE;
  863.     else return SUBSC_FIRST_TILE;
  864. }
  865.  
  866. //THe main drawing routine. Call as: DrawSubscreenTiles(GetSubscreenPane())
  867. void DrawSubscreenTiles(int pane_id){
  868.     Screen->DrawTile( SUBSC_TILE_LAYER, SUBSC_TILE_INITIAL_X+SubPaneX(pane_id), SUBSC_TILE_INITIAL_Y+SubPaneY(pane_id),
  869.                         GetPaneTile(pane_id), SUBSC_TILE_WIDTH, SUBSC_TILE_HEIGHT,
  870.                         SUBSC_TILE_CSET, SUBSC_TILE_XSCALE, SUBSC_TILE_YSCALE,
  871.                         SUBSC_TILE_RX, SUBSC_TILE_RY, SUBSC_TILE_RANGLE,
  872.                         SUBSC_TILE_FLIP, true, SUBSC_TILE_OPACITY);
  873. }
  874.  
  875.  
  876. //! Subscreen Pane Panning
  877.  
  878. //Getters for Panning
  879. int SubPaneX(int pane){
  880.     int ss_ptr = GetSubscreenPtr();
  881.     if ( pane == PANE_LEFT ) return ss_ptr[PANE_LEFT_X];
  882.     else if ( pane == PANE_RIGHT ) return ss_ptr[PANE_RIGHT_X];
  883.     else return ss_ptr[PANE_CENTRE_X];
  884. }
  885.  
  886. int SubPaneY(int pane){
  887.     int ss_ptr = GetSubscreenPtr();
  888.     if ( pane == PANE_LEFT ) return ss_ptr[PANE_LEFT_Y];
  889.     else if ( pane == PANE_RIGHT ) return ss_ptr[PANE_RIGHT_Y];
  890.     else return ss_ptr[PANE_CENTRE_Y];
  891. }
  892.  
  893. void SubPaneX(int pane, int value){
  894.     int ss_ptr = GetSubscreenPtr();
  895.     if ( pane == PANE_LEFT ) ss_ptr[PANE_LEFT_X] = value;
  896.     else if ( pane == PANE_RIGHT ) ss_ptr[PANE_RIGHT_X] = value;
  897.     else ss_ptr[PANE_CENTRE_X] = value;
  898. }
  899.  
  900. void SubPaneY(int pane, int value){
  901.     int ss_ptr = GetSubscreenPtr();
  902.     if ( pane == PANE_LEFT ) ss_ptr[PANE_LEFT_Y] = value;
  903.     else if ( pane == PANE_RIGHT ) ss_ptr[PANE_RIGHT_Y] = value;
  904.     else ss_ptr[PANE_CENTRE_Y] = value;
  905. }
  906.  
  907. //Panning routines
  908. //Pan left
  909. bool PanLeftToRight(int pane, bool in){
  910.     //Slide in fromthe left
  911.     Link->PressStart = false;
  912.     NoAction();
  913.     if ( in ) {
  914.         if ( SubPaneX(pane) <= (SCREEN_LEFT-SUBSC_PAN_SPEED) ) {
  915.             SubPaneX(pane, ( SubPaneX(pane) + SUBSC_PAN_SPEED ) );
  916.             DrawSubscreenTiles(pane);
  917.             return true;
  918.         }
  919.         //Draw tiles or bitmap.
  920.         //tiles
  921.         DrawSubscreenTiles(pane);
  922.         return false;
  923.     }
  924.     if ( !in ) {
  925.         if ( SubPaneX(pane) <= (SCREEN_RIGHT+SUBSC_PAN_SPEED) ) {
  926.             SubPaneX(pane, ( SubPaneX(pane) + SUBSC_PAN_SPEED ) );
  927.             DrawSubscreenTiles(pane);
  928.             return true;
  929.         }
  930.         //Draw tiles or bitmap.
  931.         //tiles
  932.         DrawSubscreenTiles(pane);
  933.         return false;
  934.     }
  935. }
  936.  
  937. bool PanRightToLeft(int pane, bool in){
  938.     //Slide in fromthe left
  939.     Link->PressStart = false;
  940.     NoAction();
  941.     if ( in ) {
  942.         if ( SubPaneX(pane) > (SCREEN_LEFT) ) {
  943.             SubPaneX(pane,SubPaneX(pane)-SUBSC_PAN_SPEED);
  944.             DrawSubscreenTiles(pane);
  945.             return true;
  946.         }
  947.         //Draw tiles or bitmap.
  948.         //tiles
  949.         DrawSubscreenTiles(pane);
  950.         return false;
  951.     }
  952.     if ( !in ) {
  953.         if ( SubPaneX(pane)+SCREEN_RIGHT > (SCREEN_LEFT-SUBSC_PAN_SPEED) ) {
  954.             SubPaneX(pane,SubPaneX(pane)-SUBSC_PAN_SPEED);
  955.             DrawSubscreenTiles(pane);
  956.             return true;
  957.         }
  958.         //Draw tiles or bitmap.
  959.         //tiles
  960.         DrawSubscreenTiles(pane);
  961.         return false;
  962.     }
  963. }
  964.  
  965. bool PanUpToDown(int pane, bool in){
  966.     //Slide in fromthe left
  967.     Link->PressStart = false;
  968.     NoAction();
  969.     if ( in ) {
  970.         if ( SubPaneY(pane) <= (SCREEN_TOP-SUBSC_PAN_SPEED) ) {
  971.             //if ( SubPaneY(pane) <= (SCREEN_TOP+SUBSC_PAN_SPEED) )
  972.             SubPaneY(pane,SubPaneY(pane)+SUBSC_PAN_SPEED);
  973.             //else
  974.             //SubPaneY(pane,SubPaneY(pane)+1);
  975.             DrawSubscreenTiles(pane);
  976.             return true;
  977.         }
  978.         //Draw tiles or bitmap.
  979.         //tiles
  980.         DrawSubscreenTiles(pane);
  981.         return false;
  982.     }
  983.     if ( !in ) {
  984.         if ( SubPaneY(pane) <= (SCREEN_BOTTOM-SUBSC_PAN_SPEED) ) {
  985.             SubPaneY(pane,SubPaneY(pane)+SUBSC_PAN_SPEED);
  986.             DrawSubscreenTiles(pane);
  987.             return true;
  988.         }
  989.         //Draw tiles or bitmap.
  990.         //tiles
  991.         DrawSubscreenTiles(pane);
  992.         return false;
  993.     }
  994. }
  995.  
  996. bool PanDownToUp(int pane, bool in){
  997.     //Slide in fromthe left
  998.     Link->PressStart = false;
  999.     NoAction();
  1000.     if ( in ) {
  1001.         if ( SubPaneY(pane) > (SUBSCREEN_TOP+SUBSC_PAN_SPEED) ) {
  1002.             SubPaneY(pane,SubPaneY(pane)-SUBSC_PAN_SPEED);
  1003.             DrawSubscreenTiles(pane);
  1004.             return true;
  1005.            
  1006.         }
  1007.         //Draw tiles or bitmap.
  1008.         //tiles
  1009.         DrawSubscreenTiles(pane);
  1010.         return false;
  1011.     }
  1012.     if ( !in ) {
  1013.         if ( SubPaneY(pane)+SUBSC_BITMAP_HEIGHT > (SUBSCREEN_TOP+SUBSC_PAN_SPEED) ) {
  1014.             SubPaneY(pane,SubPaneY(pane)-SUBSC_PAN_SPEED);
  1015.             DrawSubscreenTiles(pane);
  1016.             return true;
  1017.         }
  1018.         //Draw tiles or bitmap.
  1019.         //tiles
  1020.         DrawSubscreenTiles(pane);
  1021.         return false;
  1022.     }
  1023. }
  1024.  
  1025. //A special pan out routine for exiting the subscreen.
  1026. bool PanExit(int pane, bool in, item arr){
  1027.     //Slide in fromthe left
  1028.     Link->PressStart = false;
  1029.     NoAction();
  1030.     int q;
  1031.     if ( in ) {
  1032.         if ( SubPaneY(pane) > (SUBSCREEN_TOP+SUBSC_PAN_SPEED) ) {
  1033.             SubPaneY(pane,SubPaneY(pane)-SUBSC_PAN_SPEED);
  1034.             DrawSubscreenTiles(pane);
  1035.             return true;
  1036.            
  1037.         }
  1038.         //Draw tiles or bitmap.
  1039.         //tiles
  1040.         DrawSubscreenTiles(pane);
  1041.         return false;
  1042.     }
  1043.     if ( !in ) {
  1044.         if ( SubPaneY(pane)+SUBSC_BITMAP_HEIGHT > (SUBSCREEN_TOP+SUBSC_PAN_SPEED) ) {
  1045.             SubPaneY(pane,SubPaneY(pane)-SUBSC_PAN_SPEED);
  1046.             DrawSubscreenTiles(pane);
  1047.             for ( q = 0; q <= SUBSC_MAX_ITEMS; q++ )
  1048.                 DrawItemToLayer(arr[q],SUBSC_OBJ_LAYER, OP_OPAQUE);
  1049.                        
  1050.             return true;
  1051.         }
  1052.         //Draw tiles or bitmap.
  1053.         //tiles
  1054.         DrawSubscreenTiles(pane);
  1055.         for ( q = 0; q <= SUBSC_MAX_ITEMS; q++ )
  1056.             Remove(arr[ q ]); //<= to clean up cursor.
  1057.                    
  1058.         return false;
  1059.     }
  1060. }
  1061.  
  1062. //! Utilities
  1063.  
  1064. void ChangeItemScript(itemdata a, itemdata b){
  1065.     b->Script = a->Script;
  1066. }
  1067.  
  1068. void ChangeItemScript(itemdata a, item b){
  1069.     itemdata c = Game->LoadItemData(b->ID);
  1070.     a->Script = c->Script;
  1071. }
  1072.  
  1073. void ChangeItemPScript(itemdata a, itemdata b){
  1074.     b->PScript = a->PScript;
  1075. }
  1076.  
  1077. void ChangeItemPScript(itemdata a, item b){
  1078.     itemdata c = Game->LoadItemData(b->ID);
  1079.     a->PScript = c->PScript;
  1080. }
  1081.  
  1082.  
  1083. //Sample Global Active Script
  1084. global script active{
  1085.     void run(){
  1086.         SetDefaultItems();
  1087.         int a[]="ZC 2.54 Beta 46 Demo Quest One, v0.6"; TraceNL(); TraceS(a); TraceNL();
  1088.         Game->DisableActiveSubscreen = true; //Prevent the internal subscreen from appearing.
  1089.        
  1090.         while(true){
  1091.             if ( Link->PressStart ) {
  1092.                 DoSubscreen();
  1093.             }
  1094.            
  1095.             //Preserve the items on DMap change.
  1096.             //if ( !ButtonItems[BUTTONITEM_SUBSCREEN] ){
  1097.                 if ( Link->ItemA != ButtonItems[BUTTONITEM_A] && ButtonItems[BUTTONITEM_A] != 0 ) Link->ItemA = ButtonItems[BUTTONITEM_A];
  1098.                 if ( Link->ItemB != ButtonItems[BUTTONITEM_B] && ButtonItems[BUTTONITEM_B] != 0 ) Link->ItemB = ButtonItems[BUTTONITEM_B];
  1099.             //}
  1100.             //! The button items also shift when the subscreen opens and closes.
  1101.             //! Not sure why... Could this be doing it?
  1102.            
  1103.             if ( GRAM[EXITING_SUBSCREEN] ) {
  1104.                 GRAM[EXITING_SUBSCREEN] = 0;
  1105.                 if ( SUBSC_FADE_IN == 1 ) Screen->ZapIn();
  1106.                 if ( SUBSC_FADE_IN == 2 ) Screen->ZapOut();
  1107.                
  1108.             }
  1109.            
  1110.             //if ( !ButtonItems[BUTTONITEM_SUBSCREEN] ){
  1111.                 if ( Link->ItemA != ButtonItems[BUTTONITEM_A] && ButtonItems[BUTTONITEM_A] != 0 ) Link->ItemA = ButtonItems[BUTTONITEM_A];
  1112.                 if ( Link->ItemB != ButtonItems[BUTTONITEM_B] && ButtonItems[BUTTONITEM_B] != 0 ) Link->ItemB = ButtonItems[BUTTONITEM_B];
  1113.             //}
  1114.             Waitdraw();
  1115.            
  1116.             //Try callin it after waitdraw too, to prevent buggyness?
  1117.             //if ( !ButtonItems[BUTTONITEM_SUBSCREEN] ){
  1118.                 if ( Link->ItemA != ButtonItems[BUTTONITEM_A] && ButtonItems[BUTTONITEM_A] != 0 ) Link->ItemA = ButtonItems[BUTTONITEM_A];
  1119.                 if ( Link->ItemB != ButtonItems[BUTTONITEM_B] && ButtonItems[BUTTONITEM_B] != 0 ) Link->ItemB = ButtonItems[BUTTONITEM_B];
  1120.             //}
  1121.             Waitframe();
  1122.         }
  1123.     }
  1124. }
  1125.  
  1126. //Debug
  1127.  
  1128. void SSTest(int m){
  1129.     if ( SUBSCREEN_TEST_MODE < m ) return;
  1130.     if ( m == 1 ) {
  1131.         int s[]="Subscreen loaded.";
  1132.         TraceS(s);
  1133.     }
  1134.     if ( m == 2 ) {
  1135.         int s[]="Subscreen while loop running";
  1136.         TraceS(s);
  1137.     }
  1138.     if ( m == 4 ) {
  1139.         int s[]="Doing clean-up.";
  1140.         TraceS(s);
  1141.     }
  1142. }
  1143.  
  1144.  
  1145.  
  1146. ///! Object adding and reading
  1147.  
  1148. const int SUBSCREEN_OBJECTS = 506;
  1149.  
  1150. int SubscreenObjects[32];
  1151. //item Objects[32];
  1152.  
  1153. void SetSubscreenObjectsPtr(int arr){
  1154.     GRAM[SUBSCREEN_OBJECTS] = arr; //SubscreenObjects[]
  1155. }
  1156.  
  1157. int GetSubscreenObjectsPtr(){ return GRAM[SUBSCREEN_OBJECTS]; }
  1158.  
  1159. const int SUBSC_OBJ_ID      = 0;
  1160. const int SUBSC_OBJ_X       = 1;
  1161. const int SUBSC_OBJ_Y       = 2;
  1162. const int SUBSC_OBJ_ITEM    = 3;
  1163. const int SUBSC_OBJ_FUNCTION    = 4;
  1164. const int SUBSC_OBJ_NEXT_R  = 5;
  1165. const int SUBSC_OBJ_NEXT_L  = 6;
  1166. const int SUBSC_OBJ_NEXT_U  = 7;
  1167. const int SUBSC_OBJ_NEXT_D  = 8;
  1168. const int SUBSC_OBJ_TILE    = 9;
  1169. const int SUBSC_OBJ_CSET    = 10;
  1170. const int SUBSC_OBJ_INFO    = 11; //A string or string ref.
  1171. const int SUBSC_OBJ_LAST_INDEX  = 12;
  1172.  
  1173. const int SUBSC_OBJ_MISC_OFFSET = 16; //First Misc index to use.  
  1174. const int SUBSC_OBJ_MISC_RIGHT  = 0;
  1175. const int SUBSC_OBJ_MISC_LEFT   = 1;
  1176. const int SUBSC_OBJ_MISC_UP     = 2;
  1177. const int SUBSC_OBJ_MISC_DOWN   = 3;
  1178. const int SUBSC_OBJ_MISC_FUNCTION = 4;
  1179. const int SUBSC_OBJ_MISC_INFO = 5;
  1180.  
  1181. const int I_SUBSC_OBJECT    = 200;
  1182.  
  1183. void SetSubscreenObjectProperties(int id, int x, int y, int item_id, int tile, int cset, int function, int info, int up, int down, int left, int right){
  1184.     int optr = GRAM[SUBSCREEN_OBJECTS];
  1185.     int ofs = id * SUBSC_OBJ_LAST_INDEX; //offset
  1186.     optr[ofs+SUBSC_OBJ_ID] = id;
  1187.     optr[ofs+SUBSC_OBJ_X] = x;
  1188.     optr[ofs+SUBSC_OBJ_Y] = y;
  1189.     optr[ofs+SUBSC_OBJ_ITEM] = item_id;
  1190.     optr[ofs+SUBSC_OBJ_FUNCTION] = function;
  1191.     optr[ofs+SUBSC_OBJ_INFO] = info;
  1192.     optr[ofs+SUBSC_OBJ_TILE] = tile;
  1193.     optr[ofs+SUBSC_OBJ_CSET] = cset;
  1194.     optr[ofs+SUBSC_OBJ_NEXT_R] = right;
  1195.     optr[ofs+SUBSC_OBJ_NEXT_L] = left;
  1196.     optr[ofs+SUBSC_OBJ_NEXT_D] = down;
  1197.     optr[ofs+SUBSC_OBJ_NEXT_U] = up;
  1198. }
  1199.    
  1200. void CreateSubscreenObject(item arr, int id){
  1201.     int optr = GRAM[SUBSCREEN_OBJECTS];
  1202.     int ofs = id * SUBSC_OBJ_LAST_INDEX; //offset
  1203.     arr[id] = Screen->CreateItem(I_SUBSC_OBJECT);
  1204.     arr[id]->Tile = optr[ofs+SUBSC_OBJ_TILE];
  1205.     arr[id]->CSet = optr[ofs+SUBSC_OBJ_CSET];
  1206.     arr[id]->X = optr[ofs+SUBSC_OBJ_X];
  1207.     arr[id]->Y = optr[ofs+SUBSC_OBJ_Y];
  1208.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_RIGHT] = optr[ofs+SUBSC_OBJ_NEXT_R];
  1209.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_LEFT] = optr[ofs+SUBSC_OBJ_NEXT_L];
  1210.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_DOWN] = optr[ofs+SUBSC_OBJ_NEXT_D];
  1211.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_UP] = optr[ofs+SUBSC_OBJ_NEXT_U];
  1212.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_FUNCTION] = optr[ofs+SUBSC_OBJ_FUNCTION];
  1213.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_INFO] = optr[ofs+SUBSC_OBJ_INFO];
  1214. }
  1215.  
  1216. //Returns an object property from an item.
  1217. int GetSubscreenObjectProperty(item arr, int id, int property){
  1218.     if ( property == SUBSC_OBJ_ID ) return id;
  1219.     if ( property == SUBSC_OBJ_X ) return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->X;
  1220.     if ( property == SUBSC_OBJ_Y ) return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Y;
  1221.     if ( property == SUBSC_OBJ_ITEM ) return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->ID;
  1222.     if ( property == SUBSC_OBJ_NEXT_R )
  1223.         return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_RIGHT];
  1224.     if ( property == SUBSC_OBJ_NEXT_L )
  1225.         return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_LEFT];
  1226.     if ( property == SUBSC_OBJ_NEXT_D )
  1227.         return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_DOWN];
  1228.     if ( property == SUBSC_OBJ_NEXT_U )
  1229.         return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_UP];
  1230.     if ( property == SUBSC_OBJ_FUNCTION )
  1231.         return arr[ ( id * SUBSC_OBJ_LAST_INDEX ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_FUNCTION];
  1232.     if ( property == SUBSC_OBJ_NEXT_U )
  1233.         return arr[ ( id * SUBSC_OBJ_INFO ) ]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_INFO];
  1234.     return 0; //default
  1235. }
  1236.  
  1237.    
  1238.    
  1239. //Returns an object property from the global array.
  1240. int GetSubscreenObjectProperty(int id, int property){
  1241.     int optr = GRAM[SUBSCREEN_OBJECTS];
  1242.     return optr[ ( id * SUBSC_OBJ_LAST_INDEX ) + property ];
  1243. }
  1244.  
  1245. //Creates a subscreen object while defining its properties.
  1246. void CreateSubscreenObject(item arr, int id, int x, int y, int item_id, int tile, int cset, int function, int up, int down, int left, int right){
  1247.     int optr = GRAM[SUBSCREEN_OBJECTS];
  1248.     int ofs = id * SUBSC_OBJ_LAST_INDEX; //offset
  1249.     optr[ofs+SUBSC_OBJ_ID] = id;
  1250.     optr[ofs+SUBSC_OBJ_X] = x;
  1251.     optr[ofs+SUBSC_OBJ_Y] = y;
  1252.     optr[ofs+SUBSC_OBJ_ITEM] = item_id;
  1253.     optr[ofs+SUBSC_OBJ_FUNCTION] = function;
  1254.     optr[ofs+SUBSC_OBJ_TILE] = tile;
  1255.     optr[ofs+SUBSC_OBJ_CSET] = cset;
  1256.     optr[ofs+SUBSC_OBJ_NEXT_R] = right;
  1257.     optr[ofs+SUBSC_OBJ_NEXT_L] = left;
  1258.     optr[ofs+SUBSC_OBJ_NEXT_D] = down;
  1259.     optr[ofs+SUBSC_OBJ_NEXT_U] = up;
  1260.     arr[id] = Screen->CreateItem(I_SUBSC_OBJECT);
  1261.     arr[id]->Tile = optr[ofs+SUBSC_OBJ_TILE];
  1262.     arr[id]->CSet = optr[ofs+SUBSC_OBJ_CSET];
  1263.     arr[id]->X = optr[ofs+SUBSC_OBJ_X];
  1264.     arr[id]->Y = optr[ofs+SUBSC_OBJ_Y];
  1265.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_RIGHT] = optr[ofs+SUBSC_OBJ_NEXT_R];
  1266.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_LEFT] = optr[ofs+SUBSC_OBJ_NEXT_L];
  1267.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_DOWN] = optr[ofs+SUBSC_OBJ_NEXT_D];
  1268.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_UP] = optr[ofs+SUBSC_OBJ_NEXT_U];
  1269.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_FUNCTION] = optr[ofs+SUBSC_OBJ_FUNCTION];
  1270.     arr[id]->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_INFO] = optr[ofs+SUBSC_OBJ_INFO];
  1271. }
  1272.  
  1273. //List of functions
  1274. const int SubscSetItemA     = 1;
  1275. const int SubscSetItemB     = 2;
  1276. const int SubscEquip        = 3;
  1277. const int SubscEquipClass   = 4;
  1278. const int SubscInfo         = 5;
  1279.  
  1280. int RunSubscreenObjectFunction(int function, int id, int press){
  1281.     int optr = GRAM[SUBSCREEN_OBJECTS];
  1282.     int ofs = id * SUBSC_OBJ_LAST_INDEX; //offset
  1283.     if ( function == 0 ) { return 0; }
  1284.     if ( function == SubscSetItemA && press == 2 ) {
  1285.         //Set Link's A-slot item
  1286.         Link->ItemA = optr[ ofs + SUBSC_OBJ_ITEM ];
  1287.        
  1288.         //Set the array index, so tha it is properly updated.
  1289.         ButtonItems[BUTTONITEM_A] = optr[ ofs + SUBSC_OBJ_ITEM ];
  1290.         //Load the itemdata so that we can set the tile for the
  1291.         //subscreen-A-Slot icon.
  1292.         //!Needs to be done inside the pane ffc.
  1293.         //! id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemA);
  1294.         //Set the A-Slot icon on the subscreen with the proper tile
  1295.         //and cset.
  1296.         //equip[1]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  1297.         //equip[1]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  1298.         Game->PlaySound(SUBSC_SELECTED_SFX);
  1299.         return optr[ ofs + SUBSC_OBJ_ITEM ]; }
  1300.     if ( function == SubscSetItemB && press == 1 ) {
  1301.         //Set Link's A-slot item
  1302.         Link->ItemB = optr[ ofs + SUBSC_OBJ_ITEM ];
  1303.        
  1304.         //Set the array index, so tha it is properly updated.
  1305.         ButtonItems[BUTTONITEM_B] = optr[ ofs + SUBSC_OBJ_ITEM ];
  1306.         //Load the itemdata so that we can set the tile for the
  1307.         //subscreen-A-Slot icon.
  1308.         //!Needs to be done inside the pane ffc.
  1309.         //! id[SUBSC_IDATA_SCRATCH] = Game->LoadItemData(Link->ItemA);
  1310.         //Set the A-Slot icon on the subscreen with the proper tile
  1311.         //and cset.
  1312.         //equip[1]->Tile = id[SUBSC_IDATA_SCRATCH]->Tile;
  1313.         //equip[1]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  1314.         Game->PlaySound(SUBSC_SELECTED_SFX);
  1315.         return optr[ ofs + SUBSC_OBJ_ITEM ]; }
  1316.     if ( function == SubscEquip && press ) {
  1317.         Game->PlaySound(SUBSC_SFX_EQUIP);
  1318.         //Be sure to set that Link owns it...
  1319.         OwnsItems[ optr[ ofs + SUBSC_OBJ_ITEM ] ] = 1;
  1320.         //equip[0]->CSet = id[SUBSC_IDATA_SCRATCH]->CSet;
  1321.         //Equip/Unequip that item.
  1322.         DoEnableDisable( optr[ ofs + SUBSC_OBJ_ITEM ] );
  1323.         return 1000; }
  1324.     if ( function == SubscEquipClass && press ) {
  1325.         itemdata itd = Game->LoadItemData( optr[ ofs + SUBSC_OBJ_ITEM ] );
  1326.         int ic = itd->Family;
  1327.        
  1328.         for ( int q = 0; q < 256; q++ ) {
  1329.             itd = Game->LoadItemData(q);
  1330.             if ( Link->Item[q] && itd->Family == ic && q != optr[ ofs + SUBSC_OBJ_ITEM ] ) DoEnableDisable(q);
  1331.             //Disable enabled items, and enable the selected item
  1332.             DoEnableDisable(optr[ ofs + SUBSC_OBJ_ITEM ]);
  1333.         }
  1334.        
  1335.         return 2000;
  1336.     }
  1337.     if ( function == SubscInfo ) { return optr[ofs+SUBSC_OBJ_INFO]; }
  1338. }
  1339.  
  1340. const int BUTTON_ITEMS_PTR = 507;
  1341.  
  1342. //void StoreSubscreenButtonItemsPtr(){ }
  1343.  
  1344. ffc script PlaceSubscreenObjectAndTrace{
  1345.     void run(int item_id, int tile, int cset, int function_info, int up, int down, int left, int right){
  1346.         Waitframe(); //Wait so that the global active script can report to the log, first.
  1347.         int COMMA[]=", ";
  1348.         int LPAREN[]="(";
  1349.         int RPAREN[]=")";
  1350.         int IDENTIFIER[]="SetSubscreenObjectProperties";
  1351.         int SEMI[]=";";
  1352.         int x = this->X;
  1353.         int y = this->Y;
  1354.         int thisid = this->ID -1;
  1355.         int info = GetLowFloat(function_info);
  1356.         int function = GetHighFloat(function_info);
  1357.         if  ( tile < 0 ) { tile = Game->GetComboTile(this->Data); }
  1358.         if ( cset < 0 ) cset = this->Cset;
  1359.        
  1360.         int S_ID[3]; itoa(S_ID, thisid);
  1361.         int S_X[10]; ftoa(S_X, x);
  1362.        
  1363.         int S_Y[10]; ftoa(S_Y,y);
  1364.         int S_IID[4]; itoa(S_IID, item_id);
  1365.         int S_ITILE[6]; itoa(S_ITILE, tile);
  1366.         int S_ICSET[3]; itoa(S_ICSET, cset);
  1367.         int S_FUNCT[2]; itoa(S_FUNCT, function);
  1368.         int S_INFO[7]; itoa(S_INFO, info);
  1369.         int S_UP[3]; itoa(S_UP, up);
  1370.         int S_DOWN[3]; itoa(S_DOWN, down);
  1371.         int S_RIGHT[3]; itoa(S_RIGHT, right);
  1372.         int S_LEFT[3]; itoa(S_LEFT, left);
  1373.         //Trace the InitD and the Position of this ffc.
  1374.         TraceNL();
  1375.         TraceS(IDENTIFIER); TraceS(LPAREN); TraceS(S_ID); TraceS(COMMA); TraceS(S_X); TraceS(COMMA); TraceS(S_Y); TraceS(COMMA);
  1376.         TraceS(S_IID); TraceS(COMMA); TraceS(S_ITILE); TraceS(COMMA); TraceS(S_ICSET); TraceS(COMMA); TraceS(S_FUNCT); TraceS(COMMA);
  1377.         TraceS(S_INFO); TraceS(COMMA);
  1378.         TraceS(S_UP); TraceS(COMMA); TraceS(S_DOWN); TraceS(COMMA); TraceS(S_LEFT); TraceS(COMMA); TraceS(S_RIGHT); TraceS(RPAREN); TraceS(SEMI); TraceNL();
  1379.         //Do we need printf for this, to use args and other fancy stuff    
  1380.         //so that out output is formatted as functions...or will TraceS suffice?
  1381.     }
  1382. }
  1383.  
  1384.  
  1385. //Set the nitial object from a pool of placed objects
  1386.  
  1387. //Select a placed object
  1388.  
  1389. const int SUBSC_OBJ_SELECTED = 220;
  1390.  
  1391. /*
  1392. int GetObjectSelected(){ return GRAM[SUBSC_OBJ_SELECTED]; }
  1393. void SetObjectSelected(int s) { GRAM[SUBSC_OBJ_SELECTED] = s; }
  1394. */
  1395.  
  1396.  
  1397.  
  1398. int SubscCursorMove(item cursor, item itemptrs){ //itemptrs is the items[32] array
  1399.     int optr = GetSubscreenPtr();
  1400.     item sel = Screen->LoadItem(optr[SUBSC_OBJ_SELECTED]);
  1401.     int dir[4]={ sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_UP], sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_DOWN], sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_LEFT], sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_MISC_RIGHT]};
  1402.     itemptrs[32];
  1403.     //press right
  1404.     if ( Link->PressRight ) { Game->PlaySound(SUBSC_CURSOR_SFX); cursor->X = itemptrs[ dir[3] ]->X; cursor->Y = itemptrs[ dir[3] ]->Y; }
  1405.     //press left
  1406.     if ( Link->PressLeft ) { Game->PlaySound(SUBSC_CURSOR_SFX); cursor->X = itemptrs[ dir[2] ]->X; cursor->Y = itemptrs[ dir[2] ]->Y; }
  1407.     //press down
  1408.     if ( Link->PressDown ) { Game->PlaySound(SUBSC_CURSOR_SFX);  cursor->X = itemptrs[ dir[1] ]->X; cursor->Y = itemptrs[ dir[1] ]->Y; }
  1409.     //press up
  1410.     if ( Link->PressUp ) { Game->PlaySound(SUBSC_CURSOR_SFX); cursor->X = itemptrs[ dir[0] ]->X; cursor->Y = itemptrs[ dir[0] ]->Y; }
  1411.     if ( Link->PressA ) { RunSubscreenObjectFunction(sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_FUNCTION], optr[SUBSC_OBJ_SELECTED], 2);}
  1412.  
  1413.     if ( Link->PressB ) { RunSubscreenObjectFunction(sel->Misc[SUBSC_OBJ_MISC_OFFSET+SUBSC_OBJ_FUNCTION], optr[SUBSC_OBJ_SELECTED], 1);}
  1414. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement