beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
178 stars 95 forks source link

add GetUnitPhysicalState for lua #1528

Closed loveridge closed 3 weeks ago

loveridge commented 1 month ago

For https://github.com/beyond-all-reason/spring/issues/1520 Can be used to determine if a unit has any of the following:

enum PhysicalState {
    PSTATE_BIT_ONGROUND    = (1 << 0),
    PSTATE_BIT_INWATER     = (1 << 1),
    PSTATE_BIT_UNDERWATER  = (1 << 2),
    PSTATE_BIT_UNDERGROUND = (1 << 3),
    PSTATE_BIT_INAIR       = (1 << 4),
    PSTATE_BIT_INVOID      = (1 << 5),

    PSTATE_BIT_MOVING   = (1 <<  6),
    PSTATE_BIT_FLYING   = (1 <<  7),
    PSTATE_BIT_FALLING  = (1 <<  8),
    PSTATE_BIT_SKIDDING = (1 <<  9),
    PSTATE_BIT_CRASHING = (1 << 10),
    PSTATE_BIT_BLOCKING = (1 << 11),
};
WatchTheFort commented 1 month ago

How does this handle impossible states, like something being both in air and underwater at the same time? Or is it up to games to say for themselves what an impossible state is?

sprunk commented 1 month ago

If you set an impossible state via lua, the getter will just regurgitate it. Engine resets the state each simframe and will never produce something impossible.

WatchTheFort commented 1 month ago

I don't understand... you can set state via Lua, but the engine resets it every frame? Isn't that the same as not being able to set state from Lua?

sprunk commented 1 month ago

There's 2 kinds of bits in the physical state: