#library "GCSTRIFELIB"
#include "zcommon.acs"

// Sometimes, gold ends up in your inventory anyway. This is for that.
script "ExchangeGoldForDosh" ENTER{
	if(CheckInventory("Coin")>=10000){TakeInventory("Coin",10000); GiveInventory("Dosh",10000); delay(1); restart;}
	if(CheckInventory("Coin")>=5000){TakeInventory("Coin",5000); GiveInventory("Dosh",5000); delay(1); restart;}
	if(CheckInventory("Coin")>=1000){TakeInventory("Coin",1000); GiveInventory("Dosh",1000); delay(1); restart;}
	if(CheckInventory("Coin")>=500){TakeInventory("Coin",500); GiveInventory("Dosh",500); delay(1); restart;}
	if(CheckInventory("Coin")>=100){TakeInventory("Coin",100); GiveInventory("Dosh",100); delay(1); restart;}
	if(CheckInventory("Coin")>=50){TakeInventory("Coin",50); GiveInventory("Dosh",50); delay(1); restart;}
	if(CheckInventory("Coin")>=10){TakeInventory("Coin",10); GiveInventory("Dosh",10); delay(1); restart;}
	if(CheckInventory("Coin")>=5){TakeInventory("Coin",5); GiveInventory("Dosh",5); delay(1); restart;}
	if(CheckInventory("Coin")>=1){TakeInventory("Coin",1); GiveInventory("Dosh",1); delay(1); restart;}}

// This script could probably be way better, but I'm no ACS wizard, and it
// gets the job done.
script "FerisPulverizerAmmoCheckAndFill" (float checkdivisor,float filldivisor){
	float pulamt = CheckInventory("PulverizerAmmo");
	float pulcap = GetAmmoCapacity("PulverizerAmmo");
	if(pulamt<(pulcap/checkdivisor)){
		GiveInventory("PulverizerAmmo",1);
		if(pulamt<(pulcap/filldivisor)){
			setresultvalue(1);
			restart;}
		else{
			PlaySound(0,"Pulverizer/Ammo",CHAN_BODY); // Doesn't seem to work. I guess because the conversation box is open? *shrug*
			setresultvalue(2);}}
	else{
		setresultvalue(0);}}

// Replaces the AlienSpectre's native death function. Sends logs to the comm 
// unit, gives QuestItems, prints "You killed ___!" messages, etc. Script
// originally by Xaser for use with Psychic.
script "AlienSpectreDeath" (int specNum){
	SetActivator(0,AAPTR_PLAYER1); 
	switch(specNum){
	case 1:     // Programmer's Spectre (the one fought in the Ruins)
		Floor_LowerToLowest(999,8); 
		SendToCommunicator(95,0,0,0); break;
	case 2:     // Bishop's Spectre
		PrintBold(l:"TXT_KILLED_BISHOP"); 
		SendToCommunicator(74,0,0,0); 
		GiveInventory("QuestItem21",1); 
		break;
	case 3:     // Oracle's Spectre
		PrintBold(l:"TXT_KILLED_ORACLE"); 
		Thing_Destroy(900,0); 
		Door_Open(222,8); 
		GiveInventory("QuestItem23",1);
		if(CheckInventory("QuestItem21")){
			GiveInventory("QuestItem22",1);}// If bishop is dead, mark Oracle dead too.
		if(!CheckInventory("QuestItem24")){
			SendToCommunicator(87,0,0,0);} // If Macil still alive...
		else{
			SendToCommunicator(85,0,0,0);}
		break;
	case 4:     // Macil's Spectre
		PrintBold(l:"TXT_KILLED_MACIL");
		GiveInventory("QuestItem24",1); //Macil dead.
		if(!CheckInventory("QuestItem25")){
			SendToCommunicator(79,0,0,0);}// If Conversion Chapel mission not complete...
		else{
			SendToCommunicator(106,0,0,0);}
		break;
	case 5:     // Loremaster's Spectre
		PrintBold(l:"TXT_KILLED_LOREMASTER"); 
		Floor_LowerToLowest(666,8); 
		GiveInventory("QuestItem25",1); // Loremaster dead.
		if(CheckInventory("EntityKey")>=5){
			SendToCommunicator(85,0,0,0);} // If all five Spectres have been killed, it's time to go to the ship.
		else{
			SendToCommunicator(83,0,0,0);} // Otherwise, you've got at least one more to go.
		break;}}