SRL Archive - Reflection Discussion

What the hell?


n3ss3s

2009-01-05 07:38:55

Function FindObject(Var Tile: TPoint; objType: Integer): Boolean;
// Yakman's spiral algorithm =]

Var
Dir, tLength, f, X, Y: Integer;
TP: TPoint;
TileObject: UID;
Begin
TP := GetMyPos;
X := TP.X;
Y := TP.Y;
Dir := 0;
tLength := 1;
While (tLength < 9) Do
Begin
For F := 0 To tLength - 1 Do
Begin
Case Dir of
0: Dec(Y);
1: Inc(X);
2: Inc(Y);
3: Dec(X);
End;
TileObject := GetObjectAt(X, Y);
If TileObject.objType = objType Then
Begin
//Writeln('Found Type ' + IntToStr(objType) + ' at X ' + IntToStr(X) +
//' Y ' + IntToStr(Y));
Result := True;
TP := GetObjectTile(TileObject.UID);
Tile.X := TP.X
Tile.Y := TP.Y;
Exit;
End Else
//Writeln('X: '+IntToStr(X)+' Y:'+IntToStr(Y)+ ' '+IntToStr(TileObject.objType));
End;
Inc(Dir);
dir := dir Mod 4;
If Dir Mod 2 = 0 Then
Inc(tLength);
End;
End;

RAWR!

I could bet my ass that when me and bob made it and it was put into the SvN, there was a MaxLength parameter?

Anyone had trouble finding objects a little bit more far away?

While (tLength < 9) Do

ORLY? @@@@@@@@@@@@@@@@@@@@@

You can find objects only freaking max 4 tiles away from you!

Shame on whoever did this update…


/rant



EDIT: Also would be nice if you people would put what you changed into the log instead of

"It's better now! -namehere"

Capricorn

2009-01-05 07:45:55

Lol, why would they do that when if the object is offscreen you could just move to the tile via minimap?

n3ss3s

2009-01-05 07:52:50

From: Capricorn
Lol, why would they do that when if the object is offscreen you could just move to the tile via minimap?


Yeah… Someone didn't think :(

Nava2

2009-01-05 08:34:46

That might have been me by accident, but I never edited that function.

I only did the Ground Items and I didn't mod any parameters, sorry if it was me, but I don't think I did.

Edit:

I don't think there ever was that parameter actually, there would be no reason for it.

Method

2009-01-05 09:28:19

From: Nava2
That might have been me by accident, but I never edited that function.

I only did the Ground Items and I didn't mod any parameters, sorry if it was me, but I don't think I did.

Edit:

I don't think there ever was that parameter actually, there would be no reason for it.


Nava2's right, there never was a length parameter when it was first added to the SVN.

Also, what do you suggest changing that integer in the while loop to?

Narcle

2009-01-05 14:37:01

From: Nava2
I don't think there ever was that parameter actually, there would be no reason for it.


I'll confirm that. The only place you set how many to find is in Ground Items, you (or whoever) never did that for Objects.

n3ss3s

2009-01-05 15:55:46

Alright, well please someone with a Reflection SvN account add the max sidelength as a param,


Also, what do you suggest changing that integer in the while loop to?


Add a param, otherwise changing it to 104 would be the closest one to a good one :(

Nava2

2009-01-05 16:14:48

Uhm, I would rather not.

I WILL add a new function though, which uses it.

That way we won't have any scripts broken. :)

Edit:

This is what will be committed, any comments?

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- ยป Reflection Routines - Objects --||
//------------------------------------------------------------------//
// * Function GetObjectType(UID: Long): Integer; // * by Bobarkinator
// * Function GetObjectTile(UID: Long): TPoint; // * by Bobarkinator
// * Function GetObjectAt(TileX, TileY: Integer): UID; // * by Bobarkinator and n3ss3s
// * function FindObjectEx(Var Tile: TPoint; objType, // * by Bobarkinator and n3ss3s
// * MaxLength: Integer): Boolean; // *
// * Function FindObject(Var Tile: TPoint; // * by Bobarkinator and n3ss3s
// * objType: Integer): Boolean; // *
// * Procedure DumpAllObjects; // * by Bobarkinator

Type
Long = Record
High, Low: Integer;
End;

UID = Record
objType: Integer;
UID: Long;
End;



{*******************************************************************************
Function GetObjectType(UID: Long): Integer;
By: Bobarkinator
Description: Returns object type of a UID
*******************************************************************************}

Function GetObjectType(UID: Long): Integer;

Begin
Result := UID.High And $7fffffff;
End;

{*******************************************************************************
Function GetObjectTile(UID: Long): TPoint;
By: Bobarkinator
Description: Returns tile of a UID
*******************************************************************************}

Function GetObjectTile(UID: Long): TPoint;

Begin
Result.X:= (SmartGetFieldInt(0, BaseX) + (UID.Low And $7f));
Result.Y:= (SmartGetFieldInt(0, BaseY) + ((UID.Low Shr 7) And $7f));
End;

{*******************************************************************************
Function GetObjectAt(TileX, TileY: Integer): UID;
By: n3ss3s and Bobarkinator
Description: Returns the information about the object at a give tile
*******************************************************************************}

Function GetObjectAt(TileX, TileY: Integer): UID;

Var
X, Y, Z, I, obj, C, Q: Integer;
getObj, getUIDs: TStringArray;

Begin
X := TileX - SmartGetFieldInt(0, BaseX);
Y := TileY - SmartGetFieldInt(0, BaseY);
getObj := [Object1, Object2, Object3, Object4, Object5Array];
getUIDs := [ObjectUID1, ObjectUID2, ObjectUID3, ObjectUID4, ObjectUID5];
For Q := 0 To 3 Do
Begin
Z := SmartGetFieldArray3DObject(0, GroundArray, Q, X, Y);
If Z = 0 Then Continue;
For I := 0 To 4 Do
If I < 4 Then
Begin
obj := SmartGetFieldObject(Z, getObj[I]);
//WriteLn('Object is '+inttostr(obj)+' on Object1 in '+inttostr(Q)+' ground layer');
If obj <> 0 Then
Begin
Result.UID.High := SmartGetFieldLongH(obj, getUIDs[I]);
Result.UID.Low := SmartGetFieldLongL(obj, getUIDs[I]);
Result.objType := GetObjectType(Result.UID);
SmartFreeObject(obj);
SmartFreeObject(Z);
Exit;
End;
End Else
For C := 0 To SmartGetFieldArraySize(Z, Object5Array) - 1 Do
Begin
obj := SmartGetFieldArrayObject(Z, Object5Array, C);
//WriteLn('Object is ' + IntToStr(Obj) + ' on Object5Array');
If obj <> 0 Then
Begin
Result.UID.High := SmartGetFieldLongH(obj, ObjectUID5);
Result.UID.Low := SmartGetFieldLongL(obj, ObjectUID5);
Result.objType := GetObjectType(Result.UID);
SmartFreeObject(obj);
SmartFreeObject(z);
Exit;
End;
End;
End;
Result.objType := 0;
End;

{*******************************************************************************
Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
By: n3ss3s and Bobarkinator
Description: Returns True if objType is found. Tile of objType is returned in
Tile.
*******************************************************************************}

Function FindObjectEx(Var Tile: TPoint; objType, MaxLength: Integer): Boolean;
// Yakman's spiral algorithm =]

Var
Dir, tLength, f, X, Y: Integer;
TP: TPoint;
TileObject: UID;
Begin
TP := GetMyPos;
X := TP.X;
Y := TP.Y;
Dir := 0;
tLength := 1;
While (tLength < MaxLength) Do
Begin
For F := 0 To tLength - 1 Do
Begin
Case Dir of
0: Dec(Y);
1: Inc(X);
2: Inc(Y);
3: Dec(X);
End;
TileObject := GetObjectAt(X, Y);
If TileObject.objType = objType Then
Begin
//Writeln('Found Type ' + IntToStr(objType) + ' at X ' + IntToStr(X) +
//' Y ' + IntToStr(Y));
Result := True;
TP := GetObjectTile(TileObject.UID);
Tile.X := TP.X
Tile.Y := TP.Y;
Exit;
End Else
//Writeln('X: '+IntToStr(X)+' Y:'+IntToStr(Y)+ ' '+IntToStr(TileObject.objType));
End;
Inc(Dir);
dir := dir Mod 4;
If Dir Mod 2 = 0 Then
Inc(tLength);
End;
End;

{*******************************************************************************
Function FindObject(Var Tile: TPoint; objType: Integer): Boolean;
By: n3ss3s and Bobarkinator
Description: Uses FindObjectEx with the max length of 104. See FindObjectEx for
description.
*******************************************************************************}

function FindObject(Var Tile: TPoint; objType: Integer): Boolean;
begin
Result := FindObjectEx(Tile, objType, 104);
end;

{*******************************************************************************
Procedure DumpAllObjects;
By: Bobarkinator
Description: Prints out all the objects on the current map(104 x 104)
*******************************************************************************}

Procedure DumpAllObjects;

Var
BaseTileX, BaseTileY, X, Y: Integer;
O: UID;
Begin
BaseTileX := SmartGetFieldInt(0, BaseX);
BaseTileY := SmartGetFieldInt(0, BaseY);
For X := BaseTileX To 104 + BaseTileX Do
For Y := BaseTileY To 104 + BaseTileY Do
Begin
O := GetObjectAt(X, Y);
WriteLn('X ' + IntToStr(X) + ' Y ' + IntToStr(Y) + ' Type ' + IntToStr(O.objType));
End;
End;

n3ss3s

2009-01-06 08:34:15

That's nice, [drama]… But the scripts are already broken [/drama] They won't find stuff within 4 tiles, but yea, commit that…

NiCbaZ

2009-01-07 19:49:15

Yes it was always like this thats why i use FindObjectEx in my Chop Chop so i can walk to Trees on the MM