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;