--tweakables for player bounties

-- ATI Parameter indices for bounty display
--
HCPI_PlayerName         = 0
HCPI_PlayerBounty       = 1
HCPI_PlayerColour       = 2
HCPN_Parameters         = 3

PrintfCharacters = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

function KATANA_MAP_SETUP()
	local bounds = {0,0,0}
	local bounds=Universe_GetWorldBounds()
	local radius = bounds[1] -500
	local idxer = 0
	Volume_AddSphere("TheUniverse", {0,0,0}, radius)
	while idxer < KFleet do
		NAV_points=idxer
		SobGroup_Create("BUOY"..NAV_points)
		Volume_AddSphere("NAV_"..NAV_points, {RandomRange(-1*radius,radius),RandomRange(-1*radius,radius),RandomRange(-1*radius,radius)}, 3000)
		SobGroup_SpawnNewShipInSobGroup(-1,"Katana_Dreadnaught","NewBuoy","BUOY"..NAV_points,"NAV_"..NAV_points)
		idxer=idxer+1
	end
	local idexer2 = 0

	Rule_Remove("KATANA_MAP_SETUP")
end  


function KatanaCheck()

  -- any Dreads captured ? => give Points
  local playerIndex = 0
  local playerCount = Universe_PlayerCount()
  local captured = 0
  local currentRU = 0
  SobGroup_Create("captured")
  SobGroup_Create("TmpGroup")
  while playerIndex < playerCount do
    if Player_IsAlive(playerIndex) == 1 then
     SobGroup_FillCompare("captured","Player_Ships"..playerIndex,"allbounty")
     captured = SobGroup_Count("captured")
     if captured>0 then
       currentPoints = Player_PTS[playerIndex] + captured
       SobGroup_FillSubstract("TmpGroup","allbounty","captured")
       SobGroup_Clear("allbounty")
       SobGroup_SobGroupAdd("allbounty","TmpGroup")
       SubGroup_Clear("TmpGroup")
      end
      SobGroup_Clear("captured")
    end
    playerIndex = playerIndex + 1
  end     
  SobGroup_SetSwitchOwnerFlag("allbounty",0)
  
end -- Dyn_KatanaCheck


function UpdateBountyStats()
       --display bounty stats for each player using ATI
    --display bounty stats for each player using ATI
    ATI_Clear()
    playerCount = Universe_PlayerCount();
    playerIndex = playerCount - 1
    local ATIRect = {0.01, 0.1725, 0.3, 0.02}                                   --rect to left just above taskbar
    while (playerIndex >= 0) do
        --setup parameters
		if (Player_IsAlive(playerIndex)==1) then
            ATI_CreateParameters(HCPN_Parameters)

            local playerName = Player_GetName(playerIndex)
            ATI_AddWString(HCPI_PlayerName, playerName)

            --...Do our own printf here
            local formatted = " "
            local number = Player_PTS[playerIndex + 1]
            if (number < 1) then
                formatted = " 0"
            else
                while (number >= 1) do
                    formatted = number
                end
            end
            local bountyString = "B: "..formatted
            ATI_AddString(HCPI_PlayerBounty, bountyString)

            local playerColour = {1.0, 1.0, 1.0, 1.0}
            ATI_AddColour(HCPI_PlayerColour, playerColour)
            --actual display
            ATI_Display2D("playerProgress", ATIRect, 0)

    		-- go to next player
            ATIRect[2] = ATIRect[2] + 0.025
        end
		playerIndex = playerIndex - 1
    end

end

