ID:155499
 
I'm working on the AI for zombies in a zombie survival RTS game right now. In these early stages, the AI is set to walk continuously towards a destination until the reach it. When they hit a wall (the walls are obj type), they automatically start doing damage to it until it's destroyed and they can go through. Before they start destroying the wall, I want them to check the surrounding turfs to see if there's an easier way to go.

Is there a proc that checks the contents of a turf to see if it's occupied by a dense object? Thanks!
You'll need pathfinding for this, which is not necessarily a one line set of code...
In response to Ill Im
Yes I know, I'm just not sure about turf contents. Like say I check the turf directly to the left of the NPC, what would I do to see whether or not it's occupied? Would I need to populate an array of turf.contents, and then check the items in the array to see if they're dense?
In response to Calthion
If your just checking for dense objects, Enter() would probably work for you. It will return 1 if there are no other dense already present.
In response to Jotdaniel
Alright, and I can call Enter() without needing to be trying to step there? (For example Calling Enter() on location(src.x+2, src.y+1, src.z) I'll try it out! Thanks!
In response to Calthion
Right, you just need to tag the turf your trying to get to, then call Enter() on it: if(T.Enter()) something like that.
In response to Jotdaniel
All right thank you for your help!
In response to Calthion
Sorry, you can use get_step() to grab the turf at the new location. I've done this before to do a basic 3d display(room by room movement type of thing).
In response to Jotdaniel
This is what I came up with and it works quite well for the current purpose. Thank you for your help.

    Bump(var/obj/O)
..()
var/free = 0
var/turf/T
switch(src.dir)
if(NORTH)
T = get_step(src, NORTHEAST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
else
T = get_step(src, NORTHWEST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
if(EAST)
T = get_step(src, NORTHEAST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
else
T = get_step(src, SOUTHEAST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
if(SOUTH)
T = get_step(src, SOUTHEAST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
else
T = get_step(src, SOUTHWEST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
if(WEST)
T = get_step(src, NORTHWEST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
else
T = get_step(src, SOUTHWEST)
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)

O.health -= 50
O.destroy()
In response to Calthion
Looks pretty good. I'm glad I could help.
In response to Calthion
You can use turn() to cut down on a lot of that code.
In response to DarkProtest
DarkProtest wrote:
You can use turn() to cut down on a lot of that code.


I didn't even think about that, funny though because the example I made that I was pulling from used turn() extensively. Here's what this could look like:

mob/proc/MoveCheck()
T = get_step(src,turn(src.dir,-45))
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)
else
T = get_step(src,turn(src.dir,45))
free = T.Enter(src)
if(free)
walk_to(src, T)
sleep(10)
walk_towards(src, locate(250, 250, 1), 10)


//Your bump for whatever it is.


Bump(var/obj/O)
..()
var/free = 0
var/turf/T
src.MoveCheck()
O.health -= 50
O.destroy()



I didn't test this, but it should work the same as the original the OP made, a bit more efficient, and a lot less cluttered.