<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, May 07, 2010, 3:05 AM -->
<!-- MuClient version 4.51 -->

<!-- Plugin "RoD_GUI" generated by Plugin Wizard -->

<muclient>
<plugin
   name="RoD_GUI"
   author="KaVir"
   id="fd29b63111219dc368b76922"
   language="Lua"
   purpose="Custom layout for RoD"
   date_written="2010-05-07 03:05:07"
   requires="4.51"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Script  -->

<script>
<![CDATA[
--latest
local using_msdp = false
local background_window = "world_background_image"  -- miniwindow ID
local border_window = "border_image"  -- miniwindow ID
local titlebar_window = "titlebar_image"  -- miniwindow ID
local avatar_window = "avatar_image"  -- miniwindow ID
local bars_window = "bars_image"  -- miniwindow ID
local bars_border_window = "bars_border"  -- miniwindow ID
local minimap_window = "minimap_image"  -- miniwindow ID
local minimap_border_window = "minimap_border"  -- miniwindow ID
local score_window = "score_image"  -- miniwindow ID
local score_border_window = "score_border"  -- miniwindow ID
local health_window = "health_bar"  -- miniwindow ID
local mana_window = "mana_bar"  -- miniwindow ID
local movement_window = "movement_bar"  -- miniwindow ID
local exp_window = "exp_bar"  -- miniwindow ID
local msdp = {}
local colourGold = ColourNameToRGB("gold")
local colourSilver = ColourNameToRGB("silver")
local colourBlack = ColourNameToRGB("black")
local score_width = 257

-- create the layout here, on getting the prompt, or window resize
function create_layout ()

  left = 175
  top = 73
  right = GetInfo (281) - 320
  bottom = GetInfo (280) - 20  -- 32 pixels from bottom

  -- if its less than this, we lose the map
  min_width = 50 + GetInfo (213) * 81 -- offset + width for 81 characters
  if right < min_width then
    right = min_width
  end -- if

  -- avoid the plugin crashing if someone makes the window stupidly small
  if bottom < top then
    bottom = top
  end -- if

  ----------------------------------------------------------------------------
  -- Set the background, using the textured tile.
  ----------------------------------------------------------------------------

  SetBackgroundImage("RoD/layout/outer_background.bmp", 13)

  ----------------------------------------------------------------------------
  -- Set the main text area.
  ----------------------------------------------------------------------------

  -- tell the client where to draw the text
  TextRectangle(left+13,  
                top+13,   
                right-13,
                bottom-13,  
                1,  -- BorderOffset, 
                colourGold,    -- BorderColour, 
                1,  -- BorderWidth, 
                colourGold,  -- OutsideFillColour, 
                8) -- OutsideFillStyle (fine hatch)

  ----------------------------------------------------------------------------
  -- Create a black window over the text area, behind the text.
  ----------------------------------------------------------------------------

  -- make a miniwindow under the text
  if WindowCreate (border_window,   -- window ID
                left-5, 
                top-5,   
                right - left + 10, -- width
                bottom - top + 10, -- depth
                12,  -- center it (ignored anyway) 
                3,   -- draw underneath (1) + absolute location (2)
                0x000000) ~= eOK then
    -- problem creating the window.  Not sure why this happens, but it some 
    -- players have encountered a depth of -3, which causes the plugin to crash.
    return
  end -- if

  -- show the window
--  WindowShow (border_window, true)


  -- make a miniwindow under the text
  if WindowCreate (background_window,   -- window ID
                left-4, 
                top-4,   
                right - left + 8, -- width
                bottom - top + 8, -- depth
                12,  -- center it (ignored anyway) 
                3,   -- draw underneath (1) + absolute location (2)
                0x000000) ~= eOK then
    -- problem creating the window.  Not sure why this happens, but it some 
    -- players have encountered a depth of -3, which causes the plugin to crash.
    return
  end -- if

  -- load the paper background image
  if WindowLoadImage (background_window, "background_background", GetInfo (66) .. "RoD/layout/inner_background.png") == eOK then
    check (WindowDrawImage (background_window, "background_background", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/inner_background.png' is missing.")
  end -- if


  -- load the left border image
  if WindowLoadImage (background_window, "border_left", GetInfo (66) .. "RoD/layout/border_left.png") == eOK then
    check (WindowDrawImage (background_window, "border_left", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_left.png' is missing.")
  end -- if

  -- load the right border image
  if WindowLoadImage (background_window, "border_right", GetInfo (66) .. "RoD/layout/border_right.png") == eOK then
    check (WindowDrawImage (background_window, "border_right", right-left-6, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_right.png' is missing.")
  end -- if

  -- load the top border image
  if WindowLoadImage (background_window, "border_top", GetInfo (66) .. "RoD/layout/border_top.png") == eOK then
    check (WindowDrawImage (background_window, "border_top", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the bottom border image
  if WindowLoadImage (background_window, "border_bottom", GetInfo (66) .. "RoD/layout/border_bottom.png") == eOK then
    check (WindowDrawImage (background_window, "border_bottom", 0, bottom-top-6, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the top right corner image
  if WindowLoadImage (background_window, "corner_tr", GetInfo (66) .. "RoD/layout/corner_tr.png") == eOK then
    check (WindowDrawImage (background_window, "corner_tr", right-left-6, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_tr.png' is missing.")
  end -- if

  -- load the bottom right corner image
  if WindowLoadImage (background_window, "corner_br", GetInfo (66) .. "RoD/layout/corner_br.png") == eOK then
    check (WindowDrawImage (background_window, "corner_br", right-left-6, bottom-top-6, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_br.png' is missing.")
  end -- if

  -- show the window
  WindowShow (background_window, true)

  ----------------------------------------------------------------------------
  -- Create the RoD title at the top of the screen.
  ----------------------------------------------------------------------------

  title_x = (GetInfo (281) - 468) / 2

  -- make a miniwindow to the left of the text
  check (WindowCreate (titlebar_window,   -- window ID
                title_x,   -- left
                0,   -- top
                981, -- width
                187, -- depth
                12,  -- center it (ignored anyway) 
                7,          -- draw underneath (1) + absolute location (2) + transparent (4)
                0x000000))  -- background colour

  -- load the titlebar image
  check (WindowLoadImage (titlebar_window, "titlebar", GetInfo (66) .. "RoD/layout/RoD_title.png"))

  -- draw it
  check (WindowDrawImage (titlebar_window, "titlebar", 0, 0, 0, 0, 3))  -- draw it

  -- show the window
  WindowShow (titlebar_window, true)

  ----------------------------------------------------------------------------
  -- Create the bars window to the left of the text.
  ----------------------------------------------------------------------------

  -- make a miniwindow for the graphical border
  check (WindowCreate (bars_border_window,   -- window ID
                14,         -- left
                top-4,      -- top
                142,        -- width
                142,        -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- make a miniwindow for the map
  check (WindowCreate (bars_window,   -- window ID
                29,         -- left
                top+11,     -- top
                112,        -- width
                112,        -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- load the left border image
  if WindowLoadImage (bars_border_window, "border_left", GetInfo (66) .. "RoD/layout/border_left.png") == eOK then
    check (WindowDrawImage (bars_border_window, "border_left", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_left.png' is missing.")
  end -- if

  -- load the right border image
  if WindowLoadImage (bars_border_window, "border_right", GetInfo (66) .. "RoD/layout/border_right.png") == eOK then
    check (WindowDrawImage (bars_border_window, "border_right", 110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_right.png' is missing.")
  end -- if

  -- load the top border image
  if WindowLoadImage (bars_border_window, "border_top", GetInfo (66) .. "RoD/layout/border_top.png") == eOK then
    check (WindowDrawImage (bars_border_window, "border_top", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the bottom border image
  if WindowLoadImage (bars_border_window, "border_bottom", GetInfo (66) .. "RoD/layout/border_bottom.png") == eOK then
    check (WindowDrawImage (bars_border_window, "border_bottom", 0, 110+17, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the top right corner image
  if WindowLoadImage (bars_border_window, "corner_tr", GetInfo (66) .. "RoD/layout/corner_tr.png") == eOK then
    check (WindowDrawImage (bars_border_window, "corner_tr", 110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_tr.png' is missing.")
  end -- if

  -- load the bottom right corner image
  if WindowLoadImage (bars_border_window, "corner_br", GetInfo (66) .. "RoD/layout/corner_br.png") == eOK then
    check (WindowDrawImage (bars_border_window, "corner_br", 110+17, 110+17, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_br.png' is missing.")
  end -- if

  -- load the paper background image
  if WindowLoadImage (bars_window, "bars_background", GetInfo (66) .. "RoD/layout/inner_background.png") == eOK then
    check (WindowDrawImage (bars_window, "bars_background", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/inner_background.png' is missing.")
  end -- if

  -- show the window and its border
  WindowShow (bars_border_window, true)
  WindowShow (bars_window, true)

  ----------------------------------------------------------------------------
  -- Create the minimap window to the left of the text.
  ----------------------------------------------------------------------------

  -- make a miniwindow for the graphical border
  check (WindowCreate (minimap_border_window,   -- window ID
                14,         -- left
                top+153,    -- top
                142,        -- width
                142,        -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- make a miniwindow for the map
  check (WindowCreate (minimap_window,   -- window ID
                29,         -- left
                top+168,    -- top
                112,        -- width
                112,        -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- load the left border image
  if WindowLoadImage (minimap_border_window, "border_left", GetInfo (66) .. "RoD/layout/border_left.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "border_left", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_left.png' is missing.")
  end -- if

  -- load the right border image
  if WindowLoadImage (minimap_border_window, "border_right", GetInfo (66) .. "RoD/layout/border_right.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "border_right", 110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_right.png' is missing.")
  end -- if

  -- load the top border image
  if WindowLoadImage (minimap_border_window, "border_top", GetInfo (66) .. "RoD/layout/border_top.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "border_top", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the bottom border image
  if WindowLoadImage (minimap_border_window, "border_bottom", GetInfo (66) .. "RoD/layout/border_bottom.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "border_bottom", 0, 110+17, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the top right corner image
  if WindowLoadImage (minimap_border_window, "corner_tr", GetInfo (66) .. "RoD/layout/corner_tr.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "corner_tr", 110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_tr.png' is missing.")
  end -- if

  -- load the bottom right corner image
  if WindowLoadImage (minimap_border_window, "corner_br", GetInfo (66) .. "RoD/layout/corner_br.png") == eOK then
    check (WindowDrawImage (minimap_border_window, "corner_br", 110+17, 110+17, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_br.png' is missing.")
  end -- if

  -- load the paper background image
  if WindowLoadImage (minimap_window, "minimap_background", GetInfo (66) .. "RoD/layout/inner_background.png") == eOK then
    check (WindowDrawImage (minimap_window, "minimap_background", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/inner_background.png' is missing.")
  end -- if

  -- show the window and its border
  WindowShow (minimap_border_window, true)
  WindowShow (minimap_window, true)

  -- load the terrain images
  check (WindowLoadImage (minimap_window, "terrain_city", GetInfo (66) .. "RoD/maps/terrain_city.bmp"))
  check (WindowLoadImage (minimap_window, "terrain_dark", GetInfo (66) .. "RoD/maps/terrain_dark.bmp"))

  -- draw the map
  draw_minimap ()

  ----------------------------------------------------------------------------
  -- Create the score window to the right of the text.
  ----------------------------------------------------------------------------

  -- make a miniwindow for the graphical border
  check (WindowCreate (score_border_window,   -- window ID
                right+19,   -- left
                top-4,      -- top
                287,        -- width
                bottom - top + 8, -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- make a miniwindow for the inner area
  check (WindowCreate (score_window,   -- window ID
                right+34,   -- left
                top+11,     -- top
                score_width,-- width
                bottom - top - 22, -- depth
                12,         -- center it (ignored anyway) 
                2,          -- draw underneath (1) + absolute location (2)
                0x000000))  -- background colour

  -- load the left border image
  if WindowLoadImage (score_border_window, "border_left", GetInfo (66) .. "RoD/layout/border_left.png") == eOK then
    check (WindowDrawImage (score_border_window, "border_left", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_left.png' is missing.")
  end -- if

  -- load the right border image
  if WindowLoadImage (score_border_window, "border_right", GetInfo (66) .. "RoD/layout/border_right.png") == eOK then
    check (WindowDrawImage (score_border_window, "border_right", 145+110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_right.png' is missing.")
  end -- if

  -- load the top border image
  if WindowLoadImage (score_border_window, "border_top", GetInfo (66) .. "RoD/layout/border_top.png") == eOK then
    check (WindowDrawImage (score_border_window, "border_top", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the bottom border image
  if WindowLoadImage (score_border_window, "border_bottom", GetInfo (66) .. "RoD/layout/border_bottom.png") == eOK then
    check (WindowDrawImage (score_border_window, "border_bottom", 0, bottom - top - 7, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/border_top.png' is missing.")
  end -- if

  -- load the top right corner image
  if WindowLoadImage (score_border_window, "corner_tr", GetInfo (66) .. "RoD/layout/corner_tr.png") == eOK then
    check (WindowDrawImage (score_border_window, "corner_tr", 145+110+17, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_tr.png' is missing.")
  end -- if

  -- load the bottom right corner image
  if WindowLoadImage (score_border_window, "corner_br", GetInfo (66) .. "RoD/layout/corner_br.png") == eOK then
    check (WindowDrawImage (score_border_window, "corner_br", 145+110+17, bottom - top - 7, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/corner_br.png' is missing.")
  end -- if

  -- load the paper background image
  if WindowLoadImage (score_window, "score_background", GetInfo (66) .. "RoD/layout/inner_background.png") == eOK then
    check (WindowDrawImage (score_window, "score_background", 0, 0, 0, 0, 1))  -- draw it
  else -- the file is missing
    Note( "File '" .. GetInfo (66) .. "RoD/layout/inner_background.png' is missing.")
  end -- if

  -- load the avatar image
  if WindowLoadImage (score_window, "avatar", GetInfo (66) .. "RoD/avatars/Default.png") ~= eOK then
    Note( "File '" .. GetInfo (66) .. "RoD/avatars/Default.png' is missing.")
  end -- if

  -- fill in the window
  draw_score ()

  -- draw the spell affect icons
  draw_affects ()

  -- show the window and its border
  WindowShow (score_border_window, true)
  WindowShow (score_window, true)

  ----------------------------------------------------------------------------
  -- Create the health, mana and movement bars at the bottom.
  ----------------------------------------------------------------------------

  -- make a miniwindow under the text
  check (WindowCreate (health_window,   -- window ID
                35,            -- left
                91,            -- top
                100,           -- width
                20,            -- depth
                12,            -- center it (ignored anyway) 
                2,             -- draw underneath (1) + absolute location (2)
                colourBlack))  -- background colour

  -- show the window
  WindowShow (health_window, true)

  -- make a miniwindow under the text
  check (WindowCreate (mana_window,   -- window ID
                35,            -- left
                117,           -- top
                100,           -- width
                20,            -- depth
                12,            -- center it (ignored anyway) 
                2,             -- draw underneath (1) + absolute location (2)
                colourBlack))  -- background colour

  -- show the window
  WindowShow (mana_window, true)

  -- make a miniwindow under the text
  check (WindowCreate (movement_window,   -- window ID
                35,            -- left
                143,           -- top
                100,           -- width
                20,            -- depth
                12,            -- center it (ignored anyway) 
                2,             -- draw underneath (1) + absolute location (2)
                colourBlack))  -- background colour

  -- show the window
  WindowShow (movement_window, true)

  -- make a miniwindow under the text
  check (WindowCreate (exp_window,   -- window ID
                35,            -- left
                169,           -- top
                100,           -- width
                20,            -- depth
                12,            -- center it (ignored anyway) 
                2,             -- draw underneath (1) + absolute location (2)
                colourBlack))  -- background colour

  -- show the window
  WindowShow (exp_window, true)

  -- draw the energy bars
  draw_energy_bars ()

end -- create_layout


function OnPluginWorldOutputResized ()
  create_layout ()
end -- function


local RoomExit = {}
local RoomType = {}
local ExitCount = 0

function init_rooms (data)

  ExitCount = 0

  index = 0
  startpos = 1
  max = 0
  for i=1,string.len(data),1 do
    if string.byte(data,i) == 7 or i == string.len(data) then
      if string.byte(data,i) == 7 then
        endpos = 1
      else
        endpos = 0
      end -- if
      variable = string.sub(data,startpos,i-endpos)
      startpos = i+1
      index = index + 1

      pos1 = string.find(variable, ",")
      if pos1 ~= nil then
        RoomExit[index] = string.sub(variable, 1, pos1-1)
        RoomType[index] = string.sub(variable, pos1+1)
        ExitCount = ExitCount + 1
      end -- if
    end -- if
  end -- for

end -- function


-- draw one room
function draw_room (x, y, type)

  terrain_image = "terrain_dark"
  if type == "O" then
    terrain_image = "terrain_city"
  end -- if

  WindowCircleOp (minimap_window, 2, x-1, y-1, x+22, y+22, colourGold, 0, 2, 0, 1)
  WindowCircleOp (minimap_window, 2, x-1, y-1, x+21, y+21, colourBlack, 0, 1, 0, 1)
  WindowDrawImage (minimap_window, terrain_image, x, y, x+20, y+20, 1)  -- draw the terrain

end -- draw_room


-- draw the minimap
function draw_minimap ()

  data = msdp["ROOM_EXITS"]

  if data ~= nil then
    init_rooms (data)
  end -- if

  mapCentre = 45

  -- clean the background and redraw the central room
  check (WindowDrawImage (minimap_window, "minimap_background", 0, 0, 0, 0, 1))  -- draw it
  draw_room (mapCentre, mapCentre, "O")

  -- draw any surrounding rooms
  if ExitCount > 0 then
    for i=1,ExitCount,1 do
      if RoomExit[i] == "north" then
        draw_room(mapCentre, mapCentre-30, RoomType[i])
        WindowLine(minimap_window, mapCentre+9, mapCentre-2, mapCentre+9, mapCentre-10, colourGold, 0, 1)
        WindowLine(minimap_window, mapCentre+10, mapCentre-2, mapCentre+10, mapCentre-10, colourGold, 0, 1)
      elseif RoomExit[i] == "south" then
        draw_room(mapCentre, mapCentre+30, RoomType[i])
        WindowLine(minimap_window, mapCentre+9, mapCentre+28, mapCentre+9, mapCentre+20, colourGold, 0, 1)
        WindowLine(minimap_window, mapCentre+10, mapCentre+28, mapCentre+10, mapCentre+20, colourGold, 0, 1)
      elseif RoomExit[i] == "east" then
        draw_room(mapCentre+30, mapCentre, RoomType[i])
        WindowLine(minimap_window, mapCentre+22, mapCentre+9, mapCentre+28, mapCentre+9, colourGold, 0, 1)
        WindowLine(minimap_window, mapCentre+22, mapCentre+10, mapCentre+28, mapCentre+10, colourGold, 0, 1)
      elseif RoomExit[i] == "west" then
        draw_room(mapCentre-30, mapCentre, RoomType[i])
        WindowLine(minimap_window, mapCentre-3, mapCentre+9, mapCentre-10, mapCentre+9, colourGold, 0, 1)
        WindowLine(minimap_window, mapCentre-3, mapCentre+10, mapCentre-10, mapCentre+10, colourGold, 0, 1)
      end -- if
    end -- for
  end -- if

end -- draw_minimap


-- fill the three energy bars
function draw_energy_bars ()

  -- HEALTH
  current_health = msdp["HEALTH"]
  max_health = msdp["HEALTH_MAX"]

  -- initialise with empty bars
  if current_health == nil then
    current_health = 0
    max_health = 0
  end -- if

  if current_health ~= nil and max_health ~= nil then
    type = "Health"
    colour = 0x00CCCC
    colour2 = 0x003333
    draw_energy_bar(type, colour, colour2, health_window, current_health, max_health)
  end -- if

  class = msdp["CLASS"]
  if class == "Vampire" then

    -- BLOOD
    current_blood = msdp["MANA"]
    max_blood = msdp["LEVEL"]

    -- initialise with empty bars
    if current_blood == nil then
      current_blood = 0
      max_blood = 0
    end -- if

    if current_blood ~= nil and max_blood ~= nil then
      type = "Blood"
      colour = 0x0000CC
      colour2 = 0x000033
      draw_energy_bar(type, colour, colour2, mana_window, current_blood, max_blood+10)
    end -- if

  else -- they're not a vampire

    -- MANA
    current_mana = msdp["MANA"]
    max_mana = msdp["MANA_MAX"]

    -- initialise with empty bars
    if current_mana == nil then
      current_mana = 0
      max_mana = 0
    end -- if

    if current_mana ~= nil and max_mana ~= nil then
      type = "Mana"
      colour = 0xCCCC00
      colour2 = 0x333300
      draw_energy_bar(type, colour, colour2, mana_window, current_mana, max_mana)
    end -- if

  end -- if


  -- MOVEMENT
  current_movement = msdp["MOVEMENT"]
  max_movement = msdp["MOVEMENT_MAX"]

  -- initialise with empty bars
  if current_movement == nil then
    current_movement = 0
    max_movement = 0
  end -- if

  if current_movement ~= nil and max_movement ~= nil then
    type = "Move"
    colour = 0x00CC00
    colour2 = 0x003300
    draw_energy_bar(type, colour, colour2, movement_window, current_movement, max_movement)
  end -- if

  -- EXP
  current_exp = msdp["EXPERIENCE_TNL"]
  max_exp = 100

  -- initialise with empty bars
  if current_exp == nil then
    current_exp = 0
    max_exp = 0
  end -- if

  if current_exp ~= nil and max_exp ~= nil then
    type = "Exp TL"
    colour = 0xCC00CC
    colour2 = 0x330033
    draw_energy_bar(type, colour, colour2, exp_window, current_exp, max_exp)
  end -- if

end -- draw_energy_bars


-- fill the bar
function draw_energy_bar (type, colour, colour2, window, current_value, max_value)

  -- convert the strings to numbers
  current = tonumber(current_value)
  max = tonumber(max_value)

  -- Calculate health
  if current < 0 then
    current = 0
  elseif current > max then
    current = max
  end -- if

  -- clear the bars
  WindowGradient (window, 0, -1, 100, 10, colourBlack, colour2, 2)
  WindowGradient (window, 0, 10, 100, 21, colour2, colourBlack, 2)

  -- calculate the filled part
  if max > 0 then
    filled = current * 100 / max
  else -- avoid division by zero
    filled = 0
  end -- if

  -- redraw the bars
  if current > 0 then
    WindowGradient (window, 0, -1, filled, 10, colourBlack, colour, 2)
    WindowGradient (window, 0, 10, filled, 21, colour, colourBlack, 2)
  end -- if

  -- write the information inside
  outlined_text (colourGold, window, type, 9, 3, 3, 0)
  outlined_text (colourGold, window, math.ceil(filled)..'%', 9, 55, 3, 0)

end -- draw_energy_bar


-- fill the score
function draw_score ()

  if msdp["CHARACTER_NAME"] == nil or msdp["LEVEL"] == nil or 
    msdp["RACE"] == nil or msdp["CLASS"] == nil then
    return
  end -- if

  -- clear the background
  check (WindowDrawImage (score_window, "score_background", 0, 0, 0, 0, 1))  -- redraw the background

  -- draw the avatar
  check (WindowDrawImage (score_window, "avatar", 70, 50, 187, 147, 3))  -- draw it

  x_offset = score_width/2
  y_offset = 6
  text_length = outlined_text (colourGold, score_window, msdp["CHARACTER_NAME"], 12, 5, y_offset, score_width)

  y_offset = y_offset + 22
  text_line = 'Level '..msdp["LEVEL"]..' '..msdp["RACE"]..' '..msdp["CLASS"]
  outlined_text (colourGold, score_window, text_line, 10, 5, y_offset, score_width)

  y_offset = y_offset + 145
  outlined_text (colourGold, score_window, "Str:", 9, 5, y_offset, 0)
  if msdp["STR"] ~= nil and msdp["STR_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["STR"]..' ('..msdp["STR_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Hitroll:", 9, x_offset, y_offset, 0)
  if msdp["HITROLL"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["HITROLL"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Int:", 9, 5, y_offset, 0)
  if msdp["INT"] ~= nil and msdp["INT_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["INT"]..' ('..msdp["INT_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Damroll:", 9, x_offset, y_offset, 0)
  if msdp["DAMROLL"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["DAMROLL"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Wis:", 9, 5, y_offset, 0)
  if msdp["WIS"] ~= nil and msdp["WIS_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["WIS"]..' ('..msdp["WIS_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Armour:", 9, x_offset, y_offset, 0)
  if msdp["AC"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["AC"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Dex:", 9, 5, y_offset, 0)
  if msdp["DEX"] ~= nil and msdp["DEX_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["DEX"]..' ('..msdp["DEX_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Align: ", 9, x_offset, y_offset, 0)
  if msdp["ALIGNMENT"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["ALIGNMENT"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Con:", 9, 5, y_offset, 0)
  if msdp["CON"] ~= nil and msdp["CON_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["CON"]..' ('..msdp["CON_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Wimpy: ", 9, x_offset, y_offset, 0)
  if msdp["WIMPY"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["WIMPY"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Cha:", 9, 5, y_offset, 0)
  if msdp["CHA"] ~= nil and msdp["CHA_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["CHA"]..' ('..msdp["CHA_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Practice: ", 9, x_offset, y_offset, 0)
  if msdp["PRACTICE"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["PRACTICE"], 9, 65+x_offset, y_offset, 0)
  end -- if

  y_offset = y_offset + 20
  outlined_text (colourGold, score_window, "Lck:", 9, 5, y_offset, 0)
  if msdp["LCK"] ~= nil and msdp["LCK_PERM"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["LCK"]..' ('..msdp["LCK_PERM"]..')', 9, 45, y_offset, 0)
  end -- if

  outlined_text (colourGold, score_window, "Gold: ", 9, x_offset, y_offset, 0)
  if msdp["MONEY"] ~= nil then
    outlined_text (colourSilver, score_window, msdp["MONEY"], 9, 65+x_offset, y_offset, 0)
  end -- if

end -- draw_score


local AffectName = {}
local AffectDuration = {}
local AffectMax = 0

function init_affects (data)

  index = 0
  startpos = 1
  max = 0
  for i=1,string.len(data),1 do
    if string.byte(data,i) == 7 or i == string.len(data) then
      if string.byte(data,i) == 7 then
        endpos = 1
      else
        endpos = 0
      end -- if
      variable = string.sub(data,startpos,i-endpos)
      startpos = i+1
      index = index + 1

      pos1 = string.find(variable, ",")
      if pos1 ~= nil then
        AffectName[index] = string.sub(variable, 1, pos1-1)
        AffectDuration[index] = string.sub(variable, pos1+1)
      end -- if
    end -- if
  end -- for

  -- AffectMax is the highest EVER number - we need to keep track of all created icons
  if index < AffectMax then
    for i=index+1,AffectMax,1 do
      AffectName[i] = nil
      win = "affect_window_"..i
      WindowShow (win, false)
    end -- for
    AffectMax = index
  elseif index > AffectMax then
    AffectMax = index
  end -- if

end -- function


function draw_affects ()

  affects = msdp["AFFECTS"]
  if affects == nil or affects == "None" then
    for i=1,AffectMax,1 do
      WindowShow ("affect_window_"..i, false)
    end -- for
    AffectMax = 0
    return
  end -- if

  init_affects (affects)

  offset_x = 0
  offset_y = 0

  for i=1,AffectMax,1 do
    if AffectName[i] ~= nil then
      win = "affect_window_"..i
      affect = "affect_"..i

      -- draw the icons left to right, top to bottom
      if i > 1 then
        if offset_x == 0 then
          offset_x = 36
        elseif offset_x == 36 then
          offset_x = 72
        elseif offset_x == 72 then
          offset_x = 108
        else
          offset_x = 0
          offset_y = offset_y + 36
        end -- if
      end -- if

      colour = colourGold

      -- make a miniwindow under the text
      check (WindowCreate (win,   -- window ID
                    14+offset_x,  -- left
                    383+offset_y, -- top
                    34,           -- width
                    34,           -- depth
                    12,           -- center it (ignored anyway) 
                    2,            -- draw underneath (1) + absolute location (2)
                    colourBlack))      -- background colour

      -- load the icon
      if WindowLoadImage (win, affect, GetInfo (66) .. "RoD/affects/" .. AffectName[i] .. ".png") == eOK then
        check (WindowDrawImage (win, affect, 1, 1, 33, 33, 2))  -- draw the icon
      elseif WindowLoadImage (win, affect, GetInfo (66) .. "RoD/affects/default.png") == eOK then
        check (WindowDrawImage (win, affect, 1, 1, 33, 33, 2))  -- draw the default icon instead
      else -- even the default spell icon is missing
        Note( "Missing spell icons.")
        return
      end -- if

      if tonumber(AffectDuration[i]) < 10 then
        offset = 9
      elseif tonumber(AffectDuration[i]) < 100 then
        offset = 5
      else -- two digits
        offset = 1
      end -- if

      if tonumber(AffectDuration[i]) < 0 then
        -- draw an infinity symbol
        outlined_text (colour, win, "O", 6, 4, 21, 0)
        outlined_text (colour, win, "O", 6, 9, 21, 0)
        -- go over the first 'O' again, removing the outline from the second 'O'
        WindowFont(win,'f','Times New Roman',6,1,0,0,0)
        WindowText(win,'f',"O",4,21,0,0,colour,0)
      else -- write the duration
        outlined_text (colour, win, AffectDuration[i], 6, 4, 21, 0)
      end -- if

      -- show the window
      WindowShow (win, true)

      -- create a hotspot over the timer
      WindowAddHotspot(win, "hs_affect_"..i, 0, 0, 34, 34, "", "", "", "", "", AffectName[i], 1, 0)
    end -- if
  end -- for

end -- draw_affects


function outlined_text (colour, window, text, size, x, y, centre_width)

  outlineColour = colourBlack

  -- write the information inside
  WindowFont(window,'f','Verdana',size,1,0,0,0)

  if centre_width > 0 then
    width = WindowTextWidth (window, 'f', text)
    x = x + ((centre_width-width) / 2)
  end -- if

  -- smear black text around the location to create an outline, so that it's clearer to read
  WindowText(window,'f',text,x+1,y+1,0,0,outlineColour,0)
  WindowText(window,'f',text,x+1,y,0,0,outlineColour,0)
  WindowText(window,'f',text,x+1,y-1,0,0,outlineColour,0)
  WindowText(window,'f',text,x,y+1,y,0,outlineColour,0)
  WindowText(window,'f',text,x,y-1,y,0,outlineColour,0)
  WindowText(window,'f',text,x-1,y+1,0,0,outlineColour,0)
  WindowText(window,'f',text,x-1,y,0,0,outlineColour,0)
  WindowText(window,'f',text,x-1,y-1,0,0,outlineColour,0)

  -- display the text
  WindowText(window,'f',text,x,y,0,0,colour,0)

  return width
end -- outlined_text


-- MSDP negotiation
local MSDP = 69

function OnPluginTelnetRequest (type, data)
  if type == MSDP and data == "WILL" then
    using_msdp = true
    return true
  elseif type == MSDP and data == "SENT_DO" then
    -- IAC SB MSDP response IAC SE 
    SendPkt ("\255\250\69\1REPORT\2CHARACTER_NAME\2RACE\2CLASS\2HEALTH_MAX\2HEALTH\2MANA_MAX\2MANA\2MOVEMENT_MAX\2MOVEMENT\2EXPERIENCE_TNL\2BLOOD\2LEVEL\2HITROLL\2DAMROLL\2AC\2STR\2INT\2WIS\2DEX\2CON\2CHA\2LCK\2STR_PERM\2INT_PERM\2WIS_PERM\2DEX_PERM\2CON_PERM\2CHA_PERM\2LCK_PERM\2ALIGNMENT\2AFFECTS\2WIMPY\2PRACTICE\2MONEY\2ROOM_EXITS\2\255\240")
    return true
  else -- another protocol
    return false
  end -- if
end -- function OnPluginTelnetRequest

function OnPluginTelnetSubnegotiation (type, data)
  if type == MSDP then
    endpos=string.len(data)
    for i=endpos,1,-1 do
      if string.byte(data,i) == 1 then
        variable = string.sub(data,i+1,endpos)
        StoreVariable(variable, value)
        endpos = i-1
      elseif string.byte(data,i) == 2 then
        value = string.sub(data,i+1,endpos)
        endpos = i-1
      end -- if
    end -- for

    --  redraw the map
    draw_minimap ()

    -- redraw the energy bars
    draw_energy_bars ()

    -- redraw the score sheet
    draw_score ()

    -- redraw the spell affect icons
    draw_affects ()

    Redraw()

  end -- if
end -- function OnPluginTelnetSubnegotiation

function StoreVariable (MSDP_var, MSDP_val)
--Note('Variable: '..MSDP_var..' = '..MSDP_val)
  if MSDP_var == "SERVER_ID" then
    create_layout ()
    SendPkt ("\255\250\69\1PLUGIN_ID\2RoD MUSHclient plugin (version 1.0)\255\240")
  else -- store the variable
    msdp[MSDP_var] = MSDP_val
  end -- if
end -- function StoreVariable

]]>
</script>

</muclient>


