Copy to Clipboard Test

Counter Bank Code

const int SFX_BANK_DEPOSIT = 0;//Sound to play on bank deposit.
const int SFX_BANK_WITHDRAW = 0;//Sound to play on bank withdraw.

const int FONT_BANK_SHOP = 0;//Font used to render bank account details and all text in UI.
const int CSET_FONT_SHADOW_BANK = 0x71;//Shadow for HUD font drawing (Color).

//Prompt GFX
const int CMB_BANK_PROMPT = 911;//Combo ID used to render prompt, when Link steps on spot.
const int CSET_BANK_PROMPT = 11;//CSet used to render prompt, when Link steps on spot.

const int TILE_BANK_FRAME = 20052;//Id of top left corner for 3x3 frame used to render UI frame.
const int CSET_BANK_FRAME = 11;//CSet used to render UI frame.

const int C_BANK_CANT_AFFORD = 0x81;//Color to render inner counter if input is capped by player`s funds.
const int C_BANK_CAN_FINISH = 0x51;//Color to render inner counter if input is capped by exceeding charity demand.

// const int BANK_DISPLAY_X_OFFSET = 0;//Coordinates of rendering counter icon displayed in the screen, input field.
// const int BANK_DISPLAY_Y_OFFSET = -16;

const int CMB_BANK_SELECTION = 915;//Combo used for animated selection cursor 
const int CSET_BANK_SELECTION = 7;//CSet used to render animated selection cursor 
const int FONTSIZE_BANK_SELECTION = 8;//Width of each symbol in input field, in pixels.

//Audio
const int SFX_BANK_CONFIRM = 0;//Sound to play on successful donation.
const int SFX_BANK_INPUT = 5;//Sound to play on operating input.
const int SFX_BANK_CAPPED = 16;//Sound to play if unput is capped.

//Counter Bank. Stand on FFC and press either EX1 to deposit counter, or EX2 to withdraw previously deposited. Bank safe has limited capacity
//and triggers reward, if filled.

//Place FFC at trigger position.
//D0 - Screen D to keep track balance on bank account.
//D1 - Counter to be used by this bank. For blood donations, minimum of 1 full heart should left upon deposit.
//D2 - string to display if player fills bank safe via deposit.
//D3 - *****.____ - String to display on prompt to deposit counter into bank.
//D3 - _____.**** - String to display on prompt to withdraw counter from bank.
//D4 - Bank account limit. If filled, reward triggers.
//D5 - Reward. >0 - Award item ID, -1 - Secret trigger.
//D6 - Combo position to render bank account balance.
//D7 - Combo used to render counter image. CSet is FFC`s CSet.

ffc script Bank{
	void run (int ScreenD, int counter, int endmsg, int str, int capacity, int reward, int drawpos, int cmb){
		//if (Screen->D[ScreenD]==0 || Screen->D[ScreenD]==capacity) Screen->Message(string);
		int linkcmb = 0;
		int pos = ComboAt(CenterX(this),CenterY(this));
		int mincounter = 0;
		if (counter == CR_LIFE) mincounter += 16;
		int State = 0;
		int input = 0;
		int cap = 0;
		int numdigits = 4;
		int mode =0;
		int str_deposit = GetHighFloat(str);
		int str_withdraws = GetLowFloat(str);
		int str1[] = "Bank";
		int str2[] = "Deposit:";
		int str3[] = "Owned:";
		int str4[] = "1 heart";
		int str5[] = "must left";
		int str6[] = "Ex1-Confirm";
		int str7[] = "Ex2-Cancel";
		int str8[] = "/";
		int str9[] = "Withdraw:";
		bool secret = Screen->D[ScreenD]>=100000;
		
		int inputcursor=0;
		
		while(true){
			if (State==0){
				linkcmb = ComboAt (CenterLinkX(), CenterLinkY()-2);
				if (linkcmb==pos){
					Screen->FastCombo(6, Link->X,Link->Y-15,CMB_BANK_PROMPT, CSET_BANK_PROMPT,OP_OPAQUE);
					if (Link->PressEx1){
						if ((Screen->D[ScreenD]%100000)<capacity){
							if (str_deposit>0)Screen->Message(str_deposit);
							cap = Min (Game->Counter[counter]-mincounter+Game->DCounter[counter], capacity-(Screen->D[ScreenD]%100000));
							mode=0;
							input=Clamp(input, 0, cap);
							State=1;
						}
					}
					if (Link->PressEx2){
						if ((Screen->D[ScreenD]%100000)>0){
							if (str_withdraws>0)Screen->Message(str_withdraws);
							cap = Min (Game->MCounter[counter]-Game->Counter[counter]-Game->DCounter[counter], (Screen->D[ScreenD]%100000));
							mode=1;
							input=Clamp(input, 0, cap);
							State=1;
						}
					}
				}
			}
			else if (State==1){				
				DrawFrame(6,TILE_BANK_FRAME,48,16,9,9,CSET_BANK_FRAME,OP_OPAQUE);
				
				if (CSET_FONT_SHADOW_BANK>0){//Donation progress 
					Screen->DrawString(6,81, 33, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str1, OP_OPAQUE);
					Screen->DrawString(6,81, 49, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, Cond(mode>0, str9, str2), OP_OPAQUE);
				}
				Screen->DrawString(6,80, 32, FONT_BANK_SHOP, 1, -1, 0, str1, OP_OPAQUE);
				Screen->DrawString(6,80, 48, FONT_BANK_SHOP, 1, -1, 0, Cond(mode>0, str9, str2), OP_OPAQUE);
				
				Screen->FastCombo(6, 64, 64, cmb, this->CSet, OP_OPAQUE);
				if (CSET_FONT_SHADOW_BANK>0){//Progress/target
					Screen->DrawInteger(6,81, 65,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0,0, (Screen->D[ScreenD]%100000),0, OP_OPAQUE);
					Screen->DrawString(6,131, 65,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str8, OP_OPAQUE);
					Screen->DrawInteger(6,139, 65,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0,0, capacity,0, OP_OPAQUE);
				}
				Screen->DrawInteger(6,80, 64,FONT_BANK_SHOP, 1, -1, 0,0, (Screen->D[ScreenD]%100000),0, OP_OPAQUE);
				Screen->DrawString(6,130, 64,FONT_BANK_SHOP, 1, -1, 0, str8, OP_OPAQUE);
				Screen->DrawInteger(6,138, 64,FONT_BANK_SHOP, 1, -1, 0,0, capacity,0, OP_OPAQUE);
				
				if (CSET_FONT_SHADOW_BANK>0){//Owned:X 
					Screen->DrawString(6,81, 73,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str3, OP_OPAQUE);
					Screen->DrawInteger(6,139, 73,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0,0, Game->Counter[counter],0, OP_OPAQUE);
				}
				Screen->DrawString(6,80, 72,FONT_BANK_SHOP, 1, -1, 0, str3, OP_OPAQUE);
				Screen->DrawInteger(6,138, 72,FONT_BANK_SHOP, 1, -1, 0,0, Game->Counter[counter],0, OP_OPAQUE);
				
				int inputbuf[] = "0000";
				int numdigits=1;
				if (input>0) numdigits = Floor(Log10(input)) + 1;
				itoa(inputbuf,strlen(inputbuf) - numdigits,input);
				
				if (CSET_FONT_SHADOW_BANK>0){//input
					Screen->DrawString(6,139, 89, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 2, inputbuf, OP_OPAQUE);
				}
				Screen->DrawString(6,138, 88, FONT_BANK_SHOP, 1, -1, 2, inputbuf, OP_OPAQUE);
				Screen->FastCombo(6, 126-FONTSIZE_BANK_SELECTION*inputcursor, 84,CMB_BANK_SELECTION, CSET_BANK_SELECTION, OP_OPAQUE);
				
				if (mincounter>0){
					if (CSET_FONT_SHADOW_BANK>0){//1 heart must left
						Screen->DrawString(6,81, 105, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str4, OP_OPAQUE);
						Screen->DrawString(6,81, 113, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str5, OP_OPAQUE);
					}
					Screen->DrawString(6,80, 104, FONT_BANK_SHOP, 1, -1, 0, str4, OP_OPAQUE);
					Screen->DrawString(6,80, 112, FONT_BANK_SHOP, 1, -1, 0, str5, OP_OPAQUE);
				}
				
				if (CSET_FONT_SHADOW_BANK>0){//Ex1-Confirm, Ex2-Cancel
					Screen->DrawString(6,81, 129, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str6, OP_OPAQUE);
					Screen->DrawString(6,81, 137, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, 0, str7, OP_OPAQUE);
				}
				Screen->DrawString(6,80, 128, FONT_BANK_SHOP, 1, -1, 0, str6, OP_OPAQUE);
				Screen->DrawString(6,80, 136, FONT_BANK_SHOP, 1, -1, 0, str7, OP_OPAQUE);
				
				
				
				if (Link->PressLeft){
					Game->PlaySound(SFX_BANK_INPUT);
					inputcursor++;
					if (inputcursor>3)inputcursor=0;
				}
				if (Link->PressRight){
					Game->PlaySound(SFX_BANK_INPUT);
					inputcursor--;
					if (inputcursor<0)inputcursor=3;
				}
				if (Link->PressUp){
					input+=Pow(10, inputcursor);
					if (input>cap){
						Game->PlaySound(SFX_BANK_CAPPED);
						if (cap==Game->Counter[counter]-mincounter+Game->DCounter[counter] || cap == Game->MCounter[counter]-Game->Counter[counter]-Game->DCounter[counter]){
							Screen->DrawString(6,80, 72,FONT_BANK_SHOP, C_BANK_CANT_AFFORD, -1, 0, str3, OP_OPAQUE);
							Screen->DrawInteger(6,138, 72,FONT_BANK_SHOP, C_BANK_CANT_AFFORD, -1, 0,0, Game->Counter[counter],0, OP_OPAQUE);
						}
						else {
							Screen->DrawInteger(6,80, 64,FONT_BANK_SHOP, C_BANK_CAN_FINISH, -1, 0,0, (Screen->D[ScreenD]%100000),0, OP_OPAQUE);
							Screen->DrawString(6,130, 64,FONT_BANK_SHOP, C_BANK_CAN_FINISH, -1, 0, str8, OP_OPAQUE);
							Screen->DrawInteger(6,138, 64,FONT_BANK_SHOP, C_BANK_CAN_FINISH, -1, 0,0, capacity,0, OP_OPAQUE);
						}
						input=cap;
					}
					else Game->PlaySound(SFX_BANK_INPUT);
				}
				if (Link->PressDown){
					input-=Pow(10, inputcursor);
					if (input<0){
						Game->PlaySound(SFX_BANK_CAPPED);
						input=0;
					}
					else Game->PlaySound(SFX_BANK_INPUT);
				}
				if (Link->PressEx2){
					State=0;
				}
				if (Link->PressEx1 && input>0){
					Game->PlaySound(SFX_BANK_CONFIRM);
					if (counter==CR_LIFE)Game->PlaySound(SFX_OUCH);
					if (mode==0){
						Game->DCounter[counter] -= input;
						Screen->D[ScreenD] += input;
					}
					else{
						Game->DCounter[counter] += input;
						Screen->D[ScreenD] -= input;
					}
					if ((Screen->D[ScreenD]%100000)>=capacity && mode==0){						
						if (reward!=0 && !secret){
							if (reward<0 && !Screen->State[ST_SECRET]){	
								Screen->Message(endmsg);
								Waitframe();
								Game->PlaySound(SFX_SECRET);
								Screen->TriggerSecrets();
								Screen->State[ST_SECRET]=true;
								secret=true;
							}
							if (reward>0){
								Screen->Message(endmsg);
								Waitframe();
								Game->PlaySound(SFX_SECRET);
								item it = CreateItemAt(reward, Link->X, Link->Y);
								it->Pickup = 0x2;
								secret=true;
							}
						}
						Screen->D[ScreenD]=capacity+Cond(secret, 100000,0);
					}
					//else Screen->Message(progstr);
					State=0;
				}
				NoAction();
			}
			int drawx = ComboX(drawpos);
			int drawy = ComboY(drawpos);
			Screen->FastCombo(2, drawx, drawy, cmb, this->CSet, OP_OPAQUE);
			drawx+=16;
			drawy+=4;
			if (CSET_FONT_SHADOW_BANK>0)Screen->DrawInteger(2, drawx+1, drawy+1,FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, -1, -1, (Screen->D[ScreenD]%100000), 0, OP_OPAQUE);
			Screen->DrawInteger(2, drawx, drawy,FONT_BANK_SHOP, 1, -1, -1, -1,(Screen->D[ScreenD]%100000), 0, OP_OPAQUE);
			int str[]="/";
			drawx+=40;
			if (CSET_FONT_SHADOW_BANK>0)Screen->DrawString(2, drawx+1, drawy+1, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK,-1,  0, str,OP_OPAQUE);
			Screen->DrawString(2, drawx, drawy, FONT_BANK_SHOP, 1,-1,  0, str,OP_OPAQUE);
			drawx+=8;
			if (CSET_FONT_SHADOW_BANK>0)Screen->DrawInteger(2, drawx+1, drawy+1, FONT_BANK_SHOP, CSET_FONT_SHADOW_BANK, -1, -1, -1, capacity, 0, OP_OPAQUE);
			Screen->DrawInteger(2, drawx, drawy,FONT_BANK_SHOP, 1, -1, -1, -1, capacity, 0, OP_OPAQUE);
			Waitframe();
		}		
	}
	
	void DrawFrame(int layer, int tile, int posx, int posy, int sizex, int sizey, int CSet, int opacity){
		int drawx = posx;
		int drawy = posy;
		int xoffset=0;
		int yoffset=0;
		for (int w=0; w<sizex; w++){
			drawx = posx+16*w;
			xoffset=0;
			if (w>0)xoffset=1;
			if (w==sizex-1) xoffset=2;
			for (int h=0; h<sizey; h++){
				drawy = posy+16*h;
				yoffset=0;
				if (h>0)yoffset=1;
				if (h==sizey-1) yoffset=2;
				Screen->FastTile(layer, drawx, drawy, tile +xoffset+20*yoffset, CSet, opacity);
			}
		}
	}
}