Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////
- /// Shop FFC Item with Yes/No Menu ///
- /// By: ZoriaRPG ///
- /// 26-July-2016 ///
- /// v0.7.3 ///
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// ///
- /// !! Set FFC FLag 'Run on Screen Init !!! ///
- /// ///
- /// D0 : The item ID (number) to give Link. ///
- /// D1 : The price of the item. ///
- /// D2 : The item info message (high) and the OPTIONAL alternate message string for replacement items (low). ///
- /// --> Integer Portion (#####.xxxx) THe message to display for Item Info menu option. ///
- /// --> Decimal Portion (xxxxx.####) An alternate info string, for a replacement item, if desired. ///
- /// D3 : Alternate combo to use, if you want a generic combo for shop items (high) and alternate counter (low). ///
- /// --> Integer Portion (#####.xxxx) The combo ID. ///
- /// --> Decimal Portion (xxxxx.####) An alternate counter, instead of the default (CR_RUPEES), if desired. ///
- /// D4 : Sound to play if purchase is a success. ///
- /// D5 : If set to '1', Link holds the item up with one hand. If set to '2', he holds it up with two hands. ///
- /// Set to '0' for no item hold-up animation. ///
- /// D6 : This value is split between the integer portion,a nd the decimal. the decimal portion is only used for optional shop capabilities. ///
- /// --> Integer Portion ( #####.xxxx ) Set to '1' to sell only one time. ///
- /// If set to '1', a 'sold out' sign will take the place of this item when it sells. ///
- /// If set ABOVE 1, a REPLACEMENT item with this ID will take the place of the item when it sells. ///
- /// --> Decimal Portion ( xxxxx.#### ) If you wish to set a different price for a REPLACEMENT ITEM, enter it here. ///
- /// D7 : The Nth item in this shop. Set each in sequence, starting at '1', and ending at '9' (max) or whatever the number of items is that ///
- /// you have in this shop. ///
- /// --> Example: If a shop with three items, number one of them '1', another '2', and the last '3'. ///
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Requested By: JudasRising, with additional features requested by Dimentio, and Grayswandir. ///
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Crediting: ///
- /// ///
- /// JudasRising: Testing. ///
- /////////////////////////////
- //! CHANGES
- // 0.7.3 - * Added an flag to check if shops should stay open.
- // * Fixed bug with 'only_once' not being truncated in some calls.
- // * This fixes the bug with replacement items causing shops to close. The lights do go out briedly, until the new item spawns.
- // * Modified IsShopAllSoldOut(int dmap, int screen) to check for this extra flag.
- // * Still no support for replacement items being FREE. Should I just make it use this arg by default?
- // 0.7.2 - * Fixed issue with sold out sign not appearing.
- // * New bug: Replacement items don't prevent shop closure (total sell-out). This may be very tedious to correct, and
- // it would be simpler to warn not to have a shop that can be totally sold out, and have replacement goods.
- // 0.7.1 - * Somewhere between 0.6.6 and here, a bug emerged. Sold Out no logner works, and some free dummy object is being created.
- // 0.7.1 - * Add ability to set CR_LIFE s a cost, using 100 as its counter value.
- // 0.7.0 - * Fix price being incorrectly displayed if it is a decimal place lower for replacement items (10 is displayed as 100).
- // 0.6.9 - * Added support for drawing item graphcs without needing to make a combo.
- // 0.6.8 - * Added alternate info string for replacement items.
- // 0.6.7 - * Fixed alternate item price display, and display of replacement item graphics.
- // 0.6.6 - * Imitial tests of replacment item. Fixed ability to change item, and draw it.
- // 0.6.5 - * Fixed drawing of rupee icon, price, and 'x' when item is sold out.
- // * Fixed SHOP_TILE_RUPEE_ICON_OPACITY not being used.
- // * Added SHOP_BUY_BUTTON_OFFSETS_ARE_FROM_FFC. Buy button can now be set based on the ffc, or based on Link!
- // 0.6.4 - * Fixed IsShopAllSoldOut() in both incarnations.
- // 0.6.3 - * Added more debug functions and features.
- // 0.6.2 - * Bugfixes: Removed calls to CenterX/Y in door ffc. Fixed Game-> pointers for GetDMapScreenD. Fixed typos.
- // 0.6.1 - * Fxed error in FFC_NumShopItems() where ffc 32 would be ignored.
- // 0.6.0 - * Stopepd calling Quit(). This hosed the calls to FFC_NumShopItems() as the number of running shops would change!
- // 0.5.9 - * Changed darkness to a global function. Added 'Closed door' ffc.
- // 0.5.8 - * Bugfixes. Changed IsShopAllSoldOut() method. Added SHOP_DEBUG.
- // 0.5.7 - * Bugfixes: Fixed bug where 'Free' wouldn't draw - changed itoa() to strcat()
- // 0.5.6 - * Bugfixes. Fixed rupee tile.
- // 0.5.5 - * Now supports nine items. Added many new features.
- // 0.5.6 - * Fixed bug in storing flags.
- // * Fixed bugs in drawing rupee icon.
- // * Fixed bug in displayig 'Free'
- // 0.5.7 - * Changed how we check if a shop is closed.
- // * Added debug feature to ensure that the number of shops, and sold-out us are being set.
- // 0.5.8 - * Changed shop darknesss to a global component.
- // * Added functions to read shop darkness from other DMap/Screen locations
- // 0.5.9 - * Added ffc to control closing shop doors. Uses remore reading functions.
- // * Deprecated old darkness routines.
- //General Settings
- const int SHOP_REGISTER = 6; //Screen->D used for shop items.
- const int SHOP_DEBUG_ON = 0; //Set to '0' to disable debug reports in allegro.log.
- //! TURN THIS OFF BEFORE RELEASING A QUEST !
- //Combos and Tiles
- const int TILE_SOLD_SIGN = 22913; //The sold ign, if using the sell-out feature.
- const int SHOP_SIGNS_CHANGE_WHEN_ALL_ITEMS_SOLD = 0;
- //If this is set to '1', then signs will chane again if none of the itms are available to buy any longer.
- const int TILE_SHOP_CLOSED_FOREVER = 0; //Set to a combo of your choice if all the items are sold out, forever.
- //The small button icon that appears next to an item, to allow link to know he can interact with it.
- //THe tile should have a graphic that occupies the upper-rightmost 8x8pixels, as a 'minitile'.
- const int SHOP_BUY_BUTTON_TILE = 44190; //Tile of the 'open menu' button, or whatever button you use to activate the 'buy' menu.
- const int SHOP_BUY_BUTTON_TILE_CSET = 2;
- const int SHOP_BUY_BUTTON_TILE_OPACITY = 128; //128 is opaque, 64 translucent.
- const int SHOP_BUY_BUTTON_TILE_LAYER = 2; //Layer for the button. Default '2'.
- const int SHOP_BUY_BUTTON_TILE_X_OFFSET = 17; //Offsets for drawing, from the ffc's x/y position.
- const int SHOP_BUY_BUTTON_TILE_Y_OFFSET = -6;
- const int SHOP_BUY_BUTTON_TILE_BLOCKW = 1; //The number of tiles (wide) to draw. Default '1'.
- const int SHOP_BUY_BUTTON_TILE_BLOCKH = 1; //The number of tiles (high) to draw. Default '1'.
- const int SHOP_BUY_BUTTON_OFFSETS_ARE_FROM_FFC = 1; //Set to '1' to use the ffc coordinates, otherwise it uses Link->X/Y as a base.
- //Replacement Item
- const int SHOP_TILE_REPLACEMENT_ITEM_LAYER = 2;
- //Rupee Icon Tile (next to price)
- const int SHOP_TILE_RUPEE_ICON = 44180; //Tile of the rupee icon to put by the price.
- //! The script will only draw this if it is npt set to '0'.
- const int SHOP_TILE_RUPEE_ICON_LAYER = 2; //Layer for the icon. Default '1'.
- const int SHOP_TILE_RUPEE_ICON_BLOCKW = 1; //The number of tiles wide) to draw. Default '1'.
- const int SHOP_TILE_RUPEE_ICON_BLOCKH = 1; //The number of tiles (high) to draw. Default '1'.
- const int SHOP_TILE_RUPEE_ICON_CSET = 2;
- const int SHOP_TILE_RUPEE_ICON_X_OFFSET = 0; //Position of the rupee icon offsets (from the ffc x/y).
- const int SHOP_TILE_RUPEE_ICON_Y_OFFSET = 11;
- const int SHOP_TILE_RUPEE_ICON_XSCALE = 15; //Scaling factor of the tile in percent.//50
- const int SHOP_TILE_RUPEE_ICON_YSCALE = 15; //Scaling factor of the tile in percent.//50
- const int SHOP_TILE_RUPEE_ICON_OPACITY = 128; //128 is opaque, 64 translucent.
- //Text Settings for shop prices
- const int SHOP_PRICE_FONT = 2; //See std_constants.zh for font values.
- const int SHOP_PRICE_COLOUR_FOREGROUND = 0x0F; //Black
- const int SHOP_PRICE_COLOUR_BACKGROUND = 0x01; //WHite
- const int SHOP_PRICE_TEXT_LAYER = 2; //Layer to draw the text. Default '2'.
- const int SHOP_PRICE_TEXT_X_OFFSET_FOREGROUND = 12; //The x/y offsets for the text, based on the ffc coordinates.
- const int SHOP_PRICE_TEXT_X_OFFSET_BACKGROUND = 13;
- const int SHOP_PRICE_TEXT_Y_OFFSET_FOREGROUND = 13;
- const int SHOP_PRICE_TEXT_Y_OFFSET_BACKGROUND = 14;
- const int SHOP_PRICE_SIZE = 0; //Size-scale factor.
- //The 'x' between the rupee icon and the price.
- const int SHOP_PRICE_DRAW_X_SIGN = 1; //Set to 1 to draw the 'x' between the rupee icon, and the text; 0 to disqable.
- const int SHOP_PRICE_DRAW_X_SIGN_LAYER = 2; //Layer to draw the 'x'. Default '2'.
- const int SHOP_PRICE_DRAW_X_SIGN_COLOUR_FOREGROUND = 0x01; //Black
- const int SHOP_PRICE_DRAW_X_SIGN_COLOUR_BACKGROUND = 0x0F; //White
- const int SHOP_PRICE_DRAW_X_SIGN_SIZE = 0; //Size-scale factor.
- const int SHOP_PRICE_DRAW_X_SIGN_X_OFFSET_FOREGROUND = 8; //The x/y offsets for the text, based on the ffc coordinates.
- const int SHOP_PRICE_DRAW_X_SIGN_Y_OFFSET_FOREGROUND = 13;
- const int SHOP_PRICE_DRAW_X_SIGN_X_OFFSET_BACKGROUND = 9;
- const int SHOP_PRICE_DRAW_X_SIGN_Y_OFFSET_BACKGROUND = 14;
- const int SHOP_PRICE_DRAW_X_SIGN_FONT = 2; //See std_constants.zh for font values.
- //Button Settings: THe shop will activate the menu / Link will take the item based on a button press.
- //Set any button that you wish to permit the player to take the 'buy' action by enabling it here.
- //Any button enabled will work, and you may enable any combination, one, some, or all, of them.
- //Set to '1' to enable, '0' to disable.
- const int SHOP_USE_BUTTON_R = 1;
- const int SHOP_USE_BUTTON_L = 0;
- const int SHOP_USE_BUTTON_A = 1;
- const int SHOP_USE_BUTTON_B = 0;
- const int SHOP_USE_BUTTON_EX1 = 0;
- const int SHOP_USE_BUTTON_EX2 = 0;
- const int SHOP_USE_BUTTON_EX3 = 0;
- const int SHOP_USE_BUTTON_EX4 = 0;
- //Replacement Item Tile Settings
- const int SHOP_REPL_ITEM_TILE_LAYER = 1; //Replacement item tiles (via Screen->Drawtile) will appear on this layer.
- //Sound and String
- const int SFX_SHOP_ERROR = 9; //Sound to play when buying an item.
- const int MSG_SHOP_ERROR = 10; //Message to display if Link is out of funds.
- //Shop Darkness Settings
- const int SHOP_DARK_WHEN_CLOSED = 1; //Set to '1' to close the shop by turning out the lights.
- const int SHOP_DARKNESS_COLOUR = 0x0F;// Black; used by shop darkness overlay.//0x0F
- const int SHOP_DARKNESS_LAYER = 6; //Darkness effect will be drawn to this layer.
- const int SHOP_DARKNESS_SCALE = 100;
- const int SHOP_DARKNESS_OPACITY = 64; //64 is transparent, 128 is opaque.
- const int SHOP_DARKNESSS_NUM_LAYERS = 2; //How many draws to perform.
- //Closed shop door
- const int SHOP_DEFAULTCLOSED_DOOR_COMBO = 100; //Set to ID of default closed door combo.
- //Shop Functionality Setings
- const int SHOP_LINK_PROXIMITY_X_TO_ITEM = 25; //X-Distance in pixels for required proximity to activate menu.
- const int SHOP_LINK_PROXIMITY_Y_TO_ITEM = 25; //Y-Distance in pixels for required proximity to activate menu.
- const int SHOP_LINK_MUST_FACE_ITEM = 1; //Set to 0 to disable.
- const int SHOP_SHOW_ZERO = 0; //Show zero value prices. '1' to show, '0' to disable.
- //! This is mutually-exclusive with 'SHOP_ZERO_PRICE_STATES_FREE'
- const int SHOP_SHOW_NEGATIVE_PRICE = 0; //Show negative value prices. '1' to show, '0' to disable.
- const int SHOP_FREE_ITEMS_NO_MENU = 0; //Set to '1' to bypass the menu for free items, giving the player the item instantly.
- const int SHOP_SHOW_RUPEE_X_FOR_FREE_ITEMS = 1; //Set to '0'; to disable showing rupee ICON and/or X for free items. Depends on main setting to display either.
- const int SHOP_ZERO_PRICE_STATES_FREE = 1; //Set to '1' to show the string 'Free' next to 0-price items, instead of '0'.
- //! This is mutually exclusive with 'SHOP_SHOW_ZERO'.
- //Tango slot constants.
- const int WINDOW_SLOT_1 = 0;
- const int WINDOW_SLOT_2 = 1;
- const int WINDOW_SLOT_3 = 2;
- const int WINDOW_SLOT_4 = 3;
- const int WINDOW_SLOT_5 = 4;
- //Values that you probably should not change.
- //! These are the binary flags for items, used in conjunction with one-time-only sales.
- const int SHOP_SOLD_ITEM_1 = 000000001b;
- const int SHOP_SOLD_ITEM_2 = 000000010b;
- const int SHOP_SOLD_ITEM_3 = 000000100b;
- const int SHOP_SOLD_ITEM_4 = 000001000b;
- const int SHOP_SOLD_ITEM_5 = 000010000b;
- const int SHOP_SOLD_ITEM_6 = 000100000b;
- const int SHOP_SOLD_ITEM_7 = 001000000b;
- const int SHOP_SOLD_ITEM_8 = 010000000b;
- const int SHOP_SOLD_ITEM_9 = 100000000b;
- const int SHOP_STAY_OPEN = 1000000000b;
- // There are certainly other ways to handle these...
- // Vars used by the Tango menu.
- int menuCommand;
- int menuArg;
- //Tango Menu Init
- void SetUpWindow(int slot, int style, int x, int y, int size)
- {
- SetStyleSize(style, size);
- Tango_ClearSlot(slot);
- Tango_SetSlotStyle(slot, style);
- Tango_SetSlotPosition(slot, x, y);
- }
- //Quick way to drop a string into a Tango dialogue box.
- void ShowString(int string, int slot, int style, int x, int y)
- {
- SetUpWindow(slot, style, x, y, SIZE_LARGE);
- Tango_LoadString(slot, string);
- Tango_ActivateSlot(slot);
- while(Tango_SlotIsActive(slot))
- Waitframe();
- }
- //The main shop ffc.
- ffc script ShopItemMenu{
- void run(int itm, int price, int msg, int itemcombo, int sound, int holdup_type, int only_once, int itemnumber_in_shop){
- int msg_str = msg << 0; //Message string is integer of D2.
- int counter = ( itemcombo - ( itemcombo << 0 )) *10000; //Alt counte ris decimal of D2.
- if ( counter == 0 ) counter = CR_RUPEES; //Allow an alternate counter.
- if ( counter == 100 ) counter = CR_LIFE; //Permit life, just don't let it be the DEFAULT.
- item it = Screen->CreateItem(only_once << 0);
- item main; int q;
- if ( itm > 0 ) main = Screen->CreateItem(itm);
- if ( itm < 0 ) main = Screen->CreateItem(itm*-1);
- if ( !itm ) Quit();
- int choice; bool pressed; bool replace; int drawitem;
- bool dotile; //true if we use a tile, not a combo
- int str_price[6];
- int free[]="Free";
- it->X = 0; it->Y = 0;
- it->DrawXOffset = -300;
- it->HitXOffset = -300;
- it->DrawYOffset = -300;
- it->HitYOffset = -300;
- main->X = 0; main->Y = 0;
- main->DrawXOffset = -300;
- main->HitXOffset = -300;
- main->DrawYOffset = -300;
- main->HitYOffset = -300;
- if ( itm < 0 ) {
- this->Data = FFCS_INVISIBLE_COMBO;
- drawitem = itm * -1;
- itm = itm * -1;
- }
- if ( itemcombo << 0 ) this->Data = itemcombo << 0; //If we have a specific combo ID set, use it.
- if ( ( only_once << 0 ) > 1 ) {
- //We have a replacement item when this one sells, so don't put up a sold out sign.
- if ( FFC_ShopFlag(SHOP_SOLD_ITEM_1) && itemnumber_in_shop == 1 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_2) && itemnumber_in_shop == 2 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; } //We could offer drawtile for this.
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 3 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_4) && itemnumber_in_shop == 4 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_5) && itemnumber_in_shop == 5 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_6) && itemnumber_in_shop == 6 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_9) && itemnumber_in_shop == 7 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_8) && itemnumber_in_shop == 8 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 9 ) { replace = true; itm = ( only_once << 0 ); this->Data = FFCS_INVISIBLE_COMBO; }
- if ( !replace && drawitem ) {
- Screen->DrawTile(SHOP_TILE_REPLACEMENT_ITEM_LAYER,this->X,this->Y,main->Tile,main->TileWidth,main->TileHeight,main->CSet,-1,-1,0,0,0,0,true,128);
- }
- if ( replace ) {
- FFC_SetShopFlag(SHOP_STAY_OPEN,true);
- itm = ( only_once << 0 );
- //Screen->D[SHOP_REGISTER_REPL_ITEM] = ( only_once - ( only_once << 0 )) *10000;
- this->Data = FFCS_INVISIBLE_COMBO;
- //Make this ffc combo invisible, then...
- //it->DrawXOffset = this->X;
- //it->DrawYOffset = this->Y;
- //Screen->DrawTile(SHOP_REPL_ITEM_TILE_LAYER, this->X, this->Y, it->Tile, 1, 1, it->CSet, -1, -1, 0, 0, 0, 0, true, OP_OPAQUE);
- //Draw a tile so that it's easier to customise what the user sees.
- //Set an alternate price using the decimal portion of D6.
- if ( ( (only_once - ( only_once << 0 )) *10000) > 0 ) price = ( only_once - ( only_once << 0 )) *10000;
- //TracePrice(price);
- if ( !SHOP_ZERO_PRICE_STATES_FREE || price != 0 ) {
- //Wipe the string, and replace it.
- for ( q = 0; q < SizeOfArray(str_price); q++ ) str_price[q] = 0;
- itoa(str_price,price); //Store the price in a string to display it.
- }
- else {
- //Wipe the string, and replace it.
- for ( q = 0; q < SizeOfArray(str_price); q++ ) str_price[q] = 0;
- strcat(str_price,free); //Show 'Free' instead of a numeral '0'.
- }
- Screen->DrawTile(SHOP_TILE_REPLACEMENT_ITEM_LAYER,this->X,this->Y,it->Tile,it->TileWidth,it->TileHeight,it->CSet,-1,-1,0,0,0,0,true,128);
- //Set an alternate item info message, using the decimal portion of D3.
- msg_str = (msg - (msg << 0)) * 10000;
- }
- }
- if ( ( only_once << 0 ) == 1 || ( only_once << 0 ) < 0 ) {
- if ( FFC_ShopFlag(SHOP_SOLD_ITEM_1) && itemnumber_in_shop == 1 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_2) && itemnumber_in_shop == 2 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 3 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_4) && itemnumber_in_shop == 4 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_5) && itemnumber_in_shop == 5 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_6) && itemnumber_in_shop == 6 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_9) && itemnumber_in_shop == 7 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_8) && itemnumber_in_shop == 8 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 9 ) { this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( !SHOP_ZERO_PRICE_STATES_FREE || price != 0 ) itoa(str_price,price); //Store the price in a string to display it.
- else strcat(str_price,free); //Show 'Free' instead of a numeral '0'.
- //Replce the item if needed.
- if ( SHOP_DEBUG_ON ) ShopDebug();
- //if ( ( this->Data == TILE_SOLD_SIGN || this->Data == TILE_SHOP_CLOSED_FOREVER) ) {
- //&& !SHOP_DARK_WHEN_CLOSED ) {
- // this->Script = 0;
- // Quit();
- //} //Clear the ffc if the item is sold, to prevent count of running shops from reading it.
- //if ( ( this->Data == TILE_SOLD_SIGN || this->Data == TILE_SHOP_CLOSED_FOREVER) && SHOP_DARK_WHEN_CLOSED ) {
- // this->Script = FFC_GetShopDarkness();
- // Quit();
- //} //If shops should be dark, change the script.
- FFC_SetNumberShopItems(); //Store how many shops are running.
- while(true){
- //Waitframes(2); //Wait for all shops to load before setting the number of active shops running.
- if (SHOP_DEBUG_ON && (Link->InputEx1 || Link->PressEx1) && ( Link->InputEx2 || Link->PressEx2 ) ) ShopDebug();
- //if ( ( this->Data == TILE_SOLD_SIGN || this->Data == TILE_SHOP_CLOSED_FOREVER) && !SHOP_DARK_WHEN_CLOSED ){
- //this->Script = 0;
- //Quit();
- //If we clear the ffc or qit, it mucks up FFC_NumShopItems()
- //}
- //if ( IsShopAllSoldOut() && SHOP_DARK_WHEN_CLOSED ) {
- // this->Script = FFC_GetShopDarkness();
- //Quit();
- //} //If shops should be dark, change the script.
- if ( SHOP_SIGNS_CHANGE_WHEN_ALL_ITEMS_SOLD && IsShopAllSoldOut() ) this->Data = TILE_SHOP_CLOSED_FOREVER;
- if ( !replace && drawitem ) {
- Screen->DrawTile(SHOP_TILE_REPLACEMENT_ITEM_LAYER,this->X,this->Y,main->Tile,main->TileWidth,main->TileHeight,main->CSet,-1,-1,0,0,0,0,true,128);
- }
- //Draw the replacement items, as they need to have the highest drawing priority
- if ( replace ) {
- FFC_SetShopFlag(SHOP_STAY_OPEN,true);
- //! Replace with the new item
- itm = ( only_once << 0 );
- price = ( only_once - ( only_once << 0 )) *10000;
- //TracePrice(price);
- //Screen->D[SHOP_REGISTER_REPL_ITEM] = ( only_once - ( only_once << 0 )) *10000;
- this->Data = FFCS_INVISIBLE_COMBO;
- //Make this ffc combo invisible, then...
- //it->DrawXOffset = -200;
- //it->DrawYOffset = -200;
- //Draws an item to a given layer
- Screen->DrawTile(SHOP_TILE_REPLACEMENT_ITEM_LAYER,this->X,this->Y,it->Tile,it->TileWidth,it->TileHeight,it->CSet,-1,-1,0,0,0,0,true,128);
- //Screen->DrawTile(SHOP_REPL_ITEM_TILE_LAYER, this->X, this->Y, it->Tile, 1, 1, it->CSet, -1, -1, 0, 0, 0, 0, true, OP_OPAQUE);
- //Draw a tile so that it's easier to customise what the user sees.
- //Set an alternate price using the decimal portion of D6.
- if ( ( only_once - ( only_once << 0 )) *10000 > 0 ) price = ( only_once - ( only_once << 0 )) *10000;
- //TracePrice(price);
- //Update the price string.
- if ( !SHOP_ZERO_PRICE_STATES_FREE || price != 0 ) {
- //Wipe the string, and replace it.
- for ( q = 0; q < SizeOfArray(str_price); q++ ) str_price[q] = 0;
- itoa(str_price,price); //Store the price in a string to display it.
- }
- else {
- //Wipe the string, and replace it.
- for ( q = 0; q < SizeOfArray(str_price); q++ ) str_price[q] = 0;
- strcat(str_price,free); //Show 'Free' instead of a numeral '0'.
- }
- //Set an alternate item info message, using the decimal portion of D3.
- msg_str = (msg - (msg << 0)) * 10000;
- }
- //Draw the shop prices and icons:
- //If a tile is set for a rupee icon...
- if ( this->Data != TILE_SOLD_SIGN && this->Data !=TILE_SHOP_CLOSED_FOREVER ) {
- if ( ( SHOP_TILE_RUPEE_ICON && !SHOP_SHOW_RUPEE_X_FOR_FREE_ITEMS ) ||
- ( SHOP_TILE_RUPEE_ICON && SHOP_SHOW_RUPEE_X_FOR_FREE_ITEMS && price != 0 ) )
- {
- Screen->DrawTile( SHOP_TILE_RUPEE_ICON_LAYER,
- this->X + SHOP_TILE_RUPEE_ICON_X_OFFSET,
- this->Y + SHOP_TILE_RUPEE_ICON_Y_OFFSET,
- SHOP_TILE_RUPEE_ICON,
- SHOP_TILE_RUPEE_ICON_BLOCKW,
- SHOP_TILE_RUPEE_ICON_BLOCKH,
- SHOP_TILE_RUPEE_ICON_CSET,
- SHOP_TILE_RUPEE_ICON_XSCALE,
- SHOP_TILE_RUPEE_ICON_YSCALE,
- 0, 0, 0, 0, true,
- SHOP_TILE_RUPEE_ICON_OPACITY);
- }
- //If the setting to draw an 'x' between the rupee icon and the price is enabled...
- if ( ( SHOP_PRICE_DRAW_X_SIGN && !SHOP_SHOW_RUPEE_X_FOR_FREE_ITEMS ) ||
- ( SHOP_PRICE_DRAW_X_SIGN && SHOP_SHOW_RUPEE_X_FOR_FREE_ITEMS && price != 0 ) )
- FFC_DrawShopPrice_X_Sign(this); //Draw the 'x'
- //Draw the actual price.
- if ( ( ( !SHOP_SHOW_ZERO && price !=0 ) || SHOP_SHOW_ZERO && price > -1 ) &&
- ( ( !SHOP_SHOW_NEGATIVE_PRICE && price > -1 ) || SHOP_SHOW_NEGATIVE_PRICE ) )
- //Draw the background.
- Screen->DrawString(
- SHOP_PRICE_TEXT_LAYER,
- this->X+SHOP_PRICE_TEXT_X_OFFSET_BACKGROUND,
- this->Y+SHOP_PRICE_TEXT_Y_OFFSET_BACKGROUND,
- SHOP_PRICE_FONT,
- SHOP_PRICE_COLOUR_BACKGROUND,
- SHOP_PRICE_SIZE,
- TF_NORMAL, str_price, OP_OPAQUE); //Background
- //Draw the foreground.
- Screen->DrawString(
- SHOP_PRICE_TEXT_LAYER,
- this->X+SHOP_PRICE_TEXT_X_OFFSET_FOREGROUND,
- this->Y+SHOP_PRICE_TEXT_Y_OFFSET_FOREGROUND,
- SHOP_PRICE_FONT,
- SHOP_PRICE_COLOUR_BACKGROUND,
- SHOP_PRICE_SIZE,
- TF_NORMAL, str_price, OP_OPAQUE); //Foreground
- if ( __DistX(this,SHOP_LINK_PROXIMITY_X_TO_ITEM,true) && __DistY(this,SHOP_LINK_PROXIMITY_Y_TO_ITEM,true) && ( __LinkFacing(this) || !SHOP_LINK_MUST_FACE_ITEM ) ) {
- //Draw the button tile overlay.
- if ( SHOP_BUY_BUTTON_TILE && !SHOP_BUY_BUTTON_OFFSETS_ARE_FROM_FFC ) Screen->DrawTile( SHOP_BUY_BUTTON_TILE_LAYER,
- Link->X + SHOP_BUY_BUTTON_TILE_X_OFFSET,
- Link->Y + SHOP_BUY_BUTTON_TILE_Y_OFFSET,
- SHOP_BUY_BUTTON_TILE,
- SHOP_BUY_BUTTON_TILE_BLOCKW,
- SHOP_BUY_BUTTON_TILE_BLOCKH,
- SHOP_BUY_BUTTON_TILE_CSET,
- -1, -1, 0, 0, 0, 0, true,
- SHOP_BUY_BUTTON_TILE_OPACITY);
- if ( SHOP_BUY_BUTTON_TILE && SHOP_BUY_BUTTON_OFFSETS_ARE_FROM_FFC ) Screen->DrawTile( SHOP_BUY_BUTTON_TILE_LAYER,
- this->X + SHOP_BUY_BUTTON_TILE_X_OFFSET,
- this->Y + SHOP_BUY_BUTTON_TILE_Y_OFFSET,
- SHOP_BUY_BUTTON_TILE,
- SHOP_BUY_BUTTON_TILE_BLOCKW,
- SHOP_BUY_BUTTON_TILE_BLOCKH,
- SHOP_BUY_BUTTON_TILE_CSET,
- -1, -1, 0, 0, 0, 0, true,
- SHOP_BUY_BUTTON_TILE_OPACITY);
- //Check for input based on the button settings...
- if ( SHOP_USE_BUTTON_R && Link->PressR ) { pressed = true; Link->PressR = false; Link->InputR = false; }
- if ( SHOP_USE_BUTTON_L && Link->PressL ) { pressed = true; Link->PressL = false; Link->InputL = false; }
- if ( SHOP_USE_BUTTON_A && Link->PressA ) { pressed = true; Link->PressA = false; Link->InputA = false; }
- if ( SHOP_USE_BUTTON_B && Link->PressB ) { pressed = true; Link->PressB = false; Link->InputB = false; }
- if ( SHOP_USE_BUTTON_EX1 && Link->PressEx1 ) { pressed = true; Link->PressEx1 = false; Link->InputEx1 = false; }
- if ( SHOP_USE_BUTTON_EX2 && Link->PressEx2 ) { pressed = true; Link->PressEx2 = false; Link->InputEx2 = false; }
- if ( SHOP_USE_BUTTON_EX2 && Link->PressEx3 ) { pressed = true; Link->PressEx3 = false; Link->InputEx3 = false; }
- if ( SHOP_USE_BUTTON_EX2 && Link->PressEx4 ) { pressed = true; Link->PressEx4 = false; Link->InputEx4 = false; }
- //Show info on ittem, then...
- //yes/no menu
- //if ( price <= Game->Counter[CR_RUPEES] ) {
- //Yes/No
- if ( this->Data != TILE_SOLD_SIGN && this->Data !=TILE_SHOP_CLOSED_FOREVER && pressed ) { //If Link pressed a button that we want to use...
- pressed = false; //Clear pressed.
- if ( !SHOP_FREE_ITEMS_NO_MENU || ( SHOP_FREE_ITEMS_NO_MENU && price != 0) ) choice = BuyYesNo(msg_str,price);
- if ( choice == 2 || ( SHOP_FREE_ITEMS_NO_MENU && price == 0 ) ) { //Bought it.
- if ( Game->Counter[counter] >= price ) { //Bought and can buy it...
- Game->DCounter[counter] -= price;
- if ( sound ) Game->PlaySound(sound);
- item it = Screen->CreateItem(itm);
- it->X = Link->X;
- it->Y = Link->Y;
- it->Z = Link->Z;
- if ( holdup_type ) {
- Link->Action = holdup_type + 3;
- Link->HeldItem = itm;
- }
- if ( (only_once << 0) ) {
- //Set the flags.
- if ( itemnumber_in_shop == 1 ) {
- FFC_SetShopFlag(SHOP_SOLD_ITEM_1, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 2 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_2, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 3 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_3, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 4 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_4, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 5 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_5, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 6 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_6, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 7 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_7, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 8 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_8, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- if ( itemnumber_in_shop == 9 ) { FFC_SetShopFlag(SHOP_SOLD_ITEM_9, true); if ( ( only_once << 0) > 0 ) replace = true;
- if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) { replace = false; this->Data = TILE_SOLD_SIGN; drawitem = 0; }
- }
- //{
- }
- }
- else {
- //Errors
- if ( SFX_SHOP_ERROR ) Game->PlaySound(SFX_SHOP_ERROR);
- if ( MSG_SHOP_ERROR ) Screen->Message(MSG_SHOP_ERROR);
- }
- }
- else choice = 0; //Clear the choice selection.
- }
- }
- }
- Waitframe();
- }
- }
- //The following three functions are from my std.zh update, with leading underscores added in the event that you upgrade, to prevent conflicts.
- bool __DistX(ffc a, int distance, bool fromcentre) {
- int dist;
- if ( a->X > Link->X ) dist = a->X - Link->X;
- else dist = Link->X - a->X;
- return ( dist <= distance );
- } //Link to ffc distance
- bool __DistY(ffc a, int distance, bool fromcentre) {
- int dist;
- if ( a->Y > Link->Y ) dist = a->Y - Link->Y;
- else dist = Link->Y - a->Y;
- return ( dist <= distance );
- }
- bool __LinkFacing(ffc f){
- if ( Link->Dir == DIR_UP && Link->Y > f->Y ) return true;
- if ( Link->Dir == DIR_DOWN && Link->Y < f->Y ) return true;
- if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true;
- if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true;
- return false;
- }
- }
- ///////////////////////////////
- /// FFC to Close Shop Doors ///
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Place on the screen with the tile warp that leads Link into the shop. ///
- /// Place over the tile warp combo (the door/entrance). ///
- /// D0: The *destination* DMap of the tilewarp. ///
- /// D1: The *destination* Screen of the tilewarp. ///
- /// D2: The combo to use as a closed door. Uses SHOP_DEFAULTCLOSED_DOOR_COMBO by default. ///
- /// D3: THe CSet of the closed door. ///
- /// D4: The solidity of the closed door. If set to '0', the script will default it to '4' (fully solid). ///
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ffc script ShopDoorClosed{
- void run(int dmap, int screen, int combo, int cset, int solid){
- if ( !solid ) solid = 4;
- if ( !combo ) combo = SHOP_DEFAULTCLOSED_DOOR_COMBO;
- bool waiting = true;
- if ( SHOP_DEBUG_ON ) ShopDoorDebug(dmap, screen);
- while(waiting){
- if ( IsShopAllSoldOut(dmap,screen) ){
- Screen->ComboD[ComboAt(this->X+8, this->Y+8)] = combo;
- Screen->ComboT[ComboAt(this->X+8, this->Y+8)] = CT_NONE;
- Screen->ComboC[ComboAt(this->X+8, this->Y+8)] = cset;
- Screen->ComboS[ComboAt(this->X+8, this->Y+8)] = solid;
- Screen->ComboF[ComboAt(this->X+8, this->Y+8)] = CF_NONE;
- Screen->ComboI[ComboAt(this->X+8, this->Y+8)] = 0;
- waiting = false;
- }
- Waitframe();
- }
- this->Data = 0; this->Script = 0; Quit();
- }
- }
- ////////////////////////
- /// Global Functions ///
- ////////////////////////
- //Check a shop item sold-out flag.
- bool FFC_ShopFlag(int flag){
- return ( ( Screen->D[SHOP_REGISTER]<<0 )&flag ) != 0;
- }
- //The same, for remote checks.
- bool FFC_ShopFlag(int dmap, int screen, int flag){
- return ( ( Game->GetDMapScreenD(dmap,screen,SHOP_REGISTER) << 0 )&flag ) != 0;
- }
- //Set a shop item sold-out flag.
- void FFC_SetShopFlag(int flag, bool state){
- int val[3];
- val[0]= Screen->D[SHOP_REGISTER];
- val[1]= val[0] << 0; //Integer side
- val[2] = val[0] - val[1]; //Decimal side.
- if ( state ) val[1] |= flag;
- else val[1] &= ~flag;
- Screen->D[SHOP_REGISTER] = val[1]+val[2]; //Preserve the decimal, and replace the integer.
- }
- //Returns how many shop item ffcs are running.
- int FFC_NumShopItems(){
- ffc f;
- int count;
- int ff[]="ShopItemMenu";
- int ffid = Game->GetFFCScript(ff);
- for ( int q = 1; q <= 32; q++ ){
- f = Screen->LoadFFC(q);
- if ( f->Script == ffid ) count++;
- }
- return count;
- }
- //Stores the number of items in the screen register.
- void FFC_SetNumberShopItems(){
- int val[6];
- val[0]= Screen->D[SHOP_REGISTER];
- val[1]= val[0] << 0; //Integer side
- val[2] = val[0] - val[1]; //Decimal side.
- val[3] = val[2] * 10000; //Decimal to Int
- val[4] = FFC_NumShopItems(); //Read how many shops are running.
- val[5] = val[4] / 10000; //Turn it into a decimal.
- Screen->D[SHOP_REGISTER] = val[1]+val[5]; //Preserve the integer, and replace the decimal.
- }
- //Returns te stored value of the number of running shop items.
- int FFC_GetNumberShopItems(){
- int val[3];
- val[0]= Screen->D[SHOP_REGISTER];
- val[1]= val[0] << 0; //Integer side
- val[2] = val[0] - val[1]; //Decimal side.
- return val[2] * 10000;
- }
- //Check if all items are sold out. Works only if there ALL items sold out.
- bool IsShopAllSoldOut(){
- int shopsold[]={0,1,2,4,8,16,32,64,128,256};
- int count;
- //int numshopitems = FFC_GetNumberShopItems();
- //int flag = Screen->D[SHOP_REG] << 0;
- int q;
- if ( SHOP_DEBUG_ON && Link->PressEx1) DebugIsSHopAllSoldOut(shopsold[FFC_GetNumberShopItems()]);
- //int count;
- for ( q = 0; q <= FFC_GetNumberShopItems(); q++ ) {
- count += shopsold[q];
- }
- if ( SHOP_DEBUG_ON ) DebugIsSHopAllSoldOut(count);
- //if ( SHOP_DEBUG_ON ) DebugIsSHopAllSoldOut(shopsold[q]);
- return ( ( Screen->D[SHOP_REGISTER] << 0 ) >= count && shopsold[q] != 0 );
- //return ( ( Screen->D[SHOP_REGISTER] << 0 ) >= shopsold[FFC_GetNumberShopItems()+1] );
- }
- void DebugIsShopAllSoldOutCount(int val){
- int t[]="The combined index value we're comparing against for IsShopAllSoldOut() is: ";
- TraceNL(); TraceS(t); Trace(val);
- }
- void DebugIsSHopAllSoldOut(int val){
- int str[]="Doing DebugIsSHopAllSoldOut()";
- TraceNL(); TraceS(str);
- int t[]="IsShopAllSoldOut() array value selected is: ";
- TraceNL(); TraceS(t); Trace(val);
- int tt[]="and the flag is: ";
- TraceNL(); TraceS(tt); Trace(Screen->D[SHOP_REGISTER] << 0);
- }
- //Draw the 'x' between the rupee icon and the price.
- void FFC_DrawShopPrice_X_Sign(ffc f){
- int x[]="x";
- Screen->DrawString(SHOP_PRICE_DRAW_X_SIGN_LAYER, f->X+SHOP_PRICE_DRAW_X_SIGN_X_OFFSET_BACKGROUND, f->Y+SHOP_PRICE_DRAW_X_SIGN_Y_OFFSET_BACKGROUND,
- SHOP_PRICE_DRAW_X_SIGN_FONT, SHOP_PRICE_DRAW_X_SIGN_COLOUR_BACKGROUND, SHOP_PRICE_DRAW_X_SIGN_SIZE, TF_NORMAL, x, OP_OPAQUE); //Background
- Screen->DrawString(SHOP_PRICE_DRAW_X_SIGN_LAYER, f->X+SHOP_PRICE_DRAW_X_SIGN_X_OFFSET_FOREGROUND, f->Y+SHOP_PRICE_DRAW_X_SIGN_Y_OFFSET_FOREGROUND,
- SHOP_PRICE_DRAW_X_SIGN_FONT, SHOP_PRICE_DRAW_X_SIGN_COLOUR_FOREGROUND, SHOP_PRICE_DRAW_X_SIGN_SIZE, TF_NORMAL, x, OP_OPAQUE); //Background
- }
- // A simple debug function that reports the present status of the shop flags.
- void ShopDebug(){
- int t[]="Screen->D[SHOP_REGISTER] << 0 is: ";
- TraceNL(); TraceS(t); Trace( Screen->D[SHOP_REGISTER] << 0);
- int tttt[]="FFC_NumShopItems() returned: ";
- int tttt1[]="This is the value read by checking how many ffcs are running the shop script.";
- TraceNL(); TraceS(tttt); Trace(FFC_NumShopItems()); TraceNL(); TraceS(tttt1);
- int tt[]=" FFC_GetNumberShopItems() returned: ";
- int tt1[]="This is the number of shop items, based on the value in Screen->D.";
- TraceNL(); TraceS(tt); Trace( FFC_GetNumberShopItems() ); TraceNL(); TraceS(tt1);
- int ttt[]=" IsShopAllSoldOut() returned: ";
- TraceNL(); TraceS(ttt); TraceB( IsShopAllSoldOut() );
- }
- void ShopDoorDebug(int dmap, int scr){
- int t[]="FFC_GetNumberShopItems() returned: ";
- TraceNL(); TraceS(t); Trace(FFC_GetNumberShopItems(dmap,scr));
- int tt[]="IsShopAllSoldOut() returned: ";
- TraceNL(); TraceS(tt); TraceB(IsShopAllSoldOut(dmap,scr));
- }
- void DebugIsSHopAllSoldOutRemote(int val){
- int t[]="IsShopAllSoldOut(dmap,screen) array value selected is: ";
- TraceNL(); TraceS(t); Trace(val);
- }
- //! Remote flag checking.
- //Returns the stored value of the number of running shop items on the Screen 'screen' of DMap 'dmap'.
- int FFC_GetNumberShopItems(int dmap, int screen){
- int val[3];
- val[0]= Game->GetDMapScreenD(dmap,screen,SHOP_REGISTER);
- val[1]= val[0] << 0; //Integer side
- val[2] = val[0] - val[1]; //Decimal side.
- return val[2] * 10000;
- }
- //Check if all items are sold out. Works only if there ALL items sold out on the Screen 'screen' of DMap 'dmap'.
- bool IsShopAllSoldOut(int dmap, int screen){
- int shopsold[]={0,1,2,4,8,16,32,64,128,256};
- if ( SHOP_DEBUG_ON ) DebugIsSHopAllSoldOutRemote(shopsold[FFC_GetNumberShopItems(dmap,screen)]);
- int count; int q;
- for ( q = 0; q <= FFC_GetNumberShopItems(dmap,screen); q++ ) {
- count += shopsold[q];
- }
- return ( ( Game->GetDMapScreenD(dmap,screen,SHOP_REGISTER) << 0 ) >= count && shopsold[q] != 0 && (Game->GetDMapScreenD(dmap,screen,SHOP_REGISTER) << 0) !=0 && !FFC_ShopFlag(dmap, screen, SHOP_STAY_OPEN));
- //return ( ( Screen->D[SHOP_REGISTER] << 0 ) >= count );
- //return ( ( Game->GetDMapScreenD(dmap,screen,SHOP_REGISTER) << 0 ) > shopsold[FFC_GetNumberShopItems(dmap,screen)] );
- }
- /////////////////////
- /// Shop Darkness ///
- /////////////////////
- //Call before Waitdraw in global active script.
- void FFC_ShopDarkness(){
- if ( Screen->D[SHOP_REGISTER] ) {
- if ( IsShopAllSoldOut( Game->GetCurDMap(), Game->GetCurScreen() ) ){
- for ( int q = 0; q < SHOP_DARKNESSS_NUM_LAYERS; q++ )
- Screen->Rectangle(SHOP_DARKNESS_LAYER, 0, 0, 255, 175, SHOP_DARKNESS_COLOUR, SHOP_DARKNESS_SCALE, 0, 0, 0, true, SHOP_DARKNESS_OPACITY);
- }
- }
- }
- //The 'yes/no' menu called by the ffc.
- int BuyYesNo(int msg, int price) {
- int lineBreak[]="@26";
- int line1[]="@choice(1)Item Info@26";
- int line2[]="@choice(2)Buy@26@choice(3)Cancel@domenu(1)@suspend()";
- int free[]="@choice(2)Take@26@choice(3)Cancel@domenu(1)@suspend()";
- SetUpWindow(WINDOW_SLOT_1, WINDOW_STYLE_3, 32, 32, SIZE_LARGE);
- Tango_LoadString(WINDOW_SLOT_1, line1);
- if ( price == 0 ) Tango_AppendString(WINDOW_SLOT_1, free);
- else Tango_AppendString(WINDOW_SLOT_1, line2);
- Tango_ActivateSlot(WINDOW_SLOT_1);
- while(!Tango_MenuIsActive()){
- Waitframe();
- }
- // Save the state again...
- int slotState[278];
- int menuState[960];
- int cursorPos;
- Tango_SaveSlotState(WINDOW_SLOT_1, slotState);
- Tango_SaveMenuState(menuState);
- int done = 0;
- int choice;
- while(true){
- while( Tango_MenuIsActive() ) {
- cursorPos=Tango_GetMenuCursorPosition();
- Waitframe();
- }
- choice = Tango_GetLastMenuChoice();
- if ( choice == 1 ) { // Item Info
- int text[256];
- Game->GetMessage(msg,text); //Load msg into the buffer.
- ShowString(text, WINDOW_SLOT_2, WINDOW_STYLE_3, 48, 48);
- }
- else if ( choice == 2 ) { //Buy
- done = choice;
- menuArg = choice;
- }
- else if ( choice == 3 ) { //Cancel
- done = choice;
- }
- else if ( Link->PressEx1 ) {
- done = 1;
- }
- else done = 3;
- if ( done ) {
- break;
- // return choice;
- }
- else {
- Tango_RestoreSlotState(WINDOW_SLOT_1, slotState);
- Tango_RestoreMenuState(menuState);
- Tango_SetMenuCursorPosition(cursorPos);
- }
- }
- Tango_ClearSlot(WINDOW_SLOT_1);
- return done;
- }
- //Global Scripts
- //Mandatory init script: If you already have an init script, merge them.
- global script Init {
- void run(){
- SetCommonStyleData(WINDOW_STYLE_1);
- SetCommonStyleData(WINDOW_STYLE_2);
- SetCommonStyleData(WINDOW_STYLE_3);
- }
- }
- //Example global active (slot 2) script.
- global script Tango{
- void run(){
- if ( SHOP_DEBUG_ON ) ClearTrace();
- Tango_Start();
- StartGhostZH();
- while(true) {
- UpdateGhostZH1();
- Tango_Update1();
- if ( SHOP_DARK_WHEN_CLOSED ) FFC_ShopDarkness(); //Manages shop darkness.
- Waitdraw();
- UpdateGhostZH2();
- Tango_Update2();
- Waitframe();
- }
- }
- }
- //////////////////
- /// DEPRECATED ///
- //////////////////
- //Draws the darkness layer.
- void ShopSoldOut(){
- for ( int q = 0; q < SHOP_DARKNESSS_NUM_LAYERS; q++ )
- Screen->Rectangle(SHOP_DARKNESS_LAYER, 0, 0, 255, 175, SHOP_DARKNESS_COLOUR, SHOP_DARKNESS_SCALE, 0, 0, 0, true, SHOP_DARKNESS_OPACITY);
- }
- //The ffc that makes the screen dark.
- ffc script ShopDarknessFFC{
- void run(){
- while(true){
- if ( IsShopAllSoldOut() && SHOP_DARK_WHEN_CLOSED ) ShopSoldOut(); //Draw dark layer if setting enabled.
- Waitframe();
- }
- }
- }
- //Draws darkness effect if the shop is sold out, and the setting is enabled.
- int FFC_GetShopDarkness(){
- int ff[]="ShopDarknessFFC";
- return Game->GetFFCScript(ff);
- }
- void TracePrice(int val){
- int t[]="Tracing price: ";
- TraceNL(); TraceS(t); Trace(val);
- }
Add Comment
Please, Sign In to add comment