-- AmmoWarning -  Provides configuarable warnings for running out of ammo and sends a reminder to the screen.  
-- Based on bcAmmoWarning written by Kugnar
-- 


-- These variables are saved

--INITIALWARNING
--TOWNWARNING
--WARNINGINCREMENT
--TOWNINCREMENTSTORAGE
--CRITICALWARNING


-- 	Slash commands
--	/AMMOINIT Sets the initial Value AW_INITIAL_WARNING_COUNT
--	/AMMOTOWN Sets the Town value AW_TOWN_WARNING_COUNT
--	/AMMOINC Sets the Warning Increment AW_WARNING_INCREMENT
--	/AMMONTOWNINC Sets the Increment for Zone Crossing (the Friendly reminder)
-- 	/AMMOCRIT Sets the Critical Warning AW_CRITICAL_WARNING_COUNT
--	/AMMO displays this command list
--
--	This Addon is now integrated with the Cosmo UI 

-- Revisions
--  14/2/2005	Cosmos menu functionality IMPLEMENTED by sarf
--	1/8/2005	Cosmos menu functionality added and is listed as Ammo Warning
-- 	1/27/2005	Added Thrown Weapon Support (man what a pain).
-- 	1/29/2005	Localization support added
-- 	1/29/2005	Changed Print and banner functions to use the Sea.IO function library
-- 	1/29/2005	Added some functionality to identify and display ranged weapons and ammo type on the /ammo help screen
--	1/30/2005	Separated SLash commands from COSMO's (was causing a problem)
--	1/30/2005	Cleaned up some functions and isolated the loading of variables from SavedVariables.LUA
--	1/30/2005	Added an /ammoauto function Auto determines the ammount of possible ammo for setting the warnings to appropriate values
--			this function uses the TotalThrown as its base, or an argument (/ammoauto /ammoauto 2000)


--Default values
AW_ENABLED = 1;


AW_INITIAL_WARNING_COUNT = 800;
AW_TOWN_WARNING_COUNT = 1500;
AW_WARNING_INCREMENT = 25;
AW_CRITICAL_WARNING_COUNT = 600;
AW_TOWN_WARNING_INCREMENT = 10;
INITIALWARNING=800;
TOWNWARNING=1500;
WARNINGINCREMENT=25;
TOWNINCREMENT=5;
TOWNINCREMENTSTORAGE=5;	
CRITICALWARNING=600;


--These store various player states

PLAYERNORMAL 	= 1;
PLAYERISALIVE 	= 1;
PLAYERUSESAMMO 	= 1;

DEBUG 		= 0;



function AW_OnLoad()



RED	 	= { r = 1.0, g=0.0, b=0.0 };
BLUE		= { r = 0.0, g=0.0, b=1.0 };
GREEN		= { r = 0.0, g=1.0, b=0.0 };
YELLOW	 	= { r = 1.0, g=1.0, b=0.0 };
WHITE		= { r = 1.0, g=1.0, b=1.0 };





	this:RegisterEvent("UNIT_INVENTORY_CHANGED");
	this:RegisterEvent("ZONE_CHANGED_INDOORS");  
	this:RegisterEvent("ZONE_CHANGED");
	this:RegisterEvent("MERCHANT_SHOW");
	this:RegisterEvent("PLAYER_CONTROL_GAINED");
	this:RegisterEvent("PLAYER_CONTROL_LOST");
	this:RegisterEvent("PLAYER_DEAD");
	this:RegisterEvent("PLAYER_UNGHOST"); 
	this:RegisterEvent("VARIABLES_LOADED"); 
	

	-- Let the user know the mod loaded.
	Sea.IO.printc(WHITE,AMMOWARNING_LOAD);
	Setup_SLASH();

	
	-- Register with the CosmosMaster	
	if ( Cosmos_RegisterConfiguration ) then

		--Cosmos Menu Section 
		Cosmos_RegisterConfiguration(

			"COS_AMMOWARNING",
			"SECTION",
			AMMOWARNING_MENU_BLOCK,
			AMMOWARNING_MENU_BLOCK_INFO
			);		
		
		Cosmos_RegisterConfiguration("COS_AMMOWARNING_HEADER1",
			"SEPARATOR",
			AMMOWARNING_HEADER1_SEPARATOR,
			AMMOWARNING_HEADER1_SEPARATOR_INFO
			);
		
		Cosmos_RegisterConfiguration( "COS_AMMOWARNING_AMMOTOGGLEAMMOUNT", 		--CVar 
			"BOTH",							--Type
 			AMMOWARNING_ENABLE_CHECKBOX,					--Simple String
	 		AMMOWARNING_ENABLE_CHECKBOX_INFO	,
 										--Description 
		 		Ammo_Init_Set,					--Callback
 				1,						--Default Checked/Unchecked
	 			math.floor(AW_INITIAL_WARNING_COUNT/50),						--Default Value
	 			0,						--Min value
 				80,						--Max value
	 			AMMOWARNING_LOW_SLIDER_TEXT,                    --Slider Text
	 			1,						--Slider Increment
 				1,						--Slider state text on/off
	 			"",						--Slider state text append
				50						--Slider State Multiplier
 				);
		
		Cosmos_RegisterConfiguration( "COS_AMMOWARNING_AMMOINCREMENT",		--CVar 
			"SLIDER",						--Type
 			AMMOWARNING_LOW_SLIDER_INCREMENT_SIMPLE_TEXT,		--Simple String
	 		AMMOWARNING_LOW_SLIDER_INCREMENT_SIMPLE_TEXT_INFO,	--Description 
		 		Ammo_Increment_Set,				--Callback
 				1,						--Default Checked/Unchecked
	 			WARNINGINCREMENT,						--Default Value
	 			0,						--Min value
 				200,						--Max value
	 			AMMOWARNING_LOW_SLIDER_INCREMENT_TEXT,		--Slider Text
	 			5,						--Slider Increment
 				1,       					--Slider state text on/off
	 			"",						--Slider state text append
				1						--Slider State Multiplier
 				);	
		
		Cosmos_RegisterConfiguration(
			"COS_AMMOWARNING_HEADER3",
			"SEPARATOR",
			AMMOWARNING_HEADER2_SEPARATOR,
			AMMOWARNING_HEADER2_SEPARATOR_INFO	
			);
	
		Cosmos_RegisterConfiguration( "COS_AMMOWARNING_CRITICALWARNING", 		--CVar 
			"SLIDER",							--Type
 			AMMOWARNING_ENABLE_CRIT_CHECKBOX,			--Simple String
	 		AMMOWARNING_ENABLE_CRIT_CHECKBOX_INFO,			--Description 
		 		Ammo_Critical_Set,				--Callback
 				1,						--Default Checked/Unchecked
	 			math.floor(AW_CRITICAL_WARNING_COUNT/50),				--Default Value
	 			0,						--Min value
 				80,						--Max value
	 			AMMOWARNING_CRIT_SLIDER_SIMPLE_TEXT,           	--Slider Text
	 			1,						--Slider Increment
 				1,				 		--Slider state text on/off
	 			"",						--Slider state text append
				50						--Slider State Multiplier
 				);
		
		Cosmos_RegisterConfiguration(
			"COS_AMMOWARNING_HEADER2",
			"SEPARATOR",
			AMMOWARNING_HEADER3_SEPARATOR,
			AMMOWARNING_HEADER3_SEPARATOR_INFO
			);

		 Cosmos_RegisterConfiguration( "COS_AMMOWARNING_AMMOTOWNAMOUNT", 		--CVar 
			"SLIDER",							--Type
 			AMMOWARNING_ENABLE_TOWN_CHECKBOX_TEXT,			--Simple String
	 		AMMOWARNING_ENABLE_TOWN_CHECKBOX_TEXT_INFO,		--Description 
		 		Ammo_Town_Set,					--Callback
 				1,  						--Default Checked/Unchecked
	 			math.floor(TOWNWARNING/50),						--Default Value
	 			0,						--Min value
 				80,						--Max value
	 			AMMOWARNING_TOWN_SLIDER_SIMPLE_TEXT,   		--Slider Text
	 			1,						--Slider Increment
 				1,						--Slider state text on/off
	 			"",						--Slider state text append
				50						--Slider State Multiplier
 				);

		Cosmos_RegisterConfiguration( "COS_AMMOWARNING_AMMOTOWNINCREMENT", 		--CVar 
			"SLIDER",						--Type
 			AMMOWARNING_TOWN_SLIDER_INCREMENT_SIMPLE_TEXT,		--Simple String
	 		AMMOWARNING_TOWN_SLIDER_INCREMENT_TEXT_INFO,		--Description 
		 		Ammo_TownIncrement_Set,				--Callback
 				1, 						--Default Checked/Unchecked
	 			AW_TOWN_WARNING_INCREMENT,					--Default Value
	 			1,						--Min value
 				200,						--Max value
	 			AMMOWARNING_TOWN_SLIDER_INCREMENT_TEXT,         --Slider Text
	 			1,						--Slider Increment
 				1, 						--Slider state text on/off
	 			"",						--Slider state text append
				1						--Slider State Multiplier
 				);

		
		Cosmos_RegisterConfiguration(
			"COS_AMMOWARNING_HEADER4",
			"SEPARATOR",

			AMMOWARNING_HEADER4_SEPARATOR,
			AMMOWARNING_HEADER4_SEPARATOR_INFO
			);

		Cosmos_RegisterConfiguration(
			"COS_AMMOWARNING_HELPBUTTON",
			"BUTTON",
			AMMOWARNING_HELP_TEXT,
			nil,
			Ammo_Help,
			0,
			0,
			0,
			0,
			AMMOWARNING_HELP_BUTTON_TEXT
			);

		end
	

end





--Handles when the player gets on a taxi, if on a taxi we wont display any warnings
function PlayerIsNormal()

	if (event == "PLAYER_CONTROL_LOST") then
		PLAYERNORMAL=0;
	end
	if (event == "PLAYER_CONTROL_GAINED") then
		PLAYERNORMAL=1;
	end

end

--Handles the players death, if the player dies, we wont display any warnings.  Death registers a bit funny (especially for Hunters using feign death)
--Basically what we do here is trigger it on PLAYER_DEAD and it stays until the PLAYER_UNGHOST event happens, the PLAYER_ALIVE event triggers when the 
--Player ports to the graveyard, even though the player is still a ghost.
function PlayerIsAlive()

	if (event == "PLAYER_DEAD") then
		PLAYERISALIVE=0;
		
	end
	if (event == "PLAYER_UNGHOST") then
		PLAYERISALIVE=1;
	end
	
		
end


-- this event handler handles the hunting warning(s)
function AW_OnEvent()
	if ( not AW_ENABLED ) or ( AW_ENABLED ~= 1 ) then
		return;
	end
	CheckForRanged();
	
		if (event == "UNIT_INVENTORY_CHANGED" and PLAYERNORMAL == 1 and PLAYERUSESAMMO == 1 and PLAYERISALIVE == 1) then
			if (this.lastAmmoCount == nil) then
				this.lastAmmoCount = CountRanged();
			end

			this.currentAmmoCount = CountRanged();

			if (this.lastAmmoCount ~= this.currentAmmoCount) then
				if (math.mod(AW_INITIAL_WARNING_COUNT+0 - this.currentAmmoCount, AW_WARNING_INCREMENT+0) == 0 and this.currentAmmoCount <= AW_CRITICAL_WARNING_COUNT+0) then
					SendWarning (RED,CRITICAL_MESSAGE,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");
				elseif (this.currentAmmoCount == AW_INITIAL_WARNING_COUNT+0) then
					SendWarning(YELLOW,NORMAL_MESSAGE,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");			
				elseif (math.mod(AW_INITIAL_WARNING_COUNT - this.currentAmmoCount, AW_WARNING_INCREMENT+0) == 0 and this.currentAmmoCount < AW_INITIAL_WARNING_COUNT+0) then
					SendWarning(YELLOW,NORMAL_MESSAGE,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");
				end
				this.lastAmmoCount = this.currentAmmoCount;
			end
		end
	

end

-- this event handler handles the zone changes and merchant warnings
function AW_OnEvent2()
	if (DEBUG == 1) then
		DebugFlags("EVENT2 -",event);
		DebugVars("Event2");
	end
	CheckForRanged();
	if (event == "ZONE_CHANGED_INDOORS" or event == "ZONE_CHANGED" or event == "MERCHANT_SHOW") and (PLAYERNORMAL == 1 and PLAYERUSESAMMO == 1 and PLAYERISALIVE == 1)then
	
		if (this.currentAmmoCount == nil) then
			this.currentAmmoCount = CountRanged();
		end
		
		
		if (TOWNINCREMENT == TOWNINCREMENTSTORAGE) then	
			if (event == "ZONE_CHANGED_INDOORS" or event == "ZONE_CHANGED" or event == "MERCHANT_SHOW") then

				if (this.currentAmmoCount >= 0 and this.currentAmmoCount <= AW_CRITICAL_WARNING_COUNT+0) then
					SendWarning (RED,CRITICAL_MESSAGE,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");
				elseif (this.currentAmmoCount <= AW_TOWN_WARNING_COUNT+0) then
					SendWarning (YELLOW,TOWN_REMINDER,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");
				elseif (this.currentAmmoCount > 0 and this.currentAmmoCount < AW_CRITICAL_WARNING_COUNT+0) then
					SendWarning (RED,CRITICAL_MESSAGE,this.currentAmmoCount);
					PlaySound("SHEATHINGWOODWEAPONSHEATHE");
				end
				this.lastAmmoCount = this.currentAmmoCount;
				
			end

		end
		TOWNINCREMENT = TOWNINCREMENT - 1;		
		if (TOWNINCREMENT == 0 or TOWNINCREMENT == nil) then
			TOWNINCREMENT = TOWNINCREMENTSTORAGE;
		
		end
		
	end
		
	
end


-- Checks to see if the character uses AMMO/Thrown Weapons (we assume that if he does they are in his ammoslot/ranged weapon slot)

function CheckForRanged()
	if ( DynamicData ) and ( DynamicData.item ) and ( DynamicData.item.getInventoryInfo ) then
		local itemInfo = DynamicData.item.getInventoryInfo(-1, 18);
		if ( itemInfo ) then
			if ( strlen(itemInfo.name) <= 0 ) then
				PLAYERUSESAMMO = 0;
				WHATKIND = "nil";
				return;
			elseif ( itemInfo.strings ) then
				for i = 2, 12 do
					if ( itemInfo.strings[i] ) and ( itemInfo.strings[i].left) then
						if ( itemInfo.strings[i].left == TEXT(AMMO_WARNING_ITEM_TYPE_WAND) ) then
							PLAYERUSESAMMO = 0;
							WHATKIND = "nil";
							return;
						end
					end
				end
			end
		end
	end

	WHATKIND = nil;

	-- Checks to see if the character has AMMO Equipped the warning will not show.
	this.PlayerHasRanged = GetInventoryItemCount("player", CharacterAmmoSlot:GetID());	

	if (this.PlayerHasRanged <= 1) then
		PLAYERUSESAMMO = 0;
		WHATKIND = "nil";
	else
		PLAYERUSESAMMO = 1;
		WHATKIND = "AMMO";
		
	end

	-- Checks to see if the character uses thrown weapons (we assume if he does he has them equipped in his Ranged slot)	
	if (PLAYERUSESAMMO == 0) then
		this.PlayerHasRanged = GetInventoryItemLink("player", CharacterRangedSlot:GetID());	
		if (this.PlayerHasRanged == nil) then
			WHATKIND = "nil";
		else
			PLAYERUSESAMMO = 1;
			WHATKIND = "THROWN";
	
		end

	end
	return WHATKIND;
end

-- Counts the number of ammo/thrown weapons the character has (assuming it is either equipped in ammo slot OR ranged slot) 
function CountRanged()
local numbags 	= 0;
keepcount	= 0;
this.PlayerHasRangedCount = 0;	

ItemInfo = 	{	classification;
			name;
			quality;
			count;
			minLevel;
			unique;
			soulbound;
			bindOnPickup;
			bindOnEquip;
			quest;
		};

	
	if not (PLAYERUSESAMMO == 0) and (WHATKIND == "AMMO") then
		this.PlayerHasRangedCount = GetInventoryItemCount("player", CharacterAmmoSlot:GetID());		
		for i=NUM_BAG_FRAMES,0,-1 do
			local bagName = GetBagName(i);
			if bagName and (string.find(bagName, "Quiver") or string.find(bagName, "Ammo Pouch")) then
				slots = GetContainerNumSlots(i);
				for s = slots,0,-1 do
					
					if (PlayerAmmoName == nil) then	
						PlayerAmmoName = Sea.wow.item.getInventoryItemName( i, s );
					elseif (PlayerAmmoName == "") then	
						PlayerAmmoName = Sea.wow.item.getInventoryItemName( i, s );
					end
				end

			end

		end
		PlayerIsUsing = GetInventoryItemLink("player", CharacterRangedSlot:GetID());		
	elseif not (PLAYERUSESAMMO == 0) and (WHATKIND == "THROWN") then
		--Count the Number in the Ranged Slot 
		this.PlayerHasRangedCount = GetInventoryItemCount("player", CharacterRangedSlot:GetID());
		PlayerIsUsing = GetInventoryItemLink("player", CharacterRangedSlot:GetID());
		PlayerAmmoName = PlayerIsUsing;
		-- check the bags for Thrown Weapons
		for i=NUM_BAG_FRAMES,0,-1 do
			local bagname = GetBagName(i);
			local bagslots =GetContainerNumSlots(i);
			if bagname == nil then
				--Sea.IO.printc(RED,"EMPTY BAG Slot"); 
			else
				emptycount = 0;	
				for item = bagslots,1,-1 do
					ItemInfo =  Sea.wow.item.classifyInventoryItem(i, item)
					numbags = numbags + 1;
					if ItemInfo.name and (string.find(ItemInfo.name, "Throw")) then
						keepcount = keepcount + ItemInfo.count;
						PLAYERUSESTHROWN = 1;
						--PlayerIsUsing = " Thrown";
					elseif  ItemInfo.name == "" then
						emptycount = emptycount + 1;
						containerid = i;
						temp = "empty";
					end
				end
			end

		
		end
	

	end

TotalThrown = keepcount + this.PlayerHasRangedCount;
return TotalThrown;

end




-- displays when the user types /ammo
function Ammo_Help()

	
	Sea.IO.printc (WHITE,HELP1);  
	Sea.IO.printc (GREEN,HELP2,AW_INITIAL_WARNING_COUNT,"/",AW_TOWN_WARNING_COUNT);
	Sea.IO.printc (GREEN,HELP3,AW_WARNING_INCREMENT,"/",TOWNINCREMENTSTORAGE);	
	Sea.IO.printc (GREEN,HELP4,AW_CRITICAL_WARNING_COUNT);	
	Sea.IO.printc (YELLOW,HELP5);
	Sea.IO.printc (YELLOW,HELP6);
	local playerName = UnitName("player");
	if (WHATKIND == "THROWN") then
		Sea.IO.printc(WHITE,playername,AMMOWARNING_DESC, PlayerIsUsing," - " , CountRanged(), AMMOWARNING_REMAIN);
	elseif (WHATKIND == "AMMO") then
		Sea.IO.printc(WHITE,playername,AMMOWARNING_DESC, PlayerIsUsing," - " ,CountRanged (), " " , PlayerAmmoName,AMMOWARNING_REMAIN);
	end
	
end

-- Handles the banner functions (replacing UIErrorsFrame:AddMessage)
function SendWarning (color,message,currentammo)
	Sea.IO.bannerc(color, message, currentammo );
end



-- set up the slash commands
function Setup_SLASH() 

	SlashCmdList["AMMO"] = Ammo_Help; 
	SLASH_AMMO1 = "/ammo"; 

	SlashCmdList["AMMOINIT"] = Ammo_Init_Set_Slash; 
	SLASH_AMMOINIT1 = "/ammoinit"; 

	SlashCmdList["AMMOTOWN"] = Ammo_Town_Set_Slash; 
	SLASH_AMMOTOWN1 = "/ammotown"; 

	SlashCmdList["AMMOINC"] = Ammo_Increment_Set_Slash; 
	SLASH_AMMOINC1 = "/ammoinc"; 

	SlashCmdList["AMMOCRIT"] = Ammo_Critical_Set_Slash; 
	SLASH_AMMOCRIT1 = "/ammocrit"; 

	SlashCmdList["AMMOTOWNINC"] = Ammo_TownIncrement_Set_Slash; 
	SLASH_AMMOTOWNINC1 = "/ammotowninc"; 

	SlashCmdList["AMMOAUTO"] = Ammo_Auto_Slash; 
	SLASH_AMMOAUTO1 = "/ammoauto"; 


end

--All of these functions handle either the menu or /slash commands
function Ammo_Init_Set_Slash(value)  
	AW_INITIAL_WARNING_COUNT 	= value;
	INITIALWARNING 			= value;
end

function Ammo_Increment_Set_Slash(value)
	AW_WARNING_INCREMENT 		= value;
	WARNINGINCREMENT 		= value;

end

function Ammo_Town_Set_Slash(value)
	AW_TOWN_WARNING_COUNT 	= value;
	TOWNWARNING 		= value;
end



function Ammo_TownIncrement_Set_Slash(value)
	TOWNINCREMENT 		= value;
	TOWNINCREMENTSTORAGE 	= value;

end


function Ammo_Critical_Set_Slash(value)
	AW_CRITICAL_WARNING_COUNT 	= value;
	CRITICALWARNING 		= value;
end

function Ammo_Auto_Slash(value)
	if (value == "" or value == nil) then
		Sea.IO.printc (WHITE,AMMOWARNING_AUTO_TEXT);
		INITIALWARNING 		= 	round(TotalThrown * .50); 	-- 50%
		TOWNWARNING 		=	round(TotalThrown * .65); 	-- 65%
		CRITICALWARNING		=	round(TotalThrown * .20);	-- 20%
		WARNINGINCREMENT 	=	25;
		TOWNINCREMENTSTORAGE	=	10;
	
	else
		Sea.IO.printc (WHITE,AMMOWARNING_AUTO_TEXT);
		INITIALWARNING 		= 	round(value * .50); 	-- 50%
		TOWNWARNING 		=	round(value * .65); 	-- 65%
		CRITICALWARNING		=	round(value * .20);	-- 20%
		WARNINGINCREMENT	=	25;
		TOWNINCREMENTSTORAGE	=	10;

	end		

	AW_INITIAL_WARNING_COUNT	=	INITIALWARNING;
	AW_TOWN_WARNING_COUNT		=	TOWNWARNING;
	AW_CRITICAL_WARNING_COUNT 	=	CRITICALWARNING;
	AW_WARNING_INCREMENT		=	WARNINGINCREMENT			
	TOWNINCREMENT			=	TOWNINCREMENTSTORAGE;
	Ammo_Help();	


end

function Read_Vars()
	if (event == "VARIABLES_LOADED") then 
	
		--the +0 below makes sure these values stay a Number and Not a string (this is an LUA convention)	
		AW_INITIAL_WARNING_COUNT = INITIALWARNING+0;  	
		AW_TOWN_WARNING_COUNT = TOWNWARNING+0; 	
		AW_TOWN_WARNING_INCREMEMNT = TOWNINCREMENT+0;	
		AW_WARNING_INCREMENT = WARNINGINCREMENT+0;	
		AW_CRITICAL_WARNING_COUNT = CRITICALWARNING+0;	
		TOWNINCREMEMNT = TOWNINCREMENTSTORAGE+0;
	end
		CountRanged();
		CheckForRanged();

end


function DebugVars(after)
	if (DEBUG==1) then
		Sea.IO.printc(WHITE,  "After Function or event : ",after);
		Sea.IO.printc(YELLOW, "Initial Values:   AW_INITIAL_WARNING_COUNT = " ,AW_INITIAL_WARNING_COUNT);
		Sea.IO.printc(YELLOW, "Initial Values:      AW_TOWN_WARNING_COUNT = ",AW_TOWN_WARNING_COUNT);
		Sea.IO.printc(YELLOW, "Initial Values:       AW_WARNING_INCREMENT = ",AW_WARNING_INCREMENT);
		Sea.IO.printc(YELLOW, "Initial Values:  AW_CRITICAL_WARNING_COUNT = ",AW_CRITICAL_WARNING_COUNT);
		Sea.IO.printc(YELLOW, "Initial Values:  AW_TOWN_WARNING_INCREMENT = ",AW_TOWN_WARNING_INCREMENT);
		Sea.IO.printc(YELLOW, "Initial Values:             INITIALWARNING = ",INITIALWARNING);
		Sea.IO.printc(YELLOW, "Initial Values:                TOWNWARNING = ",TOWNWARNING);
		Sea.IO.printc(YELLOW, "Initial Values:           WARNINGINCREMENT = ",WARNINGINCREMENT);
		Sea.IO.printc(YELLOW, "Initial Values:              TOWNINCREMENT = ",TOWNINCREMENT);
		Sea.IO.printc(YELLOW, "Initial Values:       TOWNINCREMENTSTORAGE = ",TOWNINCREMENTSTORAGE);	
		Sea.IO.printc(YELLOW, "Initial Values:            CRITICALWARNING = ",CRITICALWARNING);
		
	end
end

function DebugFlags(after)

	if (DEBUG==1) then
		Sea.IO.printc(YELLOW, after , event);
		Sea.IO.printc(YELLOW, "Player Flags:   PLAYERUSESAMMO   = " ,PLAYERUSESAMMO);
		Sea.IO.printc(YELLOW, "                PLAYERISALIVE    = " ,PLAYERISALIVE);
		Sea.IO.printc(YELLOW, "                PLAYERISANORMAL  = " ,PLAYERNORMAL);	
		Sea.IO.printc(YELLOW, "                		toggle  = " ,toggle);
	end
		
end

function Ammo_Init_Set(toggle, value)
	AW_ENABLED = toggle;
	Cosmos_UpdateValue("COS_AMMOWARNING_AMMOTOGGLEAMMOUNT", CSM_SLIDERVALUE, value);
	AW_INITIAL_WARNING_COUNT 	= value;
	INITIALWARNING 			= value;
end

function Ammo_Critical_Set(toggle, value)
	Cosmos_UpdateValue("COS_AMMOWARNING_CRITICALWARNING", CSM_SLIDERVALUE, value);
	AW_CRITICAL_WARNING_COUNT 	= value;
	CRITICALWARNING 		= value;
end

function Ammo_Increment_Set(toggle, value)
	Cosmos_UpdateValue("COS_AMMOWARNING_AMMOINCREMENT", CSM_SLIDERVALUE, value);
	AW_WARNING_INCREMENT 		= value;
	WARNINGINCREMENT 		= value;
end

function Ammo_Town_Set(toggle, value)
	Cosmos_UpdateValue("COS_AMMOWARNING_AMMOTOWNAMOUNT", CSM_SLIDERVALUE, value);
	AW_TOWN_WARNING_COUNT 	= value;
	TOWNWARNING 		= value;
end

function Ammo_TownIncrement_Set(toggle, value)
	Cosmos_UpdateValue("COS_AMMOWARNING_AMMOTOWNINCREMENT", CSM_SLIDERVALUE, value);
	TOWNINCREMENT 		= value;
	TOWNINCREMENTSTORAGE 	= value;
end