Copy to Clipboard Test

Evil Scrub Code

const int EVIL_SCRUB_WARNTIME = 45;//Warn time before Evil Scrub fires eweapon.

const int SPR_EVIL_SCRUB_POOF = 22;//Sprite to display, when Evil scrub finds new home.

//Evil Scrub
//Hides in a combo, fires eweapons at Link. If combo changes to another combo, it flies around like crazy for certain amount of time. Then it finds another combo with the same ID as removed combo to hide inside. If no such combo found, the enemy instantly kicks the bucket. Alternatively, Link can kill this monster while he is in panic state.

//Animation. 3 rows pf tiles: Hiding, shooting, running.

ffc script EvilScrub{
	void run(int enemyID){
		npc ghost = Ghost_InitAutoGhost(this, enemyID);
		
		int HF = ghost->Homing;
		int HR = ghost->Haltrate;
		int RR = ghost->Rate;
		int HNG = ghost->Hunger;
		int SPD = ghost->Step;
		int WPND = ghost->WeaponDamage;
		
		int Shotdelay = Ghost_GetAttribute(ghost, 0, 180);//Delay between shooting eweapons.
		int WPNS =Ghost_GetAttribute(ghost, 1, -1);//Eweapon sprite.
		int panicduration = Ghost_GetAttribute(ghost, 0, 300);//Duration of enemy`s crazy run upon destruction of his home.
		
		Ghost_SetFlag(GHF_NORMAL);
		Ghost_SetFlag(GHF_FLYING_ENEMY);
		Ghost_SetFlag(GHF_IGNORE_ALL_TERRAIN);
		
		int OrigTile = ghost->OriginalTile;
		int State = 0;
		int statecounter = 0;
		int haltcounter = -1;
		int cmb = ComboAt(Ghost_X+5, Ghost_Y+5);
		int cd = Screen->ComboD[cmb];
		cmb = PickRandomComboOfThisData(cd);
		if (cmb<0)Ghost_HP=0;
		else{
			Ghost_X=ComboX(cmb);
			Ghost_Y=ComboY(cmb);
		}
		int shootcounter = Shotdelay;
		int offset = 0;
		int curcmb=cmb;
		int angle=-1;
		
		eweapon e;
		lweapon poof;
		
		int defs[18];
		Ghost_StoreDefenses(ghost,defs);
		
		ghost->CollDetection=false;
		
		while(true){
			if (State==0){
				shootcounter--;
				if (shootcounter==0 && WPND>0){
					e = FireAimedEWeapon(ghost->Weapon, Ghost_X, Ghost_Y, 0, 200, WPND, WPNS, -1, 0);
					shootcounter = Shotdelay;
				}
				if (Screen->ComboD[cmb]!=cd){
					ghost->CollDetection=true;
					statecounter = panicduration;
					State=1;
					// cmb = PickRandomComboOfThisData(cd);
					// if (cmb<0)Ghost_HP=0;
				}
			}
			else if (State==1){
				haltcounter = Ghost_ConstantWalk4(haltcounter, SPD, RR, HF, HNG);
				statecounter--;
				if (statecounter==0){
					cmb = PickRandomComboOfThisData(cd);
					if (cmb<0)Ghost_HP=0;
					else angle = Angle(Ghost_X, Ghost_Y, ComboX(cmb), ComboY(cmb));
					Ghost_Vx = SPD/100*Cos(angle);
					Ghost_Vy = SPD/100*Sin(angle);
					State=2;
				}
			}
			else if (State==2){
				//Ghost_MoveXY(Ghost_Vx, Ghost_Vy, 2);
				if (Screen->ComboD[cmb]!=cd){
					ghost->CollDetection=true;
					statecounter = 60;
					Ghost_Vx = 0;
					Ghost_Vy = 0;
					State=1;
				}
				curcmb = ComboAt(Ghost_X+5, Ghost_Y+5);
				if (curcmb==cmb){
					ghost->CollDetection=false;
					State=0;
					poof = CreateLWeaponAt(LW_SPARKLE, Ghost_X, Ghost_Y);
					poof->UseSprite(SPR_EVIL_SCRUB_POOF);
					poof->CollDetection=false;
					Ghost_Vx = 0;
					Ghost_Vy = 0;
					Ghost_X=ComboX(cmb);
					Ghost_Y=ComboY(cmb);
				}
			}
			// debugValue(1,statecounter);
			Scrub_Animation(ghost, OrigTile, State, shootcounter);
			Ghost_Waitframe(this, ghost);
		}
	}
}

void Scrub_Animation(npc ghost, int origtile, int state, int shootcounter){
	int offset = 0;
	int Shotdelay = Ghost_GetAttribute(ghost, 0, 180);
	if (state>0) offset=40;
	else if ((shootcounter<EVIL_SCRUB_WARNTIME||(Shotdelay-shootcounter) < EVIL_SCRUB_WARNTIME)&&(ghost->WeaponDamage>0)) offset = 20;
	ghost->OriginalTile = origtile + offset;
}

//Picks random combo of the given ID from the current screen and return it`s position.
int PickRandomComboOfThisData(int cmb){
	int arr[176];
	int size=0;
	for (int i=0;i<176;i++){
		if (Screen->ComboD[i]!=cmb)continue;
		arr[size]=i;
		size++;
	}
	if (size==0) return -1;
	int ret = Rand(size);
	return arr[ret];
}