Skip to content

Added event GAMEEVENT_LEVEL_INIT, which executes early in map initialization,...

Added event GAMEEVENT_LEVEL_INIT, which executes early in map initialization, before things are spawned, OPEN scripts executed, etc.

Context: I'm using the ACS Lump Reading API to read the MAPINFOs of the currently loaded WADs, to detect what WAD is currently being played so I can do actor swaps in GAMEEVENT_ACTOR_SPAWNED during map load (for compatibility fixes), get author information, etc. I need this event so I can detect the WAD before any things are spawned, so the swaps work, and so the author print in the OPEN script works.

In the future, I also want to make an Archipelago randomizer for Zandronum, and having early access to ACS before the OPEN script would allow me to do some setup before map objects are spawned in.

function void detect_wads(void)
{
	if(IsNetworkGame() && (ConsolePlayerNumber() != -1)) // Hack to prevent Zandronum from executing this on a client
		return;
	
	// We only need to do this once, the first time any map is loaded.
	if(GetCVar("sh_compat_mode") != WADCOMPAT_UNINITIALIZED)
		return;
	
	int startIndex;
	str mapinfo_data;

	while(true)
	{
		startIndex = LumpOpen("MAPINFO", startIndex + 1);
		if (startIndex == -1)
		{
			Log(s:"No more MAPINFO lumps found.");
			break;
		}
		Log(s:"Next MAPINFO lump was found at index ", d:startIndex, s:".");

		int size = LumpGetInfo(startIndex, LUMP_INFO_SIZE);
		int find_pos = 0;
		mapinfo_data = LumpReadString(startIndex, 0, size);
		
		find_pos = seek_string(mapinfo_data, "map map01 \"Sundowning\"", 0);
		find_pos = seek_string(mapinfo_data, "map map02 \"Asterion\"", find_pos);
		if(find_pos != -1)
		{
			Log(s:"MAYhem 2018: Orange Edition Detected");
			SetCVar("sh_compat_mode", WADCOMPAT_MAYHEM18O);
			return;
		}

		find_pos = seek_string(mapinfo_data, "map map01 \"Failed Mining Operation\"", 0);
		find_pos = seek_string(mapinfo_data, "map map02 \"Vasiliki Thalassa\"", find_pos);
		if(find_pos != -1)
		{
			Log(s:"MAYhem 2018: Purple Edition Detected");
			SetCVar("sh_compat_mode", WADCOMPAT_MAYHEM18P);
			return;
		}

		// Make sure to close the lump again to free the handle.
		LumpClose(startIndex);
	}
	
	SetCVar("sh_compat_mode", WADCOMPAT_NORMAL);
}

#define GAMEEVENT_LEVEL_INIT 16
script "EVENT_HANDLER" (int type, int arg1, int arg2) EVENT
{
	switch (type)
	{
		case GAMEEVENT_ACTOR_SPAWNED:
		{
			if((GetCVar("sh_enemy_mult") > 1) && arg1 == true && CheckFlag(0, "ISMONSTER"))
				multiply_actor(clamp(GetCVar("sh_enemy_mult"), 2, 100));

			if(GetCVar("sh_compat_swaps"))
			{
				// Compatibility swaps done here
				if(GetCVar("sh_compat_mode") == WADCOMPAT_MAYHEM18O)
				{
					Do some swapping here...
				}
			}
			break;
		}
		case GAMEEVENT_LEVEL_INIT:
		{
			detect_wads();
			break;
		}
	}
}
Edited by StrikerTheHedgefox

Merge request reports