Advertisement
ZoriaRPG

Subscreen8.zs

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