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]