Code: Select all
Program LumberVesper;
{$Include 'all.inc'}
type
 region= record
  minX:word;
  minY:word;
  maxX:word;
  maxY:word;
 end;
const
 hatcher=$0F43; // тип топора
 safe=$402D0282; // id хауссейфа
 logs=$1BDD; // тип логов
 Eat=$160A;
 to_house='1025';
 to_vesper='21';
 
  runebook=$40465EE2; // id книги рун
 
 l_fizzles='You hack at the tree for a while, but fail to produce any useable wood.';
 l_nothing1='There are no logs here to chop.';
 l_nothing2='You can''t reach this.';
 l_needwait ='You must wait to perform another action';
 l_success = 'in your pack.';
 l_bad ='Unexpected target info';
 l_heavy ='at your feet';
 l_far='That is too far away.';
 l_elemental ='Ent';
 l_see='You have no line of sight to that location';
 
 
var
 tfta,temp,res_arr:TFoundTilesArray;
 RegArr: array [0..10] of region;
 TreeTile:array [0..9] of word;
 rs,i,j,k,sum,arr_sum:word;
 start_p: TFoundTile;
procedure init;
begin
 // start point
 start_p.X:=2898;
 start_p.Y:=648;
 //Tile Tree
 TreeTile[0]:=3283;
 TreeTile[1]:=3277;
 TreeTile[2]:=3293;
 TreeTile[3]:=3296;
 TreeTile[4]:=3302;
 TreeTile[5]:=3299;
 TreeTile[6]:=3290;
 TreeTile[7]:=3288;
 TreeTile[8]:=3286;
 TreeTile[9]:=3280;
 
 
 //region initialization
 RegArr[0].minX:=2840;
 RegArr[0].minY:=648;
 RegArr[0].maxX:=2933;
 RegArr[0].maxY:=760;
end;
procedure Wait_Target(time_ms:Cardinal);
var
 TempTime,SumTime:Cardinal;
begin
 SumTime:=0;
 repeat
  checksave;
  wait(500);
  TempTime:=Timer;
  SumTime:=SumTime+(Timer-TempTime);
 until ((targetpresent) or (dead) or (not connected) or (SumTime>time_ms));
end;
function redcheck:boolean;
var
 nn : integer;
 l : TStringList;
 finded : Boolean;
begin
 finddistance:=7;
 finded := False;
 l := TStringList.Create();
 Ignore(self);
 FindType(-1,ground);
 GetFindedList(l);
 if (l.count > 0) then
 begin
  for nn:= 0 to (l.count-1) do
     if (IsNPC(StrToInt('$'+l.strings[nn]))) then
      if (GetNotoriety(StrToInt('$'+l.strings[nn]))>3) then
       if (not IsDead(StrToInt('$'+l.strings[nn]))) then finded := true;
 end;
 l.free;
 if WarTargetID<>0 then AddToSystemJournal('гвардуем воюющего!');
 if finded then AddToSystemJournal('просто гвардуем криминала!');
 if WarTargetID<>0 then
   if FindType(GetType(WarTargetID),ground)<>0 then finded := true;
 if finded then result:=true else result:=false;
end;
procedure check_war;
begin
if IsWarMode(self) then
 begin
  UoSay('Guards');
  SetWarMode(false);
  wait(1100);
  setWarMode(false);
 end;
end;
procedure check_hide;
var
 ctime: TDateTime;
begin
 if not isHidden(self) then
  repeat
   check_war;
   ctime:=now;
   UseSkill('Stealth');
   repeat
    check_war;
    checksave;
    wait(500);
   until (inJournalBetweenTimes('hidden|hide|wait', ctime, Now)<>-1);
  until IsHidden(self);
end;
function sqr(a:LongInt):LongInt;
begin
 result:=a*a;
end;
function vector_length(c_1,c_2:TFoundTile):LongInt;
begin
 result:=Round(sqrt(sqr(c_1.X-c_2.X)+sqr(c_1.Y-c_2.Y)));
end;
{ сортировка минимальным маршрутом }
procedure QuickSort(var item:TFoundTilesArray; count:integer; point:TFoundTile);
var
 temp_index,temp_value, tempo,i,j:LongInt;
 t_c:TFoundTile;
begin
 AddToSystemJournal('сортируем '+IntToStr(count)+' деревьев');
 //for i:=0 to count-1 do AddToSystemJournal(IntToStr(vector_length(start_p,item[i])));
 t_c:=point;
 temp_index:=0;
 temp_value:=vector_length(t_c,item[temp_index]);
 for i:=0 to count-2 do
 begin
  for j:=i to count-1 do
   begin
    tempo:=vector_length(t_c,item[j]);
    if tempo<temp_value then
     begin
      temp_index:=j;
      temp_value:=tempo;
     end;
   end;
   t_c:=item[temp_index];
   item[temp_index]:=item[i];
   item[i]:=t_c;
   temp_value:=vector_length(item[i],item[i+1]);
 end;
 AddToSystemJournal('Готово...');
end; { конец  сортировки }
procedure equip_tool(type_of_tool:word;layer:Byte);
begin
   if (GetType(ObjAtLayer(layer))<>type_of_tool) then
    begin
     if layer=RhandLayer then unequip(RhandLayer)else unequip(LhandLayer);
     wait(500);
     if layer=RhandLayer then equipt(RhandLayer,type_of_tool) else equipt(LhandLayer,type_of_tool);
    end;
  repeat
    wait(500);
    checksave;
   until (GetType(ObjAtLayer(layer))=type_of_tool);
end;
procedure Chop(f_tile:TFoundTile);
var
 ctime : TDateTime;
 iter_max:integer;
 next_lumb,lumb_result,wait_lumb: string;
 fizzles:word;
begin
 wait_lumb:=l_fizzles+'|'+l_needwait;
 next_lumb:=l_nothing1+'|'+l_nothing2+'|'+l_far+'|'+l_see;;
 lumb_result:=wait_lumb+'|'+next_lumb+'|'+l_success+'|'+l_elemental+'|'+l_bad+'|'+l_heavy;
 fizzles:=0;
 repeat
  equip_tool(hatcher,LhandLayer);
  if TargetPresent then CancelTarget;
  iter_max:=0;
  UseObject(ObjAtLayer(LhandLayer));
  Wait_Target(5000);
  ctime := Now;
  TargetToTile(f_tile.Tile,f_tile.X,f_tile.Y,f_tile.Z);
  repeat
   iter_max:=iter_max+1;
   wait(1000);
   checksave;
   check_war;
  until  ((InJournalBetweenTimes(lumb_result, ctime, Now)<>-1) or (iter_max>10));
  if (InJournalBetweenTimes(l_fizzles, ctime, Now)<>-1) then fizzles:=fizzles+1;
  if (InJournalBetweenTimes('OOPS !!! It isn''t a tree, it''s an Ent!!!|is attacking you|Vas Corp Por|notice', ctime, Now)<>-1) then
   begin
    wait(1000);
    UOSay('guards');
    alarm;
   end;
 until ((InJournalBetweenTimes(next_lumb, ctime, Now)<>-1) or (fizzles>15));
end;
procedure rec_RB(rune:string);
var
 tx,ty,i:word;
begin
 tx:=GetX(self);
 ty:=GetY(self);
 repeat
  UseObject(runebook);
  WaitGump(rune);
  i:=0;
  repeat
   checksave;
   i:=i+1;
   wait(500);
  until ((tx<>GetX(self)) and (ty<>GetY(self))) or (i>60);
 until (tx<>GetX(self)) and (ty<>GetY(self));
 addtosystemjournal('recall ok');
end;
procedure unload;
begin
 rec_RB(to_house);
 wait(500);
 //unload logs
 check_hide;
 while FindType(logs,backpack)<>0 do
  begin
   checksave;
   MoveItem(FindItem,GetQuantity(FindItem),safe,0,0,0);
   wait(1000);
  end;
 rec_RB(to_vesper);
end;
 
Begin
 //WalkUnmountTimer = 450;
 init;
 sum:=0;
 MoveXY(start_p.X,start_p.Y,true,1,false);
 // поиск деревьев и составление массива
  arr_sum:=0;
   for i:=0 to 9 do
    begin
     rs:=GetStaticTilesArray(RegArr[j].minX,RegArr[j].minY,RegArr[j].maxX,RegArr[j].maxY,1,TreeTile[i],tfta);
     if rs>0 then
      for k:=0 to rs-1 do temp[arr_sum+k]:=tfta[k];
     arr_sum:=arr_sum+rs;
    end;
   QuickSort(temp,arr_sum,start_p);
   for k:=0 to arr_sum-1 do res_arr[sum+k]:=temp[k];
   sum:=sum+arr_sum;
 // рубка по составленному массиву
 check_hide;
 while not dead do
 begin
  i:=0;
  j:=sum-1;
  //for i:=0 to sum-1 do
  while (i<j) do
   begin
   ClearBadLocationList;
   MoveXY(res_arr[i].X,res_arr[i].Y,true,1,false);
   check_hide;
   chop(res_arr[i]);
    i:=i+1;
    if Weight>=730 then
     begin
      unload;
      i:=j;
     end;
    end;
  end;
End.


