ID:273158
 
So, I've got a zombie game going...
And to add pizazz I've made Zombies have Heads using an extra mob that handles Headshots and I'm eventually going to take the zombie apart to have separate limbs.

Now, my only problem is...
The flipping undead have an intelligence of 0.
I've tried everything from
(Example; Zombie as Z)
Z.loc = src.loc
I've tried...
walk()
walk_to()
walk_towards()
step()
step_to()
step_towards

And I still lack the performance required.
My objective is to get the Zombie's Limb to correctly stay on top of the Zombie's Body and obviously overlay will not achieve my goal.
I've tried to make the zombie head spawn a proc to constantly locate itself to the zombie body and that just ends up in infinite loops and I've never dealt with set background.

So...
Any possible way of having a Walk or Step_With proc?
I'm pretty nit picky to so it's one of those, 'Needs to be perfect' sorta deals.
The head cannot whatsoever come off of the zombies body.

EDIT:
I sense a possible Library or BYOND Feature for walk_with() or step_with() to be made/added?
Make some way to check and see if something can move to a certain location but not actually attempt to move it. Use that to see if both the head and body can move, and then move both if so.
atom/movable/canMove(atom/newLoc)
var/atom/oldLoc = loc
if(oldLoc.Exit(src) && newLoc.Enter(src))
return 1
return 0

Now, assuming you give mobs a head variable which references their head, you can just do
mob/Move(atom/newLoc)
// if you have a head...
if(head)
// ...abort and return failure right now if head can't move to its spot
if(!head.canMove(get_step(newLoc, NORTH)))
return 0
// attempt to move body
. = ..()
// if the body moved and you have a head...
if(. && head)
// ...then move the head now too
head.Move(get_step(newLoc, NORTH))
In response to Loduwijk
Now, when you included NORTH as an argument, does that mean the mob default direction is North to where if the mob Body faces South, the mob Head will face North?
I'm a bit 'out there' so to speak.
Or will I need to use head.dir = src.dir?

EDIT:
Oh, I have
mob/var/Owned //The Body's Head
mob/var/Owner // The Head's Body

Yeah, I probably don't need both of those but like I said, I've been trying many ways to get this to work.
    New()
var/mob/Z = new /mob/Zombiehead(src.loc)
spawn(Z)
src.Owned = Z
To get them to stay in sync, you need to set head, limbs, etc.'s animate_movement var to SYNC_STEPS. Then the main part of the zombie (the body) would have it's animate_movement set to FORWARD_STEPS (the default).
In response to Dark Vendetta
No, just that the head is a tile to the north of the body (that is, the tile above the body).

Obviously, you don't have to do it that way. You can have a different behavior if you want to program it differently. But generally heads are a tile above the body, hence my example.
In response to Loduwijk
I actually have the Head as a layer above the Body.
I figured pulling headshots off would be easier if the head was a tile above so I didn't bother with it. The game pretty much goes by clicking and not auto-aiming to give some realism.

I'm liking this SYNC_STEPS thing.
Now, I have the zombie head at
animate_movement = SYNC_STEPS
so... Now I need some suggestions.
What would be the best possibly way to have the head stick to the body.
Walk, Step, Loc?
I'm using a Wander() proc for the Zombie Body Movement...
My next question ties with the first. Now, I should activate that while the body is randomly moving/chasing it's target and not before or after, right?
In response to Dark Vendetta
Dark Vendetta wrote:
Walk, Step, Loc?
mob/Zombies/Body
var/mob/Zombies/Head/MahHead
Move()
.=..()
if(.)
MahHead.loc=loc


First line is self explanatory,

Second line is a variable where you will need to store a reference to your head.

Third line is where we begin to override the Move() proc

Fourth line is a tiny bit more complex, and most people who use it don't understand what it does. '.' is an internal variable that any proc will return by default unless you manually override return. ..() calls the parent of whatever proc you're using, so in this case it would be calling atom/movable/Move() (unless you overrode Move() again in /mob or /mob/Zombies, in which case it would be referring to that.)

The Move() proc by default returns a 1 if it is successful and a 0 if it fails, so the next line ('if(.)') basically means "If the move() was successful", and the line after that moves the head to the body loc.
In response to AJX
Works really nice now.
Thank you all.
I had to add in Head.dir = src.dir but, that's simple as breathing.

Maybe in a future BYOND update, something like walk_with() or step_with() could be added to make a simple built in proc that allows 2 or more atoms to have synced movement if any of them move or even go further into having variables such as 'Sync_leader' and 'Sync_follower' and whatnot.
Or, just that idea alone would be a great Library.
So that during run-time, you can have it as a verb or proc that allows some sort of way to sync 2 atoms.
For example;
A 'Pet' System that would allow x amount of pets and user selectable pets to follow a specific leader.
In response to Dark Vendetta
But then you run into the problem that you have to decide how things are to move together. Differen't people wouldn't want it to work the same way.

This really is better left to the developer to work out. A large library with many options wouldn't be bad though.
In response to Loduwijk
A nice Customizable Plug'N'Play sounds great.
I've known many projects that would benefit from it.
From Party Systems, to NPC's, to whatnot.
Yeah, I guess as a built in proc, it would require many separate variables which would indeed be a hassle.
Such as delay, range, number limit of affected atom, leader, and then there's things like exceptions and whatnot.
I dunno, maybe that will be someone's new project. To develop a sync movement system with many options and features that would be plug and play compatible and offer easily understandable structure that newbies would understand better than Move() and whatnot like how AJX was commenting about, the '.' confused me like, the first few months of learning DM.
In response to Dark Vendetta
As Loduwijk said, You will find that many ideas that would seem nice to have built in would be illogical because so many different people would apply them in different ways.

You can program all of that yourself VERY easily. If you need help feel free to ask, but it isn't hard.
In response to AJX
I guess it's not so much that I need help to make it, but more like time. xD
I only wanted to see if there was a pre-existing lib if anyone made one.
I might work on a rough draft or something.