LevelPostProcessor

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


Classes: LevelPostProcessor

This ZScript class is run on map initialization and allows for some broader changes in terms of thing placement, flags, sector and line textures, etc. Adding one to your zscript is enough for it to be run automatically, it does not need to be linked elsewhere.

The postprocessor runs on the freshly loaded level data. No actors have been spawned yet, no static linedef and sector actions have been performed and no thing based initialization has been done. So you can alter things like static_init linedefs, sector specials, or thing types that do not result in a spawned actor (e.g. a slope marker, polyobj spots, SecAct things), or move vertices around.

Upon running, it calls its internal function Apply, which you can override to perform any of the below listed actions.

Internally, this class is mostly used to apply compatibility and fixes to a list of known map issues, a full list of which can be seen here

ZScript constants

       const SKILLS_ALL = 31
       const MODES_ALL = MTF_SINGLE | MTF_COOPERATIVE | MTF_DEATHMATCH

ZScript virtuals

       protected void Apply(Name checksum, String mapname)
         This action is run automatically on level load.
         It receives the checksum hash and the lump mapname (ie MAP01)

ZScript functions

The following function list should be considered self-explanatory - if you do not understand the usage of these, you likely have no reason to use a LevelPostProcessor.
	protected native void ClearSectorTags(int sector);
	protected native void AddSectorTag(int sector, int tag);
	protected native void ClearLineIDs(int line);
	protected native void AddLineID(int line, int tag);
	protected native void OffsetSectorPlane(int sector, int plane, double offset);
	protected native void SetSectorPlane(int sector, int plane, vector3 normal, double d);
	protected native uint GetThingCount()
	protected native uint AddThing(int ednum, Vector3 pos, int angle = 0, uint skills = SKILLS_ALL, uint flags = MODES_ALL)
       
	protected native int GetThingEdNum(uint thing)
	protected native void SetThingEdNum(uint thing, int ednum)
       
	protected native vector3 GetThingPos(uint thing)
	protected native void SetThingXY(uint thing, double x, double y)
	protected native void SetThingZ(uint thing, double z)
	protected native int GetThingAngle(uint thing)
	protected native void SetThingAngle(uint thing, int angle)

	protected native uint GetThingSkills(uint thing)
	protected native void SetThingSkills(uint thing, uint skills)
	protected native uint GetThingFlags(uint thing);
	protected native void SetThingFlags(uint thing, uint flags)
	protected native int GetThingID(uint thing)
	protected native void SetThingID(uint thing, int id)
	protected native int GetThingSpecial(uint thing)
	protected native void SetThingSpecial(uint thing, int special)

	protected native int GetThingArgument(uint thing, uint index)
	protected native Name GetThingStringArgument(uint thing)
	protected native void SetThingArgument(uint thing, uint index, int value)
	protected native void SetThingStringArgument(uint thing, Name value)

	protected native void SetVertex(uint vertex, double x, double y)
	protected native double, bool GetVertexZ(uint vertex, int plane)
	protected native void SetVertexZ(uint vertex, int plane, double z)
	protected native void RemoveVertexZ(uint vertex, int plane)
	protected native void SetLineVertexes(uint Line, uint v1, uint v2)
	protected native void FlipLineSideRefs(uint Line)
	protected native void SetLineSectorRef(uint line, uint side, uint sector)
	protected native Actor GetDefaultActor(Name actorclass)

	protected void FlipLineVertexes(uint Line)
	protected void FlipLineCompletely(uint Line)
	protected void SetWallTexture(int line, int side, int texpart, String texture)
	protected void SetWallTextureID(int line, int side, int texpart, TextureID texture)
	protected void SetLineFlags(int line, int setflags, int clearflags = 0)
	protected void SetLineActivation(int line, int acttype)

	protected void ClearLineSpecial(int line)
	protected void SetLineSpecial(int line, int special, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0, int arg5 = 0)
	protected void SetSectorSpecial(int sectornum, int special)
	protected void SetSectorTextureID(int sectornum, int plane, TextureID texture)
	protected void SetSectorTexture(int sectornum, int plane, String texture)
	protected void SetSectorLight(int sectornum, int newval)
	protected void SetWallYScale(int line, int side, int texpart, double scale)

Example

The following example will search for things with the ednum 2048 (AmmoBox) and replace them with ednum 2007 (clips)

class MyLevelPostProcessor : LevelPostProcessor 
{
    protected void Apply(Name checksum, String mapname)
    {
        for (int i = 0; i < GetThingCount(); i++)
        {
            int ednum = GetThingEdNum(i);
            if(ednum == 2048) // ammo box
            {
                SetThingEdNum(i, 2007); 
            }
        }
    }
}

Links

Source zscript definition on Github