| Mirage Source http://miragesource.net/forums/ |
|
| Pathfindah http://miragesource.net/forums/viewtopic.php?f=183&t=4850 |
Page 1 of 58 |
| Author: | Joost [ Mon Dec 15, 2008 1:27 pm ] |
| Post subject: | Pathfindah |
Code: Public Function FindPath(sX, sY, eX, eY) As String Dim LastPathReally As String 'the final path, really, I swear ;) For a = 1 To 7 'Find many routs, then get the shortest ReDim AIBoard(1 To BR, 1 To HG) 'Clear out the AiBoard FinalPath = "" 'empty the path string OnRoute sX, sY, eX, eY, "" 'Start genetrating a route If LastPathReally = "" Then LastPathReally = FinalPath 'if this is the first path store it If Len(FinalPath) > 0 And Len(FinalPath) < Len(LastPathReally) Then LastPathReally = FinalPath 'if the aquierd path is shorter than the current, store it FinalPath = "" 'empty once more to not leave anything Next a FindPath = LastPathReally 'apply the found path LastPathReally = "" End Function Public Function OnRoute(X, Y, gX, gY, PathSoFar) As String Dim Checked(1 To 4) As Boolean NewDire: If FinalPath <> "" Then Exit Function If Checked(1) And Checked(2) And Checked(3) And Checked(4) Then OnRoute = PathSoFar Exit Function End If a = Int(Rnd * 4) + 1 If Checked(a) Then GoTo NewDire: 'a = 1 Select Case a Case 1 Checked(a) = True If Movable(X - 1, Y) Then PathSoFar = PathSoFar & "l" If X - 1 = gX And Y = gY Then GoTo FoundRoute AIBoard(X, Y) = True OnRoute = OnRoute(X - 1, Y, gX, gY, PathSoFar) If OnRoute = PathSoFar Then 'No way found OnRoute = Left(OnRoute, Len(OnRoute) - 1) PathSoFar = OnRoute GoTo NewDire End If Else: GoTo NewDire End If Case 2 Checked(a) = True If Movable(X, Y + 1) Then PathSoFar = PathSoFar & "d" If X = gX And Y + 1 = gY Then GoTo FoundRoute AIBoard(X, Y) = True OnRoute = OnRoute(X, Y + 1, gX, gY, PathSoFar) If OnRoute = PathSoFar Then 'No way found OnRoute = Left(OnRoute, Len(OnRoute) - 1) PathSoFar = OnRoute GoTo NewDire End If Else: GoTo NewDire End If Case 3 Checked(a) = True If Movable(X + 1, Y) Then PathSoFar = PathSoFar & "r" If X + 1 = gX And Y = gY Then GoTo FoundRoute AIBoard(X, Y) = True OnRoute = OnRoute(X + 1, Y, gX, gY, PathSoFar) If OnRoute = PathSoFar Then 'No way found OnRoute = Left(OnRoute, Len(OnRoute) - 1) PathSoFar = OnRoute GoTo NewDire End If Else: GoTo NewDire End If Case 4 Checked(a) = True If Movable(X, Y - 1) Then PathSoFar = PathSoFar & "u" If X = gX And Y - 1 = gY Then GoTo FoundRoute AIBoard(X, Y) = True OnRoute = OnRoute(X, Y - 1, gX, gY, PathSoFar) If OnRoute = PathSoFar Then 'No way found OnRoute = Left(OnRoute, Len(OnRoute) - 1) PathSoFar = OnRoute GoTo NewDire End If Else: GoTo NewDire End If End Select Stop 'it should NEVER get here Exit Function FoundRoute: OnRoute = PathSoFar FinalPath = PathSoFar End Function 'THIS I HAVE TO CHANGE Function Movable(X, Y) As Boolean 'Check if player can move, return false if no, true if yes End Function To set path : Player(Index).Char(charnum).Path = FindPath(currentX, currentY, targetX, targetY) To move player Code: Public Sub MovePlayer() 'check if we can move to this square If Player(Index).Char(charnum).Path <> "" Then Select Case Mid(Player(Index).Char(charnum).Path, 1, 1) Case "l": P1.X = move player left plz Case "d": P1.Y = move player down plz Case "r": P1.X = move player right plz Case "u": P1.Y = move player up plz End Select Player(Index).Char(charnum).Path = Right(Player(Index).Char(charnum).Path , Len(Player(Index).Char(charnum).Path ) - 1) End If End Sub All of this is ripped of course. But it should be rather fast + use little memory. Untested of course. Fuck yeah. and Dim FinalPath As String Public AIBoard() As Boolean of course. Also dim Player().Path in the correct Rec somewhere. |
|
| Author: | William [ Thu Jan 15, 2009 3:26 pm ] |
| Post subject: | Re: Pathfindah |
Looks interesting, from what source was it ripped? |
|
| Author: | Dragoons Master [ Thu Jan 15, 2009 4:58 pm ] |
| Post subject: | Re: Pathfindah |
Use my AI to make the same thing. I use it in my game to make mouse moving. viewtopic.php?f=75&t=2305 |
|
| Author: | William [ Thu Jan 15, 2009 5:19 pm ] |
| Post subject: | Re: Pathfindah |
I havn't really gotten indeapth on either of them cause I never planned on having things controlled by the mouse. But now I do. |
|
| Author: | Doomy [ Thu Jan 15, 2009 7:13 pm ] |
| Post subject: | Re: Pathfindah |
i looked through it and it seems likes its one of those codes that its click to move but it moves around blocks and stuff and i right? |
|
| Author: | William [ Thu Jan 15, 2009 8:00 pm ] |
| Post subject: | Re: Pathfindah |
doomteam1 wrote: i looked through it and it seems likes its one of those codes that its click to move but it moves around blocks and stuff and i right? Not the code joost posted, you cant use it without editing. |
|
| Author: | Doomy [ Thu Jan 15, 2009 8:15 pm ] |
| Post subject: | Re: Pathfindah |
im guessing because of stuff like this Quote: move player up plz
|
|
| Author: | William [ Thu Jan 15, 2009 8:51 pm ] |
| Post subject: | Re: Pathfindah |
doomteam1 wrote: im guessing because of stuff like this Quote: move player up plz There is no Movable function too. |
|
| Author: | wanai [ Fri Dec 31, 2021 7:53 pm ] |
| Post subject: | Re: Pathfindah |
Uncl |
|
| Author: | wanai [ Fri Dec 31, 2021 7:54 pm ] |
| Post subject: | Re: Pathfindah |
69.8 |
|
| Author: | wanai [ Fri Dec 31, 2021 7:55 pm ] |
| Post subject: | Re: Pathfindah |
Bett |
|
| Author: | wanai [ Fri Dec 31, 2021 7:56 pm ] |
| Post subject: | Re: Pathfindah |
Bett |
|
| Author: | wanai [ Fri Dec 31, 2021 7:57 pm ] |
| Post subject: | Re: Pathfindah |
Alfr |
|
| Author: | wanai [ Fri Dec 31, 2021 7:58 pm ] |
| Post subject: | Re: Pathfindah |
Summ |
|
| Author: | wanai [ Fri Dec 31, 2021 8:00 pm ] |
| Post subject: | Re: Pathfindah |
Feat |
|
| Author: | wanai [ Fri Dec 31, 2021 8:01 pm ] |
| Post subject: | Re: Pathfindah |
Delp |
|
| Author: | wanai [ Fri Dec 31, 2021 8:02 pm ] |
| Post subject: | Re: Pathfindah |
Gord |
|
| Author: | wanai [ Fri Dec 31, 2021 8:03 pm ] |
| Post subject: | Re: Pathfindah |
Gram |
|
| Author: | wanai [ Fri Dec 31, 2021 8:04 pm ] |
| Post subject: | Re: Pathfindah |
Ghib |
|
| Author: | wanai [ Fri Dec 31, 2021 8:05 pm ] |
| Post subject: | Re: Pathfindah |
Omeg |
|
| Author: | wanai [ Fri Dec 31, 2021 8:06 pm ] |
| Post subject: | Re: Pathfindah |
Tesc |
|
| Author: | wanai [ Fri Dec 31, 2021 8:07 pm ] |
| Post subject: | Re: Pathfindah |
wwwd |
|
| Author: | wanai [ Fri Dec 31, 2021 8:09 pm ] |
| Post subject: | Re: Pathfindah |
Zyli |
|
| Author: | wanai [ Fri Dec 31, 2021 8:10 pm ] |
| Post subject: | Re: Pathfindah |
What |
|
| Page 1 of 58 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|