Jazz2::Scripting::LevelScriptLoader class

Binds an AngelScript script file to LevelHandler and executes the script.

Base classes

class ScriptLoader
Generic AngelScript script loader with #include and #pragma directive support.

Public types

struct StartingLook
How a new object of an event looks, see GetStartingLook().
struct BehaviorMethods
Methods of a class of a script that implements jjBEHAVIORINTERFACE, nullptr for the ones it doesn't have.

Public static functions

static auto IsStillUntilUsed(std::uint32_t behavior) -> bool
Returns whether objects of a behavior of the game stand still until a player uses them (springs, crates).

Constructors, destructors, conversion operators

LevelScriptLoader(LevelHandler* levelHandler, StringView scriptPath, StringView scriptText = {})
Creates a new instance and binds the specified script to the level handler.
~LevelScriptLoader()

Public functions

auto GetLevelHandler() const -> LevelHandler*
Returns the level handler this script is bound to.
auto PlaySample(const Vector2f& pos, std::int32_t sampleId, std::int32_t volume, std::int32_t frequency, bool sourceRelative) -> std::shared_ptr<AudioBufferPlayer>
Plays a sound sample by its original sample index (see SOUND::Sample).
auto PlayLoopedSample(const Vector2f& pos, std::int32_t sampleId, std::int32_t channel, std::int32_t volume, std::int32_t frequency) -> std::int32_t
Keeps a looped sample playing on a channel for this tick, as jjSampleLooped().
auto IsSampleLoaded(std::int32_t sampleId) -> bool
Returns true if the given built-in sample is available (loading it on first query).
auto LoadSample(std::int32_t sampleId, StringView path) -> bool
Loads a custom sample from the given content path, overriding the sample at the given index.
auto IsTSF() const -> bool
Returns true if the game is converted from version 1.24 (The Secret Files), which has more animation sets than 1.23.
auto GetAnimationTables() -> Legacy::AnimationTables&
Returns the animation tables of the script, jjAnimSets, jjAnimations and jjAnimFrames.
auto GetOriginalEvent(std::int32_t x, std::int32_t y) -> std::uint32_t
Returns the event of a tile as the original stores it, see Legacy::EventTranslator.
void SetOriginalEvent(std::int32_t x, std::int32_t y, std::uint32_t eventWord)
Changes the event of a tile to one of the original, as jjEventSet() and jjParameterSet() do.
auto AddObjectFromEvent(std::uint8_t eventId, float xPixel, float yPixel) -> std::int32_t
Spawns an object from an original JJ2 event ID at the given pixel position.
auto GetScriptObject(std::int32_t objectId) -> Actors::ActorBase*
Returns the live actor for a script object ID previously returned by AddObjectFromEvent.
auto GetObjectSpawnTick(std::int32_t objectId) const -> std::int32_t
Returns the tick of the scripts the object got its object ID in, 0 if the ID isn't given.
auto GetEventTranslator() -> Legacy::EventTranslator&
Returns the translator between the events of the game and those of the original, made on first use.
void OnActorAdded(const std::shared_ptr<Actors::ActorBase>& actor)
Called when an object is added to the level.
auto GetObjectPreset(std::uint8_t eventId) -> Legacy::jjOBJ*
Returns the template of the objects of an event of the original (jjObjectPresets), AddRef'd.
auto FirePlayerWeapon(Actors::Player* player, WeaponType weaponType) -> bool
Fires the bullets of a weapon whose bullets a script controls as JJ2+ does, false if a script doesn't control them.
auto OwnsWeather() const -> bool
Returns true if the scripts make the weather of the level, the level doesn't draw it then.
auto FindObjectPreset(std::uint8_t eventId) const -> Legacy::jjOBJ*
Returns the template of an event if a script asked for it, nullptr otherwise, not AddRef'd.
auto GetStartingLook(std::uint8_t eventId, std::int32_t tileX, std::int32_t tileY, StartingLook& look) -> bool
Returns how a new object of an event at a tile starts, false if no script asked for its template.
void OnFrameDrawn(float x, float y, std::uint32_t frame, std::uint32_t mode)
Called by what a script draws a frame by, see GetStartingLook().
void OnGameBehavior(const Legacy::jjOBJ& obj, std::uint32_t behavior)
Called when an object that isn't in the level runs a behavior of the game, see GetStartingLook().
auto WatchLookContext(asIScriptContext* ctx) -> bool
Stops a context running for GetStartingLook() after too many lines, returns true if it's watched.
auto GetDefaultPresetAnimation(std::uint8_t eventId) -> std::uint32_t
Returns the animation the template of an event has before a script changes it, 0 if it has none.
void OnWeaponSprite(std::uint32_t slot, bool powered, std::uint32_t firstFrame, std::uint32_t frameCount)
Called when a weapon of the script gets the sprite its hook shows on the screen, frames as jjAnimFrames has them.
auto GetWeaponSprite(std::uint32_t slot, bool powered, std::uint32_t& firstFrame, std::uint32_t& frameCount) const -> bool
Returns the frames of the sprite a weapon of the script shows on the screen, see OnWeaponSprite(), false if it has none.
auto GetWorldCanvas() -> Legacy::ScriptWorldCanvas&
Returns what the script draws in the level (jjDrawSprite() and the like), attached to the level on first use.
void OnDrawLayers(UI::Canvas* canvas)
Calls onDrawLayer1() to onDrawLayer8() of the script for the view being drawn, see Legacy::ScriptLayerCanvas.
auto GetSpritePaletteOffset(std::uint32_t mode, std::uint8_t param) -> std::int32_t
Returns the palette offset a palette-indexed sprite is drawn with in a sprite mode (SPRITE::Mode).
auto GetVinePaletteOffset(std::uint32_t mode, std::uint8_t param) -> std::int32_t
Returns the palette offset a swinging vine is drawn with, see GetSpritePaletteOffset().
auto GetDissolveNoise(std::uint8_t color, std::uint8_t density, std::int32_t& paletteOffset) -> Texture*
Returns how SPRITE::BLEND_DISSOLVE draws a color, as many random pixels as density says.
auto GetLayerDrawZ(std::int32_t layerNumber) const -> std::uint16_t
Returns the depth something drawn on a layer of the original, 1 to 8, is drawn at.
void InvalidateLayerDrawZ()
Forgets the depths GetLayerDrawZ() resolved, once the order or the depths of the layers change.
auto GetObjectById(std::int32_t objectId) -> Legacy::jjOBJ*
Returns the script view of the object of an object ID (jjObjects), AddRef'd.
auto GetObjectView(Actors::ActorBase* actor) -> Legacy::jjOBJ*
Returns the script view of an object of the level, not AddRef'd, nullptr if it has no object ID (see OnActorAdded()).
void RunNewObjectBehavior(std::int32_t objectId)
Runs the behavior of the script of an object of the game a script just made once, as JJ2+ runs it for a new object.
auto GetPlayerSubscreenPosition(Actors::Player* player) const -> Vector2i
Returns the top left corner of the view of a player on the screen (jjPLAYER::subscreenX/Y).
auto GetActiveBossObjectID() -> std::int32_t
Returns the object ID of the boss that's active (jjPLAYER::boss), 0 for none.
auto OnBossAreaActivated() -> bool
Called when a player activates the boss of a level without a boss of the game.
void ApplySpriteRecolors()
Recolors the frames of the sprites the level recolors (see Formats::ScriptDataChunk), as MLLE::Setup() does.
void AddWorldText(float xPixel, float yPixel, StringView text, std::uint32_t size, const Colorf& color, std::int8_t layerZ)
Draws text in the level until the next tick, as jjDrawString() does.
auto GetScriptParticle(std::int32_t index) -> Legacy::jjPARTICLE*
Returns a particle of jjParticles, nullptr out of range.
auto AddScriptParticle(std::uint32_t type) -> Legacy::jjPARTICLE*
Makes a particle of a type (PARTICLE::Type) as jjAddParticle() does, nullptr if all are in use.
auto GetScriptBossHealth(std::int32_t& health, std::int32_t& maxHealth) -> bool
Returns the health of the boss a script activated for a player (jjPLAYER::boss), false if there's none.
auto HidesNativeBossMeter() const -> bool
Returns true if the script ended the boss fight with jjPLAYER::activateBoss(false) for every player, the meter of a boss of the game is hidden then.
auto GetCharacterProfile(PlayerType type) const -> CharacterProfile
Returns the abilities of a character as jjCharacters changed them.
auto GetCharacter(PlayerType type) -> Legacy::jjCHARACTER*
Returns jjCharacters[] of a player type, a scratch copy for a type that isn't a character.
auto GetMusicPlayer() const -> nCine::AudioStreamPlayer*
Returns the player of the music of the level, nullptr if there's none.
auto WarpsTransmuteCoins() const -> bool
Returns jjWarpsTransmuteCoins.
auto IsBossAreaActivated() const -> bool
Returns true once a boss of a script was activated, see OnBossAreaActivated().
auto GetBehaviorMethods(asITypeInfo* type) -> BehaviorMethods
Returns the methods of a class of a script that implements jjBEHAVIORINTERFACE, looked up once per class.
auto GetGlobalObjectHit() const -> asIScriptFunction*
Returns the global onObjectHit() of the script, nullptr if it has none.
void ShowLevelText(StringView text, std::uint32_t size)
Shows a text of the level in a size of STRING::Size.
auto AddScriptControlledObject(std::uint8_t eventId, float xPixel, float yPixel, asIScriptFunction* behaviorFunc) -> std::int32_t
Spawns a script-controlled object whose behavior function drives it each frame.
void AddExplosion(float xPixel, float yPixel, std::int16_t anim)
Makes an explosion object playing an animation once, as the game does for the kill animation of an object.
void BreakObject(std::int32_t objectId)
Lets the object of the script of a crate that broke in the game go on without it.
void SwapActor(std::int32_t objectId, std::uint8_t eventId)
Makes the object of the game of an object ID the object of another event, which keeps its object ID and view.
auto GetLayerProxy(std::int32_t index) -> Legacy::jjLAYER*
Returns the persistent jjLAYER proxy bound to the given level layer index.
auto GetLayerIndex(std::int32_t layerNumber) const -> std::int32_t
Returns the index of the level layer a script means by a layer number of the original, 1 to 8.
auto GetOriginalTileType(std::int32_t tileId) -> std::uint8_t
Returns the type of a tile of the original game (jjTileType[]), 1 translucent, 3 invisible, 5 heat, 0 ordinary.
void SetOriginalTileType(std::int32_t tileId, std::uint8_t type)
Changes the type of a tile of the original game, every placed tile of it is drawn so.
auto GetUseLayer8Speeds() const -> bool
Returns whether layer 8 moves by its own speeds (jjUseLayer8Speeds) instead of staying fixed.
void SetUseLayer8Speeds(bool value)
Sets whether layer 8 moves by its own speeds (jjUseLayer8Speeds) instead of staying fixed.
auto FindLayerByName(StringView name) const -> std::int32_t
Returns the index of the first level layer of a given name (see Formats::LayerPropertiesChunk), or -1.
void GetLayerOrder(SmallVectorImpl<std::int32_t>& order) const
Returns the indices of the level layers in the order they are drawn, from the front, as jjLayerOrderGet().
auto SetLayerOrder(ArrayView<const std::int32_t> order) -> bool
Changes the order the level layers are drawn in, from the front, as jjLayerOrderSet().
auto CreateLayer(std::int32_t width, std::int32_t height) -> Legacy::jjLAYER*
Makes a layer of no tiles, as jjLAYER(uint, uint), and returns its jjLAYER proxy, AddRef'd for the caller.
auto CopyLayer(const Legacy::jjLAYER& source) -> Legacy::jjLAYER*
Makes a layer as a copy of a layer of the level, with its tiles and its properties, as jjLAYER(const jjLAYER &in), see CreateLayer().
auto CreateLayersFromLevel(StringView fileName, ArrayView<const std::uint32_t> layerNumbers, std::int32_t tileIdAdjustment, SmallVectorImpl<Legacy::jjLAYER*>& layers) -> bool
Makes layers of the layers of a level file, as jjLayersFromLevel(), see CreateLayer().
auto AddTilesFromTileSet(StringView fileName, std::uint32_t firstTileId, std::uint32_t tileCount, const std::uint8_t* paletteRemapping) -> bool
Adds tiles of a tile set after the tiles of the level, as jjTilesFromTileset().
auto AddTrueColorTilesFromTileSet(StringView fileName, std::uint32_t firstTileId, std::uint32_t tileCount, const Legacy::jjPAL* palette) -> bool
Adds tiles of a tile set as true color tiles, as jjTilesFromTileset32().
auto GetPlusTexture(std::int32_t index, std::uint8_t* pixels) -> bool
Fills the 256 × 256 palette indices of a texture of JJ2+ by its number (TEXTURE::Texture).
auto GetLayerDescription(std::int32_t layerNumber) -> Tiles::LayerDescription*
Returns the description of the level layer a script means by a layer number of the original, or nullptr.
auto GetTilePixels(std::int32_t tileId, std::uint8_t* pixels, const Legacy::jjPAL* palette = nullptr) -> bool
Reads the 32 × 32 palette indices of a tile that isn't animated, as scripts see them.
auto SetTilePixels(std::int32_t tileId, const std::uint8_t* pixels) -> bool
Overwrites the pixels of a tile that isn't animated by 32 × 32 palette indices, everywhere it's drawn.
auto GetTileColors(std::int32_t tileId, Legacy::jjPALCOLOR* colors, const Legacy::jjPAL& palette) -> bool
Reads the 32 × 32 colors of a tile that isn't animated, as jjCOLORMAP of JJ2+ has them.
auto SetTileColors(std::int32_t tileId, const Legacy::jjPALCOLOR* colors) -> bool
Overwrites the pixels of a tile that isn't animated by 32 × 32 colors with alpha, a true color tile.
auto IsTileTrueColor(std::int32_t tileId) -> bool
Returns whether a tile that isn't animated is a true color tile, jjTileIs32Bit[] of JJ2+.
auto GetWeapon(std::int32_t number) -> Legacy::jjWEAPON*
Returns the properties of a weapon by its number of JJ2+ (WEAPON::BLASTER is 1), jjWeapons[].
auto GetPlayers() const -> ArrayView<Actors::Player* const>
Returns list of players.
void OverridePlayerInput(Actors::Player* player, PlayerAction action, bool value)
Overrides what the specified player believes one of its controls is doing until the next tick of the scripts.
void ApplyInputOverrides(std::int32_t playerIndex)
Applies what the scripts set the controls of a local player to in the last tick to the input of this frame.
auto GetPlayerBackingStore(Actors::Player* player) -> jjPLAYER*
Returns script backing store for specified player.
auto GetPlayerBackingStore(std::int32_t playerID) -> jjPLAYER*
Returns script backing store for the player scripts know by the number (see GetScriptPlayerID()).
auto GetLocalPlayerBackingStore(std::int32_t localIndex) -> jjPLAYER*
Returns script backing store for the local player of the index, the one for absent players if there is none.
auto GetScriptPlayerID(const Actors::Player* player) const -> std::int32_t
Returns the number scripts know the player by, the same on every machine of a multiplayer game.
auto GetPlayerByScriptID(std::int32_t playerID) const -> Actors::Player*
Returns the player scripts know by the number, nullptr if it isn't in the level on this machine.
auto IsLocalPlayer(const Actors::Player* player) const -> bool
Returns whether the player is played on this machine.
auto GetLocalPlayerCount() const -> std::int32_t
Returns count of players played on this machine.
void OnLevelLoad()
Called when a level is loaded.
void OnLevelBegin()
Called when a level begins.
void OnLevelReload()
Called when a level reloads.
auto OnCheat(StringView cheat) -> bool
Called when a player enters a cheat code (onCheat()), returns true if the script handled it, the game doesn't apply it then.
auto OnLocalChat(StringView text) -> bool
Called when the local player says something in the chat (onLocalChat()), returns true if the script took it, it isn't said then.
void OnReceivePacket(std::int32_t fromClientID, ArrayView<const std::uint8_t> data)
Called when the script of another machine sent data (onReceive()), the server is client 0.
void OnReplacing()
Called when another handler is about to be made in place of the level, see IStateHandler::OnReplacing().
void OnLevelUpdate(float timeMult)
Called when a level updates (on the beginning of each frame).
auto GetGameTick() const -> std::int32_t
Returns the number of the current tick of the scripts of JJ2+, 70 of them in a second (jjGameTicks).
auto GetNextLevelDifficulty(GameDifficulty current) const -> GameDifficulty
Returns the difficulty of the next level (jjDifficultyNext), or current if it's not a valid one.
void SetLayerSpeedSeamlessly(Legacy::jjLAYER& layer, bool vertical, float newSpeed, bool newSpeedIsAnAutoSpeed)
Changes the speed or the auto speed of a layer on one axis, keeping it in place in the view of the first player.
void OnLevelCallback(Actors::ActorBase* initiator, std::uint8_t* eventParams)
Called when a level callback is triggered.
auto OnDraw(UI::HUD* hud, Actors::Player* player, const Rectf& view, DrawType type) -> bool
Called when a part of viewport or HUD is drawn.
auto GetPlayerTimer(Actors::Player* player, float& secondsLeft, bool& isPaused) const -> bool
Returns the seconds left on the timer a script started for a player (jjPLAYER::timerStart()), false if it's stopped.
void OnPlayerDied(Actors::Player* player, Actors::ActorBase* collider)
Called when a player dies.

Public variables

bool _verticalSplitscreen

Protected functions

auto OnProcessInclude(StringView includePath, StringView scriptPath) -> String override
Called when #include directive is encountered in a script file.
void OnProcessPragma(StringView content, ScriptContextType& contextType) override
Called when #pragma directive is encountered in a script file.
auto OnReadScript(StringView absolutePath, String& content) -> bool override
Called before a script file is read, returns true with content to use it instead of the file, which then needn't exist.
void OnBeforeScriptCall()
Called before a script function is called.
void OnAfterScriptCall()
Called after a script function is called.

Function documentation

Jazz2::Scripting::LevelScriptLoader::LevelScriptLoader(LevelHandler* levelHandler, StringView scriptPath, StringView scriptText = {})

Creates a new instance and binds the specified script to the level handler.

Parameters
levelHandler Level handler the script is bound to
scriptPath Path to the script file to load
scriptText Text read in place of the script file, which then needn't exist, empty to read the file

std::shared_ptr<AudioBufferPlayer> Jazz2::Scripting::LevelScriptLoader::PlaySample(const Vector2f& pos, std::int32_t sampleId, std::int32_t volume, std::int32_t frequency, bool sourceRelative)

Plays a sound sample by its original sample index (see SOUND::Sample).

Loads and caches the sample on first use. Returns the player, or nullptr if the sample couldn't be played.

std::int32_t Jazz2::Scripting::LevelScriptLoader::PlayLoopedSample(const Vector2f& pos, std::int32_t sampleId, std::int32_t channel, std::int32_t volume, std::int32_t frequency)

Keeps a looped sample playing on a channel for this tick, as jjSampleLooped().

As JJ2+ has it, channel 0 starts it on a new channel, which is returned - the script passes it again in every tick it wants to hear it (where the object is now), a loop no script played in a tick stops.

Legacy::AnimationTables& Jazz2::Scripting::LevelScriptLoader::GetAnimationTables()

Returns the animation tables of the script, jjAnimSets, jjAnimations and jjAnimFrames.

Made on first use. The sprites scripts draw come from there, see Legacy::AnimationTables.

std::uint32_t Jazz2::Scripting::LevelScriptLoader::GetOriginalEvent(std::int32_t x, std::int32_t y)

Returns the event of a tile as the original stores it, see Legacy::EventTranslator.

The event ID in the low 8 bits, the parameters from bit 12. A word a script wrote by SetOriginalEvent() stays as it was written, as long as the event of the tile isn't changed otherwise.

std::int32_t Jazz2::Scripting::LevelScriptLoader::AddObjectFromEvent(std::uint8_t eventId, float xPixel, float yPixel)

Spawns an object from an original JJ2 event ID at the given pixel position.

Converts the event to a native type, registers it, and returns a script object ID (or 0 on failure). Used by jjAddObject.

Actors::ActorBase* Jazz2::Scripting::LevelScriptLoader::GetScriptObject(std::int32_t objectId)

Returns the live actor for a script object ID previously returned by AddObjectFromEvent.

Returns nullptr if it no longer exists. Used by jjObjects.

void Jazz2::Scripting::LevelScriptLoader::OnActorAdded(const std::shared_ptr<Actors::ActorBase>& actor)

Called when an object is added to the level.

An object of an event gets an object ID (jjObjects), the event of the original it comes from is worked out by Legacy::EventTranslator. If a script gave the template of that event (jjObjectPresets) a behavior of its own, the behavior drives the object (see Legacy::ScriptObjectHost).

bool Jazz2::Scripting::LevelScriptLoader::FirePlayerWeapon(Actors::Player* player, WeaponType weaponType)

Fires the bullets of a weapon whose bullets a script controls as JJ2+ does, false if a script doesn't control them.

The bullets go by SPREAD::Spread of the weapon, the behavior of the script moves them then (see Legacy::ScriptObjectHost::RunBullet()).

bool Jazz2::Scripting::LevelScriptLoader::OwnsWeather() const

Returns true if the scripts make the weather of the level, the level doesn't draw it then.

The weather of JJ2+ is of particles scripts see (jjParticles), they steer or remove them.

bool Jazz2::Scripting::LevelScriptLoader::GetStartingLook(std::uint8_t eventId, std::int32_t tileX, std::int32_t tileY, StartingLook& look)

Returns how a new object of an event at a tile starts, false if no script asked for its template.

The behavior of a script the template has runs once on a copy of it in STATE::START, which is in no level, and for a few ticks more to see whether it changes the frame. The copy is at the tile, its behavior reads the parameters of the event there.

std::int32_t Jazz2::Scripting::LevelScriptLoader::GetSpritePaletteOffset(std::uint32_t mode, std::uint8_t param)

Returns the palette offset a palette-indexed sprite is drawn with in a sprite mode (SPRITE::Mode).

PALSHIFT and SINGLEHUE draw the sprite in the sprite palette moved by param or in the gradient from param, a row of the shared palette texture each, which the scripts keep until they go. Otherwise it's the sprite palette, 0.

std::int32_t Jazz2::Scripting::LevelScriptLoader::GetVinePaletteOffset(std::uint32_t mode, std::uint8_t param)

Returns the palette offset a swinging vine is drawn with, see GetSpritePaletteOffset().

In the sprite palette index 128 is transparent too, it's the background of vines in the original game. A sprite mode with a palette of its own keeps it.

Texture* Jazz2::Scripting::LevelScriptLoader::GetDissolveNoise(std::uint8_t color, std::uint8_t density, std::int32_t& paletteOffset)

Returns how SPRITE::BLEND_DISSOLVE draws a color, as many random pixels as density says.

Returns a repeating texture of noise and sets paletteOffset to the palette it's drawn through, or nullptr where it can't be drawn so.

Legacy::jjOBJ* Jazz2::Scripting::LevelScriptLoader::GetObjectById(std::int32_t objectId)

Returns the script view of the object of an object ID (jjObjects), AddRef'd.

An object ID nothing has, or had, gets an inactive object.

bool Jazz2::Scripting::LevelScriptLoader::OnBossAreaActivated()

Called when a player activates the boss of a level without a boss of the game.

A script of JJ2+ drives a boss of its own, it learns the boss is activated by jjPLAYER::bossActivated. Returns false if the context isn't of JJ2+, the level has no boss then.

bool Jazz2::Scripting::LevelScriptLoader::GetScriptBossHealth(std::int32_t& health, std::int32_t& maxHealth)

Returns the health of the boss a script activated for a player (jjPLAYER::boss), false if there's none.

The energy of the object against the one of its template, as JJ2+ shows the health of a boss.

void Jazz2::Scripting::LevelScriptLoader::ShowLevelText(StringView text, std::uint32_t size)

Shows a text of the level in a size of STRING::Size.

MEDIUM is how the game shows the texts of the level, SMALL is smaller and LARGE bigger.

std::int32_t Jazz2::Scripting::LevelScriptLoader::AddScriptControlledObject(std::uint8_t eventId, float xPixel, float yPixel, asIScriptFunction* behaviorFunc)

Spawns a script-controlled object whose behavior function drives it each frame.

A host actor applies its velocity, calls the behavior over the jjOBJ, and syncs the position back. Returns a script object ID. Used by jjAddObject when a custom behavior function is supplied.

void Jazz2::Scripting::LevelScriptLoader::BreakObject(std::int32_t objectId)

Lets the object of the script of a crate that broke in the game go on without it.

It's done in the next update of the scripts, see Legacy::ScriptObjectHost::OnPerish().

void Jazz2::Scripting::LevelScriptLoader::SwapActor(std::int32_t objectId, std::uint8_t eventId)

Makes the object of the game of an object ID the object of another event, which keeps its object ID and view.

As JJ2+ has an object behave as another one (food that behaves as a dog), the object of the game is that object then. It's done in the next update of the scripts, see Legacy::ScriptObjectHost::RunGameBehavior().

Legacy::jjLAYER* Jazz2::Scripting::LevelScriptLoader::GetLayerProxy(std::int32_t index)

Returns the persistent jjLAYER proxy bound to the given level layer index.

Creates and populates it from the engine layer on first access (or returns nullptr if the index is out of range). The returned handle is AddRef'd for the caller. Used by jjLayers.

std::int32_t Jazz2::Scripting::LevelScriptLoader::GetLayerIndex(std::int32_t layerNumber) const

Returns the index of the level layer a script means by a layer number of the original, 1 to 8.

The layers of a converted level know their numbers (see Formats::LayerPropertiesChunk), wherever they are drawn. In a level without them the number is counted from the sprite layer, which is always layer 4. Returns -1 if the level has no such layer.

void Jazz2::Scripting::LevelScriptLoader::SetUseLayer8Speeds(bool value)

Sets whether layer 8 moves by its own speeds (jjUseLayer8Speeds) instead of staying fixed.

Only a layer 8 the level left fixed is changed. A value set while the layers are drawn takes effect after onDrawLayer8(), where JJ2+ reads it.

void Jazz2::Scripting::LevelScriptLoader::GetLayerOrder(SmallVectorImpl<std::int32_t>& order) const

Returns the indices of the level layers in the order they are drawn, from the front, as jjLayerOrderGet().

A layer left out of the order by SetLayerOrder() isn't there.

bool Jazz2::Scripting::LevelScriptLoader::SetLayerOrder(ArrayView<const std::int32_t> order)

Changes the order the level layers are drawn in, from the front, as jjLayerOrderSet().

The layers left out aren't drawn. Returns false and changes nothing if the order doesn't have the sprite layer, or has an index that isn't a level layer.

Legacy::jjLAYER* Jazz2::Scripting::LevelScriptLoader::CreateLayer(std::int32_t width, std::int32_t height)

Makes a layer of no tiles, as jjLAYER(uint, uint), and returns its jjLAYER proxy, AddRef'd for the caller.

The layer is one of the level, which isn't drawn until it's in the order of the layers (see SetLayerOrder()). The layer of one no script refers to any more, and which isn't drawn, is used again. Returns nullptr if the size is out of range or the memory isn't there.

bool Jazz2::Scripting::LevelScriptLoader::CreateLayersFromLevel(StringView fileName, ArrayView<const std::uint32_t> layerNumbers, std::int32_t tileIdAdjustment, SmallVectorImpl<Legacy::jjLAYER*>& layers)

Makes layers of the layers of a level file, as jjLayersFromLevel(), see CreateLayer().

layerNumbers are 1 to 8. The layers of the level being played are copied as they are now, those of another level are read from its original file. tileIdAdjustment is added to every tile ID that isn't empty or animated, an animated tile is the animated tile of this level of the same index. Returns false and makes no layers if the level can't be read or doesn't have one of the layers.

bool Jazz2::Scripting::LevelScriptLoader::AddTilesFromTileSet(StringView fileName, std::uint32_t firstTileId, std::uint32_t tileCount, const std::uint8_t* paletteRemapping)

Adds tiles of a tile set after the tiles of the level, as jjTilesFromTileset().

paletteRemapping is 256 palette indices the pixels are remapped by, or nullptr. jjTileCount grows by tileCount. Returns false if the tile set can't be loaded or the tiles don't fit below the animated tiles.

bool Jazz2::Scripting::LevelScriptLoader::AddTrueColorTilesFromTileSet(StringView fileName, std::uint32_t firstTileId, std::uint32_t tileCount, const Legacy::jjPAL* palette)

Adds tiles of a tile set as true color tiles, as jjTilesFromTileset32().

The 8-bit tiles are in the colors of palette, or of the tile set's own palette without it, and don't follow the palette of the level. Otherwise the same as AddTilesFromTileSet().

bool Jazz2::Scripting::LevelScriptLoader::GetPlusTexture(std::int32_t index, std::uint8_t* pixels)

Fills the 256 × 256 palette indices of a texture of JJ2+ by its number (TEXTURE::Texture).

Plus.j2d of JJ2+ in the directory of the original game has them, it's read on first use. Returns false if there's no such texture.

Tiles::LayerDescription* Jazz2::Scripting::LevelScriptLoader::GetLayerDescription(std::int32_t layerNumber)

Returns the description of the level layer a script means by a layer number of the original, or nullptr.

See GetLayerIndex(). A change takes effect on the next frame, unless it's one the jjLAYER proxy of the layer pushes back every frame (its speeds, offsets and repeating).

bool Jazz2::Scripting::LevelScriptLoader::GetTilePixels(std::int32_t tileId, std::uint8_t* pixels, const Legacy::jjPAL* palette = nullptr)

Reads the 32 × 32 palette indices of a tile that isn't animated, as scripts see them.

The pixels come from the file of the tile set, read on first use, and include what a script saved into the tile since (see SetTilePixels()). A true color tile is mapped to the nearest colors of palette, or of jjPalette without it. Returns false and leaves pixels untouched if the tile has none, e.g. one of a tile set stored in the level.

bool Jazz2::Scripting::LevelScriptLoader::GetTileColors(std::int32_t tileId, Legacy::jjPALCOLOR* colors, const Legacy::jjPAL& palette)

Reads the 32 × 32 colors of a tile that isn't animated, as jjCOLORMAP of JJ2+ has them.

A true color tile has its own colors, an 8-bit one those of palette, index 0 transparent. Returns false as GetTilePixels() does.

bool Jazz2::Scripting::LevelScriptLoader::SetTileColors(std::int32_t tileId, const Legacy::jjPALCOLOR* colors)

Overwrites the pixels of a tile that isn't animated by 32 × 32 colors with alpha, a true color tile.

A tile of a tile set drawn palette-indexed can't have colors of its own, it gets the nearest colors of jjPalette instead.

Legacy::jjWEAPON* Jazz2::Scripting::LevelScriptLoader::GetWeapon(std::int32_t number)

Returns the properties of a weapon by its number of JJ2+ (WEAPON::BLASTER is 1), jjWeapons[].

Scripts read and write them, the game itself doesn't take most of them. A number out of range gives a scratch entry.

void Jazz2::Scripting::LevelScriptLoader::OverridePlayerInput(Actors::Player* player, PlayerAction action, bool value)

Overrides what the specified player believes one of its controls is doing until the next tick of the scripts.

As a tick of JJ2+ is what the player does in it, the frames without a tick (the display is faster than the 70 ticks of a second) keep it too.

void Jazz2::Scripting::LevelScriptLoader::OnReplacing()

Called when another handler is about to be made in place of the level, see IStateHandler::OnReplacing().

The sprites of the game the script redrew are given back as they were, the next level would otherwise load them changed, and they may be freed before the level goes.