Jazz2::Scripting::Legacy::ScriptObjectHost class

Drives an object of the game by a behavior of a level script, as JJ2+ does with the objects whose template (jjObjectPresets) has a behavior of the script.

The behavior replaces the per-frame update of the object. Most behaviors of scripts wrap the one the object has in the game (obj.behave(BEHAVIOR::PICKUP); ...), and a behavior of the game run that way is the object's own update. Before the behavior the jjOBJ gets the position, the speed, the direction, the energy, the state and the frame of the object, after it what the behavior changed goes back to the object. The object is drawn only if the behavior asks for it, by running a behavior of the game with drawing or by jjOBJ::draw(), as in JJ2+.

The frame is that of the animation of the original the object shows (see AnimationTables::FindAnimationOfGraphics()). An animation a script gives the object (by curAnim of the object or of its template) is shown in its place, its frame of the same position, so a behavior of the game still animates it - and a frame a script chooses is drawn as it is, not by the object of the game.

Collisions with players and bullets are handled by the script as JJ2+ does with scriptedCollisions, and as the playerHandling and bulletHandling a script set say (see OnCollision()).

Base classes

class Jazz2::Actors::IActorUpdateOverride
Takes over the per-frame update of an object.

Public static variables

static float PositionOffset constexpr
How much further right and down an object of the game is than the jjOBJ of it.

Public static functions

static void LiftStandingPlayers(LevelScriptLoader* levelScripts, const AABBf& oldBox, float deltaY)
Lifts the players standing on a solid object that moved up by deltaY from oldBox.
static void TouchPlayers(LevelScriptLoader* levelScripts, jjOBJ& obj)
Tells the behavior of an object a script controls entirely of the players touching it, as TouchPlayersByBox() does for the others.
static void TouchStandingPlayer(LevelScriptLoader* levelScripts, jjOBJ& obj, Actors::Player& player)
Tells the behavior of a solid object a player stands or lands on of it, once in a tick, as TouchPlayers().
static auto GetTouchForce(LevelScriptLoader* levelScripts, jjOBJ& obj, Actors::Player& player) -> std::int32_t
Returns the force a player touching a special object hits it by, 1 while attacking, a buttstomp only by its first touch.
static void SetVineEnd(jjOBJ& obj)
Puts a swinging vine object at the end of the vine, as JJ2 has it, from its var[1] and var[2].
static auto SpawnInPlace(LevelScriptLoader* levelScripts, Actors::ActorBase& actor, std::uint8_t eventId) -> std::shared_ptr<Actors::ActorBase>
Spawns the object of an event where an object of the game is, as made of the same event, nullptr if it has none.
static void InitializeScriptedBullet(jjOBJ& obj, const jjOBJ& preset, Actors::ActorBase& actor, std::int8_t spreadSlot, float gunspotOffsetY, bool upward = false, float aimAngle = -1.0f)
Sets up the bullet of a weapon whose bullets a script controls as JJ2+ fires it, see IsScriptedBullet().
static void PullFromActor(LevelScriptLoader* levelScripts, jjOBJ& obj, Actors::ActorBase& actor, bool withAnimation = true)
Gives the jjOBJ the properties of the object of the game.
static void PushToActor(jjOBJ& obj, Actors::ActorBase& actor, bool deferKill = false)
Gives the object of the game the properties a script changed since PullFromActor().
static void UpdateSkin(jjOBJ& obj)
Takes the animation a script gave the object since PullFromActor() as the one it shows.
static auto NeedsHost(const jjOBJ& obj) -> bool
Returns true if a script gave an object (or its template) what only a host can do, a behavior, an animation, collisions or a light of its own.
static auto GetSkinOffsetY(LevelScriptLoader* levelScripts, const jjOBJ& obj, const Actors::ActorBase& actor) -> float
Returns how much lower yPos of a walker with an animation a script gave it is than the object of the game, so its frame stands on the ground by its coldspot.
static auto GetRestingY(const Actors::ActorBase& actor) -> float
Returns the vertical position of an object of the game, of a floating collectible the one it rests at.
static auto GetSpawnPos(const Actors::ActorBase& actor) -> Vector2f
Returns where the object of the game was spawned.
static auto GetOriginTile(const Actors::ActorBase& actor) -> Vector2i
Returns the tile of the event the object of the game comes from.
static void DeleteActor(Actors::ActorBase& actor)
Removes an object of the game, the event it comes from isn't spawned again.
static void DeactivateActor(Actors::ActorBase& actor)
Removes an object of the game, the event it comes from spawns it again when it's seen again.
static auto IsOutOfActivationRange(LevelScriptLoader* levelScripts, const jjOBJ& obj) -> bool
Returns true if an object a script made is told to deactivate now, too far from every player.
static auto CallScriptBehavior(LevelScriptLoader* levelScripts, jjOBJ& obj, const jjBEHAVIOR& behavior, bool draw = true) -> bool
Runs a behavior of the script on a jjOBJ, false if it isn't one.
static auto CallObjectHit(LevelScriptLoader* levelScripts, jjOBJ& obj, jjOBJ* bullet, jjPLAYER* player, std::int32_t force) -> bool
Calls onObjectHit() of the behavior of a jjOBJ, and the global ones if it has none or it returns false.
static void DrawFrame(LevelScriptLoader* levelScripts, const jjOBJ& obj, float offsetY = 0.0f, bool translucent = false)
Draws the current frame of a jjOBJ where it is in the level (offsetY lower), as jjOBJ::draw(), translucent if translucent.
static auto IsUpsideDown(std::int8_t direction) -> bool
Returns true if an object of a direction (SPRITE::Direction) is drawn upside down.
static void TurnUpsideDown(Actors::ActorBase& actor)
Turns an object of the game upside down, as JJ2+ has the objects of a template whose direction is SPRITE::FLIPV.
static auto BreakScenery(LevelScriptLoader* levelScripts, Actors::ActorBase& actor, const jjOBJ& bullet, WeaponType weaponType, std::int32_t strength, SmallVectorImpl<std::int32_t>* hitTiles = nullptr) -> bool
Breaks the destructible scenery a bullet of a player touches, as a shot of its weapon breaks it, returns true if it broke any.

Constructors, destructors, conversion operators

ScriptObjectHost(LevelScriptLoader* levelScripts, jjOBJ* obj, Actors::ActorBase* actor)
Creates a new instance driving an object of the game, takes a reference of the jjOBJ.
~ScriptObjectHost() override
ScriptObjectHost(const ScriptObjectHost&) deleted

Public functions

auto operator=(const ScriptObjectHost&) -> ScriptObjectHost& deleted
void OnUpdate(Actors::ActorBase* actor, float timeMult) override
Called instead of the per-frame update of the object.
auto IsDrawn() const -> bool override
Returns false if the object isn't drawn in this frame.
auto OnCollision(Actors::ActorBase* actor, Actors::ActorBase* other) -> bool override
Lets the script handle a collision of the object with a player or a bullet.
auto OnUpdateHitbox(Actors::ActorBase* actor) -> bool override
Makes a solid object as big as the pixels of the frame of an animation a script gave it.
void OnEmitLights(Actors::ActorBase* actor, SmallVectorImpl<LightEmitter>& lights) override
Adds the light a script gave the object, see EmitObjectLight().
auto OnPerish(Actors::ActorBase* actor, Actors::ActorBase* collider) -> bool override
Lets a crate the behavior drives break as in JJ2+.
auto OwnsDebris() const -> bool override
Returns true once a crate breaks as in JJ2+, its pieces are objects then (see OnPerish()), or for an object showing an animation of a script.
auto OwnsLights() const -> bool override
Returns true for an object the level illuminates, which lights as JJ2+ has it (LIGHT::LASER).
auto OnTileDeactivated(Actors::ActorBase* actor) -> bool override
Tells the behavior to deactivate the object, as JJ2+ does by STATE::DEACTIVATE.
void BePlatform(float xOld, float yOld, std::int32_t width)
Makes the object a platform for this tick, as jjOBJ::bePlatform().
void ClearPlatform()
Lets go of the players standing on the object, as jjOBJ::clearPlatform().
void BeSolid()
Makes the object solid for this tick, as jjOBJ::beSolid().
void RunFirstTick()
Runs the behavior for the tick the object is made in, before its first update, see LevelScriptLoader::RunNewObjectBehavior().
void RunOwnBehavior(bool draw)
Runs the object's own update, as jjOBJ::behave() with a behavior of the game.
void RunGameBehavior(std::uint32_t behavior, bool draw)
Runs a behavior of the game, as jjOBJ::behave().
void RunSwingingVine(bool draw)
Runs BEHAVIOR::SWINGINGVINE of JJ2+, the object is the end of the vine.
void DrawVine(bool draw)
Draws a swinging vine, by the vine of the game or by the frame after curFrame.
void RunMonitor(bool draw)
Runs BEHAVIOR::MONITOR of JJ2+ on the object of the game, which is pushed as it is.
auto IsScriptedBullet() const -> bool
Returns true for a bullet a player fired of a weapon whose bullets a script controls.
void RunBullet(bool draw)
Runs BEHAVIOR::BULLET of JJ2+ on a bullet of a weapon whose bullets a script controls.
void FollowScriptMovement()
Makes the object of the game follow a behavior that moves the object itself (BEHAVIOR::WALKINGENEMY).
void Draw()
Draws the object in this frame, as jjOBJ::draw().
void Delete()
Removes the object, the event it comes from isn't spawned again.
void Deactivate()
Removes the object, the event it comes from spawns it again when it's seen again if it's an object of the level.

Function documentation

static void Jazz2::Scripting::Legacy::ScriptObjectHost::LiftStandingPlayers(LevelScriptLoader* levelScripts, const AABBf& oldBox, float deltaY)

Lifts the players standing on a solid object that moved up by deltaY from oldBox.

As measured in JJ2+, a solid object a behavior moves carries them up, they fall when it goes down and stay where they are when it goes sideways.

static void Jazz2::Scripting::Legacy::ScriptObjectHost::InitializeScriptedBullet(jjOBJ& obj, const jjOBJ& preset, Actors::ActorBase& actor, std::int8_t spreadSlot, float gunspotOffsetY, bool upward = false, float aimAngle = -1.0f)

Sets up the bullet of a weapon whose bullets a script controls as JJ2+ fires it, see IsScriptedBullet().

spreadSlot is -1 for the bullet angled up, 0 for the straight one and 1 for the one angled down, gunspotOffsetY how far below the player the gunspot of the pose it was fired in was, upward if the player aimed up, aimAngle the angle a script fired it at (0 up, clockwise, negative for none).

static void Jazz2::Scripting::Legacy::ScriptObjectHost::PullFromActor(LevelScriptLoader* levelScripts, jjOBJ& obj, Actors::ActorBase& actor, bool withAnimation = true)

Gives the jjOBJ the properties of the object of the game.

The frame only withAnimation - an object a behavior of the script drives animates only when its own behavior runs, the behavior of the script counts the frames itself otherwise.

static void Jazz2::Scripting::Legacy::ScriptObjectHost::PushToActor(jjOBJ& obj, Actors::ActorBase& actor, bool deferKill = false)

Gives the object of the game the properties a script changed since PullFromActor().

With deferKill, STATE::KILL doesn't kill it yet, its behavior is to see it first.

static bool Jazz2::Scripting::Legacy::ScriptObjectHost::CallScriptBehavior(LevelScriptLoader* levelScripts, jjOBJ& obj, const jjBEHAVIOR& behavior, bool draw = true)

Runs a behavior of the script on a jjOBJ, false if it isn't one.

A behavior of a class also draws by its onDraw() unless draw is false, as JJ2+ calls it.

static bool Jazz2::Scripting::Legacy::ScriptObjectHost::CallObjectHit(LevelScriptLoader* levelScripts, jjOBJ& obj, jjOBJ* bullet, jjPLAYER* player, std::int32_t force)

Calls onObjectHit() of the behavior of a jjOBJ, and the global ones if it has none or it returns false.

Returns true if the method of the behavior returned true or a global one was called.

static void Jazz2::Scripting::Legacy::ScriptObjectHost::TurnUpsideDown(Actors::ActorBase& actor)

Turns an object of the game upside down, as JJ2+ has the objects of a template whose direction is SPRITE::FLIPV.

It's drawn flipped vertically, a solid object (a crate, a bird cage) hangs from the ceiling above it instead of standing on the ground, its hitbox flipped with it.

static bool Jazz2::Scripting::Legacy::ScriptObjectHost::BreakScenery(LevelScriptLoader* levelScripts, Actors::ActorBase& actor, const jjOBJ& bullet, WeaponType weaponType, std::int32_t strength, SmallVectorImpl<std::int32_t>* hitTiles = nullptr)

Breaks the destructible scenery a bullet of a player touches, as a shot of its weapon breaks it, returns true if it broke any.

By the pixels of the frame the bullet shows, by its position without one. Its weapon is weaponType, or the one of var[3] (1 to 9, the weapons of scripts set it) - one that doesn't freeze breaks it as the Blaster where the Freezer would freeze it. The tiles in hitTiles aren't hit again, the ones it breaks are added there.

bool Jazz2::Scripting::Legacy::ScriptObjectHost::OnCollision(Actors::ActorBase* actor, Actors::ActorBase* other) override

Lets the script handle a collision of the object with a player or a bullet.

With scriptedCollisions, a player touching a pickup and a player attacking or a bullet hitting anything else calls onObjectHit() of the behavior or the global ones (a false of the method lets the game handle it). A playerHandling of PARTICLE makes the object untouchable by players and bullets (whatever its bulletHandling is), a bulletHandling of IGNOREBULLET lets bullets fly through it and DESTROYBULLET stops them without harm.

bool Jazz2::Scripting::Legacy::ScriptObjectHost::OnUpdateHitbox(Actors::ActorBase* actor) override

Makes a solid object as big as the pixels of the frame of an animation a script gave it.

The objects of JJ2+ are solid by their frames, so a crate drawn bigger stands on the ground by its frame.

bool Jazz2::Scripting::Legacy::ScriptObjectHost::OnPerish(Actors::ActorBase* actor, Actors::ActorBase* collider) override

Lets a crate the behavior drives break as in JJ2+.

The object of the game breaks (and gives what's in it), but the object of the script stays - in STATE::ACTION, as JJ2+ has a crate that was hit, so BEHAVIOR::CRATE breaks it into pieces of OBJECT::SHARD and the behavior can keep what remains of it (see LevelScriptLoader::BreakObjects()). Anything else perishes as in the game, unless a behavior of the script brings it back (puppet hands).

bool Jazz2::Scripting::Legacy::ScriptObjectHost::OwnsLights() const override

Returns true for an object the level illuminates, which lights as JJ2+ has it (LIGHT::LASER).

The game's own light of an illuminated object brightens its surroundings beyond full light, JJ2+ doesn't.

bool Jazz2::Scripting::Legacy::ScriptObjectHost::OnTileDeactivated(Actors::ActorBase* actor) override

Tells the behavior to deactivate the object, as JJ2+ does by STATE::DEACTIVATE.

The behavior deactivates it (and deletes what it made), an object whose deactivates is false stays. One whose behavior hasn't run yet is deactivated by the game.

void Jazz2::Scripting::Legacy::ScriptObjectHost::BePlatform(float xOld, float yOld, std::int32_t width)

Makes the object a platform for this tick, as jjOBJ::bePlatform().

As measured in JJ2+, a player stands 24 pixels above the object over the width of its frame (or width) and goes along with it by how far it moved since xOld and yOld, it's one only while the behavior makes it one.

void Jazz2::Scripting::Legacy::ScriptObjectHost::BeSolid()

Makes the object solid for this tick, as jjOBJ::beSolid().

As measured in JJ2+, an object that isn't solid by itself is solid by its frame then, where it is (it isn't put on the ground), and only while the behavior keeps making it solid.

void Jazz2::Scripting::Legacy::ScriptObjectHost::RunGameBehavior(std::uint32_t behavior, bool draw)

Runs a behavior of the game, as jjOBJ::behave().

The behavior of the object of another event makes the object of the game that object from the next update of the scripts (see LevelScriptLoader::SwapActor()), the object's own update runs until then.

void Jazz2::Scripting::Legacy::ScriptObjectHost::RunMonitor(bool draw)

Runs BEHAVIOR::MONITOR of JJ2+ on the object of the game, which is pushed as it is.

The object falls when there's no ground right below its frame, it's in STATE::FALL then and in STATE::SLEEP when it rests on the ground.

bool Jazz2::Scripting::Legacy::ScriptObjectHost::IsScriptedBullet() const

Returns true for a bullet a player fired of a weapon whose bullets a script controls.

See LevelScriptLoader::FirePlayerWeapon(), such a bullet flies as BEHAVIOR::BULLET of JJ2+ (see RunBullet()).

void Jazz2::Scripting::Legacy::ScriptObjectHost::RunBullet(bool draw)

Runs BEHAVIOR::BULLET of JJ2+ on a bullet of a weapon whose bullets a script controls.

It flies by its speeds and accelerations until its counterEnd or a wall, then plays its killAnim and is gone. The shot of the game neither moves nor is drawn then.

void Jazz2::Scripting::Legacy::ScriptObjectHost::FollowScriptMovement()

Makes the object of the game follow a behavior that moves the object itself (BEHAVIOR::WALKINGENEMY).

It's put where the jjOBJ is, without gravity of its own and without the speeds, which are the behavior's.

Variable documentation

static float Jazz2::Scripting::Legacy::ScriptObjectHost::PositionOffset constexpr

How much further right and down an object of the game is than the jjOBJ of it.

The objects of events are at the 15th pixel of their tile in JJ2+ (xOrg of the second tile is 47), the objects of the game at the 16th - scripts compare the positions with the ones of JJ2+.