SRL Archive - Reflection Development

Better Random Tile


Bad Boy JH

2010-09-17 08:55:41

This will improve the Walk To Tile, It basically checks all tiles in the area Randomness around The Centre tile, and returns a random tile, that is on the Minimap, unable to test speed as hooks are outdated
Function RandomTile(CentreTile: TTile; Randomness: Integer): TTile;
var
X, Y: Integer;
Tiles: Array of TTile;
begin
For X := - Randomness to Randomness do
For Y := - Randomness to Randomness do
if TileOnMM(Tile(CentreTile.x + X, CentreTile.y)) then
begin
SetLength(Tiles, Length(Tiles) + 1);
Tiles[High(Tiles)] := (Tile(CentreTile.x + X, CentreTile.y));
end;
Result := Tiles[Random(Length(Tiles))];
end;

I will be inspired from time to time to think of something, exuse me if its already in, Im not really scripting atm.

Sir R. M8gic1an

2010-09-17 09:22:06

That looks like a bullet proof way to do it, however it does look quite slow…
I'd consider just checking the corners first, and if they aren't on the MM then make adjustments.

~RM

Nava2

2010-09-17 14:50:58

That looks very slow, mainly because you are copying into memory many many times.

Bad Boy JH

2010-09-17 18:25:07

whilst normally I don't really see the need for a fast speed, this case, cause the player is moving, its clearly neccessary to have the pace. Perhaps the pre-check for the corners, cause if all 4 corners are on, its impossible (I think) to have other points off..

Wyn

2010-09-24 10:42:32

I will test tonight.

Wyn

2010-09-24 16:17:31

Sorry for double posting within 5 hours but I can't seem to get it working..

Var is 234234: TTile;

I chose a point with this: 234234 := Point(3109,3500)

Tryed to make it happen with this: RandomTile(234234, 3);

Hmmm….

Sir R. M8gic1an

2010-09-25 16:06:34

Bottom left of your post. Edit button ;)

~RM