ID:166311
 
I'm in the middle of designing a game and I've come to another hard part. I won't be able to reach a pc for the next day to day and a half so I was hoping someone could help in my time missing.

If you limit a mob to not move diagonally oftentimes when you call get_step, get_step_towards and the others along those lines if they attempt to move towards a mob and a diagonal occurs in the AI they'll freeze up until the mob is within a cardinal x,y axis of their own. I've tried making the diagonals read off as the nearest tile in the direction based off of where the player is(Which I set up as the mob's var/mob/Target var to keep the target stored there) depending on the x,y in consideration of where the mob is itself.

Anyone able to push me in the right direction. Advice, snippet, library, demo, anything to help so I can try to work it around this system.

Well, without having to think up a long solution, I could provide a simple shortcut. Granted, the shortcut may not necessarily work for your AI entirely, but I think it should prevent freezing up.

Instead of preventing movement when a mob tries to move diagonally, you could always take a different route; filter out how the movement itself works. Here's a quickie of what I mean:
atom/movable
Move(l, d)
if(d != NORTH && d & NORTH)
step(src, NORTH)
sleep(3)
step(src, d-NORTH)
else if(d != SOUTH && d & SOUTH)
step(src, SOUTH)
sleep(3)
step(src, d-SOUTH)
else ..()


Of course, you could make yours more flexible, depending on your own game's needs. That's just an example of how you can avoid completely blocking out diagonals, which should hopefully prevent freezing up. Also, when trying to find a path to another object, you should use get_step_to(), because you'll want to take obstacles into account, of course.

Sorry for the brevity of my help. I'm not in the right way to be doing long help posts right now. :|

Hiead
In response to Hiead
Thanks for the help Hiead, got lucky and hit an internet cafe since my laptop stays with me pretty much everywhere I go. Don't have the time to plug it in and test, but calling atom/movable wouldn't take into account my player's vars such as mob/var/Agility and mob/var/Delay in a small algorithm, any way I could adjust that. Maybe var/mob? Hmm... Anyone able to help?
In response to Jowy
Jowy wrote:
Thanks for the help Hiead, got lucky and hit an internet cafe since my laptop stays with me pretty much everywhere I go. Don't have the time to plug it in and test, but calling atom/movable wouldn't take into account my player's vars such as mob/var/Agility and mob/var/Delay in a small algorithm, any way I could adjust that. Maybe var/mob? Hmm... Anyone able to help?

Well, /atom/movable was basically used because it is the catch-all type for movable objects---That way you wouldn't have to worry about anything moving diagonally in a crazy world where /objs and the like can move.

If you still wanted to use /atom/movable, but handle /mob types specially, you could always perform a check and typecast:
atom/movable/Move(l, d)
if(ismob(src))
var/mob/M = src
// Stuff that only applies to /mob movers here
// Use M as a reference
else
// Stuff that applies to non-/mobs


Alternatively, if you only wanted to edit the movement of the /mob type, you could always rewrite /mob/Move() in a similar fashion.

Hiead
In response to Hiead
For some odd reason I can't get my custom sleep() which is the mob's delay - mob's agility * 0.1 to work on npc's, I can get it working for mobs, and I can get a numbered sleep on npc's, but I can't call the var's for the mob for npc sleep delays. It must be the sleep deprivation I've been on or something, but I'm lost. lol
In response to Jowy
It usually helps to provide some code with what you're trying when asking for help on why something's not working. :P

Hiead