//Funny init
local pnk = "\x8E"
local wht = "\x80"

rawset(_G, "TR", TICRATE)

rawset(_G, "TAKIS_SKIN", "takisthefox")
rawset(_G, "TAKIS_MAX_HEARTCARDS", 6)
rawset(_G, "TAKIS_HEARTCARDS_SHAKETIME", 17)
rawset(_G, "TAKIS_MAX_COMBOTIME", 7*TR)
rawset(_G, "TAKIS_PART_COMBOTIME", 4*TR/5)
//just soap lol!
rawset(_G, "TAKIS_COMBO_RANKS", {
	"Lame...",
	"\x83Soapy",
	"\x88".."Alright...",
	"\x8B".."Going Places!",
	"\x82Nice!",
	"\x84".."Gamer!",
	"\x8D".."Destructive!",
	"\x87".."Demolition Expert!",
	"\x85Menacing!",
	"\x86WICKED!!",
	"\x85".."Adobe Flash!",
	"\x86Robo!",
	"\x88".."BLAST!!",
	"F"..pnk.."u"..wht.."n"..pnk.."n"..wht.."y"..pnk.."!",
	"\x86Unfunny.",
	"EAT EAT EAT!",
	"\x82Holy Moly!",
	"\x86Please, no more!",
	"\x84".."BALLER!",
	"\x82Super Cool!",
	"\x87".."Combo Fodder",
})
rawset(_G, "TAKIS_COMBO_UP", 5)
rawset(_G, "TAKIS_MAX_SUNSTROKE", 3)
rawset(_G, "TAKIS_MAX_ICETIME", 10*TR)
rawset(_G, "TAKIS_MAX_ICECOUNT", 60*TR)
rawset(_G, "TAKIS_MAX_UNFREEZE", 2*TR)
rawset(_G, "TAKIS_SHADE_BRIGHTNESS", 200)


rawset(_G, "TAKIS_NET", {
	inspecialstage = false,
	
	texasarea = false,
	donotsunstroke = false,
	
	icyarea = false,
	donotfreeze = false,
	
	livescount = 0,
	usesheartcards = true,
})

rawset(_G, "TakisInitTable", function(p)
	//why print?
	CONS_Printf(p,"\x86"+"Initializing Takis' table...")

	p.takistable = {
		//buttons
		jump = 0,
		use = 0,
		tossflag = 0,
		c1 = 0,
		c2 = 0,
		c3 = 0,
		
		//vars
		accspeed = 0,
		prevspeed = 0,
		clutchcombo = 0,
		clutchcombotime = 0,
		clutchtime = 0,
		clutchingtime = 0,
		afterimaging = 0,
		beingcrushed = false,
		slidetime = 0,
		YDcount = 0,
		jumptime = 0,
		wavedashcapable = false,
		dived = false,
		steppedthisframe = false,
		prevmomz = 0,
		dontlanddust = false,
		ticsforpain = 0,
		timesdeathpitted = 0,
		saveddmgt = 0,
		yeahwait = 0, 
		yeahed = false,
		altdisfx = 0,
		setmusic = false,
		crushtime = 0,
		timescrushed = 0,
		goingfast = false,
		wentfast = 0,
		sweat = 0,
		inshade = false,
		body = 0,
		stoprolling = false,
		inwaterslide = false,
		glowyeffects = 0,
		sethappyend = false,
		
		taunttime = 0,
		tauntid = 0,
		tauntspecial = false,
		
		hammerblastdown = 0,
		hammerblastwentdown = false,
		hammerblasthitbox = nil,
		hammerblastjumped = 0,
		
		gravflip = 1,
		
		lastgroundedpos = {},
		hurtfreeze = 0,
		
		heartcards = TAKIS_MAX_HEARTCARDS,
		heartcardpieces = 0,	//collect 7 rings to heal
		
		combo = {
			count = 0,
			time = 0,
			rank = 1,
			verylevel = 0,
			
			//anim stuff
			intro = 0,
			outro = 0,
			outrotics = 0,
			frozen = false,
		},
		io = {
			loaded = false,
			nostrafe = 0,
			nohappyhour = 0, //do stuff with this
		},
		aliments = {
			sunstroked = false,
			sunstrokecount = 0,
			
			iced = false,
			icecount = 0,
			timetoice = 0,
			iceremove = 0,
		},
		
		//bools
		onGround = false,
		inPain = false,
		isTakis = false,
		isSinglePlayer = false,
		inWater = false,
		inGoop = false,
		inFakePain = false,
		notCarried = false,
		
		//fake powers
		fakeflashing = 0,
		stasistic = 0,
		thokked = false,
		fakesprung = false,
		
		//hud
		//useful if this gets in yalls modmakers' ways
		HUD = {
			statusface = {
				priority = 0,
				state = "IDLE",
				frame = 0,
				evilgrintic = 0,
				happyfacetic = 0,
				painfacetic = 0,
			},
			heartcards = {
				shake = 0,
				add = 0,
			},
			rings = {
				FIXED = { 90*FU-(13*FU*6)+(7*FU), 62*FU-(6*FU) },
				int = {90-(13*6)+75+15+15, 49-6}
			},
			//timer has 2 different sets for spectator and when finished
			timer = {
				text = 90-(13*6)+7-5,
				int = {90-(13*6)+75+15 +15, (62-6)+4},		
				spectator = {90-(13*6)+75+15 +15,(62-6)+20+24},
				finished = {90-(13*6)+75+15 +15,(62-6)+20},
			},
			combo = {
				meter = {
					FIXED = {(hudinfo[HUD_RINGS].x+5-8)*FU,(hudinfo[HUD_RINGS].y+14)*FU},
					int = {(hudinfo[HUD_RINGS].x+18+8-22),(hudinfo[HUD_RINGS].y+30-2+3)},
					shake = 0,
				},
				num = {
					int = {hudinfo[HUD_RINGS].x+16+8+6,hudinfo[HUD_RINGS].y+18},
				},
				
			},
			funny = {
				y = 500*FU,
				alsofunny = false,
				tics = 0,
			},
			happyhour = {
				falldown = false,
				doingit = false,
				xadd = 0,
				its = {
					scale = FU/20,
					expectedtime = TR,
					x = 60*FU,
					yadd = 0, 
					patch = "TAHY_ITS",
					frame = 0,
				},
				happy = {
					scale = FU/20,
					expectedtime = 3*TR/2,
					x = 155*FU,
					yadd = 0, 
					patch = "TAHY_HAPY",
					frame = 0,
				},
				hour = {
					scale = FU/20,
					expectedtime = 2*TR,
					x = 260*FU,
					yadd = 0, 
					patch = "TAHY_HOUR",
					frame = 0,
				},
				face = {
					x = 155*FU,
					expectedtime = TR,
					yadd = 0,
					patch = "TAHY_FACE",
					frame = 0,
					
				}
			},
			
			
		},
		
	}

	//now we can tell if this actually worked or not
	CONS_Printf(p, "\n"+"\x84"+"Initialized Takis stuff!")

	return true
end)

//from chrispy chars!!! by Lach!!!!
local function SafeFreeslot(...)
	for _, item in ipairs({...})
		if rawget(_G, item) == nil
			freeslot(item)
		end
	end
end

freeslot("sfx_clutch")
sfxinfo[sfx_clutch].caption = "Clutch Boost"
freeslot("sfx_cltch2")
sfxinfo[sfx_cltch2].caption = "Clutch Boost"

freeslot("sfx_eeugh")
sfxinfo[sfx_eeugh].caption = '\x86"Ehh!"\x80'
freeslot("sfx_antow1")
sfxinfo[sfx_antow1].caption = '\x86"Aah!!"\x80'
freeslot("sfx_antow2")
sfxinfo[sfx_antow2].caption = '\x86"Eargh!"\x80'
freeslot("sfx_antow3")
sfxinfo[sfx_antow3].caption = '\x86"Grr!"\x80'
freeslot("sfx_antow4")
sfxinfo[sfx_antow4].caption = '\x86"Hey, hey!"\x80'
freeslot("sfx_antow5")
sfxinfo[sfx_antow5].caption = '\x86"Oh boy!"\x80'
freeslot("sfx_tayeah")
sfxinfo[sfx_tayeah].caption = '\x86"Yyyeahh!"\x80'
freeslot("sfx_hapyhr")
sfxinfo[sfx_hapyhr].caption = '\x86'.."IT'S HAPPY HOUR!!"..'\x80'

freeslot("sfx_takdiv")
sfxinfo[sfx_takdiv].caption = 'Dive'
freeslot("sfx_airham")
sfxinfo[sfx_airham].caption = 'Air swing'
freeslot("sfx_tawhip")
sfxinfo[sfx_tawhip].caption = '\x82Johnny Test!\x80'
freeslot("sfx_takhel")
sfxinfo[sfx_takhel].caption = '\x8EHealed!\x80'
freeslot("sfx_smack")
sfxinfo[sfx_smack].caption = "\x8DSmacked!\x80"
freeslot("sfx_takoww")
sfxinfo[sfx_takoww] = {
	flags = SF_X4AWAYSOUND,
	caption = "\x85".."EUROOOOWWWW!!!\x80"
}
freeslot("sfx_takdjm")
sfxinfo[sfx_takdjm].caption = "Double jump"
freeslot("sfx_takst1")
sfxinfo[sfx_takst1].caption = "Step"
freeslot("sfx_takst2")
sfxinfo[sfx_takst2].caption = "Step"
freeslot("sfx_takst3")
sfxinfo[sfx_takst3].caption = "Step"
freeslot("sfx_takst4")
sfxinfo[sfx_takst4].caption = "Land"
freeslot("sfx_tkapow")
sfxinfo[sfx_tkapow] = {
	flags = SF_X2AWAYSOUND,
	caption = "\x82KaPOW!!!\x80"
}
freeslot("sfx_tacrit")
sfxinfo[sfx_tacrit] = {
	flags = SF_X2AWAYSOUND,
	caption = "\x82".."Crit!".."\x80"
}
SafeFreeslot("sfx_slam")
sfxinfo[sfx_slam].caption = "\x8DSlam!!\x80"
SafeFreeslot("sfx_jumpsc")
sfxinfo[sfx_jumpsc].caption = "\x85".."AAAAAHHHHH!!!!\x80"
SafeFreeslot("sfx_mclang")
sfxinfo[sfx_mclang] = {
	caption = "\x8DMysterious clanging\x80",
	flags = SF_X2AWAYSOUND|SF_NOMULTIPLESOUND|SF_TOTALLYSINGLE,
}


--spr_ freeslot

SafeFreeslot("spr_wdrg")
SafeFreeslot("SPR_SWET")
SafeFreeslot("SPR_STB1")
SafeFreeslot("SPR_STB2")
SafeFreeslot("SPR_STB3")
SafeFreeslot("SPR_STB4")
SafeFreeslot("SPR_STB5")

--

--spr2 freeslot

SafeFreeslot("SPR2_TAKI")
SafeFreeslot("SPR2_TAK2")
SafeFreeslot("SPR2_TDED")
SafeFreeslot("SPR2_THUP")
spr2defaults[SPR2_THUP] = SPR2_STND
SafeFreeslot("SPR2_TDD2")
spr2defaults[SPR2_TDD2] = SPR2_TDED
SafeFreeslot("SPR2_SLID")
SafeFreeslot("SPR2_TICE")

--

--state freeslot

freeslot("S_PLAY_TAKIS_SMUGASSGRIN")
states[S_PLAY_TAKIS_SMUGASSGRIN] = {
    sprite = SPR_PLAY,
    frame = SPR2_TAKI,
    tics = -1,
    nextstate = S_PLAY_STND
}
freeslot("S_PLAY_TAKIS_SMUGASSGRIN2")
states[S_PLAY_TAKIS_SMUGASSGRIN2] = {
    sprite = SPR_PLAY,
    frame = SPR2_TAK2,
    tics = -1,
    nextstate = S_PLAY_STND
}
freeslot("S_TAKIS_SWEAT1")
freeslot("S_TAKIS_SWEAT2")
freeslot("S_TAKIS_SWEAT3")
freeslot("S_TAKIS_SWEAT4")
states[S_TAKIS_SWEAT1] = {
    //sprite = SPR_RING,
	sprite = SPR_SWET,
    frame = A|FF_ANIMATE,
	var1 = 6,
	var2 = 2,
	tics = 6*2,
    nextstate = S_TAKIS_SWEAT2
}
states[S_TAKIS_SWEAT2] = {
	sprite = SPR_SWET,
    frame = G|FF_ANIMATE,
	var1 = 2,
	var2 = 2,
	tics = 2*2,
    nextstate = S_TAKIS_SWEAT3
}
states[S_TAKIS_SWEAT3] = {
	sprite = SPR_SWET,
    frame = I|FF_ANIMATE,
	var1 = 6,
 	var2 = 2,
	tics = 6*2,
    nextstate = S_TAKIS_SWEAT4
}
states[S_TAKIS_SWEAT4] = {
	sprite = SPR_SWET,
    frame = O|FF_ANIMATE,
	var1 = 2,
	var2 = 2,
	tics = 2*2,
    nextstate = S_TAKIS_SWEAT1
}

//jeez
SafeFreeslot("S_SOAP_SUPERTAUNT_FLYINGBOLT1")
SafeFreeslot("S_SOAP_SUPERTAUNT_FLYINGBOLT2")
SafeFreeslot("S_SOAP_SUPERTAUNT_FLYINGBOLT3")
SafeFreeslot("S_SOAP_SUPERTAUNT_FLYINGBOLT4")
SafeFreeslot("S_SOAP_SUPERTAUNT_FLYINGBOLT5")

states[S_SOAP_SUPERTAUNT_FLYINGBOLT1] = {
	sprite = SPR_STB1,
	frame = FF_PAPERSPRITE|FF_ANIMATE,
	var1 = 4,
	var2 = 2,
	tics = 4*2
}
states[S_SOAP_SUPERTAUNT_FLYINGBOLT2] = {
	sprite = SPR_STB2,
	frame = FF_PAPERSPRITE|FF_ANIMATE,
	tics = 4*2,
	var1 = 4,
	var2 = 2
}
states[S_SOAP_SUPERTAUNT_FLYINGBOLT3] = {
	sprite = SPR_STB3,
	frame = FF_PAPERSPRITE|FF_ANIMATE,
	var1 = 4,
	var2 = 2,
	tics = 4*2
}
states[S_SOAP_SUPERTAUNT_FLYINGBOLT4] = {
	sprite = SPR_STB4,
	frame = FF_PAPERSPRITE|FF_ANIMATE,
	tics = 4*2,
	var1 = 4,
	var2 = 2
}
states[S_SOAP_SUPERTAUNT_FLYINGBOLT5] = {
	sprite = SPR_STB5,
	frame = FF_PAPERSPRITE|FF_ANIMATE,
	tics = 4*2,
	var1 = 4,
	var2 = 2
}

freeslot("S_PLAY_TAKIS_SLIDE")
states[S_PLAY_TAKIS_SLIDE] = {
    sprite = SPR_PLAY,
    frame = SPR2_SLID,
    tics = -1,
    nextstate = S_PLAY_STND
}

--

--mobj freeslot

freeslot("MT_TAKIS_AFTERIMAGE")

mobjinfo[MT_TAKIS_AFTERIMAGE] = {
	doomednum = -1,
	spawnstate = S_PLAY_WAIT,
	radius = 12*FRACUNIT,
	height = 10*FRACUNIT,
	flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY|MF_NOBLOCKMAP	
}

freeslot("MT_WINDRINGLOL")
freeslot("S_SOAPYWINDRINGLOL")

--Wallbounce ring effect object
mobjinfo[MT_WINDRINGLOL] = {
	doomednum = -1,
	spawnstate = S_SOAPYWINDRINGLOL,
	flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_SCENERY|MF_NOGRAVITY
}
states[S_SOAPYWINDRINGLOL] = {
	sprite = SPR_WDRG,
	frame = TR_TRANS10|FF_PAPERSPRITE|A
}

freeslot("MT_TAKIS_HAMMERHITBOX")
freeslot("S_TAKIS_HAMMERHITBOX")
mobjinfo[MT_TAKIS_HAMMERHITBOX] = {
	doomednum = -1,
	spawnstate = S_TAKIS_HAMMERHITBOX,
	height = 148*FRACUNIT,
	width = 200*FRACUNIT,
	flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY|MF_SOLID
}
states[S_TAKIS_HAMMERHITBOX] = {
	sprite = SPR_RING,
	frame = A
}

freeslot("MT_TAKIS_BADNIK_RAGDOLL")
mobjinfo[MT_TAKIS_BADNIK_RAGDOLL] = {
	doomednum = -1,
	spawnstate = S_PLAY_WAIT,
	deathstate = S_XPLD1,
	height = 5*FRACUNIT,
	width = 5*FRACUNIT,
}

freeslot("MT_TAKIS_SWEAT")
mobjinfo[MT_TAKIS_SWEAT] = {
	doomednum = -1,
	spawnstate = S_TAKIS_SWEAT1,
	height = 5*FU,
	width = 5*FRACUNIT,
	flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY

}

SafeFreeslot("MT_SOAP_SUPERTAUNT_FLYINGBOLT")
mobjinfo[MT_SOAP_SUPERTAUNT_FLYINGBOLT] = {
	doomednum = -1,
	spawnstate = S_SOAP_SUPERTAUNT_FLYINGBOLT1,
	flags = MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY
}

freeslot("MT_TAKIS_DEADBODY")
mobjinfo[MT_TAKIS_DEADBODY] = {
	doomednum = -1,
	spawnstate = S_NULL,
	//mt_playuer
	flags = MF_NOCLIP|MF_SLIDEME|MF_NOCLIPTHING|MF_NOGRAVITY,
	height = 5*FRACUNIT,
	width = 5*FRACUNIT,
}

addHook("NetVars",function(n)
	TAKIS_NET = n($)
end)

freeslot("SKINCOLOR_TAKIS_BARYELLOW")
skincolors[SKINCOLOR_TAKIS_BARYELLOW] = {
    name = "Alt Yellow",
//  ramp = {82,-82,83,-74,74,74,-76,75,-77,76,-78,77,78,78,79,237},
    ramp = {82, 72,83, 74,74,74, 75,75, 76,76, 77,77,78,78,79,237},
    invcolor = SKINCOLOR_CORNFLOWER,
    invshade = 35,
    chatcolor = V_YELLOWMAP,
    accessible = false
}


