#Include "zcommon.acs"
#library "DarkForces"

//---------------Start Map Script, change player tid-------------//
Script 900 ENTER
{
	Thing_ChangeTid(0,1000+PlayerNumber());
}
//---------------------------------------------------------------//

//----------It's script using by Phase2. It's checking Z-distance for flying--// 
Script 901 (int ZDistance)
{
	int PhaseZ = GetActorZ(0) >> 16; //Get Phase2's Z coordinate

    SetActivatorToTarget(0);
	
	int TargetZ = GetActorZ(0) >> 16; //Get Player Z-Coordinate, or Target Z Coordinate
	
	ZDistance = abs(PhaseZ - TargetZ);
	
	SetResultValue(ZDistance);

}

Script 902 (int ActorSpeed)
{
   SetActorProperty(0,APROP_Speed, ActorSpeed*1.0);
}   

Script 903 (int KellDistance)
{
    
	int KellX = GetActorX(0) >> 16;
	int KellY = GetActorY(0) >> 16;
	
	SetActivatorToTarget(0);
	
	int PlayerX = (GetActorX(0) >> 16); 
	int PlayerY = (GetActorY(0) >> 16);
	
	int X = KellX - PlayerX;
	int Y = KellY - PlayerY;
	
	KellDistance = sqrt(X*X + Y*Y);
	
	SetResultValue(KellDistance);
}

//I'm create it's script for using custom bobstyle. Here checking 
//2 types - Vels and Buttons. Why? It's for clear bugs(bobstyle use many sprites and offset property)
//
Script 904 (int PlayerMove)
{
   int Button = GetPlayerInput(-1, INPUT_BUTTONS);
   if (Button & BT_FORWARD || Button & BT_BACK || Button & BT_MOVELEFT || Button & BT_MOVERIGHT)
   {
        //if(GetActorVelX(0) != 0 || GetActorVelY(0) != 0)
        //{
        PlayerMove = 1;
        //}
    }  
SetResultValue(PlayerMove);
}  

//------------Goggles Script-----------//
Script 905 (void)
{
int N;
GiveInventory("SpecialInfared", 1);
While(CheckInventory("InventoryBattery") != 0 && CheckInventory("GogglesCheck") != 0)
{
   if(N == 35)
      {
      GiveInventory("SpecialInfared", 1);
      TakeInventory("InventoryBattery", 1);
	  N = 0;
	  }
    Delay(1);
	N += 1;
}
TakeInventory("GogglesCheck", 1);
TakeInventory("SpecialInfared", 999);
terminate;
}
//---------GasMask Script---------------// 
Script 906 (void)
{
SetHudSize(320, 200, True);
Setfont("GMASK");
Hudmessage(s:"A"; HUDMSG_PLAIN, 1, -1, 105.5, 200.2, 1, 99.0);
SetActorState(0,"UseMask");
//PlaySound(0, "MaskWork", 6, 1.0, True);
int N;
GiveInventory("SpecialIronFeet", 1);
While(CheckInventory("InventoryBattery") != 0 && CheckInventory("GasMaskCheck") != 0)
{
   if(N == 35)
      {
      GiveInventory("SpecialIronFeet", 1);
      TakeInventory("InventoryBattery", 1);
	  N = 0;
	  }
    Delay(1);
	N += 1;
}
TakeInventory("GasMaskCheck", 1);
TakeInventory("SpecialIronFeet", 999);
Hudmessage(s:" "; HUDMSG_PLAIN, 1, -1, 105.5, 200.2, 1, 99.0);
SetActorState(0,"DoneMask");
//StopSound(0, 6);
terminate;
}

//---------------Head Light Script--------------//
Script 907 (int Factor)
{
int N;
While(CheckInventory("InventoryBattery") != 0 && CheckInventory("HeadLightCheck") != 0)
{
   if(N == Factor)
      {
      TakeInventory("InventoryBattery", 1);
	  N = 0;
	  }
    Delay(1);
	N += 1;
}
TakeInventory("HeadLightCheck", 1);
terminate;
}
 
//--------------SewerBug Pain-script------------------------// 
Script 908 (void)
{
int Health;
int LastHealth = GetActorProperty(0, APROP_Health);

While(GetActorProperty(0, APROP_Health) > 0)
{
   Health = GetActorProperty(0, APROP_Health);
   if(Health < LastHealth)
      {
      ActivatorSound("SewerBug/Pain", 90);
	  LastHealth = GetActorProperty(0, APROP_Health);
	  }
    Delay(1);
}
terminate;
} 

//-----------SewerBug check floor, for spawner------------//

Script 909 (void)
{
int IsWater;
   if(CheckActorFloorTexture(0, "FWATER1") || CheckActorFloorTexture(0, "FWATER2") || CheckActorFloorTexture(0, "FWATER3")|| CheckActorFloorTexture(0, "FWATER4")
   || CheckActorFloorTexture(0, "NUKAGE1") || CheckActorFloorTexture(0, "NUKAGE2") || CheckActorFloorTexture(0, "NUKAGE3")|| CheckActorFloorTexture(0, "LAVA1") 
   || CheckActorFloorTexture(0, "LAVA2") || CheckActorFloorTexture(0, "LAVA3") || CheckActorFloorTexture(0, "LAVA4") || CheckActorFloorTexture(0, "BLOOD1")
   || CheckActorFloorTexture(0, "BLOOD2") || CheckActorFloorTexture(0, "BLOOD3") || CheckActorFloorTexture(0, "SLIME01") || CheckActorFloorTexture(0, "SLIME02")
   || CheckActorFloorTexture(0, "SLIME03")|| CheckActorFloorTexture(0, "SLIME04")|| CheckActorFloorTexture(0, "SLIME05")|| CheckActorFloorTexture(0, "SLIME06")
   || CheckActorFloorTexture(0, "SLIME07")|| CheckActorFloorTexture(0, "SLIME08"))
   {
    IsWater = 1;
	}
SetResultValue(IsWater);
}	


Script 910 (void)
{
int X;
int Y;
While(/*CheckInventory("InventoryBattery") != 0 &&*/ CheckInventory("IceCleatsCheck") != 0)
{
   X = GetActorVelX(0);
   Print(i: X);
   //if(N == Factor)
      //{
      //TakeInventory("InventoryBattery", 1);
	  //N = 0;
	  //}
    Delay(1);
	//N += 1;
}
TakeInventory("HeadLightCheck", 1);
terminate;
}

/*CheckActorFloorTexture(0, "NUKAGE1") == True ||*/
	/*|| CheckActorFloorTexture(0, "LAVA1") == True || CheckActorFloorTexture(0, "BLOOD1") == True*/ 
//function int distance (void)
//{
    //int x, y, d;
    //x = PlayerStartX - GetActorX(0) >> 16; // Convert fixed point to integer
    //y = PlayerStartY - GetActorY(0) >> 16;
    //d = sqrt( x*x + y*y );
    //return d;
//}

//----------------------------------------------------------------------------//

//---------Square Function------//
function int sqrt (int x)
{
    int r;
    x = x + 1 >> 1;
    while (x > r)
        x -= r++;
    return r;
}
//--------------------------------//

//-------Module Function-----------//
function int abs (int x)
{
    if (x < 0)
        return -x;

    return x;
}
//----------------------------------//