LordJashin Posted December 8, 2012 Share Posted December 8, 2012 My brain hurts atm. Please help if you can! Can't seem to make this on my own. This needs to be added to OSI/MSSL anyway... Quote Link to comment Share on other sites More sharing options...
Janilabo Posted December 8, 2012 Share Posted December 8, 2012 +1 to this. Although, MantisBT is the key here. Should be easy job for Freddy to add version for TEA (now that TIA and TPA are already supported).. I don't blame you for getting a headache of trying to make function like it. It's some scary math + logic behind it. BTW, script version might be a bit too slow anyways, so lets hope Freddy adds this in SCAR. -Jani Quote Link to comment Share on other sites More sharing options...
LordJashin Posted December 8, 2012 Author Share Posted December 8, 2012 (edited) Just trying to achieve my goal with this damn rotated DTM. Here's how I've got it setup: 1. Does one point at a time. Rotates that point as specified...saves all those points in the RotationTPA. 2. Also saves all the rotations in Rotation TExtArray. 3. Extracts Box (XS, YS, XE, YE) to get rid of the out of bounds points. 4. Then uses FindColorTPATolEx 5. Then with everything found. I get the rotations that each point was supposed to have been rotated at, and put the rotation amount into an array. 6. Then I find which rotation showed up the most (FREQUENCY). And if it shows up more than the number of SubPoints the DTM has. Then thats the right answer 7. Finally because we got the right answer we return everything yadadada and here's the code, I'm going to try some more things. I think the P variable might be the problem... [scar] type TJashDTMPoint = record Point: TPoint; Color, Tolerance: Integer; end; TJashDTMPointArray = array of TJashDTMPoint; TJashDTM = record MainPoint: TJashDTMPoint; SubPoints: TJashDTMPointArray; end; function JashDTMTPA(JDTM: TJashDTM): TPointArray; var i, h, j: Integer; begin h := high(JDTM.SubPoints); SetLength(Result, h + 2); Result[0] := JDTM.MainPoint.Point; for i := 1 to high(Result) do begin Result := JDTM.SubPoints[j].Point; j := j + 1; end; end; function TPAPositions(TPA: TPointArray; pt: TPoint): TIntArray; {==============================================================================] Created: September 30th, 2012. Contributors: Janilabo Explanation: Returns all the pt positions in TPA. [==============================================================================} var i, h, rC: Integer; begin h := High(TPA); SetLength(Result, (h + 1)); for i := 0 to h do if ((pt.x = TPA.x) and (pt.y = TPA.y)) then begin Result[rC] := i; Inc(rC); end; SetLength(Result, rC); end; procedure JashTEAMaxFreq(TEA: TExtArray; out Freq, Index: Integer); var i, j, h, z: Integer; Freqs, Indxs: TIntArray; begin h := high(TEA); if h < 1 then Exit; for i := 0 to h do begin z := TEAPosEx(TEA, TEA, 0); Repeat if (z > -1) then j := j + 1; z := TEAPosEx(TEA, TEA, z + 1); until (z = -1); SetLength(Freqs, i + 1); SetLength(Indxs, i + 1); Freqs := j; Indxs := i; end; Freq := TIAMaxEx(Freqs, Index); SetLength(Freqs, 0); SetLength(Indxs, 0); end; function JashDTMFindRotated(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; StartAng, EndAng, AngStep: Extended; var ang: Extended): Boolean; var i, h, j, k, t, z, Freq, Indx: Integer; P: TPoint; Indxs: TIntArray; MainTPA, FoundTPA, RotationTPA: TPointArray; Rotation: TExtArray; RotationTExt: TExtArray; currAng: Extended; B: Boolean; begin //if not JashDTMExists(JDTM) then Exit; if not FindColorTolEx(MainTPA, JDTM.MainPoint.Color, XS, YS, XE, YE, JDTM.MainPoint.Tolerance) then Exit; h := high(JDTM.SubPoints); k := high(MainTPA); for i := 0 to h do JDTM.SubPoints.Point := RotatePoint(JDTM.SubPoints.Point, JDTM.MainPoint.Point, StartAng); currAng := StartAng; ang := StartAng; for i := 0 to k do begin for j := 0 to h do begin repeat P := Point((MainTPA.X + (JDTM.SubPoints[j].Point.X - JDTM.MainPoint.Point.X)), (MainTPA.Y + (JDTM.SubPoints[j].Point.Y - JDTM.MainPoint.Point.Y))); SetLength(RotationTPA, z + 1); SetLength(Rotation, z + 1); Inc(z); RotationTPA[z - 1] := P; Rotation[z - 1] := currAng; RotatePoint(P, JDTM.MainPoint.Point, AngStep); currAng := currAng + AngStep; until ((currAng - AngStep) >= EndAng); TPAExtractBoxes(RotationTPA, [box(XS, YS, XE, YE)]); if FindColorTPATolEx(FoundTPA, JDTM.SubPoints[j].Color, RotationTPA, JDTM.SubPoints[j].Tolerance) then begin for z := 0 to high(FoundTPA) do begin Indxs := TPAPositions(RotationTPA, FoundTPA[z]); for t := 0 to high(Indxs) do begin SetLength(RotationTExt, Length(RotationTExt) + 1); RotationTExt[Length(RotationTExt) - 1] := Rotation[indxs[t]]; end; end; end; end; JashTEAMaxFreq(RotationTExt, Freq, Indx); if (Freq > (h + 1)) then begin Result := True; X := MainTPA.X; Y := MainTPA.Y; ang := RotationTExt[indx]; B := True; end; SetLength(FoundTPA, 0); SetLength(RotationTPA, 0); SetLength(Rotation, 0); SetLength(RotationTExt, 0); SetLength(Indxs, 0); if B then Break; end; SetLength(MainTPA, 0); end; function JashDTMFind(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer): Boolean; var ang: Extended; begin Result := JashDTMFindRotated(X, Y, JDTM, XS, YS, XE, YE, 0, 0, 0, ang); end; [/scar] This is the hard way of doing it, but hell this thing would be a lot faster. The old one i had always took 5+ seconds to find one that was rotated. EDIT: Well I debugged it, and its messing up when it first makes the rotation array, and some other things... Edited December 8, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
tweakmeup Posted December 9, 2012 Share Posted December 9, 2012 Well when you finish this function and freddy puts it into scar I can promise you I will be the first one using it . Thanks for all your hard work, anr if I knew how to do this sort of thing I woukd certainly help you out. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted December 9, 2012 Author Share Posted December 9, 2012 (edited) I'm glad you posted. Sometimes I feel like I'm beating a dead horse on here . Freddy will do things as planned, so just wait a couple months and things will get better . There is no easy way for this. It would either be my DTM functions or the Bitmaps I've been thinking of for minimap walking. For the functions I created. The rotate one takes too long. I tried to recreate it, but at the moment it is dead lols. I won't continue on this any longer until Freddy adds TEAFreq to SCAR svn. Then I will try again... Now....How to do this with bitmaps. Well. Think about DTMs and Bitmaps. DTMs are just a set of points and the colors at each point. Then FindDTM is supposed to find all of that. We can recreate this with bitmaps in steps like this: 1. Make a new bitmap, Make it the SIZE OF THE DTM e.g. Width, and Height of it 2. Clear the Bitmap so it is totally black (if it isn't already ) 3. Make the TranspColor property to Black, so when using Bitmap searchs black is left out 4. Color certain pixels (points) on the Bitmap to their specified colors that the DTM has. 5. Use FindBitmapRotated on it now This may sound confusing, but its just MATH + Logic + Colors/Points I would try this out right now but I'm burnt out atm EDIT: I wish SCAR's dang debugging would work with those DTM functions I created. Makes finding the problems harder. I will try using comments too eventually. I've already done writelning Edited December 9, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
tweakmeup Posted December 11, 2012 Share Posted December 11, 2012 Looks like 3.38b gave you teafreq hooefully it will help you out a bit more. Havent heard any updates on this lately, hope things are going well. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted December 11, 2012 Author Share Posted December 11, 2012 Been busy lately, I will try it out more when I can, later. Quote Link to comment Share on other sites More sharing options...