Page 1 of 1

Function to change level parameters in zone.lua

Posted: Mon Jun 10, 2013 12:38 pm
by Zonk
One can use the 'levels' field in zone.lua to have the levels of a zone use different sizes, layouts, generators...

This is quite useful, but what if one wanted to create a very deep zone where each level changed followed a pattern/function?

For example, making a dungeon smaller or larger with each level or alternating level layouts/map generators,
Doing this manually for a large amount of levels is possible, but frustrating.

So I'm asking for 'width' and 'height'(and other fields where it makes sense) to allow functions, and also for a way to change the generators/other properties of specific level using a function. In both cases of course level would be a required argument...

For example, say I wanted every even level of my zone to have no NPCs, then I could use...

Code: Select all

adjust_level = function(zone, level) if level % 2 == 0 then zone.generator.actor.nb_npc = {0,0} end
...
(this is of course pseudocode, it shouldn't actually alter the zone but only the parameters for the level to be generated)

Re: Function to change level parameters in zone.lua

Posted: Tue Jun 11, 2013 4:20 pm
by Hachem_Muche
I agree, this would be a nice feature.

In the meantime, I've put in code to make level by level adjustments for Infinite500 via the on_setup (called when the zone is loaded) and on_leave (called when leaving each level) functions in the zone definition table:

Code: Select all

on_setup = function(self)
		self.width = 50 + rng.range(0,40)
		self.height = math.ceil(4900/self.width)
		self:updateBaseLevel()
		self.generator.map.rooms = {"random_room", {"pit",3}, {"greater_vault",5 + 4*self.base_level/(self.base_level+15)}} --I5 more vaults at higher player levels
	end,

Code: Select all

on_leave = function(lev, old_lev, newzone)
		--set up for next level generation
		game.zone.width = 50 + rng.range(0,40)
		game.zone.height = math.ceil(4900/game.zone.width)
		game.zone.generator.map.rooms = {"random_room", {"pit",3}, {"greater_vault",5 + 4*game.zone.base_level/(game.zone.base_level+15)}} --I5 more vaults at higher levels
	end,
It's a little bit of a kludge, but I don't see any reason you couldn't specify a completely new generator table for each level. (Perhaps just randomly pick from a list of generator specs, for example.)

Re: Function to change level parameters in zone.lua

Posted: Tue Jun 11, 2013 6:47 pm
by darkgod

Re: Function to change level parameters in zone.lua

Posted: Tue Jun 11, 2013 6:52 pm
by Zonk
That was fast, thanks :)

Re: Function to change level parameters in zone.lua

Posted: Tue Jun 11, 2013 6:56 pm
by darkgod