SCRMaps
/
Sign in

Moving a unit yourself

Teleporting, walking, turning on the spot and a no-go zone an auto-mouse cannot beat - all of it out of the same three or four fields.

16 min read

Moving a unit is two different jobs: teleport it there, or make it walk there. MoveUnit does only the first, and in exchange it wipes the order, loses the attack target and switches on tile-collision ignoring. From the struct you get both, and none of that.

Walking is the simpler of the two. A unit whose 0x10 moveTargetXY differs from its 0x28 position walks to close the gap, so it is two lines.

const xy = x + (y << 16);
SetMemoryEPD(epd + 0x10/4, SetTo, xy);   // moveTargetXY
SetMemoryEPD(epd + 0x18/4, SetTo, xy);   // nextMovementWaypoint
0x18 is there because some units do not move without it. With both, every unit that can move at all does.

Redirect it mid-walk, though, and the unit shuffles instead of turning. Writing the facing in the same pass fixes it.

const ux, uy = posread_epd(epd + 0x28/4);
const dir = atan2_256(y - uy, x - ux);
SetMemoryXEPD(epd + 0x20/4, SetTo, (dir << 24) + (dir << 8), 0xFF00FF00);
That single masked write touches two fields inside the dword at 0x20.
The two directions inside 0x20
0x21 currentDirection1The direction the unit is facing.
0x23 velocityDirection1The direction the unit is travelling.

Writing only 0x21 turns the picture. Writing both makes the unit set off instantly with no turn animation - smoother than the game's own movement. Set them differently on purpose and a unit faces one way while sliding another, except that when the destination is within roughly 180 degrees of 0x23 the engine uses the real destination.

Four things that follow
The order target survivesThe order target survives, which is how “keep attacking while repositioning” is built.
For WASD, write 0x1C tooA scheme that pins 0x21 must write 0x1C too, or a unit that stops faces backwards.
A computer's ordinary units go backA computer's ordinary units carry a return-to-region AI that undoes those writes. Make them heroes, or use the order route.
Players 9-12 and Door types work tooIt works for players 9-12, and on Door-type units that have been made into units.

There is an order-based route - write the destination to 0x58 and set 0x4D to 6, Move - and it is the worse one.

It responds slowly and the destination cannot be changed mid-walk, because 0x58 does not feed 0x18 and 0x1C. Writing 0x4E to 0 restores mid-walk redirection and 0x85 to 0 improves the latency, but measured side by side the two-line form is still faster. And do not mix the two: with 0x58 in play, 0x10 is ignored.

That slowness has a recognisable signature. A damage-font system built on the order route had its font units occasionally scatter in random directions; switching to 0x10/0x18 ended it. If a group of effect units sometimes breaks formation, suspect this.

For teleporting, the field is halt: 0x2C and 0x30 hold where the unit is actually travelling to, as the coordinate times 256. The unit chases halt, not the destination.

SetMemoryEPD (epd + 0x2C/4, SetTo, x << 8);        // halt X
SetMemoryEPD (epd + 0x30/4, SetTo, y << 8);        // halt Y
const xy = x + (y << 16);
SetMemoryEPD (epd + 0x10/4, SetTo, xy);
SetMemoryEPD (epd + 0x18/4, SetTo, xy);
SetMemoryEPD (epd + 0x1C/4, SetTo, xy);
SetMemoryXEPD(epd + 0x20/4, SetTo, 0x14, 0x14);    // 제동 + 이동 / braking + moving
0x14 is 0x4 braking plus 0x10 moving. Braking is what stops it turning first and stops it dead on arrival; moving is the state halt needs. All three waypoint writes are load-bearing - leave one out and the unit walks back to roughly where it was.

If halt is ever left different from the 0x28 position, that unit can never move again - alive, taking orders, silently stuck. Sending it somewhere it cannot reach leaves it in that state, and the only repair is writing halt back equal to position. A unit frozen after a dash is almost always this.

Look the addresses up and you will find 0x18 and 0x1C marked unsupported on Remastered - while the techniques above work, with video. When the two disagree, trust the compiler: eudplib turns a field that would throw an EUD error into a compile error, so if the build passed, the field is reachable. The offset tables are at their best for what a field means.

Facing is the single byte 0x21, and writing it alone does not turn a ground unit. It needs an air unit's movement character first: either 0x97 set to 7, or the 0x4 bit of 0x20.

SetMemoryXEPD(epd + 0x20/4, SetTo, 4, 4);                // 공중 특성 / air character
SetMemoryXEPD(epd + 0x20/4, SetTo, dir << 8, 0xFF00);   // 0x21 방향 / facing
SetMemoryEPD (epd + 0x10/4, SetTo, 0);                  // 제자리 걸음 / walk in place

Use the 0x20 bit rather than 0x97. Setting 0x97 to 7 does not come back until you write it back, and while it is set the unit grinds across terrain a ground unit should not cross; the flag bit clears itself. A few units do not respond to the flag, and for those 0x97 set to 9 - the ground stopping state - works.

The last line is walking in place: with moveTargetXY at 0 the unit plays its walk motion and goes nowhere. Pin the position with MoveUnit first if it must not drift - the order is MoveUnit, air character, facing, then 0x10 = 0. Those four lines are the protagonist of every side-scroller.

The same two lines also make a no-go zone an auto-mouse cannot beat. A fence is almost always built with the Order action, and the reason an auto-mouse walks through it is simple: the Order action goes through the whole coordinate-and-order refresh, and repeated clicking is faster than that. Which is why people end up patching it with KillUnit or MoveUnit.

The real cause is the delay between orders: StarCraft does not run a queued order until orderQueueTimer, at 0x85, reaches zero. Write that field to zero yourself and push the unit back through the struct rather than with an Order, and the delay is gone.

if (Bring(cp, AtLeast, 1, unitX, "금지구역")) {
    bwrite_epd(epd + 0x85/4, 1, 0);                   // 지금 수행 / execute now
    const xy = dwread_epd(epd + 0x28/4) - 0x400000;   // y를 64px 위로 / y up 64 px
    SetMemoryEPD(epd + 0x10/4, SetTo, xy);
    SetMemoryEPD(epd + 0x18/4, SetTo, xy);
    SetMemoryEPD(epd + 0x1C/4, SetTo, xy);
}
0x400000 is 64 shifted up 16 bits. Position is packed as x + 65536*y, so adding or subtracting in the upper half moves on Y and in the lower half on X - the whole push is one subtraction, and because it is relative it works on any number of units at once.

Pushing them back with an Order action defeats the whole thing: the Order re-enters the refresh and the zeroed timer stops mattering. The push has to be the struct write. And use Bring only when fencing a single unit - with several, testing 0x28 directly is far cheaper.

One more feature made from the same fields: the RPG “get on the horse”. It is not a transport - it is two units kept on top of each other, with the player's clicks relayed to the one underneath.

What each unit is
The riderThe larger unit. This is what the player selects and clicks with.
The mountThe smaller unit, flagged as a building with its buttons removed and an AI that makes it uncontrollable. It is a building for exactly one reason: a building is not counted in Men, so the crowding check below can test for the rider alone.
// 타기 / mount:   InAir | NoCollide | IsGathering
SetMemoryXEPD(hero + 0xDC/4, Add, 0xA00004, 0xFFFFFFFF);
// 내리기 / dismount: 같은 세 비트의 2의 보수
SetMemoryXEPD(hero + 0xDC/4, Add, 0xFF5FFFFC, 0xFFFFFFFF);
0xA00004 is InAir (0x4) plus both collision bits - NoCollide (0x200000, “others will not collide with me”) and IsGathering (0x800000, “I will not collide with others”). You need the pair; one alone leaves the rider shoving or being shoved. 0xFF5FFFFC is exactly -0xA00004, so Add subtracts them.

Gate both mount and dismount on Bring(AllPlayers, Exactly, 1, "Men", moveLoc[cp]). Summoning or dismissing the mount while the rider is pressed against another unit causes grinding, and that intermittently FREEZES StarCraft - not a glitch, a freeze. Exactly 1 because the rider itself is a Men unit and the mount, being a building, is not.

  • Not riding: keep moveLoc[cp] on the rider.
  • Riding: read the rider's moveTarget at 0x10, move a scratch location there, and order the mount to it. The player clicks the rider; the mount does the walking.
  • Every pass, clear IgnoreTileCollision (0x40000) on the mount. The rider is being MoveUnit-ed onto it constantly, which sets that bit, and left set it restricts the mount's own movement.

If you lift an old EUDSetLocation, check one version detail: the location table is addressed EPD(0x58DC4C) + locationNum * 5, the 1-based form. Functions written before euddraft 0.9.0.0 use 0x58DC60 and are off by one record - the same trap as MSQC's QCLoc.

Area effects and knockbackThree ways to read the struct wrong