class GlowingCrystal : Actor
{
	//$Title Crystal Cluster Giant
	//$Category Decoration/Crystals
	//$NotAngled
	//$IsDecoration
    
    int colour;
    int size;
    bool ceiling;

    default {
        //$Arg0 Colour
        //$Arg0Type 11
        //$Arg0Enum {0 = "White"; 1 = "Green"; 2 = "Yellow"; 3 = "Rose"; 4 = "Red"; 5 = "Blue"; 6 = "Purple"; 7 = "Orange";}
        //$Arg1 Size
        //$Arg1Type 11
        //$Arg1Enum {0 = "Tiny"; 1 = "Small"; 2 = "Medium"; 3 = "Large";}
        //$Arg2 Position
        //$Arg2Type 11
        //$Arg2Enum {0 = "Floor"; 1 = "Ceiling";}
        Radius 20;
        Height 64;
        Alpha 0.9;
        +SOLID;
	}

	States
	{
        Cache:
            CRYS A 0; CRYS B 0; CRYS C 0; CRYS D 0; CRYS E 0; CRYS F 0; CRYS G 0; CRYS H 0;
            CRYC A 0; CRYC B 0; CRYC C 0; CRYC D 0; CRYC E 0; CRYC F 0; CRYC G 0; CRYC H 0;
		Spawn:
			CRYS A -1;
			Stop;
	}
    
    override void PostBeginPlay() {
        colour = self.args[0];
        size = self.args[1];
        ceiling = self.args[2];
        
        int lightSize = 64;
        let lightOffset = (0, 0, 32);

        //Colour adjustment
        if (colour >= 0 && colour <= 7) {
            self.frame = colour;
        } else {
            colour = 0;
        }
        //Size adjustment
        if (size == 0) { self.A_SetSize(8, 14);  self.Scale = (0.2, 0.2); lightSize = 14; bSOLID = false; }
        if (size == 1) { self.A_SetSize(12, 26); self.Scale = (0.4, 0.4); lightSize = 26; }
        if (size == 2) { self.A_SetSize(16, 52); self.Scale = (0.8, 0.8); lightSize = 52; }

        //Ceiling adjustment
        if (ceiling) {
            self.sprite = GetSpriteIndex("CRYC");
            bNOGRAVITY = true;
            let mypos = self.pos; Sector s;
            [mypos.z, s] = self.curSector.HighestCeilingAt((mypos.X, mypos.Y));            
            self.SetOrigin(mypos, false);
            lightOffset = (0, 0, -16);
        }
        
        Color colors[8] = {Color(100, 100, 100), Color(0, 100, 0), Color(100, 100, 0), Color(100, 50, 50), Color(100, 0, 0), Color(25, 25, 100), Color(100, 0, 75), Color(100, 25, 25)};
        
        //Attach a light
        self.A_AttachLight("GlowLight", DynamicLight.PointLight, colors[colour], lightSize, lightSize, DYNAMICLIGHT.LF_ATTENUATE, lightOffset);
        
        //Random sprite flip
        if (Random(0, 1) == 0) {
            bSPRITEFLIP = true;
        }
    }
}
