SRL Archive - MSI Suggestions

Obstacle Handling


Coh3n

2010-08-21 12:18:43

This project has been taken over by RM as I lack the time. The new thread can be found here.
________________________________________________________________________________________________________________

[INDENT]Obstacle handling has been discussed a lot in the Procedural Pointers thread, and I think it's time to get moving with this. :)

Currently we have only open paths, but what happens when we want to add a script that has a door in the middle of the path? Or a ladder? Or 2 doors and 3 ladders? Well, this is where this system comes in.

Here's the general idea:
[INDENT]You may have noticed that there are some commented out path attributes in the TScript records:

// ObstaclePoints := [];
// Obstacles := [];
// DoObstacles := [];
The idea behind those are that the ObstaclePoints are the points on the path where we find the obstacle. For example, say there's a ladder between point 3 and 4, then ObstaclePoints would have a 3 in the array so the script will look for the obstacle after walking to the third point.

Obstacles is pretty straight forward - the constants for the object record. There would be one for ladder, door, stairs, etc.

DoObstacles would be an array of functions and would be pointed to whichever function handles whichever obstacle. For example, if there's a ladder at point 3, then:

DoObstacles[2] := @MSI_ClimbLadder;
The length of DoObstacles would be the same as the path and if there was no obstacle at that path point, then that index for DoObstacles would just be nil.

Here is some rough code that I wrote up a while ago, although the way I used to pointers wouldn't work, so I need some ideas on how to fix that.

function MSI_DoObstacle(Which: Integer): Boolean;
begin
case Which of
OBSTACLE_LADDER:
Result := MSI_ClimbLadder();

OBSTACLE_GATE:
Result := MSI_OpenGate();

OBSTACLE_DOOR:
Result := MSI_OpenDoor();

else
MSI_SubDebug('Invalid obstacle in MSI_DoObstacle!');
end;
end;

function MSI_LoadPath(sLoc, eLoc: Integer): TPointArray;
var
i, j: integer;
Script: TScript;
ObstaclePoints: TPointArray;
begin
Script := MSI_Scripts[];

if (sLoc = Script.PathInfo.StartLoc) then
Result := Script.PathInfo.RefTo
else
if (sLoc = Script.PathInfo.EndLoc) then
Result := MSI_MirrorTPA(Script.PathInfo.RefTo);

ObstaclePoints := Script.PathInfo.ObstaclePoints;

for i := 0 to High(Result) do
for j := 0 to High(ObstaclePoints) do
if SameTPA([Result[i]], [ObstaclePoints[j]]) then
Script.PathInfo.DoObstacles[j] := @MSI_DoObstacle();
end;

function MSI_WalkPath(sLoc, eLoc: Integer): Boolean
var
i, j: integer;
PathInfo: TPath;
Script: TScript;
begin
Script := MSI_Scripts[];
Path := MSI_LoadPath(sLoc, eLoc);

for i := High(Path) downto 0 do
begin
if (Script.PathInfo.DoObstacles[i]() <> nil) then
begin
Script.PathInfo.DoObstacles[i](Script.PathInfo.Obstacles[j]);
Inc(j);
end;

//usual stuff here
end;
end;

Also, we have to take into consideration the paths to and from the bank because the obstacle points would be different. We could have six different attributes (three for each way) in the record, but I would really rather avoid that.
[/INDENT]

Thoughts? Suggestions?[/INDENT]

mormonman

2010-08-21 12:51:50

I can see this leading to adding the mining guild…and maybe even the new resource dungeons?

Coh3n

2010-08-21 12:57:09

From: mormonman
I can see this leading to adding the mining guild…and maybe even the new resource dungeons?

No idea what the resource dungeons are, but yeah the Mining guild was in the back of my mind. :rolleyes:

Nava2

2010-08-21 23:33:26

STOP USING THE FREAKING INDENT!

:|

a

Coh3n

2010-08-21 23:44:56

From: Nava2
STOP USING THE FREAKING INDENT!

:|

a

[INDENT][INDENT][INDENT][INDENT][INDENT]How come?[/INDENT][/INDENT][/INDENT][/INDENT][/INDENT]

[INDENT][INDENT]Is it annoying?[/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT][INDENT][INDENT]Does it look bad?[/INDENT][/INDENT][/INDENT][/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT]Or does it just piss you off in general?[/INDENT][/INDENT][/INDENT][/INDENT]

i luffs yeww

2010-08-21 23:58:53

Yes, Yes, Yes.

nickrules

2010-08-24 18:52:38

I like this idea. I like it a lot. lol.

I smell a guild miner in the future….

EDIT: :duh: It looks like I wasn't the only one who thought this

Nava2

2010-08-24 22:36:00

Yes, yes, yes.

I like this system though. Great job folks.

Coh3n

2010-09-03 19:23:13

I updated the first post. I edited a few things and it should work (I think). The other functions just need to be written, then tested. :)

E: I'm also thinking about a function to reverse the obstacle points, etc. for the path back to the bank. That way we don't have to have 6 attributes. Shouldn't be too difficult.

Sir R. M8gic1an

2010-09-03 23:52:39

From: Coh3n
I updated the first post. I edited a few things and it should work (I think). The other functions just need to be written, then tested. :)

E: I'm also thinking about a function to reverse the obstacle points, etc. for the path back to the bank. That way we don't have to have 6 attributes. Shouldn't be too difficult.


MirrorTPA?

edit: Actually… We might need both. Or at least for some cases, eg essence mine.

~RM

Coh3n

2010-09-04 01:25:25

Yeah. MirrorTPA would work for the points, but the obstacle type must also be reversed and matched up. Regardless, shouldn't be too difficult (I hope).