proc/get_n_steps(targ, dir, dist)
//This is like get_step, but it can get a tile X steps away
. = targ
for(var/index = 1 to dist)
. = get_step(., dir)
mob/proc/AI()
...
//once you get to the point where you want to try and get to a spot to shoot at the target, assuming you have one
var
distance = get_dist(src, target)
//sweet_spots list keeps track of the 4 locations the object could shoot from
list/sweet_spots = list(\
get_n_steps(target, NORTH, distance),\
get_n_steps(target, SOUTH, distance),\
get_n_steps(target, EAST, distance),\
get_n_steps(target, WEST, distance))
turf
target_loc; T
Retry
for(var/turf/spot in sweet_spots)
//This loop finds the closest location of the 4 in sweet_spots
if(!spot) continue
if(!T)
T = spot
continue
if(get_dist(src, spot) < get_dist(src, T))
T = spot
distance = get_dist(target, T)
var/direction = get_dir(target, T)
target_loc = target
for(var/index = 1 to distance)
//This loop makes sure the shots aren't obstructed.
//For instance, if there is a wall in the way, this will make it move to the correct side of the wall.
var/turf/temp = target_loc
target_loc = get_step(target_loc, direction)
if(!target_loc.Enter(src))
target_loc = temp
break
if(target_loc == target)
//This will only happen if the target creature is adjacent to a wall on the side attempting to move to.
//If that happens, obviously you can't shoot it from that side and have to get on a different side of it.
//It gets a different angle by removing T from sweet_spots and checking for the best target location again.
if(sweet_spots.len)
sweet_spots.Remove(T)
goto Retry
//if it gets in here but bypasses the above if statement, you can't get to the target
//I don't know what you'd want in such a case though
step_to(src, target_loc)
//And there you have it, the AI-controlled object moves toward the appropriate location.
ID:167221
Apr 12 2006, 11:07 pm
|
|
I was going down the forums and I saw this...
|
Apr 12 2006, 11:19 pm
|
|
Mainly by looking at the already build-in procs in the reference that were used in that piece of coding. Then understand the procs he made, and understand for what that can be used.
|
It looks like some sort of pathfinding. I understand some of it, but I don't really know what it does. get_n_steps is obvious.
There is the word "Retry" in the middle of no where. Is that meant to be used in a goto statement? I don't see one, though. Reguardless, goto shouldn't be used. Actually, it looks like it would be a code to place monsters in a place where they could shoot at the players without any interference from dense objects by looking at the comments. |
CaptFalcon33035 wrote:
There is the word "Retry" in the middle of no where. Is that meant to be used in a goto statement? I don't see one, though. It's right in the middle! Speedro wrote: > //It gets a different angle by removing T from sweet_spots and checking for the best target location again. |
In response to CaptFalcon33035
|
|
Ctrl+F my friend, Ctrl+F.
|
In response to Hell Ramen
|
|
I didn't know that worked within the DM tags. That's pretty sweet to know.
|