@@ -27,6 +27,7 @@ Main type to handle {ref}`RSEntity`.
2727 TRSEntity = record
2828 UpText: TStringArray;
2929 Size: TVector3;
30+ Model: TModel;
3031 Coordinates: TPointArray;
3132 Filter: TRSDotFilterArray;
3233 Finder: TColorFinder;
99100
100101function TRSEntity.Create(json: TJSONObject): TRSEntity; static; overload;
101102var
102- i: Integer;
103- colors: TColorArray;
103+ i, j, l: Integer;
104+ unique: array of TColorArray;
105+ color: TColor;
104106 best: TBestColor;
105107 coord: TJSONArray;
106108begin
@@ -134,12 +136,27 @@ begin
134136
135137 with json.Item[Ord(ENPCData.COLORS)] do
136138 for i := 0 to Count-1 do
137- colors += Item[i].AsInt;
139+ begin
140+ color := Item[i].AsInt;
141+
142+ for j := 0 to High(unique) do
143+ begin
144+ for l := 0 to High(unique[j]) do
145+ if ColorDistance(color, unique[j, l], EColorSpace.HSL, [1.5, 1.5, 1.5]) < 15 then
146+ begin
147+ unique[j] += color;
148+ Continue(3);
149+ end;
150+ end;
151+
152+ unique += [color];
153+ end;
138154
139- if colors <> [] then
155+ for i := 0 to High(unique) do
140156 begin
141- best := GetBestColor(EColorSpace.HSV, colors);
142- Result.Finder.Colors += [best.Color, best.Tolerance, EColorSpace.HSV, best.Mods];
157+ best := GetBestColor(EColorSpace.HSL, unique[i]);
158+ WriteLn best;
159+ Result.Finder.Colors += [best.Color, best.Tolerance*1.5, EColorSpace.HSL, [best.Mods[0]*1.5, best.Mods[1]*1.5, best.Mods[2]*1.5]];
143160 end;
144161
145162 Result.Walker := @Map.Walker;
@@ -181,19 +198,21 @@ end;
181198
182199
183200(*
184- ## Entity._GetCuboid
201+ ## Entity._GetBounds
185202```pascal
186- function TRSEntity._GetCuboid (me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;
203+ function TRSEntity._GetBounds (me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;
187204```
188- Internal helper function for {ref}`TRSEntity.GetCuboidArray `.
205+ Internal helper function for {ref}`TRSEntity.GetBoundsArray `.
189206*)
190- function TRSEntity._GetCuboid (me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid ;
207+ function TRSEntity._GetBounds (me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TPolygon ;
191208var
192209 corners: TVector3Array;
193210 pt: TPoint;
194- arr: TPointArray;
195211begin
196212 pt := me + vector.ToPoint() - Minimap.Center;
213+ if Self.Model <> nil then
214+ Exit(Self.Model.GetArea(Self.Model.Project(vector.ToVec3(Self.Walker^.Height(pt, False) - height), 0, radians)));
215+
197216
198217 size.X := size.X*2;
199218 size.Y := size.Y*2;
@@ -209,21 +228,18 @@ begin
209228 [vector.X-size.X, vector.Y+size.Y, Self.Walker^.Height(pt - [1,1], False) - height+size.Z]
210229 ];
211230
212- arr := Projection.Run(corners, radians);
213- Result := [
214- [arr[4], arr[5], arr[6], arr[7]], [arr[0], arr[1], arr[2], arr[3]]
215- ];
231+ Result := Projection.Run(corners, radians).ConvexHull();
216232end;
217233
218234(*
219- ## Entity.GetCuboidArray
235+ ## Entity.GetBoundsArray
220236```pascal
221- function TRSEntity.GetCuboidArray (me: TPoint; angle: Single = $FFFF): TCuboidArray;
237+ function TRSEntity.GetBoundsArray (me: TPoint; angle: Single = $FFFF): TCuboidArray;
222238```
223239Internal function that returns an array of cuboids of the entity if it's visible
224240on the {ref}`MainScreen`.
225241*)
226- function TRSEntity.GetCuboidArray (me: TPoint; out coordinates: TPointArray; radians: Single = $FFFF): TCuboidArray ;
242+ function TRSEntity.GetBoundsArray (me: TPoint; out coordinates: TPointArray; radians: Single = $FFFF): TPolygonArray ;
227243var
228244 weights: TDoubleArray;
229245 meLocal, pt: TPoint;
@@ -255,7 +271,7 @@ begin
255271
256272 vector := Self.Walker^.Point2MMVec(me, pt, radians);
257273 vector := vector.Rotate(-radians, Minimap.Center);
258- Result += Self._GetCuboid (meLocal, vector, Self.Size, h, radians);
274+ Result += Self._GetBounds (meLocal, vector, Self.Size, h, radians);
259275 end;
260276 Exit;
261277 end;
@@ -272,12 +288,12 @@ begin
272288
273289 vector := Self.Walker^.Point2MMVec(me, pt, radians);
274290 vector := vector.Rotate(-radians, Minimap.Center);
275- Result += Self._GetCuboid (meLocal, vector, Self.Size, h, radians);
291+ Result += Self._GetBounds (meLocal, vector, Self.Size, h, radians);
276292 end;
277293
278294 if Result <> [] then
279295 begin
280- Result. Sort(weights, True);
296+ Sort(Result, weights, True);
281297 coordinates.Sort(weights, True);
282298 end;
283299end;
@@ -288,17 +304,17 @@ end;
288304function TRSEntity.Find(cuboidArray: TCuboidArray): T2DPointArray;
289305```
290306Internal TRSEntity method responsible for filtering a TCuboidArray by what's visible in the mainscren.
291- This is meant to filter TRSEntity.GetCuboidArray () so targets that are outside of the mainscreen are filtered out.
307+ This is meant to filter TRSEntity.GetBoundsArray () so targets that are outside of the mainscreen are filtered out.
292308You will probably never need to use this directly.
293309*)
294- function TRSEntity.FindOnMainScreen(out coordinates: TPointArray; cuboidArray: TCuboidArray ): T2DPointArray;
310+ function TRSEntity.FindOnMainScreen(out coordinates: TPointArray; boundsArray: TPolygonArray ): T2DPointArray;
295311var
296312 i: Integer;
297313 found: TBooleanArray;
298314begin
299315 if Self.Finder <> Default(TColorFinder) then
300316 begin
301- Self.Finder.FindEx(Result, found, cuboidArray );
317+ Self.Finder.FindEx(Result, found, boundsArray, Self.Model = nil );
302318
303319 for i := High(found) downto 0 do
304320 if not found[i] then
@@ -307,8 +323,8 @@ begin
307323 Exit;
308324 end;
309325
310- for i := 0 to High(cuboidArray ) do
311- Result += cuboidArray [i].ShapeFill();
326+ for i := 0 to High(boundsArray ) do
327+ Result += TPointArray(boundsArray [i]) .ShapeFill();
312328end;
313329
314330(*
@@ -327,29 +343,29 @@ WriteLn RSObjects.GEBank.Find(atpa); //Be in ge and with a walker setup there.
327343Debug(atpa);
328344```
329345*)
330- function TRSEntity.FindEx(me: TPoint; out cuboids: TCuboidArray ; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
346+ function TRSEntity.FindEx(me: TPoint; out boundsArray: TPolygonArray ; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
331347begin
332- cuboids := Self.GetCuboidArray (me, coordinates);
333- if cuboids = [] then Exit;
334- atpa := Self.FindOnMainScreen(coordinates, cuboids );
348+ boundsArray := Self.GetBoundsArray (me, coordinates);
349+ if boundsArray = [] then Exit;
350+ atpa := Self.FindOnMainScreen(coordinates, boundsArray );
335351
336352 Result := atpa <> [];
337353end;
338354
339355
340356function TRSEntity.Find(out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
341357var
342- cuboids: TCuboidArray ;
358+ boundsArray: TPolygonArray ;
343359begin
344- Result := Self.FindEx(Self.Walker^.Position(), cuboids , coordinates, atpa);
360+ Result := Self.FindEx(Self.Walker^.Position(), boundsArray , coordinates, atpa);
345361end;
346362
347363function TRSEntity.FindFrom(position: TPoint; out atpa: T2DPointArray): Boolean;
348364var
349- cuboids: TCuboidArray ;
365+ boundsArray: TPolygonArray ;
350366 coordinates: TPointArray;
351367begin
352- Result := Self.FindEx(position, cuboids , coordinates, atpa);
368+ Result := Self.FindEx(position, boundsArray , coordinates, atpa);
353369end;
354370
355371(*
@@ -803,7 +819,7 @@ procedure TImage.DrawEntity(entity: TRSEntity);
803819var
804820 me: TPoint;
805821 atpa: T2DPointArray;
806- cuboids: TCuboidArray ;
822+ boundsArray: TPolygonArray ;
807823 i: Integer;
808824 filters: TRSDotFilterArray;
809825 filter: TRSDotFilter;
@@ -826,22 +842,15 @@ begin
826842 Self.DrawCircle(filter.Circle);
827843 end;
828844
829- if not entity.FindEx(me, cuboids, coordinates, atpa) then
830- Exit;
831-
832- Self.DrawColor := $00FFFF;
833- for i := 0 to High(cuboids) do
845+ if entity.FindEx(me, boundsArray, coordinates, atpa) then
834846 begin
835- Self.DrawTPA(cuboids[i].Bottom.Corners.Connect().Grow(1) );
836- Self.DrawTPA(cuboids[i].Top.Corners.Connect().Grow(1) );
847+ Self.DrawColor := TColor.Random( );
848+ Self.DrawATPA(atpa );
837849 end;
838850
839- Self.DrawColor := TColor.Random();
840- Self.DrawATPA(atpa);
841-
842- Self.DrawColor := $FFFFFF;
843- for i := 0 to High(cuboids) do
844- Self.DrawTPA(cuboids[i].Edges());
851+ Self.DrawColor := $FFFFF;
852+ for i := 0 to High(boundsArray) do
853+ Self.DrawTPA(boundsArray[i].Connect());
845854end;
846855
847856procedure ShowOnTarget(entity: TRSEntity); overload;
0 commit comments