unit using;

interface

uses
  sysutils, loadz, svet, inventar, speak;



procedure richag;

procedure talking(xx, yy: shortint);
procedure put_item;


implementation

uses
  MyCRT;

function IsObiskan(x, y: byte): boolean;
begin
  IsObiskan := ((cur_lev.map[x, y].attrz and 32) > 0);
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 put_item;
var
  tx, ty: byte;
  item: titem;
  moneyget: word;
  s: string;
  i: byte;
begin
  moneyget := 0;
  tx := wherex;
  ty := wherey;
  item.number := cur_lev.map[tx, ty].item;
  iteminfo(cur_lev.map[tx, ty].item, item);
  if (item.number >= MONEY_MIN) and (item.number <= MONEY_MAX) then
  begin
    if cur_lev.map[tx, ty].ItemCount = 0 then
    begin
      case item.number of
        MONEY_MIN: moneyget := random(10) + 1;
        MONEY_MIN + 1: moneyget := random(100 - 10) + 10;
        MONEY_MIN + 2: moneyget := random(1000 - 100) + 100;
        MONEY_MIN + 3: moneyget := random(10000 - 1000) + 1000;
        MONEY_MIN + 4: moneyget := random(65534 - 10000) + 10000;
      end;
    end
    else
      moneyget := cur_lev.map[tx, ty].ItemCount;

    inc(data.money, moneyget);
    hudmessage(STR_WAS_FOUND + IntToStr(moneyget) + STR_N_MONETS2 + FemaleSklon(moneyget), MT_INFO, true);
    cur_lev.map[tx, ty].item := 0;
    cur_lev.map[tx, ty].ItemCount := 0;
    gotoxy(tx, ty);
    osv;
    exit;
  end;
  iteminfo(cur_lev.map[tx, ty].item, item);
  if (item.IsShooting) and (item.InOboyma > 0) then
  begin
    if hasinv(cur_lev.map[tx, ty].item, 1) then
    begin
      addinv(cur_lev.map[tx, ty].item, cur_lev.map[tx, ty].ItemCount);
      gotoxy(1, RESOLUTION_Y + 3);
      textcolor(cyan);
      if (item.InOboyma > 0) then
      begin
        hudmessage(STR_WAS_FOUND + item.name + ' (' + IntToStr(cur_lev.map[tx, ty].ItemCount) + '\' + IntToStr(item.InOboyma) + ')', MT_INFO, true);
        if Assigned(item.OnPickup) then
          item.OnPickup(tx, ty);
      end
      else
      begin
        hudmessage(STR_WAS_FOUND + item.name, MT_INFO, true);
        if Assigned(item.OnPickup) then
          item.OnPickup(tx, ty);
      end;
      cur_lev.map[tx, ty].item := 0;
      cur_lev.map[tx, ty].ItemCount := 0;
      gotoxy(tx, ty);
      osv;
      exit;
    end
    else if HasWeight(cur_lev.map[tx, ty].item, 1) then
      hudmessage(STR_INVENTORY_FULL, MT_ERROR, false)
    else
      hudmessage(STR_TOO_HEAVY, MT_ERROR, false);
    exit;
  end;
  if (item.itemtype = ITAmmo) then
  begin
    if Hasinv(item.number, cur_lev.map[tx, ty].ItemCount) then
    begin
      hudmessage(STR_WAS_FOUND + item.name + ' (' + inttostr(cur_lev.map[tx, ty].ItemCount) + ')', MT_INFO, true);
      addammo(item.number, cur_lev.map[tx, ty].ItemCount);
      if Assigned(item.OnPickup) then
        item.OnPickup(tx, ty);
      cur_lev.map[tx, ty].item := 0;
      cur_lev.map[tx, ty].ItemCount := 0;
    end
    else if HasWeight(cur_lev.map[tx, ty].item, cur_lev.map[tx, ty].ItemCount) then
      hudmessage(STR_INVENTORY_FULL, MT_ERROR, false)
    else
      hudmessage(STR_TOO_HEAVY, MT_ERROR, false);
    exit;
  end;
  if hasinv(cur_lev.map[tx, ty].item, cur_lev.map[tx, ty].ItemCount) then
  begin
    addinv(cur_lev.map[tx, ty].item, cur_lev.map[tx, ty].ItemCount);
    gotoxy(1, RESOLUTION_Y + 3);
    textcolor(green);
    s := item.name;
    if ((item.number >= TECHNO_MIN) and (item.number <= TECHNO_MAX)) then
    begin
      i := data.technoZ[cur_lev.map[tx, ty].item - TECHNO_MIN + 1].num;
      s := STR_TECHNOZ[i] + STR_TECHNO;
      if (data.TechnoZ[cur_lev.map[tx, ty].item - TECHNO_MIN + 1].examined) then
        s := s + item.name;
    end
    else if ((item.number >= FLOPPY_MIN) and (item.number <= FLOPPY_MAX)) then
    begin
      i := data.nanoz[cur_lev.map[tx, ty].item - FLOPPY_MIN + 1].num;
      s := STR_PROG + ' ';
      if data.NanoZ[cur_lev.map[tx, ty].item - FLOPPY_MIN + 1].examined then
        s := s + item.name
      else
        s := s + STR_NANOZ[i];
    end
    else if ((item.number >= DRINK_MIN) and (item.number <= DRINK_MAX)) then
    begin
      s := STR_DRINK;
      if data.DrinkZ[cur_lev.map[tx, ty].item - DRINK_MIN + 1].examined then
        s := s + item.name
      else
        s := STR_DRINKZ[data.drinkZ[cur_lev.map[tx, ty].item - DRINK_MIN + 1].num] + ' ' + s;
    end;
    hudmessage(STR_WAS_FOUND + s, MT_INFO, true);
    if Assigned(item.OnPickup) then
      item.OnPickup(tx, ty);
    cur_lev.map[tx, ty].item := 0;
    cur_lev.map[tx, ty].ItemCount := 0;
  end
  else if HasWeight(cur_lev.map[tx, ty].item, cur_lev.map[tx, ty].ItemCount) then
    hudmessage(STR_INVENTORY_FULL, MT_ERROR, false)
  else
    hudmessage(STR_TOO_HEAVY, MT_ERROR, false);
  gotoxy(tx, ty);
  osv;
end;

procedure talking(xx, yy: shortint);
var
  x, y: byte;
begin
  x := wherex;
  y := wherey;
  if (cur_lev.map[x + xx, y + yy].Monster.montype = 60001) then
  begin
    data.posx := wherex;
    data.posy := wherey;
    data.IsInInv := true;
    aTradeMenu(cur_lev.map[x + xx, y + yy].Monster.montype);
    data.IsInInv := false;
    gotoxy(data.posx, data.posy);
    clean_all;
    osv;
  end
  else
  begin
    x := wherex;
    y := wherey;
    if not molchun(x + xx, y + yy) then
      talk(x + xx, y + yy)
    else
      SayRandomPhrase(x + xx, y + yy);
    clrscr;
    gotoxy(x, y);
    clean_all;
    osv;
  end;
end;


procedure richag;
var
  xt, yt: byte;
  sobx, soby: integer;
begin
  xt := wherex;
  yt := wherey;
  sobx := cur_lev.map[wherex, wherey].ObjAttrz div 256;
  soby := cur_lev.map[wherex, wherey].ObjAttrz mod 256;
  if (sobx > 0) and (soby > 0) then
  begin
    if (IsType(sobx, soby, 'Wall')) then
    begin
      SetElement(sobx, soby, 'Floor');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_WALL_DOWN, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
        hudmessage(STR_WALL_DOWN, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Floor')) then
    begin
      SetElement(sobx, soby, 'Wall');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_WALL_UP, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_WALL_UP, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Water')) then
    begin
      SetElement(sobx, soby, 'Floor_water');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_BRIDGE_UP, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_BRIDGE_UP, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Floor_water')) then
    begin
      SetElement(sobx, soby, 'Water');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_BRIDGE_DOWN, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_BRIDGE_DOWN, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Blood')) then
    begin
      SetElement(sobx, soby, 'Floor_blood');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_BRIDGE_UP, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_BRIDGE_UP, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Floor_blood')) then
    begin
      SetElement(sobx, soby, 'Blood');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_BRIDGE_DOWN, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_BRIDGE_DOWN, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Door')) then
    begin
      SetElement(sobx, soby, 'Door_open');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_DOOR_OPENED, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_DOOR_OPENED, MT_TEXT, false);
    end
    else if (IsType(sobx, soby, 'Door_open')) then
    begin
      SetElement(sobx, soby, 'Door');
      if (cur_lev.map[sobx, soby].vid <> #0) then
      begin
        GoToXY(sobx, soby);
        osv;
        hudmessage(STR_DOOR_CLOSED, MT_TEXT, false);
        readkey;
        GoToXY(xt, yt);
      end
      else
         hudmessage(STR_DOOR_CLOSED, MT_TEXT, false);
    end;
  end;
  if (IsObject(xt, yt, 'Richag')) then
    SetObject(xt, yt, 'Richag_2')
  else
    SetObject(xt, yt, 'Richag');
  gotoxy(xt, yt);
  osv(data.Light_color, true);
end;

begin
end.