unit Editor1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, aData, loadz, arc, StdCtrls, ExtCtrls, ComCtrls;

type
  TForm2 = class(TForm)
    Image1: TImage;
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    SaveDialog1: TSaveDialog;
    Panel3: TPanel;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    UpDown1: TUpDown;
    UpDown2: TUpDown;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    Label3: TLabel;
    Edit3: TEdit;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Button5: TButton;
    StatusBar1: TStatusBar;
    GroupBox2: TGroupBox;
    Label6: TLabel;
    Edit6: TEdit;
    Label7: TLabel;
    Edit7: TEdit;
    GroupBox3: TGroupBox;
    Label8: TLabel;
    Edit8: TEdit;
    Edit9: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    Label12: TLabel;
    ComboBox1: TComboBox;
    Button16: TButton;
    Button17: TButton;
    GroupBox4: TGroupBox;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Edit10: TEdit;
    Label18: TLabel;
    Edit11: TEdit;
    Label19: TLabel;
    Edit12: TEdit;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Edit13: TEdit;
    Label23: TLabel;
    Edit14: TEdit;
    Label24: TLabel;
    Edit15: TEdit;
    Label25: TLabel;
    Edit16: TEdit;
    Label26: TLabel;
    Edit17: TEdit;
    Label27: TLabel;
    Edit18: TEdit;
    Label28: TLabel;
    Edit19: TEdit;
    Label29: TLabel;
    Edit20: TEdit;
    Label30: TLabel;
    Edit21: TEdit;
    Label31: TLabel;
    Edit22: TEdit;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    GroupBox5: TGroupBox;
    Label32: TLabel;
    Edit23: TEdit;
    Label33: TLabel;
    Edit24: TEdit;
    Label34: TLabel;
    Label35: TLabel;
    Edit25: TEdit;
    Edit26: TEdit;
    Label36: TLabel;
    Edit27: TEdit;
    Label37: TLabel;
    Edit28: TEdit;
    Label38: TLabel;
    Edit29: TEdit;
    Label39: TLabel;
    CheckBox17: TCheckBox;
    Button18: TButton;
    Button19: TButton;
    Edit30: TEdit;
    Label41: TLabel;
    Edit31: TEdit;
    Label42: TLabel;
    CheckBox18: TCheckBox;
    Button22: TButton;
    Panel4: TPanel;
    Label40: TLabel;
    Label43: TLabel;
    Label44: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    Label52: TLabel;
    Label53: TLabel;
    Label54: TLabel;
    ComboBox2: TComboBox;
    Edit32: TEdit;
    Edit33: TEdit;
    Edit34: TEdit;
    Edit35: TEdit;
    CheckBox19: TCheckBox;
    Edit36: TEdit;
    Edit37: TEdit;
    Edit38: TEdit;
    Edit39: TEdit;
    Edit40: TEdit;
    Edit41: TEdit;
    memo1: TMemo;
    Button20: TButton;
    Button21: TButton;
    Panel5: TPanel;
    Label55: TLabel;
    ComboBox3: TComboBox;
    Label56: TLabel;
    Edit42: TEdit;
    Label57: TLabel;
    Edit43: TEdit;
    Edit44: TEdit;
    Label58: TLabel;
    Edit45: TEdit;
    Label59: TLabel;
    Edit46: TEdit;
    Label60: TLabel;
    Edit47: TEdit;
    Label61: TLabel;
    Edit48: TEdit;
    Label62: TLabel;
    Edit49: TEdit;
    Label63: TLabel;
    Edit50: TEdit;
    Label64: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    Edit51: TEdit;
    Label67: TLabel;
    Edit52: TEdit;
    Label68: TLabel;
    Edit53: TEdit;
    Label69: TLabel;
    Edit54: TEdit;
    Label70: TLabel;
    Edit55: TEdit;
    Label71: TLabel;
    Edit56: TEdit;
    Label72: TLabel;
    Edit57: TEdit;
    Label73: TLabel;
    Edit58: TEdit;
    Label74: TLabel;
    Edit59: TEdit;
    Label75: TLabel;
    Edit60: TEdit;
    Label76: TLabel;
    Edit61: TEdit;
    Label77: TLabel;
    Edit62: TEdit;
    Label78: TLabel;
    Edit63: TEdit;
    Label79: TLabel;
    Edit64: TEdit;
    CheckBox20: TCheckBox;
    CheckBox21: TCheckBox;
    CheckBox22: TCheckBox;
    CheckBox23: TCheckBox;
    CheckBox24: TCheckBox;
    CheckBox25: TCheckBox;
    CheckBox26: TCheckBox;
    CheckBox27: TCheckBox;
    CheckBox28: TCheckBox;
    CheckBox29: TCheckBox;
    CheckBox30: TCheckBox;
    Label80: TLabel;
    Edit65: TEdit;
    Label81: TLabel;
    Edit66: TEdit;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Button26: TButton;
    Button10: TButton;
    Button6: TButton;
    Button11: TButton;
    Button7: TButton;
    Button13: TButton;
    Button8: TButton;
    Button12: TButton;
    Button9: TButton;
    Button14: TButton;
    Button15: TButton;
    label83: TLabel;
    edit68: TEdit;
    btn1: TButton;
    chk1: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button25Click(Sender: TObject);
    procedure Button26Click(Sender: TObject);
    procedure Button24Click(Sender: TObject);
    procedure ComboBox3Change(Sender: TObject);
    procedure Edit11Change(Sender: TObject);
    procedure Edit12Change(Sender: TObject);
    procedure Edit13Change(Sender: TObject);
    procedure Edit14Change(Sender: TObject);
    procedure Edit15Change(Sender: TObject);
    procedure Edit16Change(Sender: TObject);
    procedure Edit17Change(Sender: TObject);
    procedure Edit18Change(Sender: TObject);
    procedure Edit19Change(Sender: TObject);
    procedure Edit20Change(Sender: TObject);
    procedure Edit21Change(Sender: TObject);
    procedure Edit22Change(Sender: TObject);
    procedure Edit23Change(Sender: TObject);
    procedure Edit24Change(Sender: TObject);
    procedure Edit25Change(Sender: TObject);
    procedure Edit26Change(Sender: TObject);
    procedure Edit27Change(Sender: TObject);
    procedure Edit28Change(Sender: TObject);
    procedure Edit29Change(Sender: TObject);
    procedure Edit30Change(Sender: TObject);
    procedure Edit31Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure Edit5Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure CheckBox15MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox10MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox11MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox13MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox14MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox12MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox16MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox17MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox18MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CheckBox4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Edit10KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edit68KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btn1Click(Sender: TObject);
    procedure edit68KeyPress(Sender: TObject; var Key: Char);
    procedure chk1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    procedure InitPole;
    procedure GetLevelInfo;
    procedure Hud(s: string);
    procedure GetCellInfo(x, y: integer);
    procedure GetItemNumber;
    procedure GetEnemyInfo;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  lev_filename: string = '';
  x: integer = 1;
  y: integer = 1;
  called: integer = 0;
  temp: integer = 0;
  placelev: Boolean = false;
  placeinhouse: Boolean = false;

implementation

{$R *.dfm}

var
  lev: level_rec;

const
  arr: array[1..TypesCount] of string =
  (
    'Пусто', 'Стена', 'Куча земли', 'Земля', 'Лес', 'Забор (|)', 'Забор (-)',
    'Сетчатая перегородка (|)', 'Сетчатая перегородка (-)', 'Столб', 'Деревянный столб' ,
    'Окно', 'Разбитое окно', 'Земля (#)', 'Лестница вниз', 'Лестница вверх',
    'Сундук', 'Открытый сундук', 'Дерево', 'Пол', 'Трава', 'Лужа воды',
    'Лужа крови', 'Вода', 'Кровь', 'Болото', 'Дверь', 'Открытая дверь', 'Гора',
    'Ящик', 'Камень', 'Труп', 'Обысканный труп (?)', 'Скелет',
    'Обысканный скелет (?)', 'Выход на MAIN', 'Фиктивный выход на MAIN',
    'Земля (.)', 'Вход в поселение', 'Дневник', 'Бочка',
    'Куча мусора', 'Куча мусора 2', 'Рычаг (\)', 'Рычаг (/)', 'Телепортатор',
    'Терминал камер', 'Терминал', 'Статуя', 'Деревянный мост', 'Деревянная платформа',
    'Песок', 'Дорога', 'Пустота', 'Неизвестная отрава', 'Ловушка', 'Асфальт', 'Надгробная плита',
    'Куст(л)', 'Куст'
  );

procedure Draw(x, y: integer; c: char; color: TColor);
begin
  Form2.Image1.Canvas.Font.Color := color;
  Form2.Image1.Canvas.TextOut((x - 1) * 8 + 1, (y - 1) * 11 + 1, c);
end;

function IsSecretDoor(attrz: integer): boolean;
begin
  Result := ((attrz and 16) > 0);
end;

function IsBlood(attrz: integer): boolean;
begin
  Result := ((attrz and 8) > 0);
end;

function IsForBlood(attrz: integer): boolean;
begin
  Result := ((attrz and 16) > 0);
end;

function IsVisible(i: Integer): boolean;
begin
  IsVisible := ((i and 16) <> 0);
end;

procedure osvkletka(x, y: integer; Color: TColor = White; IsBold: boolean = false);
var
  enemy: TEnemy;
  item: TItem;
begin
  if (IsBold) then
    Form2.Image1.Canvas.Font.Style := Form2.Image1.Canvas.Font.Style + [fsBold]
  else
    Form2.Image1.Canvas.Font.Style := Form2.Image1.Canvas.Font.Style - [fsBold];
  if (lev.map[x, y].Monster.montype <> 0) then
  begin
    mon_info(lev.map[x, y].Monster.montype, enemy);
    if (IsVisible(enemy.Attrz) and (Color = White)) then
      Draw(x, y, enemy.character, enemy.charcolor)
    else if (Color = White) then
      Draw(x, y, enemy.character, LightBlue)
    else
      Draw(x, y, enemy.character, Color);
  end
  else if (lev.map[x, y].AnObject <> #0) then
  begin
    if ((IsSecretDoor(lev.map[x, y].ObjAttrz)) and (Color = White)) then
      Draw(x, y, lev.map[x, y].AnObject, Yellow)
    else if ((IsBlood(lev.map[x, y].ObjAttrz)) and (Color = White)) then
      Draw(x, y, lev.map[x, y].AnObject, Red)
    else if (Color = White) then
      Draw(x, y, lev.map[x, y].AnObject, lev.map[x, y].AnObjectColor)
    else
      Draw(x, y, lev.map[x, y].AnObject, Color);
  end
  else if(lev.map[x, y].item <> 0) then
  begin
    iteminfo(lev.map[x, y].item, item);
    if (Color = White) then
      Draw(x, y, item.ItemChar, item.ItemColor)
    else
      Draw(x, y, item.ItemChar, Color);
  end
  else if ((IsBlood(lev.map[x, y].attrz)) and (Color = White)) then
    Draw(x, y, lev.map[x, y].lev, Red)
  else if ((IsSecretDoor(lev.map[x, y].attrz)) and (Color = White)) then
    Draw(x, y, lev.map[x, y].lev, Yellow)
  else if (Color = White) then
    Draw(x, y, lev.map[x, y].lev, lev.map[x, y].color)
  else if (lev.map[x, y].shadow) then
    Draw(x, y, lev.map[x, y].lev, DarkGray)
  else
    Draw(x, y, lev.map[x, y].lev, Color);
end;

procedure osv_all;
var
  i, j: integer;
begin
  for i := 1 to RESOLUTION_X do
    for j := 1 to RESOLUTION_Y do
      osvkletka(i, j);
end;

procedure SetElement(x, y: integer; aType: string);
var
  i: integer;
begin
  for i := 1 to TypesCount do
    if (KletArr[i].TypeName = aType) then
    begin
      lev.map[x, y].lev := KletArr[i].c;
      lev.map[x, y].color := KletArr[i].col;
      exit;
    end;
end;

procedure SetObject(x, y: integer; aType: string);
var
  i: integer;
begin
  for i := 1 to TypesCount do
    if (KletArr[i].TypeName = aType) then
    begin
      lev.map[x, y].AnObject := KletArr[i].c;
      lev.map[x, y].AnObjectColor := KletArr[i].col;
      exit;
    end;
end;

procedure SetItem(x, y: integer; num, count: integer);
begin
  lev.map[x, y].item := num;
  lev.map[x, y].ItemCount := count;
end;

procedure SetMonster(x, y: integer; aName: string);
var
  i: integer;
begin
  for i := 1 to MonstersCount do
    if (MonArr[i].name = aName) then
    begin
      lev.map[x, y].Monster.montype := MonArr[i].montype;
      lev.map[x, y].Monster.health := MonArr[i].health;
      lev.map[x, y].Monster.monchar := MonArr[i].character;
      lev.map[x, y].Monster.item := MonArr[i].Item;
      lev.map[x, y].Monster.count := MonArr[i].Count;
      lev.map[x, y].Monster.gold := Random(100);
      lev.map[x, y].Monster.Attrz := MonArr[i].Attrz;
      exit;
    end;
end;

procedure InitLevel(initType: string);
var
  i, j: integer;
begin
  for i := 1 to RESOLUTION_X do
    for j := 1 to RESOLUTION_Y do
    begin
      SetElement(i, j, initType);
      lev.map[i, j].vid := #0;
      lev.map[i, j].now := #0;
      lev.map[i, j].levAttrz := 0;
      lev.map[i, j].item := 0;
      lev.map[i, j].ItemCount := 0;
      lev.map[i, j].AnObject := #0;
      lev.map[i, j].AnObjectColor := 0;
      lev.map[i, j].ObjAttrz := 0;
      lev.map[i, j].DoorCode := 0;
      lev.map[i, j].attrz := 0;
    end;
end;

procedure SaveLevel(filename: string);
var
  f: File of level_rec;
  s: string;
begin
  s := Copy(filename, 1, Length(filename) - 4);
  AssignFile(f, s);
  rewrite(f);
  write(f, lev);
  CloseFile(f);
  DoCompress(s, filename);
end;

procedure LoadLevel(filename: string);
var
  f: File of level_rec;
begin
  DoUnCompress(filename, Copy(filename, 1, Length(filename) - 4));
  filename := Copy(filename, 1, length(filename) - 4);
  AssignFile(f, filename);
  reset(f);
  read(f, lev);
  CloseFile(f);
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  i: integer;
begin
  InitLevel('Grass');
  for i := 1 to 5 do
  begin
    SetElement(i, 1, 'Mountain');
    SetElement(1, i, 'Mountain');
    SetElement(i, 5, 'Mountain');
    SetElement(5, i, 'Mountain');
  end;
  SetElement(3, 2, 'Ground');
  SetElement(3, 3, 'Ground');
  SetElement(3, 4, 'Ground');
  SetObject(4, 4, 'Entrace');
  SaveLevel('data\levels\main.lev');
end;

procedure TForm2.InitPole;
begin
  image1.Canvas.Brush.Color := clBlack;
  image1.Canvas.Font.Name := 'Lucida Console';
  image1.Canvas.Font.Size := 8;
  image1.Canvas.Rectangle(1, 1, image1.Width, image1.Height);
  InitLevel('Floor');
end;

procedure TForm2.GetLevelInfo;
begin
  UpDown1.Position := lev.gamer_x;
  UpDown2.Position := lev.gamer_y;
  CheckBox1.Checked := lev.street;
  CheckBox2.Checked := lev.dark;
  CheckBox3.Checked := lev.sleep;
  edit3.text := lev.name;
  edit4.Text := lev.feeling;
  edit5.Text := DateToStr(lev.LastVisit);
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  if (opendialog1.InitialDir = '') then
    opendialog1.InitialDir := ExtractFilePath(ParamStr(0)) + 'data\levels\';
  if (opendialog1.Execute) then
  begin
    InitPole;
    LoadLevel(opendialog1.FileName);
    osv_all;
    GetLevelInfo;
    panel3.Show;
    panel1.Show;
    lev_filename := opendialog1.FileName;
    Hud('Успешно загружено из "' + lev_filename + '"');
    Caption := Application.Title + ' - [' + ExtractFileName(lev_filename) + ']';
    osvkletka(1, 1, LightCyan, true);
    GetCellInfo(1, 1);
  end;
end;

procedure TForm2.Button4Click(Sender: TObject);
begin
  if (savedialog1.InitialDir = '') then
    savedialog1.InitialDir := ExtractFilePath(ParamStr(0)) + '\data\levels\';
  if (savedialog1.Execute) then
  begin
    SaveLevel(savedialog1.FileName);
    lev_filename := savedialog1.filename;
    Hud('Успешно сохранено в "' + lev_filename + '"');
    Caption := Application.Title + ' - [' + ExtractFileName(lev_filename) + ']'
  end;
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
  InitPole;
  osv_all;
  panel3.Show;
  panel1.Show;
  Hud('Уровень инициализирован.');
  osvkletka(1, 1, LightCyan, true);
  GetCellInfo(1, 1);
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
begin
  UpDown1.Max := RESOLUTION_X;
  UpDown2.Max := RESOLUTION_Y;
  for i := 1 to TypesCount do
    ComboBox1.Items.Add(arr[i]);
  Combobox1.Sorted := true;
  for i := 1 to aData.MaxItemsCount do
  begin
    if ((ItemsArr[i].number >= TECHNO_MIN) and (ItemsArr[i].number <= TECHNO_MAX)) then
      ComboBox2.Items.Add('Технобраслет' + ItemsArr[i].name)
    else if ((ItemsArr[i].number >= FLOPPY_MIN) and (ItemsArr[i].number <= FLOPPY_MAX)) then
      ComboBox2.Items.Add('Нанокод' + ItemsArr[i].name)
    else if ((ItemsArr[i].number >= DRINK_MIN) and (ItemsArr[i].number <= DRINK_MAX)) then
      ComboBox2.Items.Add('Нанороботы' + ItemsArr[i].name)
    else
      ComboBox2.Items.add(ItemsArr[i].name);
  end;
  for i := 1 to MonstersCount do
    ComboBox3.Items.Add(MonArr[i].name);
end;

procedure TForm2.Hud(s: string);
begin
  StatusBar1.SimpleText := s;
end;

procedure TForm2.Button5Click(Sender: TObject);
begin
  if (lev_filename = '') then
    Button4Click(Sender)
  else
  begin
    SaveLevel(lev_filename);
    Hud('Успешно сохранено в "' + lev_filename + '"');
  end;
end;

procedure TForm2.GetCellInfo(x, y: integer);
var
  i: TKletka;
  enemy: TEnemy;
begin
  Form2.Caption := IntToStr(x) + ' ' + IntToStr(y);
  i := lev.map[x, y];
  if (i.vid <> '&') then
    label14.Caption := ' ' + i.vid
  else
    label14.Caption := ' &&';
  if (label16.Caption <> '&') then
    label16.Caption := ' ' + i.now
  else
    label16.Caption := ' &&';
  label21.Font.Color := i.AnObjectColor;
  if (i.AnObject <> '&') then
    label21.Caption := ' ' + i.AnObject + ' '
  else
    label21.Caption := ' && ';
  edit10.Text := IntToStr(i.levAttrz);
  edit11.Text := IntToStr(i.item);
  edit12.Text := IntToStr(i.ItemCount);
  edit13.Text := IntToStr(i.ObjAttrz);
  edit14.text := IntToStr(i.DoorCode);
  edit15.text := IntToStr(i.Light);
  edit16.text := IntToStr(i.ZapahType);
  edit17.Text := IntToStr(i.Zapah);
  edit18.Text := IntToStr(i.VoiceType);
  edit19.text := IntToStr(i.Voice);
  edit20.Text := IntToStr(i.EffectType);
  edit21.text := IntToStr(i.Effect);
  edit22.Text := IntToStr(i.StrIndex);
  CheckBox10.Checked := i.shadow;
  //Caption := IntToStr(i.attrz);
  CheckBox11.Checked := ((i.attrz and 1) > 0);
  CheckBox12.Checked := ((i.attrz and 2) > 0);
  CheckBox13.Checked := ((i.attrz and 8) > 0);
  CheckBox14.Checked := ((i.attrz and 16) > 0);
  CheckBox15.Checked := ((i.attrz and 64) > 0);
  CheckBox16.Checked := ((i.attrz and 128) > 0);
  chk1.Checked := ((i.attrz and 256) > 0);
  edit23.Text := IntToStr(i.Monster.montype);
  edit24.text := IntToStr(i.Monster.health);
  mon_info(i.Monster.montype, enemy);
  label34.Caption := '\ ' + IntToStr(enemy.health);
  edit25.text := i.Monster.monchar;
  edit26.Text := IntToStr(i.Monster.item);
  edit27.Text := IntToStr(i.Monster.count);
  edit28.Text := IntToStr(i.Monster.point);
  edit29.Text := IntToStr(i.Monster.gold);
  edit30.Text := IntToStr(i.Monster.Zak.ZakType);
  edit31.text := IntToStr(i.Monster.Zak.ZakLong);
  CheckBox17.Checked := i.Monster.shod;
  CheckBox18.Checked := ((i.Monster.Attrz and 1) > 0);
end;

procedure TForm2.Button10Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x > 1) then
    dec(x)
  else
    x := RESOLUTION_X;
  if (Y > 1) then
    dec(y)
  else
    y := RESOLUTION_Y;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button6Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (y > 1) then
    dec(y)
  else
    y := RESOLUTION_Y;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button11Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x < RESOLUTION_X) then
    inc(x)
  else
    x := 1;
  if (y > 1) then
    dec(y)
  else
    y := RESOLUTION_Y;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button7Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x < RESOLUTION_X) then
    inc(x)
  else
    x := 1;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button13Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x < RESOLUTION_X) then
    inc(x)
  else
    x := 1;
  if (y < RESOLUTION_Y) then
    inc(y)
  else
    y := 1;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button8Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (y < RESOLUTION_Y) then
    inc(y)
  else
    y := 1;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button12Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x > 1) then
    dec(x)
  else
    x := RESOLUTION_X;
  if (y < RESOLUTION_Y) then
    inc(y)
  else
    y := 1;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.Button9Click(Sender: TObject);
begin
  osvkletka(x, y, White, false);
  if (x > 1) then
    dec(x)
  else
    x := RESOLUTION_X;
  if (placelev) then
    Button14Click(Self);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
  edit6.Text := IntToStr(x);
  edit7.Text := IntToStr(y);
  GetCellInfo(x, y);
end;

procedure TForm2.ComboBox1Change(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to TypesCount - 1 do
    if (ComboBox1.Text = arr[i + 1]) then
    begin
      edit8.Text := KletArr[i + 1].TypeName;
      edit9.Text := KletArr[i + 1].Help;
      label11.Font.Color := KletArr[i + 1].col;
      label11.Caption := ' ' + KletArr[i + 1].c + ' ';
      if (KletArr[i + 1].c = '&') then
        label11.Caption := ' && ';
      CheckBox5.Checked := ((KletArr[i + 1].Attrz and 1) > 0);
      CheckBox6.Checked := ((KletArr[i + 1].Attrz and 2) > 0);
      CheckBox7.Checked := ((KletArr[i + 1].Attrz and 4) > 0);
      CheckBox8.Checked := ((KletArr[i + 1].Attrz and 8) > 0);
      CheckBox9.Checked := ((KletArr[i + 1].Attrz and 16) > 0);
      exit;
    end;
end;

procedure TForm2.Button14Click(Sender: TObject);
begin
  if (edit8.text <> '') then
    SetElement(x, y, edit8.Text);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
end;

procedure TForm2.Button15Click(Sender: TObject);
begin
  if (edit8.Text <> '') then
    SetObject(x, y, edit8.Text);
  osvkletka(x, y, LightCyan, true);
  GetCellInfo(x, y);
end;

procedure TForm2.Button16Click(Sender: TObject);
begin
  lev.map[x, y].vid := label11.caption[2];
  GetCellInfo(x, y);
end;

procedure TForm2.Button17Click(Sender: TObject);
begin
  lev.map[x, y].now := label11.caption[2];
  GetCellInfo(x, y);
end;

function CheckInt(s: string): boolean;
var
  i, error: integer;
begin
  val(s, i, error);
  Result := (error = 0);
end;

procedure TForm2.GetItemNumber;
var
  i: integer;
begin
  for i := 1 to MaxItemsCount do
    if (ItemsArr[i].number = temp) then
    begin
      ComboBox2.Text := ComboBox2.Items.Strings[i - 1];
      exit;
    end;
end;

procedure TForm2.ComboBox2Change(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to ComboBox2.Items.Count - 1 do
    if (ComboBox2.Text = ComboBox2.Items.Strings[i]) then
    begin
      edit32.text := ItemsArr[i + 1].name;
      edit33.Text := IntToStr(ItemsArr[i + 1].number);
      edit34.text := IntToStr(ItemsArr[i + 1].expa);
      case ItemsArr[i + 1].itemtype of
        ITPrimitive: edit35.Text := 'Холодное оружие';
        ITFire: edit35.Text := 'Пистолеты, атоматы';
        ITShells: edit35.text := 'Дробовики';
        ITNapalm: edit35.text := 'Огнеметы';
        ITBows: edit35.text := 'Арбалеты, самострелы';
        ITElectric: edit35.text := 'Электрооружие';
        ITRockets: edit35.text := 'Ракетометы';
        ITCell: edit35.text := 'Энергооружие';
        ITPsi: edit35.Text := 'Пси-оужие';
        ITArmor: edit35.Text := 'Куртки, жилетки';
        ITSapogi: edit35.Text := 'Сапоги';
        ITPlashch: edit35.Text := 'Накидка';
        ITShapka: edit35.Text := 'Шапка';
        ITTrousers: edit35.Text := 'Штаны';
        ITGloves: edit35.Text := 'Перчатки';
        ITAmulet: edit35.Text := 'Амулеты';
        ITNanoRobot: edit35.Text := 'Нанороботы';
        ITEat: edit35.Text := 'Еда';
        ITBioImplant: edit35.Text := 'Имплантанты';
        ITHealth: edit35.Text := 'Аптечки, бинты';
        ITAmmo: edit35.Text := 'Боеприпасы';
        ITMoney: edit35.Text := 'Деньги';
        ITKey: edit35.Text := 'Ключевые предметы';
        ITFloppy: edit35.Text := 'Нанокоды';
        ITBook: edit35.Text := 'Книги';
        ITTechno: edit35.Text := 'Технобраслеты';
        ITLitter: edit35.Text := 'Мусор';
      end;
      CheckBox19.Checked := ItemsArr[i + 1].IsShooting;
      edit36.Text := IntToStr(ItemsArr[i + 1].InOboyma);
      edit37.Text := IntToStr(ItemsArr[i + 1].ShootsCount);
      edit38.text := IntToStr(ItemsArr[i + 1].Effect);
      edit39.Text := IntToStr(ItemsArr[i + 1].cost);
      edit40.text := IntToStr(ItemsArr[i + 1].weight);
      edit41.Text := IntToStr(ItemsArr[i + 1].Frailty);
      Memo1.Text := ItemsArr[i + 1].help;
      label54.Font.Color := ItemsArr[i + 1].ItemColor;
      if (ItemsArr[i + 1].ItemChar <> '&') then
        label54.Caption := ' ' + ItemsArr[i + 1].ItemChar + ' '
      else
        label54.Caption := ' && ';
      exit;
    end;
end;

procedure TForm2.Button21Click(Sender: TObject);
begin
  panel4.Hide;
  panel1.Enabled := true;
end;

procedure TForm2.Button18Click(Sender: TObject);
begin
  called := 1;
  if (edit11.text <> '') then
    temp := StrToInt(edit11.Text)
  else
    temp := 0;
  GetItemNumber;  
  panel1.Enabled := false;
  panel4.Show;
end;

procedure TForm2.Button22Click(Sender: TObject);
begin
  called := 2;
  if (edit26.text <> '') then
    temp := StrToInt(edit26.Text)
  else
    temp := 0;
  GetItemNumber;  
  panel1.Enabled := false;
  panel4.Show;
end;

procedure TForm2.Button20Click(Sender: TObject);
begin
  case called of
    1: edit11.Text := edit33.Text;
    2: edit26.Text := edit33.Text; 
  end;
  panel4.Hide;
  panel1.Enabled := true;
end;

procedure TForm2.Button23Click(Sender: TObject);
begin
  panel5.Hide;
  panel1.Enabled := true;
end;

procedure TForm2.Button19Click(Sender: TObject);
begin
  called := 1;
  if (edit23.text <> '') then
    temp := StrToInt(edit23.Text)
  else
    temp := 0;
  GetEnemyInfo;  
  panel1.Enabled := false;
  panel5.Show;
end;

procedure TForm2.GetEnemyInfo;
var
  i: integer;
begin
  for i := 1 to MonstersCount do
    if (MonArr[i].montype = temp) then
    begin
      ComboBox3.Text := ComboBox3.Items.Strings[i];
      exit;
    end;
end;

procedure TForm2.Button25Click(Sender: TObject);
begin
  called := 2;
  if (edit16.text <> '') then
    temp := StrToInt(edit16.Text)
  else
    temp := 0;
  GetEnemyInfo;
  panel1.Enabled := false;
  panel5.Show;
end;

procedure TForm2.Button26Click(Sender: TObject);
begin
  called := 3;
  if (edit18.text <> '') then
    temp := StrToInt(edit18.Text)
  else
    temp := 0;
  GetEnemyInfo;  
  panel1.Enabled := false;
  panel5.Show;
end;

procedure TForm2.Button24Click(Sender: TObject);
begin
  case called of
    1: edit23.text := edit43.text;
    2: edit16.Text := edit43.Text;
    3: edit18.Text := edit43.text;
  end;
  panel5.Hide;
  panel1.Enabled := true;
end;

procedure TForm2.ComboBox3Change(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to ComboBox3.Items.Count - 1 do
    if (ComboBox3.Text = MonArr[i + 1].Name) then
    begin
      edit42.text := MonArr[i + 1].name;
      label65.Font.Color := MonArr[i + 1].charcolor;
      if (MonArr[i + 1].character <> '&') then
        label65.Caption := ' ' + MonArr[i + 1].character + ' '
      else
        label65.Caption := ' && ';
      edit43.text := IntToStr(MonArr[i + 1].montype);
      edit44.Text := IntToStr(MonArr[i + 1].expa);
      edit45.Text := IntToStr(MonArr[i + 1].health);
      edit46.Text := IntToStr(MonArr[i + 1].strength);
      edit47.text := IntToStr(MonArr[i + 1].rasseyannost);
      edit48.Text := IntToStr(MonArr[i + 1].nyuh);
      edit49.Text := IntToStr(MonArr[i + 1].sluh);
      case MonArr[i + 1].Intellect of
        AIHuman: edit50.Text := 'Человек';
        AIZomby: edit50.Text := 'Зомби';
        AIGrib: edit50.Text := 'Гриб';
        AIGhoul: edit50.Text := 'Призрак';
        AIWorm: edit50.Text := 'Червь';
        AITurret: edit50.Text := 'Турель';
        AIBomzh: edit50.Text := 'Бомж';
        AICat: edit50.Text := 'Кошка';
        AIDog: edit50.Text := 'Собака';
        AIIdiot: edit50.Text := 'Деревенщина';
        AIBeggar: edit50.Text := 'Нищий';
        AISeller: edit50.Text := 'Продавец';
      end;
      edit51.Text := IntToStr(MonArr[i + 1].protect_base);
      edit52.Text := IntToStr(MonArr[i + 1].protect_fire);
      edit53.Text := IntToStr(MonArr[i + 1].protect_electric);
      edit54.text := IntToStr(MonArr[i + 1].protect_psi);
      edit55.Text := IntToStr(MonArr[i + 1].chance_blood);
      edit56.text := IntToStr(MonArr[i + 1].chance_bolen);
      case MonArr[i + 1].Death of
        DDeath: edit57.text := 'Обыкновенная';
        DBloodDeath: edit57.text := 'Кровавая';
        DAllBloodDeath: edit57.Text := 'Гиперкровавая';
        DDisappear: edit57.text := 'Исчезновение';
        DLopnul: edit57.Text := 'Лопнул';
      end;
      edit58.Text := IntToStr(MonArr[i + 1].zapahStrength);
      edit59.Text := IntToStr(MonArr[i + 1].VoiceStrength);
      case MonArr[i + 1].sex of
        Male: edit60.text := 'Мужской';
        Female: edit60.Text := 'Женский';
        Other: edit60.Text := 'Средний';
      end;
      edit61.Text := IntToStr(MonArr[i + 1].Item);
      edit62.Text := IntToStr(MonArr[i + 1].Count);
      edit63.Text := IntToStr(MonArr[i + 1].w1Min);
      edit64.Text := IntToStr(MonArr[i + 1].w1Max);
      edit65.text := IntToStr(MonArr[i + 1].w2Min);
      edit66.text := IntToStr(MonArr[i + 1].w2Max);
      CheckBox20.Checked := ((MonArr[i + 1].Attrz and 1) > 0);
      CheckBox21.Checked := ((MonArr[i + 1].Attrz and 2) = 0);
      CheckBox22.Checked := ((MonArr[i + 1].Attrz and 4) > 0);
      CheckBox23.Checked := ((MonArr[i + 1].Attrz and 8) > 0);
      CheckBox24.Checked := ((MonArr[i + 1].Attrz and 16) > 0);
      CheckBox25.Checked := ((MonArr[i + 1].Attrz and 32) > 0);
      CheckBox26.Checked := ((MonArr[i + 1].Attrz and 64) > 0);
      CheckBox27.Checked := ((MonArr[i + 1].Attrz and 128) > 0);
      CheckBox28.Checked := ((MonArr[i + 1].Attrz and 256) > 0);
      CheckBox29.Checked := ((MonArr[i + 1].Attrz and 512) > 0);
      CheckBox30.Checked := ((MonArr[i + 1].Attrz and 1024) > 0);
      exit;
    end;
end;

procedure TForm2.Edit11Change(Sender: TObject);
begin
  if (CheckInt(edit11.Text)) then
  begin
    edit11.Color := White;
    lev.map[x, y].item := StrToInt(edit11.Text)
  end
  else
    edit11.Color := LightRed;
end;

procedure TForm2.Edit12Change(Sender: TObject);
begin
  if (CheckInt(edit12.Text)) then
  begin
    edit12.Color := White;
    lev.map[x, y].ItemCount := StrToInt(edit12.Text)
  end
  else
    edit12.Color := LightRed;
end;

procedure TForm2.Edit13Change(Sender: TObject);
begin
  if (CheckInt(edit13.Text)) then
  begin
    edit13.Color := White;
    lev.map[x, y].ObjAttrz := StrToInt(edit13.Text)
  end
  else
    edit13.Color := LightRed;
end;

procedure TForm2.Edit14Change(Sender: TObject);
begin
  if (CheckInt(edit14.Text)) then
  begin
    edit14.Color := White;
    lev.map[x, y].DoorCode := StrToInt(edit14.Text)
  end
  else
    edit14.Color := LightRed;
end;

procedure TForm2.Edit15Change(Sender: TObject);
begin
  if (CheckInt(edit15.Text)) then
  begin
    edit15.Color := White;
    lev.map[x, y].light := StrToInt(edit15.Text)
  end
  else
    edit15.Color := LightRed;
end;

procedure TForm2.Edit16Change(Sender: TObject);
begin
  if (CheckInt(edit16.Text)) then
  begin
    edit16.Color := White;
    lev.map[x, y].ZapahType := StrToInt(edit16.Text)
  end
  else
    edit16.Color := LightRed;
end;

procedure TForm2.Edit17Change(Sender: TObject);
begin
  if (CheckInt(edit17.Text)) then
  begin
    edit17.Color := White;
    lev.map[x, y].Zapah := StrToInt(edit17.Text)
  end
  else
    edit17.Color := LightRed;
end;

procedure TForm2.Edit18Change(Sender: TObject);
begin
  if (CheckInt(edit18.Text)) then
  begin
    edit18.Color := White;
    lev.map[x, y].VoiceType := StrToInt(edit18.Text)
  end
  else
    edit18.Color := LightRed;
end;

procedure TForm2.Edit19Change(Sender: TObject);
begin
  if (CheckInt(edit19.Text)) then
  begin
    edit19.Color := White;
    lev.map[x, y].VoiceType := StrToInt(edit19.Text)
  end
  else
    edit19.Color := LightRed;
end;

procedure TForm2.Edit20Change(Sender: TObject);
begin
  if (CheckInt(edit20.Text)) then
  begin
    edit20.Color := White;
    lev.map[x, y].EffectType := StrToInt(edit20.Text)
  end
  else
    edit20.Color := LightRed;
end;

procedure TForm2.Edit21Change(Sender: TObject);
begin
  if (CheckInt(edit21.Text)) then
  begin
    edit21.Color := White;
    lev.map[x, y].Effect := StrToInt(edit21.Text)
  end
  else
    edit21.Color := LightRed;
end;

procedure TForm2.Edit22Change(Sender: TObject);
begin
  if (CheckInt(edit22.Text)) then
  begin
    edit22.Color := White;
    lev.map[x, y].StrIndex := StrToInt(edit22.Text)
  end
  else
    edit22.Color := LightRed;
end;

procedure TForm2.Edit23Change(Sender: TObject);
begin
  if (CheckInt(edit23.Text)) then
  begin
    edit23.Color := White;
    lev.map[x, y].Monster.montype := StrToInt(edit23.Text)
  end
  else
    edit23.Color := LightRed;
end;

procedure TForm2.Edit24Change(Sender: TObject);
begin
  if (CheckInt(edit24.Text)) then
  begin
    edit24.Color := White;
    lev.map[x, y].Monster.health := StrToInt(edit24.Text)
  end
  else
    edit24.Color := LightRed;
end;

procedure TForm2.Edit25Change(Sender: TObject);
begin
  if (edit25.Text <> '') then
    lev.map[x, y].Monster.monchar := edit25.Text[1]
  else
    lev.map[x, y].Monster.monchar := #0;
end;

procedure TForm2.Edit26Change(Sender: TObject);
begin
  if (CheckInt(edit26.Text)) then
  begin
    edit26.Color := White;
    lev.map[x, y].Monster.item := StrToInt(edit26.Text)
  end
  else
    edit26.Color := LightRed;
end;

procedure TForm2.Edit27Change(Sender: TObject);
begin
  if (CheckInt(edit27.Text)) then
  begin
    edit27.Color := White;
    lev.map[x, y].Monster.count := StrToInt(edit27.Text)
  end
  else
    edit27.Color := LightRed;
end;

procedure TForm2.Edit28Change(Sender: TObject);
begin
  if (CheckInt(edit28.Text)) then
  begin
    edit28.Color := White;
    lev.map[x, y].Monster.point := StrToInt(edit28.Text)
  end
  else
    edit28.Color := LightRed;
end;

procedure TForm2.Edit29Change(Sender: TObject);
begin
  if (CheckInt(edit29.Text)) then
  begin
    edit29.Color := White;
    lev.map[x, y].Monster.gold := StrToInt(edit29.Text)
  end
  else
    edit29.Color := LightRed;
end;

procedure TForm2.Edit30Change(Sender: TObject);
begin
  if (CheckInt(edit30.Text)) then
  begin
    edit30.Color := White;
    lev.map[x, y].Monster.Zak.ZakType := StrToInt(edit30.Text)
  end
  else
    edit30.Color := LightRed;
end;

procedure TForm2.Edit31Change(Sender: TObject);
begin
  if (CheckInt(edit31.Text)) then
  begin
    edit31.Color := White;
    lev.map[x, y].Monster.Zak.ZakLong := StrToInt(edit31.Text)
  end
  else
    edit31.Color := LightRed;
end;

procedure TForm2.Edit3Change(Sender: TObject);
begin
  lev.name := edit3.Text;
end;

procedure TForm2.Edit4Change(Sender: TObject);
begin
  lev.feeling := edit4.text;
end;

procedure TForm2.Edit5Change(Sender: TObject);
begin
  lev.LastVisit := StrToDateTime(edit5.Text);
end;

procedure TForm2.Edit1Change(Sender: TObject);
begin
  if (CheckInt(edit1.text)) then
  begin
    lev.gamer_x := StrToInt(edit1.text);
    edit1.Color := White;
  end
  else
    Edit1.Color := LightRed;
end;

procedure TForm2.Edit2Change(Sender: TObject);
begin
  if (CheckInt(edit2.text)) then
  begin
    lev.gamer_y := StrToInt(edit2.text);
    edit2.Color := White;
  end
  else
    Edit2.Color := LightRed;
end;

procedure TForm2.CheckBox15MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox15.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 64)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 64);
end;

procedure TForm2.CheckBox10MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.map[Editor1.x, Editor1.y].shadow := not CheckBox10.Checked;
end;

procedure TForm2.CheckBox11MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox11.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 1)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz);
end;

procedure TForm2.CheckBox13MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox13.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 8)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 8);
end;

procedure TForm2.CheckBox14MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox14.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 16)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 16);
end;

procedure TForm2.CheckBox12MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox12.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 2)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 2);
end;

procedure TForm2.CheckBox16MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox16.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 128)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 128);
end;

procedure TForm2.CheckBox17MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.map[Editor1.x, Editor1.y].Monster.shod := not CheckBox17.Checked;
end;

procedure TForm2.CheckBox18MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox18.Checked) then
    inc(lev.map[Editor1.x, Editor1.y].Monster.Attrz)
  else
    dec(lev.map[Editor1.x, Editor1.y].Monster.attrz);
end;

procedure TForm2.CheckBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.street := not CheckBox1.Checked;
end;

procedure TForm2.CheckBox2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.dark := not CheckBox2.Checked;
end;

procedure TForm2.CheckBox3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.groza := not CheckBox3.Checked;
end;

procedure TForm2.CheckBox4MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lev.sleep := not CheckBox4.Checked;
end;

procedure TForm2.Edit10KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (CheckInt(edit10.Text)) then
  begin
    edit10.Color := White;
    lev.map[x, y].levAttrz := StrToInt(edit10.Text)
  end
  else
    edit10.Color := LightRed;
end;

procedure TForm2.Button3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_RIGHT) then
    self.Button7Click(self);
end;

procedure TForm2.edit68KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (key = VK_LEFT) then
    button9click(sender)
  else if (key = VK_RIGHT) then
    button7click(Sender)
  else if (key = VK_UP) then
    button6click(Sender)
  else if (key = VK_DOWN) then
    button8click(Sender)
  else if (key = VK_RETURN) then
    button15Click(Sender)
  else if (key = VK_SPACE) then
    button14click(Sender);
  if (key in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_SPACE]) then
    if (placeinhouse) then
      lev.map[x, y].attrz := lev.map[x, y].attrz or 2;
  Key := 0;
  edit68.Text := '';
end;

procedure TForm2.btn1Click(Sender: TObject);
begin
  if (btn1.Caption = 'Не став.') then
    btn1.Caption := 'Ставить'
  else
    btn1.Caption := 'Не став.';
  placelev := not placelev;
end;

procedure TForm2.edit68KeyPress(Sender: TObject; var Key: Char);
begin
  if (key = 'h') then
  begin
    placeinhouse := not placeinhouse;
    if (placeinhouse) then
      label83.Caption := 'Поле управления(h)'
    else
      label83.Caption := 'Поле управления';
  end;
  Key := #0;
end;

procedure TForm2.chk1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (not CheckBox16.Checked) then
    lev.map[Editor1.x, Editor1.y].attrz := (lev.map[Editor1.x, Editor1.y].attrz or 256)
  else
    dec(lev.map[Editor1.x, Editor1.y].attrz, 256);
end;

end.
