ID:1785550
 
(See the best response by Kaiochao.)
My game involves the undead, but it's intended to be relatively large scale and action orientated. Thus in this motif the undead should walk towards you from any distance accross the map (I don't want Zombies randomly shambling about a million miles away being useless), hopefully keeping a steady stream of them coming into interaction with the player.

The issue is this tiny little caveat in the ref, regarding step_to:

'Move Ref on a path to the location Trg, taking obstacles into account. If Ref is within Min steps of Trg, no action will be taken. This is also the case if the target is too far away (more than twice world.view steps). '

What use is that?
I don't want to use step_towards and get them stuck on random walls a million miles away, I want to use step_to. I think I understand the principle is to reduce the lag on large scale pathfinding but still, is there any way around this? I don't particularly want to use the walk commands as that requires rewriting vast portions of my AI that I've already written.
                    if(get_dist(src,src.target) > world.view*2) //Max range for step_to pathfinding
var/turf/T = get_step(src,get_dir(src,src.target))
if(T && T.density)
step_rand(src) //If we hit something while we're too far to step_to then step_rand
else
step_towards(src,src.target)
else
var/turf/T = get_step(src,get_dir(src,src.target))
if(T && T.density)
step_to(src,src.target) //If we're in range to step_to, but still hit something, we can use pathfinding
else
step_towards(src,src.target) //If we don't hit any turfs, step_towards, which calls Bump() for objects and mobs
sleep(rand(src.speedMin,src.speedMax))


Working on this... Does anyone see any obvious efficiency or issues that might arise? AI is not my strong suit.
Try using step_to when appropriate (i.e. in view) instead of all of the time. The zombies that aren't serving a purpose really shouldn't be doing anything, that's a waste of CPU.
In response to FKI
FKI wrote:
Try using step_to when appropriate (i.e. in view) instead of all of the time. The zombies that aren't serving a purpose really shouldn't be doing anything, that's a waste of CPU.

That's kind of the point. I don't WANT any zombies doing nothing. I want them all on a steady stream towards the battle area.
In response to Rushnut
Can you tell me more about the game? I'm trying to get an idea why you need all zombies to be moving toward a location. There has to be a shortcut in doing what you want, without actually doing all the work you are trying to do.
Effectively, the maps are on a medium to large scale.

Zombie spawn points are all around the map, originating from within or the edge of the maps. There's no pre-defined specific place for them all to spawn, it's all up to the map.

All zombies should shamble towards the players location, who can also be anywhere on the map at any given time.

Additionally there will sometimes be objectives that will spawn anywhere on map (I.E opposite side of the map from where the players currently are).

As such I want the zombies presence to feel overwhelming in terms of numbers and advancing in terms of AI. At any given time you might need to wade through a mass of zombies to get to an objective that's spawned far behind them, so there needs to be mass amounts of them on the map, however the pressure should always be on. Zombies should always be heading towards players, so that they are kept busy and never have too much time to rest.

Using a modified example of the above AI I posted, I can get roughly 1000 zombies moving smoothly at around 20% CPU, which isn't perfect but it will suffice unless you can propose any better ideas.
Hmm, off top, two solutions come to mind.

The first would be to make it appear that the zombies are shambling toward the player's location, without actually moving them in the background. Think of ambush triggers via entering a certain area, clearing an objective, etc. but done in a fashion that makes it look like the zombies have been there the whole time. I don't think this would work too well if your game is multiplayer though (it sounds single player).

The second would be to create a movement system for your zombie AI that does what step_to doesn't. Path-finding is probably your ideal candidate, I don't know too much about that though.
Solution 1 won't work because, as you said, multiplayer.

Solution 2 is what I'd do in an ideal world but pathfinding is just above me entirely.
Best response
You could continuously spawn zombies right outside of each player's view (and remove them when they're too far from a player). That way, you can use step_to.
I remember making a zombie game a long time ago. You simply cannot have a thousand zombies all doing something constantly, especially if it involves path finding. You have to find alternatives and work arounds.

What I did was the following.

Keep a list of all zombies and all players.

Every x seconds (for me 10) loop through all zombies and have them figure out the closest player to them, and their exact distance.

Every x seconds (I used 5) have the zombies far away from a player move a small distance closer. This was not using walk or step, but it was teleporting them using move and locate.

Zombies within a medium distance to a player would wander randomly, but every so often (25-33% of the time) walk towards the closest player. This was at a slower rate than the normal AI would loop however.

Zombies close to a player would do the same thing, but their AI would loop at normal speed.

Zombies who saw a player would chase after them.

Zombies who were far away from players for a long period of time (1 minute for me) were simply deleted.

The numbers for times and distances worked for me, for you they'd need adjusting, but I made it so it was never possible for a player to go from being far away from a zombie, to close to it in less than 10 seconds (which is how often I'd check distance).

There is no reason to have zombies doing everything when there are simply no players around to observe them doing things. Have these zombies imitate the actions you want them to do but make it less CPU intensive.
I never thought about simply making them teleport to a viable position closer on the map on a large-ish interval. That's a fantastic idea!
In response to Rushnut
Honestly, the best solution would be kaiochao's. Have regions in which zombies spawn, to which you add those regions to the map(to which you can set amounts of zombies to spawn, how quickly you want them to spawn, ect.) and spawn the zombies out of the player's view.
you can even use this if the zombie summons anywhere in the world

mob/proc
Zombiewalk()
var/move//direction of zombie
while(src&&src.hp>=0)//i think you understood what i am saying
FOUND=min(FOUND,1)
var/mob/Zombie/Z
var/Y=200//here y represents the size of map in x,y direction so for zombie to sense the player in the map
for(var/mob/player/M in world)
if(get_dist(M,src)<=Y)
FOUND=1
Z=M
if(!M)
FOUND=0
return
for(var/mob/player/M in world)
if(Z==M)
move=get_dir(src,M)
FOUND=1
if(FOUND==0)
for(var/mob/Zombie/Z in range(6,src))
move=Z.dir
return

it wont take much of CPU usage and if you want limit the no of zombies being spawned according to the no of player in the world