unit inventar;

interface

uses
  sysutils, loadz, svet, attack;

procedure showinv;
procedure shownow;
procedure sell;
procedure buy(montype: integer);
procedure HealthyHealth;
procedure aTradeMenu(aType: word);
procedure dropItem2(x, y, number, count: integer);
procedure RegularizeThings;
procedure SetImplants;

implementation

uses
  MyCRT, NewUnit1, aData;

var
  startnum, endnum: integer;
  aTrading: boolean = false;
  arr: TItemsArray;

function FindFirstSlot: integer;
begin
  for Result := 1 to MAXITEMS do
    if data.inventory[Result].number = 0 then
      exit;
  FindFirstSlot := -1;
end;

function IsExitAfterUsing(num: integer): boolean;
var
  item: TItem;
begin
  iteminfo(num, item);
  IsExitAfterUsing := ((item.Attrz and 1) > 0);
end;

procedure RegularizeThings;
var
  i, j, k: integer;
  Slot: TSlot;

begin
  for i := 1 to MAXITEMS do
  begin
    if data.inventory[i].number <> 0 then
    begin
      Slot := data.inventory[i];
      data.inventory[i] := EmptySlot;
      j := FindFirstSlot;
      data.inventory[j] := Slot;
    end;
  end;
  k := 1;
  while (data.inventory[k].number <> 0) do
    inc(k);
  dec(k);
  for i := 1 to k - 1 do
    for j := 1 to k - i do
      if (data.inventory[j].number > data.inventory[j + 1].number) then
      begin
        Slot := data.inventory[j];
        data.inventory[j] := data.inventory[j + 1];
        data.inventory[j + 1] := Slot;
      end;
end;

procedure AList;
var
  i: integer;
  item: TItem;
begin
  textcolor(white);
  for i := 1 to MAXTRADEITEMS do
  begin
    gotoxy(3, i + 2);
    iteminfo(arr[i].number, item);
    TextColor(item.ItemColor);
    write(IntToStr(i div 10) + IntToStr(i mod 10) + ') ' + item.name);
    if (item.IsShooting) and (item.InOboyma > 0) then
      write(' [' + IntToStr(arr[i].ammo) + '\' + IntToStr(item.inOboyma) + ']')
    else if (arr[i].count > 1) then
      write(' (' + IntToStr(arr[i].count) + ')');
    while wherex < RESOLUTION_X div 2 - 2 do
      write(' ');
  end;
end;

procedure WriteAnActive(num: byte; AColor: byte; anActive: boolean);
var
  Item: TItem;
  x, y: integer;
begin
  textcolor(AColor);
  gotoxy(2, num + 2);
  iteminfo(arr[num].number, item);
  if (anActive) then
    write('>' + IntToStr(num div 10) + IntToStr(num mod 10) + ')[' + item.name)
  else
    write(' ' + IntToStr(num div 10) + IntToStr(num mod 10) + ') ' + item.name);
  if (item.IsShooting) and (item.InOboyma > 0) then
      write(' [' + IntToStr(arr[num].ammo) + '\' + IntToStr(item.inOboyma) + ']')
  if (arr[num].count > 1) then
      write(' (' + IntToStr(arr[num].count) + ')');
  if (anActive) then
    write(']');
  while wherex < RESOLUTION_X div 2 do
    write(' ');
  x := wherex;
  y := wherey;
  gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 3);
  TextColor(White);
  Write(STR_YOUR_GOLD + IntToStr(data.money));
  gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 2);
  Write(STR_YOUR_HEALTH + IntToStr(data.health) + '\' + IntToStr(data.max_health));
  gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 1);
  write(STR_YOUR_WEIGHT + Weight(GetWeight) + '\' + Weight(data.maxweight)) + STR_KG;
  gotoxy(x, y);
  PasteScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
end;

function anstoim(num: integer): word;
var
  item: TItem;
  cost: word;
begin
  iteminfo(num, item);
  cost := item.cost;
  if (data.Intellect < 100) then
    Result := item.cost + ((item.cost * (200 - data.Intellect * 2)) div 100)
  else
    Result := item.cost;
end;

procedure WriteClean;
var
  x, y: byte;
  i: integer;
begin
  x := wherex;
  y := wherey;
  gotoxy(1, RESOLUTION_Y + 1);
  for i := 1 to RESOLUTION_X - 1 do
    Write(' ');
  gotoxy(x, y);
end;

procedure WriteCost(Active: integer);
var
  x, y: byte;
begin
  x := wherex;
  y := wherey;
  WriteClean;
  gotoxy(2, RESOLUTION_y + 1);
  textcolor(white);
  write(STR_COST_1 + instr(anstoim(arr[Active].number)) + STR_COST_2 + BuySellMonetsSklon(anstoim(arr[Active].number)));
  gotoxy(x, y);
end;

function addinv(d: TSlot): boolean;
var
  f, j: integer;
  item: TItem;
begin
  iteminfo(d.number, item);
  result := true;
  j := -1;
  if (isCountable(item)) then
  begin
    j := FirstItemSlot(item);
    if (j = -1) then
      j := FirstEmptySlot;
  end
  else
    j := FirstEmptySlot;
  if (j = -1) then
    Result := false
  else
  begin
    if (data.inventory[j].number <> 0) then
      Inc(data.inventory[j].count, d.count)
    else
      data.inventory[j] := d;
    if (Assigned(item.onPickup)) then
      for f := 1 to d.count do
        item.OnPickup(0, j);
    if (d.ammo > 0) then
    begin
      iteminfo(item.AmmoType, item);
      for f := 1 to d.count do
        for j := 1 to d.ammo do
          item.OnPickup(0, 0);
    end;
  end;
end;

procedure SellItem(Active: integer; count: integer);
var
  cost: integer;
  i: integer;
  item: TItem;
  temp: integer;
  slot: TSlot;
begin
  cost := anstoim(arr[Active].number);
  iteminfo(arr[Active].number, item);
  if ((item.IsShooting) and (item.InOboyma > 0) and (arr[Active].ammo > 0)) then
  begin
    iteminfo(item.AmmoType);
    for i := 1 to arr[Active].ammo do
      cost := cost + (anstoim(item.number));
  end;
  cost := cost * count;
  if (data.money < cost) then
    hudmessage(STR_I_HAVENT_ENOUGH_MONEY, MT_ERROR)
  else
  begin
    temp := hasinv(arr[Active], count);
    if (temp = -1) then
      hudmessage(STR_I_HAVENT_INV, MT_ERROR)
    else if (temp = -2) then
      hudmessage(STR_TOO_HEAVY, MT_ERROR);
    else
    begin
      Dec(data.money, cost);
      slot := arr[Active];
      slot.count := count;
      addinv(slot);
    end;
  end;
end;

procedure MyReadLn(var s: string);
var
  c: char;
begin
  s := '';
  repeat
    c := readkey;
    if (Length(s) < 10) and (c in ['0'..'9']) then
    begin
      s := s + c;
      write(c);
    end
    else if (c = KEY_BACKSPACE) and (Length(s) > 0) then
    begin
      s := Copy(s, 1, Length(s) - 1);
      gotoxy(wherex - 1, wherey);
      write(' ');
      gotoxy(wherex - 1, wherey);
    end;
  until (c = #27) or (c = #13);
  if (c = #27) then
    s := 'No'
  else if (c = #13) and (s = '') then
    s := '1';
end;

procedure aSell(Active: integer);
var
  StrCount: string;
  aCount: integer;
  error: integer;
  item: TItem;
begin
  iteminfo(arr[Active].number, item);
  if (arr[Active].count > 1) then
  begin
    gotoxy(1, RESOLUTION_Y + 1);
    textcolor(white);
    for error := wherex to RESOLUTION_X do
      WriteChrXY(error, RESOLUTION_Y + 1, ' ');
    write(STR_INPUT_COUNT);
    MyReadLn(StrCount);
    if (StrCount = 'No') then
    begin
      hudmessage('', MT_TEXT, false);
      exit;
    end;
    val(StrCount, aCount, error);
    if (error <> 0) then
      hudmessage(STR_INCORRECT_INPUT, MT_ERROR)
    else if (aCount > arr[Active].count) then
      hudmessage(STR_I_HAVENT_ENOUGH, MT_ERROR)
    else
      SellItem(Active, aCount);
  end
  else
    SellItem(Active, arr[Active].count);
end;

function GetNextWord(s: string; startfrom: integer): string;
var
  i: integer;
  res: string;
  len: integer;
begin
  res := '';
  len := Length(s);
  i := startfrom;
  while (i <= len) and (s[i] = ' ') do
  begin
    res := res + s[i];
    inc(i);
  end;
  while (i <= len) and (s[i] <> ' ') do
  begin
    res := res + s[i];
    inc(i);
  end;
  Result := res;
end;

function ukor(s: string): string;
var
  i, j: integer;
begin
  Result := '';
  for i := 1 to Length(s) do
    if (s[i] <> ' ') then
    begin
      for j := i to Length(s) do
        Result := Result + s[j];
      exit;
    end;
end;

procedure ZapolnStroka;
begin
  while wherex < (RESOLUTION_X) do
    write(' ');
end;

procedure WriteHelp(s: string; NewXPos: byte = (RESOLUTION_X div 2) + 2);
var
  StartPos: integer;
  xPos: integer;
  st: string;
  z: integer;
begin
  StartPos := 1;
  z := Length(s);
  while (StartPos <= z) do
  begin
    xPos := wherex;
    st := GetNextWord(s, StartPos);
    if xPos + Length(st) < RESOLUTION_X - 2 then
    begin
      write(st);
      StartPos := StartPos + Length(st);
    end
    else
    begin
      ZapolnStroka;
      GotoXY(NewXPos, Wherey + 1);
      StartPos := StartPos + Length(st);
      write(ukor(st));
    end;
  end;
end;

function podh(anItem: integer; navik: word): integer;
{
  weapon - 1
  bracelet - 2
  armor - 3
  legs - 4
  spina - 5
  baska - 6
  trousers - 7
  gloves - 8
  amulet - 9
  nano - 10
  bioimplant - 11
  floppy - 12
  book - 13
  health - 14
  eat - 15
  ammo - 16
}
var
  aType: TItemType;
begin
  aType := GetItemType(anItem);
  if (aType = ITWeapon) and (data.weapon >= navik) then result := 1
  else if (aType = ITTechno) then result := 2
  else if (aType = ITArmor) then result := 3
  else if (aType = ITSapogi) then result := 4
  else if (aType = ITPlashch) then result := 5
  else if (aType = ITShapka) then result := 6
  else if (aType = ITTrousers) then result := 7
  else if (aType = ITGloves) then result := 8
  else if (aType = ITAmulet) then result := 9
  else if (aType = ITNanoRobot) then result := 10
  else if (aType = ITBioImplant) and (data.ImplantsPerk) then result := 11
  else if (aType = ITFloppy) then result := 12
  else if (aType = ITBook) then result := 13
  else if (aType = ITHealth) then result := 14
  else if (aType = ITEat) then result := 15
  else if (aType = ITAmmo) then result := 16
  else result := 0;
end;

function GetItemString(num: integer): string;
var
  aType: TItemType;
begin
  aType := GetItemType(num);
  case aType of
    ITPrimitive: GetItemString := STR_SKILL_WEAPON;
    ITBows, ITFire, ITShells, ITRockets: GetItemString := STR_SKILL_WEAPON;
    ITElectric, ITCell: GetItemString := STR_SKILL_WEAPON;
    ITPsi: GetItemString := STR_SKILL_WEAPON;
  end;
end;

function CheckForNotHelp(num: integer): boolean;
begin
  Result := ((num >= TECHNO_MIN) and (num <= TECHNO_MAX) and (data.TechnoZ[num - TECHNO_MIN + 1].examined))
    or (num < TECHNO_MIN) or (num > TECHNO_MAX);
  if Result then
    Result := Result and (((num >= FLOPPY_MIN) and (num <= FLOPPY_MAX) and (data.NanoZ[num - FLOPPY_MIN + 1].examined))
      or (num < FLOPPY_MIN) or (num > FLOPPY_MAX));
  if Result then
    Result := Result and (((num >= DRINK_MIN) and (num <= DRINK_MAX) and (data.DrinkZ[num - DRINK_MIN + 1].examined))
      or (num < DRINK_MIN) or (num > DRINK_MAX));
end;

procedure DrawItemInfo(num: integer; const RES: integer = (RESOLUTION_X div 2) + 2);
var
  Item: TItem;
  temp: Integer;
  temps: string;
begin
  textcolor(white);
  GotoXY(RES, 3);
  ItemInfo(num, Item);
  if (num >= TECHNO_MIN) and (num <= TECHNO_MAX) then
  begin
    write(STR_TECHNOZ[data.technoZ[num - TECHNO_MIN + 1].num] + STR_TECHNO);
    if data.TechnoZ[num - TECHNO_MIN + 1].examined then
      write(item.name);
  end
  else if (num >= FLOPPY_MIN) and (num <= FLOPPY_MAX) then
  begin
    write(STR_PROG);
    if (data.NanoZ[num - FLOPPY_MIN + 1].examined) then
      write(item.name)
    else
      write(STR_NANOZ[data.NanoZ[num - FLOPPY_MIN + 1].num]);
  end
  else if (num >= DRINK_MIN) and (num <= DRINK_MAX) then
  begin
    if data.DrinkZ[num - DRINK_MIN + 1].examined then
      write(STR_DRINK + item.name)
    else
      write(STR_DRINKZ[data.DrinkZ[num - DRINK_MIN + 1].num] + ' ' + STR_DRINK);
  end
  else
    write(Item.name);
  ZapolnStroka;
  GotoXY(RES, 5);
  if (Gettype(num) = 'Weapon') then
    write(STR_HELP_ATTACK + IntToStr(Item.effect))
  else if (Gettype(num) = 'Armor') then
    write(STR_HELP_DEFENCE + IntToStr(Item.effect));
  ZapolnStroka;
  GotoXY(RES, 6);
  if (item.expa > 0) and (not data.TradeImplants) then
  begin
    write(STR_MIN_SKILL);
    if podh(num, item.expa) = 0 then
      textcolor(LightRed)
    else
      textcolor(white);
    write(GetItemString(num) + ' (' + IntToStr(item.expa) + ')');
    TextColor(white);
    ZapolnStroka;
    GotoXY(RES, wherey + 1);
  end
  else if (data.TradeImplants) then
  begin
    write(STR_IT_WILL_COST);
    temp := (item.cost - (data.trading * 5)) * item.expa * 5;
    if (temp < 1) then
      temp := 1;
    Write(IntToStr(temp));
    write(STR_MONETS);
    GoToXY(RES, WhereY + 1);
  end;
  write(STR_HELP_WEIGHT + Weight(Item.weight) + STR_KG);
  ZapolnStroka;
  GotoXY(RES, WhereY + 1);
  if CheckForNotHelp(item.number) then
      WriteHelp(Item.help, RES);
end;

procedure DrawFullHelp(num: integer; const RES: integer = 3);
var
  Item: TItem;
begin
  textcolor(white);
  GotoXY(RES, 3);
  ItemInfo(num, Item);
  if (num >= TECHNO_MIN) and (num <= TECHNO_MAX) then
  begin
    write(STR_TECHNOZ[data.technoZ[num - TECHNO_MIN + 1].num] + STR_TECHNO);
    if data.TechnoZ[num - TECHNO_MIN + 1].examined then
      write(item.name);
  end
  else if (num >= FLOPPY_MIN) and (num <= FLOPPY_MAX) then
  begin
    write(STR_PROG);
    if (data.NanoZ[num - FLOPPY_MIN + 1].examined) then
      write(item.name)
    else
      write(STR_NANOZ[data.NanoZ[num - FLOPPY_MIN + 1].num]);
  end
  else if (num >= DRINK_MIN) and (num <= DRINK_MAX) then
  begin
    if data.DrinkZ[num - DRINK_MIN + 1].examined then
      write(STR_DRINK + item.name)
    else
      write(STR_DRINKZ[data.DrinkZ[num - DRINK_MIN + 1].num] + ' ' + STR_DRINK);
  end
  else
    write(Item.name);
  ZapolnStroka;
  GotoXY(RES, 5);
  if (Gettype(num) = 'Weapon') then
    write(STR_HELP_ATTACK + IntToStr(Item.effect))
  else if (Gettype(num) = 'Armor') then
    write(STR_HELP_DEFENCE + IntToStr(Item.effect));
  ZapolnStroka;
  GotoXY(RES, 6);
  if item.expa > 0 then
  begin
    write(STR_MIN_SKILL);
    if podh(num, item.expa) = 0 then
      textcolor(LightRed)
    else
      textcolor(white);
    write(GetItemString(num) + ' (' + IntToStr(item.expa) + ')');
    TextColor(white);
    ZapolnStroka;
    GotoXY(RES, wherey + 1);
  end;
  GotoXY(RES, WhereY + 1);
  write(STR_HELP_WEIGHT + IntToStr(Item.weight));
  ZapolnStroka;
  GotoXY(RES, WhereY + 1);
  if CheckForNotHelp(num) then
    WriteHelp(Item.help, RES);
  while (wherey < (RESOLUTION_Y - 2)) do
  begin
    ZapolnStroka;
    Gotoxy(RES, wherey + 1);
  end;
end;

procedure ClearItemInfo(const RES: integer = (RESOLUTION_X div 2) + 2);
var
  i, j: byte;
begin
  GotoXY(RES, 2);
  for j := 2 to RESOLUTION_Y - 1 do
  begin
    for i := RES to RESOLUTION_X - 1 do
      write(' ');
    GotoXY(RES, wherey + 1);
  end;
end;

procedure buy(montype: integer);
var
  Active: integer;
  c: char;
  item: TItem;
  i: integer;
begin
  case montype of
    TRADER_WEAPONS: arr := data.trade_weapons;
    TRADER_ARMOR: arr := data.trade_armor;
    TRADER_OTHER: arr := data.trade_other;
  end;
  clrscr;
  textcolor(LightGray);
  AList;
  Active := 1;
  Ramka(white, 8);
  for i := 2 to RESOLUTION_Y do
    WriteChrXY(RESOLUTION_X div 2, i, '|');
  WriteChrXY(RESOLUTION_X div 2, 1, '+');
  WriteChrXY(RESOLUTION_X div 2, RESOLUTION_Y, '+');
  CopyScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
  repeat
    iteminfo(arr[active].number, item);
    WriteAnActive(Active, Cyan, true);
    if (arr[active].number <> 0) then
      DrawItemInfo(arr[active].number);
    if arr[active].number <> 0 then
      WriteCost(Active)
    c := readkey;
    WriteAnActive(Active, Item.ItemColor, false);
    case c of
      KEY_UP:
      begin
        dec(Active);
        if (Active < 1) then
          Active := MAXTRADEITEMS;
      end;
      KEY_DOWN:
      begin
        inc(Active);
        if (Active > MAXTRADEITEMS) then
          Active := 1;
      end;
      KEY_RETURN:
      begin
        if (arr[Active].number <> 0) then
          aSell(Active);
      end;
    end;
  until (c = #27);
  case montype of
    TRADER_WEAPONS: data.trade_weapons := arr;
    TRADER_ARMOR: data.trade_armor := arr;
    TRADER_OTHER: data.trade_other := arr;
  end;
end;


procedure ATradeList;
var
  i: byte;
begin
  textcolor(white);
  for i := 1 to Length(STR_WHAT) do
  begin
    gotoxy(3, 2 + i);
    write(STR_WHAT[i]);
  end;
end;

procedure DrawTradeActive(num, color: byte);
begin
  textcolor(color);
  gotoxy(3, 2 + num);
  write(STR_WHAT[num]);
end;

procedure HealthyHealth;
var
  cost: integer;
  c: char;
begin
  clrscr;
  if (data.health = data.max_health) and (data.bolezn = 0) and (data.bloodchosen = 0) then
  begin
    textcolor(white);
    write(STR_YOU_ALREADY_HEALTH);
    readkey;
    exit;
  end;
  cost := (data.max_health - data.health) * ((data.max_health - data.health) * (MAX_SKILL - data.intellect) div 100));
  if (data.Desease > 0) then
    cost := cost + (data.Desease * (5 - (data.intellect div 20)));
  if (data.bloodchosen > 0) then
    cost := cost + (data.bloodchosen * (20 - (data.intellect div 5)));
  write(STR_THIS_COST_1 + instr(cost) + STR_THIS_COST_2);
  repeat
    c := readkey;
  until (c in ['y', 'n', #13, #27]);
  case c of
    'y', #13:
    begin
      if (data.money > cost) then
      begin
        dec(data.money, cost);
        data.bloodchosen := 0;
        data.Desease := 0;
        data.health := data.max_health;
        gotoxy(1, 3);
        write(STR_HEALTH_SUCCESS);
        readkey;
      end
      else
      begin
        gotoxy(1, 3);
        write(STR_NOT_HEALTH_MONEY);
        readkey;
      end;
    end;
  end;
end;

procedure aTradeMenu(aType: word);
var
  active: byte;
  c: char;
begin
  clrscr;
  textcolor(white);
  writeln(' ' + STR_WHAT_YOU_WANT);
  writeln;
  aTradeList;
  active := 1;
  repeat
    DrawTradeActive(active, LightRed);
    c := readkey;
    DrawTradeActive(active, white);
    if (c = KEY_UP) then
    begin
      dec(active);
      if (active < 1) then
        active := Length(STR_WHAT);
    end
    else if (c = KEY_DOWN) then
    begin
      inc(active);
      if (active > Length(STR_WHAT)) then
        active := 1;
    end
    else if (c = KEY_RETURN) then
    begin
      case Active of
        1: Sell;
        2: Buy(TRADER_WEAPONS);
        3: Buy(TRADER_ARMOR);
        4: Buy(TRADER_OTHER);
        5: HealthyHealth;
        6: exit;
      end;
      clrscr;
      textcolor(white);
      writeln(' ' + STR_WHAT_YOU_WANT);
      writeln;
      aTradeList;
    end;
  until (c = KEY_ESCAPE);
end;

procedure sell;
begin
  aTrading := true;
  showinv;
end;

procedure dropitem(x, y: shortint; num: integer);
var
  j: integer;
  item: TItem;
begin
  if cur_lev.map[data.posx + x, data.posy + y].item = 0 then
  begin
    iteminfo(data.inventory[num].number, item);
    if Assigned(item.OnDrop) then
      for j := 1 to data.inventory[num].count do
        item.OnDrop(data.posx + x, data.posy + y);
    cur_lev.map[data.posx + x, data.posy + y].item := data.inventory[num].number;
    cur_lev.map[data.posx + x, data.posy + y].ItemCount := data.inventory[num].count;
  end;
  if data.inventory[num].number = ITEM_IRGLASSES then
    data.infrared := false;
  data.inventory[num].number := 0;
  data.inventory[num].count := 0;
end;

procedure dropitemnow(x, y: shortint; var num: integer; anChar: byte = 0);
var
  item: TItem;
  IsInInv: boolean;
begin
  IsInInv := data.IsInInv;
  data.IsInInv := true;
  if cur_lev.map[data.posx + x, data.posy + y].item = 0 then
  begin
    cur_lev.map[data.posx + x, data.posy + y].item := num;
    cur_lev.map[data.posx + x, data.posy + y].ItemCount := 1;
    iteminfo(num, item);
    if Assigned(item.OnUnWear) then
    begin
      if ((item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX)) then
        item.OnUnWear(0, anChar)
      else
        item.OnUnWear(data.posx + x, data.posy + y);
    end;
    if Assigned(item.OnDrop) then
      item.OnDrop(data.posx + x, data.posy + y);
  end;
  num := 0;
  data.IsInInv := IsInInv;
end;

function MayDropNow(x, y: shortint): boolean;
begin
  MayDropNow := (cur_lev.map[data.posx + x, data.posy + y].item = 0);
end;

procedure DropNow(var num: integer; anChar: byte = 0);
begin
  if num = 0 then
    exit;
  if maydropnow(0, 0) then
    dropitemnow(0, 0, num, anChar)
  else if maydropnow(0, -1) then
    dropitemnow(0, -1, num, anChar)
  else if maydropnow(0, 1) then
    dropitemnow(0, 1, num, anChar)
  else if maydropnow(-1, 0) then
    dropitemnow(-1, 0, num, anChar)
  else if maydropnow(1, 0) then
    dropitemnow(1, 0, num, anChar)
  else if maydropnow(-1, -1) then
    dropitemnow(-1, -1, num, anChar)
  else if maydropnow(-1, 1) then
    dropitemnow(-1, 1, num, anChar)
  else if maydropnow(1, -1) then
    dropitemnow(1, -1, num, anChar)
  else if maydropnow(1, 1) then
    dropitemnow(1, 1, num, anChar)
  else
    hudmessage(STR_CANT_DROP_HERE, MT_ERROR);
end;

function IsMayDropMany(i: integer): boolean;
begin
  IsMayDropMany := false;
end;

function maydrop(x, y: shortint; item: byte): boolean;
begin
  maydrop := ((cur_lev.map[data.posx + x, data.posy + y].lev = GetFloorChar)
      and ((cur_lev.map[data.posx + x, data.posy + y].item = 0)
        or ((cur_lev.map[data.posx + x, data.posy + y].item =
          data.inventory[item].number) and (IsMayDropMany(data.inventory[item].number)))));
end;

function MayDropItem(x, y: integer): boolean;
begin
  MayDropItem := ((cur_lev.map[x, y].item = 0) and (IsFloor(x, y)) and (x in [2..RESOLUTION_X - 1]) and (y in [2..RESOLUTION_Y - 1]));
end;

procedure DropItem3(x, y: integer; item: TSlot);
begin
  cur_lev.map[x, y].item := item;
  if (x = data.posx) and (y = data.posy) then
    hudmessage(STR_UNDER_LEGS, MT_TEXT);
end;

type
  Point = record
    x, y: Shortint;
  end;
var
  arr2: array of Point;

procedure AddPoint(x, y: shortint);
begin
  SetLength(arr2, Length(arr2) + 1);
  arr2[Length(arr2) - 1].x := x;
  arr2[Length(arr2) - 1].y := y;
end;

procedure dropItem2(x, y: integer; item: TSlot);
var
  i: integer;
begin
  SetLength(arr2, 0);
  if maydropItem(x, y - 1) then
    AddPoint(0, -1);
  if maydropItem(x, y + 1) then
    AddPoint(0, 1);
  if maydropItem(x - 1, y) then
    AddPoint(-1, 0);
  if maydropItem(x + 1, y) then
    AddPoint(1, 0);
  if maydropItem(x - 1, y - 1) then
    AddPoint(-1, -1);
  if maydropItem(x - 1, y + 1) then
    AddPoint(-1, 1);
  if maydropItem(x + 1, y - 1) then
    AddPoint(1, -1);
  if maydropItem(x + 1, y + 1) then
    AddPoint(1, 1);
  if (Length(arr) = 0) and (maydropItem(x, y)) then
    dropitem3(x, y, item)
  else if Length(arr) > 0 then
  begin
    i := Random(Length(arr2));
    dropitem3(x + arr2[i].x, y + arr2[i].y, item);
  end;
end;

procedure drop(number: byte);
begin
  if data.inventory[number].number = 0 then
  begin
    hudmessage(STR_NOTHING_TO_DROP, MT_INFO);
    exit;
  end;
  if maydrop(0, 0, number) then
    dropitem(0, 0, number)
  else if maydrop(0, -1, number) then
    dropitem(0, -1, number)
  else if maydrop(0, 1, number) then
    dropitem(0, 1, number)
  else if maydrop(-1, 0, number) then
    dropitem(-1, 0, number)
  else if maydrop(1, 0, number) then
    dropitem(1, 0, number)
  else if maydrop(-1, -1, number) then
    dropitem(-1, -1, number)
  else if maydrop(-1, 1, number) then
    dropitem(-1, 1, number)
  else if maydrop(1, -1, number) then
    dropitem(1, -1, number)
  else if maydrop(1, 1, number) then
    dropitem(1, 1, number);
  if data.inventory[number].number <> 0 then
    hudmessage(STR_CANT_DROP_HERE, MT_ERROR);
end;

function hasmesto: byte;
var
  i: byte;
begin
  result := 0;
  for i := 1 to MAXITEMS do
  begin
    if data.inventory[i].number = 0 then
    begin
      result := i;
      break;
    end;
  end;
  hasmesto := result;
end;

function podh_bez(num: integer): integer;
var
  aType: TItemType;
begin
  aType := GetItemType(num);
  result := 0;
  case aType of
    ITPrimitive, ITBows, ITFire, ITShells, ITNapalm, ITElectric,
      ITRockets, ITCell, ITPsi: result := 1;
    ITTechno: result := 2;
    ITArmor: result := 3;
    ITSapogi: result := 4;
    ITPlashch: result := 5;
    ITShapka: result := 6;
    ITTrousers: result := 7;
    ITGloves: result := 8;
    ITAmulet: result := 9;
    ITNanoRobot: result := 10;
    ITBioImplant: result := 11;
    ITFloppy: result := 12;
    ITBook: result := 13;
    ITHealth: result := 14;
    ITEat: result := 15;
    ITAmmo: result := 16;
  end;
end;

function geteffect(num: integer): word;
var
  item: TItem;
begin
  geteffect := 0;
  iteminfo(num, item);
  if item.number = num then
    geteffect := item.Effect;
end;

procedure healthy(num: byte);
begin
  if data.health + num >= data.max_health then
    data.health := data.max_health
  else
    data.health := data.health + num;
end;

procedure inven(num: integer);
var
  i: integer;
  y: byte;
  Item: TItem;
  s: string;
begin
  y := 2;
  for i := num to num + RESOLUTION_Y - 2 do
  begin
    if (i < MAXITEMS) then
    begin
      gotoxy(2, y);
      Item.number := data.inventory[i].number;
      if data.inventory[i].number <> 0 then
        ItemInfo(data.inventory[i].number, Item)
      else
        Item.name := '--';
      if (item.name <> '--') then
        TextColor(item.ItemColor)
      else
        TextColor(white);
      write(' ' + IntToStr(i) + '): ');
      if ((item.number > TECHNO_MAX) or (item.number < TECHNO_MIN))
        and ((item.number > FLOPPY_MAX) or (item.number < FLOPPY_MIN))
          and ((item.number > DRINK_MAX) or (item.number < DRINK_MIN)) then
            write(Item.name);
      if (item.name <> '--') then
      begin
        if (Item.IsShooting) and (Item.InOboyma > 0) then
          write(' (' + IntToStr(data.inventory[i].count) + '\' + IntToStr(Item.InOboyma) + ')')
        else if (item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX) then
        begin
          s := item.name;
          item.name := STR_TECHNOZ[data.technoZ[item.number - TECHNO_MIN + 1].num] + STR_TECHNO;
          if data.TechnoZ[item.number - TECHNO_MIN + 1].examined then
            item.name := item.name + s;
          write(item.name);
        end
        else if (item.number >= FLOPPY_MIN) and (item.number <= FLOPPY_MAX) then
        begin
          s := item.name;
          item.name := STR_PROG;
          if data.NanoZ[item.number - FLOPPY_MIN + 1].examined then
            item.name := item.name + s
          else
            item.name := item.name + ' ' + STR_NANOZ[data.nanoZ[item.number - FLOPPY_MIN + 1].num];
          write(item.name);
        end
        else if (item.number >= DRINK_MIN) and (item.number <= DRINK_MAX) then
        begin
          s := item.name;
          item.name := STR_DRINK;
          if data.DrinkZ[item.number - DRINK_MIN + 1].examined then
            item.name := item.name + s
          else
            item.name := STR_DRINKZ[data.drinkZ[item.number - DRINK_MIN + 1].num] + ' ' + item.name;
          write(item.name);
        end
        else if data.inventory[i].count > 1 then
          write(' (' + IntToStr(data.inventory[i].count) + ')');
      end;
      while (wherex < (RESOLUTION_X div 2)) do
        write(' ');
      inc(y);
    end
    else
      break;
  end;
end;

procedure inven_implants(num: integer);
var
  i: integer;
  y: byte;
  Item: TItem;
  s: string;
begin
  y := 2;
  for i := num to num + RESOLUTION_Y - 2 do
  begin
    if (i < MAXITEMS) then
    begin
      gotoxy(2, y);
      Item.number := data.implants[i].item.number;
      if data.implants[i].item.number <> 0 then
        ItemInfo(data.implants[i].item.number, Item)
      else
        Item.name := '--';
      if (item.name <> '--') then
        TextColor(item.ItemColor)
      else
        TextColor(white);
      write(' ' + IntToStr(i) + '): ');
      write(Item.name);
      while (wherex < (RESOLUTION_X div 2)) do
        write(' ');
      inc(y);
    end
    else
      break;
  end;
end;

function stoim(num: integer): word;
var
  item: TItem;
  cost: integer;
begin
  if (num = 0) then
  begin
    stoim := 0;
    exit;
  end;
  iteminfo(num, item);
  cost := item.cost;
  cost := cost - (20 - (data.trading div 9)) - (item.cost div (data.trading + 2));
  if (num >= TECHNO_MIN) and (num <= TECHNO_MAX) and (not data.TechnoZ[num - TECHNO_MIN + 1].examined) then
    cost := cost div 2
  else if (num >= FLOPPY_MIN) and (num <= FLOPPY_MAX) and (not data.NanoZ[num - FLOPPY_MIN + 1].examined) then
    cost := cost div 2
  else if (num >= DRINK_MIN) and (num <= DRINK_MAX) and (not data.DrinkZ[num - DRINK_MIN + 1].examined) then
    cost := cost div 2;
  if cost <= 0 then
    cost := 1;
  stoim := cost;
end;

procedure WriteEmptyStolb;
var
  i: integer;
const
  RES_X = (RESOLUTION_X div 2);
begin
  PutSymbol(RES_X, 1, LightGray, '=');
  PutSymbol(RES_X, RESOLUTION_Y + 1, LightGray, '=');
  for i := 2 to RESOLUTION_Y do
    PutSymbol(RES_X, i, LightGray, ' ');
end;

procedure WriteStolb;
var
  i: integer;
const
  RES_X = (RESOLUTION_X div 2);
begin
  PutSymbol(RES_X, 1, LightGray, '+');
  PutSymbol(RES_X, RESOLUTION_Y + 1, LightGray, '+');
  for i := 2 to RESOLUTION_Y do
  begin
    PutSymbol(RES_X, i, LightGray, '|');
    PutSymbol(RES_X + 1, i, Black, ' ');
  end;
end;

{$Warnings Off}
procedure DownRamka;
var
  j: integer;
begin
  textcolor(white);
  WriteChrXY(1, RESOLUTION_Y + 1, '+');
  for j := 2 to (RESOLUTION_X div 2) - 1 do
    WriteChrXY(j, RESOLUTION_Y + 1, '=');
  WriteChrXY(RESOLUTION_X div 2, RESOLUTION_Y + 1, '+');
  for j := j + 1 to RESOLUTION_X - 1 do
    WriteChrXY(j, RESOLUTION_Y + 1, '=');
  WriteChrXY(RESOLUTION_X, RESOLUTION_Y + 1, '+');
  GoToXY(1, RESOLUTION_Y + 2);
  GraphicClearHud;
end;
{$Warnings On}

procedure InvRamka;
var
  j: integer;
begin
  Ramka(white, 7);
  textcolor(white);
  for j := 1 to RESOLUTION_Y do
    WriteChrXY((RESOLUTION_X div 2), j, '|');
  WriteChrXY((RESOLUTION_X div 2), 1, '+');
  WriteChrXY((RESOLUTION_X div 2), RESOLUTION_Y + 1, '+');
end;

procedure DrawItem(num: integer);
var
  Item: TItem;
  x, y: byte;
  s: string;
  t: word;
  ccx, ccy: byte;
begin
  gotoxy(2, num - startnum + 2);
  if (data.inventory[num].number <> 0) then
    iteminfo(data.inventory[num].number, Item)
  else
  begin
    item.number := 0;
    Item.name := '--';
  end;
  if (item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX) then
  begin
    s := item.name;
    item.name := STR_TECHNOZ[data.technoZ[item.number - TECHNO_MIN + 1].num] + STR_TECHNO;
    if data.TechnoZ[item.number - TECHNO_MIN + 1].examined then
      item.name := item.name + s;
  end
  else if (item.number >= FLOPPY_MIN) and (item.number <= FLOPPY_MAX) then
  begin
    s := item.name;
    item.name := STR_PROG;
    if data.NanoZ[item.number - FLOPPY_MIN + 1].examined then
      item.name := item.name + s
    else
      item.name := item.name + ' ' + STR_NANOZ[data.nanoZ[item.number - FLOPPY_MIN + 1].num];
  end
  else if (item.number >= DRINK_MIN) and (item.number <= DRINK_MAX) then
  begin
    s := item.name;
    item.name := STR_DRINK;
    if data.DrinkZ[item.number - DRINK_MIN + 1].examined then
      item.name := item.name + s
    else
      item.name := STR_DRINKZ[data.drinkZ[item.number - DRINK_MIN + 1].num] + ' ' + item.name;
  end;
  ccx := wherex;
  ccy := wherey;
  if (data.inventory[num].number <> 0)
    and ((data.inventory[num].number < TECHNO_MIN) or (data.inventory[num].number > TECHNO_MAX))
    and ((data.inventory[num].number < FLOPPY_MIN) or (data.inventory[num].number > FLOPPY_MAX))
    and ((data.inventory[num].number < DRINK_MIN) or (data.inventory[num].number > DRINK_MAX)) then
  begin
    WriteStolb;
    DrawItemInfo(data.inventory[num].number);
  end
  else if
    ((data.inventory[num].number < TECHNO_MIN) or (data.inventory[num].number > TECHNO_MAX))
    and ((data.inventory[num].number < FLOPPY_MIN) or (data.inventory[num].number > FLOPPY_MAX))
      and ((data.inventory[num].number < DRINK_MIN) or (data.inventory[num].number > DRINK_MAX)) then
  begin
    WriteStolb;
//    ClearItemInfo;
  end
  else
  begin
    {WriteEmptyStolb;
    for t := 2 to RESOLUTION_Y - 2 do
    begin
      gotoxy(40, t);
      ZapolnStroka;
    end;}
  end;
  gotoxy(ccx, ccy);
  textcolor(Cyan);
  write('>' + IntToStr(num) + '):[' + Item.name);
  if (item.name <> '--') then
    if (Item.IsShooting) and (Item.InOboyma > 0) then
      write(' (' + IntToStr(data.inventory[num].count) + '\' + IntToStr(Item.InOboyma) + ')')
    else if (data.inventory[num].count > 1) then
      write(' (' + IntToStr(data.inventory[num].count) + ')');
  write(']');
  while (wherex < RESOLUTION_X div 2) do
    write(' ');
  if aTrading then
  begin
    x := wherex;
    y := wherey;
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 3);
    TextColor(White);
    Write(STR_YOUR_GOLD + IntToStr(data.money));
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 2);
    Write(STR_YOUR_HEALTH + IntToStr(data.health) + '\' + IntToStr(data.max_health));
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 1);
    write(STR_YOUR_WEIGHT + IntToStr(GetWeight) + '\' + IntToStr(data.maxweight));
    gotoxy(x, y);
  end;
  textcolor(white);
  if (aTrading) and (data.inventory[num].number <> 0) then
  begin
    x := wherex;
    y := wherey;
    iteminfo(data.inventory[num].number, item);
    if (data.inventory[num].number < TECHNO_MAX) and (data.inventory[num].number >= TECHNO_BAD) and (data.TechnoZ[data.inventory[num].number - TECHNO_MIN + 1].examined) then
      s := STR_SORRY_NOT_INTERESTED
    else if (data.inventory[num].number < FLOPPY_MAX) and (data.inventory[num].number >= FLOPPY_BAD) and (data.NanoZ[data.inventory[num].number - FLOPPY_MIN + 1].examined) then
      s := STR_SORRY_NOT_INTERESTED
    else if ((item.itemtype = ITLitter) and (item.cost = 1)) then
      s := STR_SORRY_NOT_INTERESTED
    else if (item.itemtype = ITKey) then
      s := STR_KEY_NOT_INTERESTED
    else
      s := STR_BUY_1 + InStr(stoim(data.inventory[num].number)) + STR_BUY_2 + BuySellMonetsSklon(stoim(data.inventory[num].number)) + STR_BUY_3;
    Ramka(white, 7);
    gotoxy((RESOLUTION_X - Length(s)) div 2, RESOLUTION_Y + 1);
    write(s);
    GoToXY(1, WhereY + 1);
    while (WhereX < RESOLUTION_X) do
      write(' ');
    gotoxy(x, y);
  end
  else if ((data.inventory[num].number >= TECHNO_MIN) and (data.inventory[num].number <= TECHNO_MAX))
  or ((data.inventory[num].number >= DRINK_MIN) and (data.inventory[num].number <= DRINK_MAX))
  or ((data.inventory[num].number >= FLOPPY_MIN) and (data.inventory[num].number <= FLOPPY_MAX)) then
    hudmessage(STR_H_IS_HELP, MT_TEXT, false)
  else
    DownRamka;
end;

procedure DrawInActive(num: integer);
var
  Item: TItem;
  s: string;
begin
  gotoxy(2, num - startnum + 2);
  if (data.inventory[num].number <> 0) then
    iteminfo(data.inventory[num].number, Item)
  else
    Item.name := '--';
  if (Item.name <> '--') then
    TextColor(item.ItemColor)
  else
    TextColor(white);
  write(' ' + IntToStr(num) + '): ');
  if ((item.number < TECHNO_MIN) or (item.number > TECHNO_MAX)) and
    ((item.number < FLOPPY_MIN) or (item.number > FLOPPY_MAX)) and
      ((item.number < DRINK_MIN) or (item.number > DRINK_MAX)) then
        write(item.name);
  if (item.name <> '--') then
    if (Item.IsShooting) and (Item.InOboyma > 0) then
      write(' (' + IntToStr(data.inventory[num].count) + '\' + IntToStr(Item.InOboyma) + ')')
    else if (item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX) then
    begin
      s := item.name;
      item.name := STR_TECHNOZ[data.technoZ[item.number - TECHNO_MIN + 1].num] + STR_TECHNO;
      if data.TechnoZ[item.number - TECHNO_MIN + 1].examined then
        item.name := item.name + s;

      write(item.name);
    end
    else if (item.number >= FLOPPY_MIN) and (item.number <= FLOPPY_MAX) then
    begin
      s := item.name;
      item.name := STR_PROG;
      if data.NanoZ[item.number - FLOPPY_MIN + 1].examined then
        item.name := item.name + s
      else
        item.name := item.name + ' ' + STR_NANOZ[data.nanoZ[item.number - FLOPPY_MIN + 1].num];
      write(item.name)
    end
    else if (item.number >= DRINK_MIN) and (item.number <= DRINK_MAX) then
    begin
      s := item.name;
      item.name := STR_DRINK;
      if data.DrinkZ[item.number - DRINK_MIN + 1].examined then
        item.name := item.name + s
      else
        item.name := STR_DRINKZ[data.drinkZ[item.number - DRINK_MIN + 1].num] + ' ' + item.name;
      write(item.name);
    end
    else if data.inventory[num].count > 1 then
      write(' (' + IntToStr(data.inventory[num].count) + ')');
  while (wherex < RESOLUTION_X div 2) do
    write(' ');
  PasteScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
end;

procedure DrawItem2(num: integer);
var
  Item: TItem;
  x, y: byte;
  s: string;
  t: word;
  ccx, ccy: byte;
begin
  ccx := WhereX;
  ccy := WhereY;
  gotoxy(2, num - startnum + 2);
  if (data.implants[num].item.number <> 0) then
  begin
    iteminfo(data.implants[num].item.number, Item);
    WriteStolb;
    DrawItemInfo(data.implants[num].item.number);
  end
  else
  begin
    item.number := 0;
    Item.name := '--';
  end;
  gotoxy(2, (num - startnum + 2));
  textcolor(Cyan);
  write('>' + IntToStr(num) + '):[' + Item.name);
  write(']');
  while (wherex < RESOLUTION_X div 2) do
    write(' ');
  textcolor(white);
end;

procedure DrawInActive2(num: integer);
var
  Item: TItem;
  s: string;
begin
  gotoxy(2, num - startnum + 2);
  if (data.implants[num].item.number <> 0) then
    iteminfo(data.implants[num].item.number, Item)
  else
    Item.name := '--';
  if (Item.name <> '--') then
    TextColor(item.ItemColor)
  else
    TextColor(white);
  write(' ' + IntToStr(num) + '): ' + item.name);
  while (wherex < RESOLUTION_X div 2) do
    write(' ');
  PasteScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
end;

procedure GetHealth(num: integer);
var
  item: TItem;
begin
  if data.health = data.max_health then
    hudmessage(STR_YOU_FEEL_NOT, MT_TEXT)
  else
  begin
    iteminfo(data.inventory[num].number, item);
    if item.Effect < 65535 then
    begin
      if data.health + item.Effect > data.max_health then
        data.health := data.max_health
      else
        inc(data.health, item.Effect);
    end
    else
      data.health := data.max_health;
    if (data.bloodchosen <= item.Effect) and (data.bloodchosen > 0) then
    begin
      data.bloodchosen := 0;
      hudmessage(STR_NO_BLOOD, MT_TEXT);
    end
    else if (data.bloodchosen > 0) then
    begin
      dec(data.bloodchosen, item.Effect);
      hudmessage(STR_YET_BLOOD, MT_TEXT);
    end;
  end;
  if (data.inventory[num].number = 413) and (data.bolezn > 0) then
  begin
    data.bolezn := 0;
    hudmessage(STR_NOT_BOLEN, MT_TEXT);
  end;
  dec(data.inventory[num].count);
  if data.inventory[num].count = 0 then
    data.inventory[num].number := 0;
  hudmessage(STR_YOU_FEEL_BETTER, MT_TEXT);
end;

procedure StrengthDrop(num: integer);  // num - inventory item
var
  w: word;
  wx, wy: integer;
  item: TItem;
begin
  if data.inventory[num].number = 0 then
  begin
    hudmessage(STR_NOTHING_TO_DROP, MT_INFO);
    exit;
  end;
  clrscr;
  gotoxy(data.posx, data.posy);
  clean_all;
  gotoxy(data.posx, data.posy);
  osv(data.Light_color, false);
  w := pricel(data.posx + 1, data.posy);
  wx := w div 256;
  wy := w mod 256;
  if (w <> 0) and (w <> 65535) then
  begin
    ItemWay(data.posx, data.posy, wx, wy, data.inventory[num].number, data.inventory[num].count);
    iteminfo(data.inventory[num].number, item);
    if not item.IsShooting then
      dec(data.inventory[num].count)
    else
      data.inventory[num].count := 0;
    if (data.inventory[num].count = 0) then
      data.inventory[num].number := 0;
    if Assigned(item.OnDrop) then
      item.OnDrop(0, 0);
  end;
end;

function Answer: boolean;
var
  c: char;
begin
  data.LastMessages[RESOLUTION_Y - 3] := '';
  hudmessage(STR_ARE_YOU_WANT, MT_TEXT, false);
  repeat
    c := readkey;
  until (c in ['y', 'n', #27, #13]);
  Result := (c in ['y', #13]);
end;

procedure showinv;
var
  active: integer;
  c: char;
  itemnum, itemcount: integer;
  cost: integer;
  j: integer;
  item: TItem;
  x, y: integer;
  temp: integer;
begin
  RegularizeThings;
  startnum := 1;
  endnum := RESOLUTION_Y - 2;
  TextColor(White);
  active := 1;
  clrscr;
  InvRamka;
  CopyScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
  inven(1);
  DrawItem(active);
  repeat
  begin
    x := wherex;
    y := wherey;
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 3);
    TextColor(White);
    Write(STR_YOUR_GOLD + IntToStr(data.money));
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 2);
    Write(STR_YOUR_HEALTH + IntToStr(data.health) + '\' + IntToStr(data.max_health));
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 1);
    Write(STR_YOUR_WEIGHT + IntToStr(GetWeight) + '\' + IntToStr(data.maxweight));
    gotoxy(x, y);
    c := readkey;
    if (c = KEY_DOWN) then
    begin
      DrawInActive(active);
      inc(active);
      if (active > MAXITEMS) then
      begin
        active := 1;
        startnum := 1;
        endnum := RESOLUTION_Y - 2;
        inven(1);
      end
      else if (active > endnum) then
      begin
        inc(startnum, (active - endnum));
        endnum := active;
        inven(startnum);
      end;
      DrawItem(active);
    end
    else if (c = KEY_UP) then
    begin
      DrawInActive(active);
      dec(active);
      if (active < 1) then
      begin
        active := MAXITEMS;
        endnum := MAXITEMS;
        startnum := MAXITEMS - RESOLUTION_Y + 2;
        inven(startnum);
      end
      else if (active < startnum) then
      begin
        startnum := active;
        endnum := startnum + RESOLUTION_Y - 2;
        inven(startnum);
      end;
      DrawItem(active);
    end
    else if (c = KEY_INV_HELP) then
    begin
      clrscr;
      Ramka(white, 7);
      DrawFullHelp(data.inventory[active].number);
      readkey;
      clrscr;
      Ramka(white, 7);
      textcolor(white);
      for j := 1 to RESOLUTION_Y do
        WriteChrXY((RESOLUTION_X div 2), j, '|');
      WriteChrXY((RESOLUTION_X div 2), 1, '+');
      WriteChrXY((RESOLUTION_X div 2), RESOLUTION_Y + 1, '+');
      inven(startnum);
      DownRamka;
      DrawItem(active);
    end
    else if (c = KEY_RETURN) then
    begin
      if (not aTrading) and (not data.anAnnigil) then
      begin
        if (data.Palsy > 0) then
          hudmessage(STR_YOU_PALSED, MT_TEXT)
        else
        begin
          itemnum := data.inventory[active].number;
          iteminfo(itemnum, item);
          if (itemnum >= TECHNO_MIN) and (itemnum <= TECHNO_MAX) then
            data.TechnoZ[itemnum - TECHNO_MIN + 1].examined := true
          else if (itemnum >= FLOPPY_MIN) and (itemnum <= FLOPPY_MAX) then
            data.NanoZ[itemnum - FLOPPY_MIN + 1].examined := true
          else if (itemnum >= DRINK_MIN) and (itemnum <= DRINK_MAX) then
            data.DrinkZ[itemnum - DRINK_MIN + 1].examined := true;
          if Assigned(item.OnUsing) then
          begin
            if (itemnum >= FLOPPY_MIN) and (itemnum <= FLOPPY_MAX) then
            begin
              iteminfo(data.inventory[active].number, item);
              hudmessage(STR_PROGRAM_ACTIVE + item.name, MT_TEXT);
              itemnum := data.inventory[active].number;
              data.inventory[active].number := 0;
              data.inventory[active].count := 0;
              item.OnUsing(active, 0);
              if IsExitAfterUsing(item.number) then
                exit;
            end
            else if (itemnum >= DRINK_MIN) and (itemnum <= DRINK_MAX) then
            begin
              iteminfo(data.inventory[active].number, item);
              hudmessage(STR_DRINK_ACTIVE + item.name, MT_TEXT);
              item.OnUsing(active, 0);
              dec(data.inventory[active].count);
              if data.inventory[active].count <= 0 then
                data.inventory[active].number := 0;
            end
            else if (itemnum >= IMPLANTS_MIN) and (itemnum <= IMPLANTS_MAX) then
            begin
              iteminfo(data.inventory[active].number, item);
              if (data.surgery < item.expa) then
                hudmessage(STR_SURGERY_TOO_SMALL, MT_TEXT)
              else
                item.OnUsing(item.Effect, data.inventory[active].number - IMPLANTS_MIN + 1);
            end;
          end
          else
          begin
            temp := podh_bez(itemnum);
            case temp of
              1:
              begin
                if podh(itemnum, GetItemExpa(itemnum)) <> 0 then
                begin
                  itemnum := data.r_hand;
                  iteminfo(data.r_hand, item);
                  if (item.IsShooting) and (item.InOboyma > 0) then
                    itemcount := data.InRozhok
                  else
                    itemcount := 1;
                  data.r_hand := data.inventory[active].number;
                  iteminfo(data.inventory[active].number, item);
                  if Assigned(item.OnWear) then
                    item.OnWear(0, 0);
                  if (item.IsShooting) and (item.InOboyma > 0) then
                    data.InRozhok := data.inventory[active].count;
                  data.inventory[active].number := itemnum;
                  data.inventory[active].count := itemcount;
                  iteminfo(data.inventory[active].number, item);
                  if Assigned(item.OnUnWear) then
                    item.OnUnWear(0, 0);
                end
                else
                begin
                  hudmessage(STR_CANT_USE_THIS, MT_ERROR);
                  textcolor(white);
                end;
              end;
              2:
              begin
                if (data.bracelet1 = 0) then
                begin
                  data.bracelet1 := data.inventory[active].number;
                  dec(data.inventory[active].count);
                  if data.inventory[active].count <= 0 then
                    data.inventory[active].number := 0;
                  iteminfo(data.bracelet1, item);
                  hudmessage(STR_YOU_WEARED_TECHNO + item.name, MT_TEXT);
                  if Assigned(item.OnWear) then
                    item.OnWear(active, 1);
                  if data.bracelet1 = 624 then
                    exit;
                end
                else if (data.bracelet2 = 0) then
                begin
                  data.bracelet2 := data.inventory[active].number;
                  dec(data.inventory[active].count);
                  if data.inventory[active].count <= 0 then
                    data.inventory[active].number := 0;
                  iteminfo(data.bracelet2, item);
                  hudmessage(STR_YOU_WEARED_TECHNO + item.name, MT_TEXT);
                  if Assigned(item.OnWear) then
                    item.OnWear(active, 2);
                  if data.bracelet2 = 624 then
                    exit;
                end
                else
                begin
                  if (data.bracelet1 < TECHNO_BAD) then
                  begin
                    addinv(data.bracelet1);
                    iteminfo(data.bracelet1, item);
                    if Assigned(item.OnUnWear) then
                      item.OnUnWear(0, 0);
                    data.bracelet1 := data.inventory[active].number;
                    dec(data.inventory[active].count);
                    if data.inventory[active].count <= 0 then
                      data.inventory[active].number := 0;
                    iteminfo(data.bracelet1, item);
                    hudmessage(STR_YOU_WEARED_TECHNO + item.name, MT_TEXT);
                    if Assigned(item.OnWear) then
                      item.OnWear(active, 0);
                    if data.bracelet1 = 624 then
                      exit;
                  end
                  else if (data.bracelet2 < TECHNO_BAD) then
                  begin
                    addinv(data.bracelet2);
                    iteminfo(data.bracelet2, item);
                    if Assigned(item.OnUnWear) then
                      item.OnUnWear(0, 0);
                    data.bracelet2 := data.inventory[active].number;
                    dec(data.inventory[active].count);
                    if data.inventory[active].count <= 0 then
                      data.inventory[active].number := 0;
                    iteminfo(data.bracelet2, item);
                    hudmessage(STR_YOU_WEARED_TECHNO + item.name, MT_TEXT);
                    if Assigned(item.OnWear) then
                      item.OnWear(active, 0);
                    if data.bracelet2 = 624 then
                      exit;
                  end
                  else
                    hudmessage(STR_CANT_WEAR_TECHNO, MT_TEXT);
                end;
              end;
              //11: SetImplant(active);
              7:
              begin
                itemnum := data.trousers;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.trousers := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.trousers, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              8:
              begin
                itemnum := data.gloves;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.gloves := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.gloves, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              9:
              begin
                itemnum := data.amulet;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.amulet := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.amulet, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              3:
              begin
                itemnum := data.dosp;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.dosp := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.dosp, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              4:
              begin
                itemnum := data.sapogi;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.sapogi := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.sapogi, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              5:
              begin
                itemnum := data.plashch;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.plashch := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.plashch, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
              6:
              begin
                itemnum := data.shapka;
                iteminfo(itemnum, item);
                if Assigned(item.OnUnWear) then
                  item.OnUnWear(0, 0);
                data.shapka := data.inventory[active].number;
                data.inventory[active].number := itemnum;
                data.inventory[active].count := 1;
                iteminfo(data.shapka, item);
                if Assigned(item.OnWear) then
                  item.OnWear(0, 0);
              end;
            end;
            inven(startnum);
          end;
        end;
      end
      else if not data.anAnnigil then
      begin
        itemnum := data.inventory[active].number;
        if ((GetItemType(itemnum) = ITLitter) and (item.cost <= 1)) then
          hudmessage(STR_NOT_INTERESTED, MT_TEXT)
        else if (GetItemType(itemnum) = ITKey) then
          hudmessage(STR_NOT_INTERESTED, MT_TEXT)
        else if ((itemnum < TECHNO_MAX) and (itemnum >= TECHNO_BAD)
          and (data.TechnoZ[itemnum - TECHNO_MIN + 1].examined)) then
            hudmessage(STR_NOT_INTERESTED, MT_TEXT)
        else if ((itemnum < FLOPPY_MAX) and (itemnum >= FLOPPY_BAD)
          and (data.NanoZ[itemnum - FLOPPY_MIN + 1].examined)) then
            hudmessage(STR_NOT_INTERESTED, MT_TEXT)
        else if ((itemnum < DRINK_MAX) and (itemnum >= DRINK_BAD)
          and (data.DrinkZ[itemnum - DRINK_MIN + 1].examined)) then
            hudmessage(STR_NOT_INTERESTED, MT_TEXT)
        else
        begin
          cost := stoim(data.inventory[active].number);
          iteminfo(data.inventory[active].number, item);
          if (cost < 1) and (itemnum <> 0) then
            cost := 1;
          if (not item.IsShooting) or (item.InOboyma = 0) then
            dec(data.inventory[active].count)
          else
            data.inventory[active].count := 0;
          if (data.inventory[active].count <= 0) then
            data.inventory[active].number := 0;
          if Assigned(item.OnDrop) then
            item.OnDrop(0, 0);
          inc(data.money, cost);
        end;
      end
      else
      begin
        itemnum := data.inventory[active].number;
        iteminfo(itemnum, item);
        if (itemnum > TECHNO_MIN) and (itemnum < TECHNO_MAX) and (not data.TechnoZ[itemnum - TECHNO_MIN + 1].examined) then
        begin
          data.TechnoZ[itemnum - TECHNO_MIN + 1].examined := true;
          hudmessage(STR_TECHNO + item.name + ' (' + item.help + ')', MT_TEXT);
          exit;
        end
        else if (itemnum > FLOPPY_MIN) and (itemnum > FLOPPY_MAX) and (not data.NanoZ[itemnum - FLOPPY_MIN + 1].examined) then
        begin
          data.NanoZ[itemnum - FLOPPY_MIN + 1].examined := true;
          hudmessage(STR_PROG + item.name + ' (' + item.help + ')', MT_TEXT);
          exit;
        end
        else if (itemnum <> 0) then
          hudmessage(STR_NOT_NEED, MT_TEXT);
      end;
      clrscr;
      Ramka(white, 7);
      textcolor(white);
      for j := 1 to RESOLUTION_Y do
        WriteChrXY((RESOLUTION_X div 2), j, '|');
      WriteChrXY((RESOLUTION_X div 2), 1, '+');
      WriteChrXY((RESOLUTION_X div 2), RESOLUTION_Y + 1, '+');
      inven(startnum);
      DownRamka;
      DrawItem(active);
    end
    else if (c = KEY_INV_DROP) and (not aTrading) and (not data.anAnnigil) then
    begin
      if (data.Palsy = 0) then
        Drop(active)
      else
        hudmessage(STR_YOU_PALSED, MT_TEXT);
      DrawItem(active);
    end
    else if (c = KEY_INV_STRENGTH_DROP) and (not data.anAnnigil) then
    begin
      if (data.Palsy = 0) then
      begin
        if (data.inventory[Active].number <> 0) then
          c := KEY_ESCAPE;
        StrengthDrop(Active);
      end
      else
        hudmessage(STR_YOU_PALSED, MT_TEXT);
      DrawItem(active);
    end
  end;
  until ((c in [KEY_ESCAPE, KEY_INVENTORY]) and (not data.anAnnigil)) or ((c = KEY_ESCAPE) and (data.anAnnigil) and (Answer));
  aTrading := false;
  RegularizeThings;
end;

procedure SetImplants;
var
  active: integer;
  c: char;
  itemnum, itemcount: integer;
  cost: integer;
  j: integer;
  item: TItem;
  x, y: integer;
  temp: integer;
  itemscount: Integer;
begin
  data.TradeImplants := true;
  RegularizeThings;
  startnum := 1;
  endnum := RESOLUTION_Y - 2;
  TextColor(White);
  active := 1;
  x := 1;
  data.IsInInv := true;
  itemscount := 0;
  for j := 1 to IMPLANTS_MAX - IMPLANTS_MIN + 1 do
    data.implants[j].item := EmptySlot;
  for j := 1 to MAXITEMS do
    if (data.inventory[j].number in [IMPLANTS_MIN..IMPLANTS_MAX]) then
    begin
      inc(itemscount);
      data.implants[itemscount].item := data.inventory[j];
      data.implants[itemscount].itemnum := j;
      Inc(itemscount);
    end;
  if (itemscount > 0) then
    dec(itemscount);
  clrscr;
  InvRamka;
  CopyScreen(Form1.Image1.Width div 2, 1, Form1.Image1.Width, Form1.Image1.Height, RESOLUTION_X div 2, 1, RESOLUTION_X, RESOLUTION_Y + HUDSIZE);
  inven_implants(1);
  DrawItem2(active);
  repeat
  begin
    x := wherex;
    y := wherey;
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 3);
    TextColor(White);
    Write(STR_YOUR_GOLD + IntToStr(data.money));
    ZapolnStroka;
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 2);
    Write(STR_YOUR_HEALTH + IntToStr(data.health) + '\' + IntToStr(data.max_health));
    ZapolnStroka;
    gotoxy(RESOLUTION_X div 2 + 3, RESOLUTION_Y - 1);
    Write(STR_YOUR_WEIGHT + IntToStr(GetWeight) + '\' + IntToStr(data.maxweight));
    ZapolnStroka;
    gotoxy(x, y);
    c := readkey;
    if (c = KEY_DOWN) then
    begin
      DrawInActive2(active);
      inc(active);
      if (active >= itemscount) then
      begin
        active := 1;
        startnum := 1;
        endnum := RESOLUTION_Y - 2;
        inven_implants(1);
      end
      else if (active > endnum) then
      begin
        inc(startnum, (active - endnum));
        endnum := active;
        inven_implants(startnum);
      end;
      DrawItem2(active);
    end
    else if (c = KEY_UP) then
    begin
      DrawInActive2(active);
      dec(active);
      if (active < 1) then
      begin
        active := itemscount;
        if (itemscount > RESOLUTION_Y + 2) then
          endnum := itemscount
        else
          endnum := RESOLUTION_Y + 2;
        startnum := endnum - RESOLUTION_Y - 2;
        if (startnum < 1) then
          startnum := 1;
        inven_implants(startnum);
      end
      else if (active < startnum) then
      begin
        startnum := active;
        endnum := startnum + RESOLUTION_Y - 2;
        inven_implants(startnum);
      end;
      DrawItem2(active);
    end
    else if (c = KEY_RETURN) then
    begin
      if (data.implants[active].item.number <> 0) then
      begin
        if (not data.UsedImplants[data.implants[active].item.number - IMPLANTS_MIN + 1]) then
        begin
          iteminfo(data.implants[active].item.number, item);
          j := (item.cost - (data.trading * 5)) * item.expa * 5;
          if (j < 1) then
            j := 1;
          if (j > data.money) then
          begin
            hudmessage(STR_NOT_ENOUGH_MONEY, MT_TEXT);
            DownRamka;
          end
          else
          begin
            Dec(data.money, j);
            item.OnUsing(item.Effect, item.number - IMPLANTS_MIN + 1);
            DownRamka;
            if (item.number - IMPLANTS_MIN + 1 < 9) or (data.UsedImplants[item.number - IMPLANTS_MIN + 1 - 9]) then
            begin
              data.inventory[data.implants[active].itemnum].number := 0;
              data.inventory[data.implants[active].itemnum].count := 0;
              data.implants[active].item := EmptySlot;
              data.implants[active].itemnum := 0;
            end;
            DrawItem2(active);
          end;
        end
        else
        begin
          hudmessage(STR_YOU_ALREADY_HAVE_IMPLANT, MT_TEXT);
          DownRamka;
        end;
      end;
    end;
  end;
  until (c = KEY_ESCAPE);
  aTrading := false;
  data.IsInInv := false;
  RegularizeThings;
  data.TradeImplants := false;
end;

procedure WriteNow;
var
  item: TItem;
  s: string;
begin
  Ramka(LightGray, 7);
  gotoxy(3, 3);
  WriteStolb;
  textcolor(white);
  iteminfo(data.r_hand, item);
  s := item.name;
  if (item.IsShooting) then
    if (item.InOboyma > 0) then
      s := s + ' (' + inttostr(data.InRozhok) + '\' + inttostr(item.InOboyma) + ') [' + inttostr(HasAmmoLeft) + ']'
    else
      s := s + ' [' + inttostr(HasAmmoLeft) + ']';
  write(STR_R_HAND + s);
  gotoxy(3, wherey + 1);
  iteminfo(data.l_hand, item);
  write(STR_L_HAND + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.amulet, item);
  write(STR_AMULET + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.shapka, item);
  write(STR_SHAPKA + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.dosp, item);
  write(STR_DOSP + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.plashch, item);
  write(STR_PLASHCH + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.gloves, item);
  write(STR_GLOVES + item.name);
  gotoxy(3, wherey + 1);
  s := STR_TECHNO;
  s := ' Ò' + Copy(s, 3, Length(s) - 2);
  iteminfo(data.bracelet1, item);
  if item.number <> 0 then
    write(STR_BRACELET1 + s)
  else
    write(STR_BRACELET1 + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.bracelet2, item);
  if item.number <> 0 then
    write(STR_BRACELET2 + s)
  else
    write(STR_BRACELET2 + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.trousers, item);
  write(STR_TROUSERS + item.name);
  gotoxy(3, wherey + 1);
  iteminfo(data.sapogi, item);
  write(STR_SAPOGI + item.name);
end;

procedure WriteActive(num: integer; color: byte);
var
  item: TItem;
  temp: string;
  t: integer;
  s: string;
begin
  case num of
    1: iteminfo(data.r_hand, item);
    2: iteminfo(data.l_hand, item);
    3: iteminfo(data.amulet, item);
    4: iteminfo(data.shapka, item);
    5: iteminfo(data.dosp, item);
    6: iteminfo(data.plashch, item);
    7: iteminfo(data.gloves, item);
    8: iteminfo(data.bracelet1, item);
    9: iteminfo(data.bracelet2, item);
    10: iteminfo(data.trousers, item);
    11: iteminfo(data.sapogi, item);
  end;
  temp := '';
  case num of
    1: temp := STR_R_HAND;
    2: temp := STR_L_HAND;
    3: temp := STR_AMULET;
    4: temp := STR_SHAPKA;
    5: temp := STR_DOSP;
    6: temp := STR_PLASHCH;
    7: temp := STR_GLOVES;
    8: temp := STR_BRACELET1;
    9: temp := STR_BRACELET2;
    10: temp := STR_TROUSERS;
    11: temp := STR_SAPOGI;
  end;
  if (item.number < TECHNO_MIN) or (item.number > TECHNO_MAX) then
  begin
    WriteStolb;
    DrawItemInfo(item.number);
  end
  else
  begin
    WriteEmptyStolb;
    for t := 2 to RESOLUTION_Y - 2 do
    begin
      gotoxy(40, t);
      ZapolnStroka;
    end;
  end;
  gotoxy(3, num + 2);
  textcolor(color);
  if (item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX) then
  begin
    s := STR_TECHNO;
    if (color = LightRed) then
      s := s + item.name;
    s := ' Ò' + Copy(s, 3, Length(s) - 2);
  end
  else
    s := item.name;
  if (item.IsShooting) then
    if (item.InOboyma > 0) then
      s := s + ' (' + inttostr(data.InRozhok) + '\' + inttostr(item.InOboyma) + ') [' + inttostr(HasAmmoLeft) + ']'
    else
      s := s + ' [' + inttostr(HasAmmoLeft) + ']';
  write(temp + s);
  while (wherex < RESOLUTION_X div 2) do
    write(' ');
end;

function GetActiveParameter(num: byte): integer;
begin
  GetActiveParameter := 0;
  case num of
    1: GetActiveParameter := data.r_hand;
    2: GetActiveParameter := data.l_hand;
    3: GetActiveParameter := data.amulet;
    4: GetActiveParameter := data.shapka;
    5: GetActiveParameter := data.dosp;
    6: GetActiveParameter := data.plashch;
    7: GetActiveParameter := data.gloves;
    8: GetActiveParameter := data.bracelet1;
    9: GetActiveParameter := data.bracelet2;
    10: GetActiveParameter := data.trousers;
    11: GetActiveParameter := data.sapogi;
  end;
end;

procedure shownow;
var
  active: integer;
  c: char;
  item: TItem;
begin
  clrscr;
  active := 1;
  WriteNow;
  data.IsInInv := true;
  repeat
    WriteActive(active, LightRed);
    c := readkey;
    WriteActive(active, White);
    if (c = KEY_UP) then
    begin
      dec(active);
      if (active < 1) then
        active := 11;
    end
    else if (c = KEY_DOWN) then
    begin
      inc(active);
      if (active > 11) then
        active := 1;
    end
    else if (c = KEY_RETURN) then
    begin
      if (not data.anAnnigil) then
      begin
        if data.Palsy > 0 then
          hudmessage(STR_YOU_PALSED, MT_TEXT)
        else if (GetActiveParameter(active) <> 0) then
        begin
          if ((active = 8) and (data.bracelet1 >= TECHNO_BAD)) or
            ((active = 9) and (data.bracelet2 >= TECHNO_BAD)) then
              hudmessage(STR_CANT_DROP_PROKLYAT, MT_TEXT)
          else if hasinv(GetActiveParameter(active), 1) then
          begin
            if (active in [8, 9]) then
            begin
              if ((active = 8) and (data.bracelet1 < TECHNO_BAD)) or
                ((active = 9) and (data.bracelet2 < TECHNO_BAD)) then
                  addinv(GetActiveParameter(active), active - 7)
              else
                hudmessage(STR_CANT_DROP_PROKLYAT, MT_TEXT);
            end
            else
              addinv(GetActiveParameter(active));
            case active of
              1: data.r_hand := 0;
              2: data.l_hand := 0;
              3: data.amulet := 0;
              4: data.shapka := 0;
              5: data.dosp := 0;
              6: data.plashch := 0;
              7: data.gloves := 0;
              8:
                if data.bracelet1 < TECHNO_BAD + 100 then
                  data.bracelet1 := 0;
              9:
                if data.bracelet2 < TECHNO_BAD + 100 then
                  data.bracelet2 := 0;
              10: data.trousers := 0;
              11: data.sapogi := 0;
            end;
          end
          else if HasWeight(GetActiveParameter(active), 1) then
            hudmessage(STR_INVENTORY_FULL, MT_ERROR)
          else
            hudmessage(STR_TOO_HEAVY, MT_ERROR);
        end;
      end
      else
      begin
        if (GetActiveParameter(active)) <> 0 then
        begin
          iteminfo(GetActiveParameter(active), item);
          if Assigned(item.OnUnWear) then
            if (active in [8, 9]) then
              item.OnUnWear(0, active - 7)
            else
              item.OnUnWear(0, 0);
          case Active of
            1:
            begin
              data.r_hand := 0;
              data.InRozhok := 0;
            end;
            2: data.l_hand := 0;
            3: data.amulet := 0;
            4: data.shapka := 0;
            5: data.dosp := 0;
            6: data.plashch := 0;
            7: data.gloves := 0;
            8: data.bracelet1 := 0;
            9: data.bracelet2 := 0;
            10: data.trousers := 0;
            11: data.sapogi := 0;
          end;
          hudmessage(STR_ITEM_DESTROYED, MT_TEXT);
          exit;
        end;
      end;
    end
    else if (c = KEY_INV_DROP) and (not data.anAnnigil) then
    begin
      if data.Palsy > 0 then
        hudmessage(STR_YOU_PALSED, MT_TEXT)
      else
        case active of
          1: DropNow(data.r_hand);
          2: DropNow(data.l_hand);
          3: DropNow(data.amulet);
          4: DropNow(data.shapka);
          5: DropNow(data.dosp);
          6: DropNow(data.plashch);
          7: DropNow(data.gloves);
          8:
            if (data.bracelet1 < TECHNO_BAD) then
              DropNow(data.bracelet1, 1)
            else
              hudmessage(STR_CANT_DROP_PROKLYAT, MT_TEXT);
          9:
            if (data.bracelet2 < TECHNO_BAD) then
              DropNow(data.bracelet2, 2)
            else
              hudmessage(STR_CANT_DROP_PROKLYAT, MT_TEXT);
          10: DropNow(data.trousers);
          11: DropNow(data.sapogi);
        end;
    end;
    Ramka(LightGray, 7);
  until ((c = KEY_ESCAPE) and (not data.anAnnigil)) or ((c = KEY_ESCAPE) and (data.anAnnigil) and (Answer));
  data.IsInInv := false;
end;

end.