context: //  Author:
  //       scemino <scemino74@gmail.com>
  //
  //  Copyright (c) 2015 
  //
  //  This program is free software: you can redistribute it and/or modify
  //  it under the terms of the GNU General Public License as published by
  //  the Free Software Foundation, either version 3 of the License, or
  //  (at your option) any later version.
  //
  //  This program is distributed in the hope that it will be useful,
  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  //  GNU General Public License for more details.
  //
  //  You should have received a copy of the GNU General Public License
  //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  namespace NScumm.Sword1
  {
      public static class MenuObject
      {
          public const int textDesc = 0;
          public const int bigIconRes = 1;
          public const int bigIconFrame = 2;
          public const int luggageIconRes = 3;
          public const int useScript = 4;
      }
  
      enum MenuState
      {
          MENU_CLOSED,
          MENU_CLOSING,
          MENU_OPENING,
          MENU_OPEN
      }
  
      internal class Menu
      {
          const int TOTAL_pockets = 52;
          public const int MENU_TOP = 0;
          public const int MENU_BOT = 1;
          const int BASE_SUBJECT = 256;
  
          private Screen _screen;
          private Mouse _mouse;
          private MenuState _subjectBarStatus;
          private MenuState _objectBarStatus;
          private uint _inMenu;
          private uint[] _menuList = new uint[TOTAL_pockets];
          MenuIcon[] _objects = new MenuIcon[TOTAL_pockets];
          sbyte _fadeObject;
          MenuIcon[] _subjects = new MenuIcon[16];
          uint[] _subjectBar = new uint[16];
          private sbyte _fadeSubject;
  
          static readonly byte[] _fadeEffectTop = {
              1, 7, 5, 3, 2, 4, 6, 0,
              3, 1, 7, 5, 4, 6, 0, 2,
              5, 3, 1, 7, 6, 0, 2, 4,
              7, 5, 3, 1, 0, 2, 4, 6,
              7, 5, 3, 1, 0, 2, 4, 6,
              5, 3, 1, 7, 6, 0, 2, 4,
              3, 1, 7, 5, 4, 6, 0, 2,
              1, 7, 5, 3, 2, 4, 6, 0
          };
  
          static readonly byte[] _fadeEffectBottom = {
              7, 6, 5, 4, 3, 2, 1, 0,
              0, 7, 6, 5, 4, 3, 2, 1,
              1, 0, 7, 6, 5, 4, 3, 2,
              2, 1, 0, 7, 6, 5, 4, 3,
              3, 2, 1, 0, 7, 6, 5, 4,
              4, 3, 2, 1, 0, 7, 6, 5,
              5, 4, 3, 2, 1, 0, 7, 6,
              6, 5, 4, 3, 2, 1, 0, 7
          };
  
          public Menu(Screen screen, Mouse mouse)
          {
              _screen = screen;
              _mouse = mouse;
              _subjectBarStatus = MenuState.MENU_CLOSED;
              _objectBarStatus = MenuState.MENU_CLOSED;
          }
  
          public void Refresh(byte menuType)
          {
              uint i;
  
              if (menuType == MENU_TOP)
              {
                  if (_objectBarStatus == MenuState.MENU_OPENING || _objectBarStatus == MenuState.MENU_CLOSING)
                  {
                      for (i = 0; i < 16; i++)
                      {
                          if (_objects[i] != null)
                              _objects[i].Draw(_fadeEffectTop, _fadeObject);
                          else
                              _screen.ShowFrame((ushort)(i * 40), 0, 0xffffffff, 0, _fadeEffectTop, _fadeObject);
                      }
                  }
                  if (_objectBarStatus == MenuState.MENU_OPENING)
                  {
                      if (_fadeObject < 8)
                          _fadeObject++;
                      else
                          _objectBarStatus = MenuState.MENU_OPEN;
                  }
                  else if (_objectBarStatus == MenuState.MENU_CLOSING)
                  {
                      if (_fadeObject > 0)
                          _fadeObject--;
                      else
                      {
                          for (i = 0; i < _inMenu; i++)
                          {
                              _objects[i] = null;
                          }
                          _objectBarStatus = MenuState.MENU_CLOSED;
                      }
                  }
              }
              else
              {
                  if (_subjectBarStatus == MenuState.MENU_OPENING || _subjectBarStatus == MenuState.MENU_CLOSING)
                  {
                      for (i = 0; i < 16; i++)
                      {
                          if (_subjects[i] != null)
                              _subjects[i].Draw(_fadeEffectBottom, _fadeSubject);
                          else
                              _screen.ShowFrame((ushort)(i * 40), 440, 0xffffffff, 0, _fadeEffectBottom, _fadeSubject);
                      }
                  }
                  if (_subjectBarStatus == MenuState.MENU_OPENING)
                  {
                      if (_fadeSubject < 8)
                          _fadeSubject++;
                      else
                          _subjectBarStatus = MenuState.MENU_OPEN;
                  }
                  else if (_subjectBarStatus == MenuState.MENU_CLOSING)
                  {
                      if (_fadeSubject > 0)
                          _fadeSubject--;
                      else
                      {
                          for (i = 0; i < Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]; i++)
                          {
                              _subjects[i] = null;
                          }
                          _subjectBarStatus = MenuState.MENU_CLOSED;
                      }
                  }
              }
          }
  
          public void FnChooser(SwordObject compact)
          {
              Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = 0;
              _mouse.SetLuggage(0, 0);
              BuildSubjects();
              compact.logic = Logic.LOGIC_choose;
              _mouse.ControlPanel(true); // so the mouse cursor will be shown.
              _subjectBarStatus = MenuState.MENU_OPENING;
          }
  
          private void BuildSubjects()
          {
              for (var cnt = 0; cnt < 16; cnt++)
                  _subjects[cnt] = null;
  
              for (var cnt = 0; cnt < Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]; cnt++)
              {
                  uint res = (uint)_subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT, 0];
                  uint frame = (uint)_subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT, 1];
                  _subjects[cnt] = new MenuIcon(MENU_BOT, (byte)cnt, res, frame, _screen);
                  if (Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] != 0)
                      _subjects[cnt].SetSelect(_subjectBar[cnt] == Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD]);
                  else
                      _subjects[cnt].SetSelect(true);
              }
          }
  
          public void FnEndChooser()
          {
              Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = 0;
              _subjectBarStatus = MenuState.MENU_CLOSING;
              _objectBarStatus = MenuState.MENU_CLOSING;
              _mouse.ControlPanel(false);
              _mouse.SetLuggage(0, 0);
          }
  
          public void FnStartMenu()
          {
              Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = 0; // icon no longer selected
              Logic.ScriptVars[(int)ScriptVariableNames.SECOND_ITEM] = 0; // second icon no longer selected (after using one on another)
              Logic.ScriptVars[(int)ScriptVariableNames.MENU_LOOKING] = 0; // no longer 'looking at' an icon
              BuildMenu();
              ShowMenu(MENU_TOP);
          }
  
          private void ShowMenu(int menuType)
          {
              if (menuType == MENU_TOP)
              {
                  if (_objectBarStatus == MenuState.MENU_OPEN)
                  {
                      for (var cnt = 0; cnt < 16; cnt++)
                      {
                          if (_objects[cnt] != null)
                              _objects[cnt].Draw();
                          else
                              _screen.ShowFrame((ushort)(cnt * 40), 0, 0xffffffff, 0);
                      }
                  }
                  else if (_objectBarStatus == MenuState.MENU_CLOSED)
                  {
                      _objectBarStatus = MenuState.MENU_OPENING;
                      _fadeObject = 0;
                  }
                  else if (_objectBarStatus == MenuState.MENU_CLOSING)
                      _objectBarStatus = MenuState.MENU_OPENING;
              }
          }
  
          private void BuildMenu()
          {
              for (var cnt = 0; cnt < _inMenu; cnt++)
                  _objects[cnt] = null;
  
              _inMenu = 0;
              for (var pocketNo = 0; pocketNo < TOTAL_pockets; pocketNo++)
              {
                  if (Logic.ScriptVars[(int)(ScriptVariableNames.POCKET_1 + pocketNo)] != 0)
                  {
                      _menuList[_inMenu] = (uint)(pocketNo + 1);
                      _inMenu++;
                  }
              }
  
              for (var menuSlot = 0; menuSlot < _inMenu; menuSlot++)
              {
                  _objects[menuSlot] = new MenuIcon(MENU_TOP, (byte)menuSlot, (uint) _objectDefs[_menuList[menuSlot],MenuObject.bigIconRes], (uint) _objectDefs[_menuList[menuSlot], MenuObject.bigIconFrame], _screen);
                  uint objHeld = Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD];
  
                  // check highlighting
                  if (Logic.ScriptVars[(int)ScriptVariableNames.MENU_LOOKING] != 0 || _subjectBarStatus == MenuState.MENU_OPEN)
                  { // either we're in the chooser or we're doing a 'LOOK AT'
                      if ((objHeld == 0) || (objHeld == _menuList[menuSlot]))
                          _objects[menuSlot].SetSelect(true);
                  }
                  else if (Logic.ScriptVars[(int)ScriptVariableNames.SECOND_ITEM] != 0)
                  { // clicked luggage onto 2nd icon - we need to color-highlight the 2 relevant icons & grey out the rest
                      if ((_menuList[menuSlot] == objHeld) || (_menuList[menuSlot] == Logic.ScriptVars[(int)ScriptVariableNames.SECOND_ITEM]))
                          _objects[menuSlot].SetSelect(true);
                  }
                  else
                  { // this object is selected - ie. GREYED OUT
                      if (objHeld != _menuList[menuSlot])
                          _objects[menuSlot].SetSelect(true);
                  }
              }
          }
  
          public void FnEndMenu()
          {
              if (_objectBarStatus != MenuState.MENU_CLOSED)
                  _objectBarStatus = MenuState.MENU_CLOSING;
          }
  
          public void CfnReleaseMenu()
          {
              _objectBarStatus = MenuState.MENU_CLOSING;
          }
  
          public void FnAddSubject(int sub)
          {
              _subjectBar[Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]] = (uint)sub;
              Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]++;
          }
  
          public void CheckTopMenu()
          {
              if (_objectBarStatus == MenuState.MENU_OPEN)
                  CheckMenuClick(MENU_TOP);
          }
  
          private byte CheckMenuClick(int menuType)
          {
              ushort mouseEvent = _mouse.TestEvent();
              if (mouseEvent == 0)
                  return 0;
              ushort x, y;
              _mouse.GiveCoords(out x, out y);
              if (_subjectBarStatus == MenuState.MENU_OPEN)
              {
                  // Conversation mode. Icons are highlighted on mouse-down, but
                  // the actual response is made on mouse-up.
                  if (menuType == MENU_BOT)
                  {
                      if (Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] != 0 && ((mouseEvent & Mouse.BS1L_BUTTON_UP) != 0))
                      {
                          for (var cnt = 0; cnt < Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]; cnt++)
                          {
                              if (_subjectBar[cnt] == Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD])
                                  return (byte)(cnt + 1);
                          }
                      }
                      else if ((mouseEvent & Mouse.BS1L_BUTTON_DOWN) != 0)
                      {
                          for (var cnt = 0; cnt < Logic.ScriptVars[(int)ScriptVariableNames.IN_SUBJECT]; cnt++)
                          {
                              if (_subjects[cnt].WasClicked(x, y))
                              {
                                  Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = _subjectBar[cnt];
                                  RefreshMenus();
                                  break;
                              }
                          }
                      }
                  }
                  else
                  {
                      if (Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] != 0 && ((mouseEvent & Mouse.BS1L_BUTTON_UP) != 0))
                      {
                          for (var cnt = 0; cnt < _inMenu; cnt++)
                          {
                              if (_menuList[cnt] == Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD])
                                  return (byte)(cnt + 1);
                          }
                      }
                      else if ((mouseEvent & Mouse.BS1L_BUTTON_DOWN) != 0)
                      {
                          for (var cnt = 0; cnt < _inMenu; cnt++)
                          {
                              if (_objects[cnt].WasClicked(x, y))
                              {
                                  Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = _menuList[cnt];
                                  RefreshMenus();
                                  break;
                              }
                          }
                      }
                  }
              }
              else
              {
                  // Normal use, i.e. inventory. Things happen on mouse-down.
                  if (menuType == MENU_TOP)
                  {
                      for (var cnt = 0; cnt < _inMenu; cnt++)
                      {
                          if (_objects[cnt].WasClicked(x, y))
                          {
                              if ((mouseEvent & Mouse.BS1R_BUTTON_DOWN) != 0)
                              { // looking at item
                                  Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = _menuList[cnt];
                                  Logic.ScriptVars[(int)ScriptVariableNames.MENU_LOOKING] = 1;
                                  Logic.ScriptVars[(int)ScriptVariableNames.DEFAULT_ICON_TEXT] = (uint)_objectDefs[_menuList[cnt], MenuObject.textDesc];
                              }
                              else if ((mouseEvent & Mouse.BS1L_BUTTON_DOWN) != 0)
                              {
                                  if (Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] != 0)
                                  {
                                      if (Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] == _menuList[cnt])
                                      {
                                          _mouse.SetLuggage(0, 0);
                                          Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = 0; // reselected => deselect it
                                      }
                                      else
                                      { // the player is clicking another item on this one.
                                        // run its use-script, if there is one
                                          Logic.ScriptVars[(int)ScriptVariableNames.SECOND_ITEM] = _menuList[cnt];
                                          _mouse.SetLuggage(0, 0);
                                      }
                                  }
                                  else
                                  {
                                      Logic.ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = _menuList[cnt];
                                      _mouse.SetLuggage((uint) _objectDefs[_menuList[cnt], MenuObject.luggageIconRes], 0);
                                  }
                              }
                              RefreshMenus();
                              break;
                          }
                      }
                  }
              }
              return 0;
          }
  
          private void RefreshMenus()
          {
              if (_objectBarStatus == MenuState.MENU_OPEN)
              {
                  BuildMenu();
                  for (var cnt = 0; cnt < 16; cnt++)
                  {
                      if (_objects[cnt] != null)
                          _objects[cnt].Draw();
                      else
                          _screen.ShowFrame((ushort)(cnt * 40), 0, 0xffffffff, 0);
                  }
              }
              if (_subjectBarStatus == MenuState.MENU_OPEN)
              {
                  BuildSubjects();
                  for (var cnt = 0; cnt < 16; cnt++)
                  {
                      if (_subjects[cnt] != null)
                          _subjects[cnt].Draw();
                      else
                          _screen.ShowFrame((ushort)(cnt * 40), 440, 0xffffffff, 0);
                  }
              }
          }
  
          public int LogicChooser(SwordObject compact)
          {
              byte objSelected = 0;
              if (_objectBarStatus == MenuState.MENU_OPEN)
                  objSelected = CheckMenuClick(MENU_TOP);
              if (objSelected == 0)
                  objSelected = CheckMenuClick(MENU_BOT);
              if (objSelected != 0)
              {
                  compact.logic = Logic.LOGIC_script;
                  return 1;
              }
              return 0;
          }
  
          static readonly int[,] _subjectList = {
              {	// 256
  		        0,								// subject_res
  		        0									// subject_frame
  	        },
              {	// 257
  		        ICON_BEER,				// subject_res
  		        0									// subject_frame
  	        },
              {	// 258
  		        ICON_CASTLE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 259
  		        ICON_YES,					// subject_res
  		        0									// subject_frame
  	        },
              { // 260
  		        ICON_NO,					// subject_res
  		        0									// subject_frame
  	        },
              { // 261
  		        ICON_PEAGRAM,			// subject_res
  		        0									// subject_frame
  	        },
              { // 262
  		        ICON_DIG,					// subject_res
  		        0									// subject_frame
  	        },
              { // 263
  		        ICON_SEAN,				// subject_res
  		        0									// subject_frame
  	        },
              { // 264
  		        ICON_GEM,					// subject_res
  		        0									// subject_frame
  	        },
              { // 265
  		        ICON_TEMPLARS,		// subject_res
  		        0									// subject_frame
  	        },
              { // 266
  		        ICON_LEPRECHAUN,	// subject_res
  		        0									// subject_frame
  	        },
              { // 267
  		        ICON_GOODBYE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 268
  		        ICON_GEORGE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 269
  		        ICON_ROSSO,				// subject_res
  		        0									// subject_frame
  	        },
              { // 270
  		        ICON_GHOST,				// subject_res
  		        0									// subject_frame
  	        },
              { // 271
  		        ICON_CLOWN,				// subject_res
  		        0									// subject_frame
  	        },
              { // 272
  		        ICON_CAR,					// subject_res
  		        0									// subject_frame
  	        },
              { // 273
  		        ICON_MOUE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 274
  		        ICON_NICO,				// subject_res
  		        0									// subject_frame
  	        },
              { // 275
  		        ICON_MOB,					// subject_res
  		        0									// subject_frame
  	        },
              { // 276
  		        ICON_CHANTELLE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 277
  		        ICON_PLANTARD,		// subject_res
  		        0									// subject_frame
  	        },
              { // 278
  		        ICON_JACKET,			// subject_res
  		        0									// subject_frame
  	        },
              { // 279
  		        ICON_BRIEFCASE,		// subject_res
  		        0									// subject_frame
  	        },
              {
                  0, //ICON_GLASS,	// subject_res
  		        0									// subject_frame
  	        },
              { // 281
  		        ICON_GLASS_EYE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 282
  		        ICON_BULL,				// subject_res
  		        0									// subject_frame
  	        },
              { // 283
  		        ICON_KLAUSNER,		// subject_res
  		        0									// subject_frame
  	        },
              { // 284
  		        0, //ICON_LOOM,		// subject_res
  		        0									// subject_frame
  	        },
              { // 285
  		        ICON_ULTAR,				// subject_res
  		        0									// subject_frame
  	        },
              { // 286
  		        ICON_PHONE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 287
  		        ICON_PHOTOGRAPH,	// subject_res
  		        0									// subject_frame
  	        },
              { // 288
  		        ICON_CREST,				// subject_res
  		        0									// subject_frame
  	        },
              { // 289
  		        ICON_LOBINEAU,		// subject_res
  		        0									// subject_frame
  	        },
              { // 290
  		        ICON_BOOK,				// subject_res
  		        0									// subject_frame
  	        },
              { // 291 (SNARE)
  		        ICON_FUSE_WIRE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 292
  		        ICON_LEARY,				// subject_res
  		        0									// subject_frame
  	        },
              { // 293
  		        ICON_LADDER,			// subject_res
  		        0									// subject_frame
  	        },
              { // 294
  		        ICON_GOAT,				// subject_res
  		        0									// subject_frame
  	        },
              { // 295
  		        ICON_TOOLBOX,			// subject_res
  		        0									// subject_frame
  	        },
              { // 296
  		        ICON_PACKAGE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 297
  		        ICON_FISH,				// subject_res
  		        0									// subject_frame
  	        },
              { // 298
  		        ICON_NEJO,				// subject_res
  		        0									// subject_frame
  	        },
              { // 299
  		        ICON_CAT,					// subject_res
  		        0									// subject_frame
  	        },
              { // 300
  		        ICON_AYUB,				// subject_res
  		        0									// subject_frame
  	        },
              { // 301
  		        ICON_STATUETTE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 302
  		        ICON_NEJO_STALL,	// subject_res
  		        0									// subject_frame
  	        },
              { // 303
  		        ICON_TEMPLARS,		// subject_res
  		        0									// subject_frame
  	        },
              { // 304
  		        ICON_ARTO,				// subject_res
  		        0									// subject_frame
  	        },
              { // 305
  		        ICON_HENDERSONS,	// subject_res
  		        0									// subject_frame
  	        },
              { // 306
  		        ICON_CLUB,				// subject_res
  		        0									// subject_frame
  	        },
              { // 307
  		        ICON_SIGN,				// subject_res
  		        0									// subject_frame
  	        },
              { // 308
  		        ICON_TAXI,				// subject_res
  		        0									// subject_frame
  	        },
              { // 309
  		        ICON_BULLS_HEAD,	// subject_res
  		        0									// subject_frame
  	        },
              { // 310
  		        ICON_DUANE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 311
  		        ICON_PEARL,				// subject_res
  		        0									// subject_frame
  	        },
              { // 312
  		        ICON_TRUTH,				// subject_res
  		        0									// subject_frame
  	        },
              { // 313
  		        ICON_LIE,					// subject_res
  		        0									// subject_frame
  	        },
              { // 314
  		        0, //ICON_SUBJECT,// subject_res
  		        0									// subject_frame
  	        },
              { // 315 KEY
  		        ICON_HOTEL_KEY,		// subject_res
  		        0									// subject_frame
  	        },
              { // 316
  		        ICON_FLOWERS,			// subject_res
  		        0									// subject_frame
  	        },
              { // 317
  		        ICON_BUST,				// subject_res
  		        0									// subject_frame
  	        },
              { // 318
  		        ICON_MANUSCRIPT,	// subject_res
  		        0									// subject_frame
  	        },
              { // 319
  		        ICON_WEASEL,			// subject_res
  		        0									// subject_frame
  	        },
              { // 320
  		        ICON_BANANA,			// subject_res
  		        0									// subject_frame
  	        },
              { // 321
  		        ICON_WEAVER,			// subject_res
  		        0									// subject_frame
  	        },
              { // 322
  		        ICON_KNIGHT,			// subject_res
  		        0									// subject_frame
  	        },
              { // 323
  		        ICON_QUEEN,				// subject_res
  		        0									// subject_frame
  	        },
              { // 324
  		        ICON_PIERMONT,		// subject_res
  		        0									// subject_frame
  	        },
              { // 325
  		        ICON_BALL,				// subject_res
  		        0									// subject_frame
  	        },
              { // 326
  		        ICON_COUNTESS,		// subject_res
  		        0									// subject_frame
  	        },
              { // 327
  		        ICON_MARQUET,			// subject_res
  		        0									// subject_frame
  	        },
              { // 328
  		        ICON_SAFE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 329
  		        ICON_COINS,				// subject_res
  		        0									// subject_frame
  	        },
              { // 330
  		        ICON_CHESS_SET,		// subject_res
  		        0									// subject_frame
  	        },
              { // 331
  		        ICON_TOMB,				// subject_res
  		        0									// subject_frame
  	        },
              { // 332
  		        ICON_CANDLE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 333
  		        ICON_MARY,				// subject_res
  		        0									// subject_frame
  	        },
              { // 334
  		        ICON_CHESSBOARD,	// subject_res
  		        0									// subject_frame
  	        },
              { // 335
  		        ICON_TRIPOD,			// subject_res
  		        0									// subject_frame
  	        },
              { // 336
  		        ICON_POTS,				// subject_res
  		        0									// subject_frame
  	        },
              { // 337
  		        ICON_ALARM,				// subject_res
  		        0									// subject_frame
  	        },
              { // 338
  		        ICON_BAPHOMET,		// subject_res
  		        0									// subject_frame
  	        },
              { // 339
  		        ICON_PHRASE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 340
  		        ICON_POLISHED_CHALICE,	// subject_res
  		        0												// subject_frame
  	        },
              { // 341
  		        ICON_NURSE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 342
  		        ICON_WELL,				// subject_res
  		        0									// subject_frame
  	        },
              { // 343
  		        ICON_WELL2,				// subject_res
  		        0									// subject_frame
  	        },
              { // 344
  		        ICON_HAZEL_WAND,	// subject_res
  		        0									// subject_frame
  	        },
              { // 345
  		        ICON_CHALICE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 346
  		        ICON_MR_SHINY,		// subject_res
  		        0									// subject_frame
  	        },
              { // 347
  		        ICON_PHOTOGRAPH,	// subject_res
  		        0									// subject_frame
  	        },
              { // 348
  		        ICON_PHILIPPE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 349
  		        ICON_ERIC,				// subject_res
  		        0									// subject_frame
  	        },
              { // 350
  		        ICON_ROZZER,			// subject_res
  		        0									// subject_frame
  	        },
              { // 351
  		        ICON_JUGGLER,			// subject_res
  		        0									// subject_frame
  	        },
              { // 352
  		        ICON_PRIEST,			// subject_res
  		        0									// subject_frame
  	        },
              { // 353
  		        ICON_WINDOW,			// subject_res
  		        0									// subject_frame
  	        },
              { // 354
  		        ICON_SCROLL,			// subject_res
  		        0									// subject_frame
  	        },
              { // 355
  		        ICON_PRESSURE_GAUGE,	// subject_res
  		        0											// subject_frame
  	        },
              { // 356
  		        ICON_RENEE,				// subject_res
  		        0									// subject_frame
  	        },
              { // 357
  		        ICON_CHURCH,			// subject_res
  		        0									// subject_frame
  	        },
              { // 358
  		        ICON_EKLUND,			// subject_res
  		        0									// subject_frame
  	        },
              { // 359
  		        ICON_FORTUNE,			// subject_res
  		        0									// subject_frame
  	        },
              { // 360
  		        ICON_PAINTER,			// subject_res
  		        0									// subject_frame
  	        },
              { // 361
  		        0, //ICON_SWORD,	// subject_res
  		        0									// subject_frame
  	        },
              { // 362
  		        ICON_GUARD,				// subject_res
  		        0									// subject_frame
  	        },
              { // 363
  		        ICON_THERMOSTAT,	// subject_res
  		        0									// subject_frame
  	        },
              { // 364
  		        ICON_TOILET,			// subject_res
  		        0									// subject_frame
  	        },
              { // 365
  		        ICON_MONTFAUCON,	// subject_res
  		        0									// subject_frame
  	        },
              { // 366
  		        ICON_ASSASSIN,		// subject_res
  		        0									// subject_frame
  	        },
              { // 367
  		        ICON_HASH,				// subject_res
  		        0									// subject_frame
  	        },
              { // 368
  		        ICON_DOG,					// subject_res
  		        0									// subject_frame
  	        },
              { // 369
  		        ICON_AYUB,				// subject_res
  		        0									// subject_frame
  	        },
              { // 370
  		        ICON_LENS,				// subject_res
  		        0									// subject_frame
  	        },
              { // 371
  		        ICON_RED_NOSE,		// subject_res
  		        0									// subject_frame
  	        },
              { // 372
  		        0,								// subject_res
  		        0									// subject_frame
  	        },
              { // 373
  		        0,								// subject_res
  		        0									// subject_frame
  	        },
              { // 374
  		        0,								// subject_res
  		        0									// subject_frame
  	        }
          };
  
          public static readonly int[,] _objectDefs = {
              {	// 0 can't use
  		        0, 0, 0, 0, 0
              },
              {	// 1 NEWSPAPER
  		        menu_newspaper,							// text_desc
  		        ICON_NEWSPAPER,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_NEWSPAPER,							// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 2 HAZEL_WAND
  		        menu_hazel_wand,						// text_desc
  		        ICON_HAZEL_WAND,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_HAZEL_WAND,						// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 3 BEER_TOWEL
  		        0,													// text_desc - SEE MENU.SCR
  		        ICON_BEER_TOWEL,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_BEER_TOWEL,						// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 4 HOTEL_KEY
  		        menu_hotel_key,							// text_desc
  		        ICON_HOTEL_KEY,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_HOTEL_KEY,							// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 5 BALL
  		        menu_ball,									// text_desc
  		        ICON_BALL,									// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_BALL,									// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 6 STATUETTE
  		        menu_statuette,							// text_desc
  		        ICON_STATUETTE,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_STATUETTE,							// luggage_icon_res
  		        SCR_icon_combine_script,		// use_script
  	        },
              {	// 7 RED_NOSE
  		        0,													// text_desc - SEE MENU.SCR
  		        ICON_RED_NOSE,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_RED_NOSE,							// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 8 POLISHED_CHALICE
  		        menu_polished_chalice,			// text_desc
  		        ICON_POLISHED_CHALICE,			// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_POLISHED_CHALICE,			// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 9 DOLLAR_BILL
  		        menu_dollar_bill,						// text_desc
  		        ICON_DOLLAR_BILL,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_DOLLAR_BILL,						// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 10 PHOTO
  		        menu_photograph,						// text_desc
  		        ICON_PHOTOGRAPH,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_PHOTOGRAPH,						// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 11 FLASHLIGHT
  		        menu_flashlight,						// text_desc
  		        ICON_FLASHLIGHT,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_FLASHLIGHT,						// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 12 FUSE_WIRE
  		        menu_fuse_wire,							// text_desc
  		        ICON_FUSE_WIRE,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_FUSE_WIRE,							// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 13 GEM
  		        menu_gem,										// text_desc
  		        ICON_GEM,										// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_GEM,										// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 14 STATUETTE_PAINT
  		        menu_statuette_paint,				// text_desc
  		        ICON_STATUETTE_PAINT,				// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_STATUETTE_PAINT,				// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 15 STICK
  		        menu_stick,									// text_desc
  		        ICON_STICK,									// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_STICK,									// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 16 EXCAV_KEY
  		        menu_excav_key,							// text_desc
  		        ICON_EXCAV_KEY,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_EXCAV_KEY,							// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 17 LAB_PASS
  		        menu_lab_pass,							// text_desc
  		        ICON_LAB_PASS,							// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_LAB_PASS,							// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 18 LIFTING_KEYS
  		        menu_lifting_keys,					// text_desc
  		        ICON_LIFTING_KEYS,					// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_LIFTING_KEYS,					// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
              {	// 19 MANUSCRIPT
  		        menu_manuscript,						// text_desc
  		        ICON_MANUSCRIPT,						// big_icon_res
  		        0,													// big_icon_frame
  		        SwordRes.LUGG_MANUSCRIPT,						// luggage_icon_res
  		        SCR_icon_combine_script,			// use_script
  	        },
  
gt:             {	// 20 MATCH_BOOK