Code: Select all
{$Region 'Declaration of specific types'}
type
TTree = record
Tile : Word;
X,Y,Z : Integer;
WhenChopped : TDateTime;
DistanceToChest : Word;
end;
type
TLootItem = record
TypeOf : Word;
Color : Word;
Name : String;
SessionCount : Integer;
end;
type
TUnloadChest = record
X,Y : Integer;
Id : Cardinal;
end;
type
TConstants = record
UnloadChest : TUnloadChest;
TrashBarrel : Cardinal;
ThrowAwayItems : Array of Word;
HatchetsTypes : Array of Word;
end;
type
TRessurrecter = record
Name : String;
Id : Cardinal;
ApproxX, ApproxY : Integer;
end;
type
TForestSpot = record
X,Y : Integer;
Name : String;
end;
type
TSessionHarvestedData = record
StartTime : TDateTime;
LootItems : Array of TLootItem;
end;
type
TLumberjackerData = record
Constants : TConstants;
SessionHarvestedData : TSessionHarvestedData;
Trees : Array of TTree;
ForestSpots : Array of TForestSpot;
Ressurrecters : Array of TRessurrecter;
end;
{$EndRegion}
var
LumberjackerData : TLumberjackerData;
FlagStop : Boolean;
{$Region 'Configuring'}
Procedure InitScriptSystemData(ConfigName : String);
begin
//Initializing global constant section
with LumberjackerData.Constants do begin
ThrowAwayItems := [$1F03];
HatchetsTypes := [$0F43];
end;
LumberjackerData.SessionHarvestedData.StartTime := Now;
//Data specified to some house with unloadchest and trashbarrel
case ConfigName of
'Domik #1' : with LumberjackerData.Constants do begin
UnloadChest.Id := $0100001;
UnloadChest.X := 3461;
UnloadChest.Y := 2640;
end;
end;
end;
Procedure AddForestSpot(X, Y : Integer; Name : String);
begin
with LumberjackerData do begin
SetLength(ForestSpots, Length(ForestSpots) + 1);
ForestSpots[High(ForestSpots)].X := X;
ForestSpots[High(ForestSpots)].Y := Y;
ForestSpots[High(ForestSpots)].Name := Name;
end;
end;
Function SetConfigByCharName(CharName : String) : String;
begin
case CharName of
'Kranze' : begin
AddForestSpot(2015, 330, 'Kranze');
AddForestSpot(2015, 330, 'Kranze');
Result := 'Domik #1';
end;
end;
end;
{$EndRegion}
{$Region 'Trees array handling'}
Procedure AddTreeToArray(var TreesArray : Array of TTree; Tile : Word; X,Y,Z, UnloadChestX, UnloadChestY : Integer);
begin
SetLength(TreesArray, Length(TreesArray) + 1);
TreesArray[High(TreesArray)].X := X;
TreesArray[High(TreesArray)].Y := Y;
TreesArray[High(TreesArray)].Z := Z;
TreesArray[High(TreesArray)].DistanceToChest := Dist(X, Y, UnloadChestX, UnloadChestY);
end;
Procedure SortTreesArrayByDistanceToChest(var TreesArray : Array of TTree);
var
//arr : array of integer;
i : integer;
f : boolean;
c : integer;
begin
repeat
f := false;
//AddToSystemJournal(IntToStr(Length(arr)));
for i := Low(TreesArray) to High(TreesArray)-1 do
if (TreesArray[i].DistanceToChest > TreesArray[i+1].DistanceToChest) then
begin
f := true;
c := TreesArray[i].DistanceToChest;
TreesArray[i].DistanceToChest := TreesArray[i+1].DistanceToChest;
TreesArray[i+1].DistanceToChest := c;
end;
until not f;
end;
//return count of trees marked
Function SetTreesAtForestSpot(var TreesArray : Array of TTree) : Integer;
var
ATiles : Array of Integer;
x,y,i,k : Integer;
TileInfo : TStaticCell;
begin
ATiles := [3274,3275,3277,3280,3283,3286,3288,3290,3293,3296,3299,3302,3320,3323,3326,3329,3393,3394,3395,3396,3415,3416,3417,3418,3419,3438,3439,3440,3441,3442,3460,3461,3462,3476,3478,3480,3482,3484,3492,3496];
for x := (-1 * 20) to 20 do
for y := (-1 * 20) to 20 do
begin
//AddToSystemJournal(IntToStr(Length(ATiles)));
TileInfo := ReadStaticsXY(GetX(self)+x, GetY(self)+y, 0);
if TileInfo.StaticCount > 0 then
for i := Low(TileInfo.Statics) to High(TileInfo.Statics) do
for k := 0 to Length(ATiles)-1 do
begin
//AddToSystemJournal(IntToStr(TileInfo.Statics[i].Tile) + ' + ' + IntToStr(ATiles[k]));
if (TileInfo.Statics[i].Tile = ATiles[k]) then
AddTreeToArray(LumberjackerData.Trees ,TileInfo.Statics[i].Tile, TileInfo.Statics[i].x, TileInfo.Statics[i].y, TileInfo.Statics[i].z, LumberjackerData.Constants.UnloadChest.X, LumberjackerData.Constants.UnloadChest.Y);
end;
end;
Result := Length(LumberjackerData.Trees);
SortTreesArrayByDistanceToChest(LumberjackerData.Trees);
end;