Programming levelgens

From Bitfighter

Creating levelgen scripts is very straightforward. The methodology basically follows that used in the level definition files. If you are familiar with that format, you will find understanding the levelgen methods very easy. The easiest way to learn how level files are structured is to create a sample level in the editor, and examine it in a text editor. Don't worry, it's not complicated!

You might want to read about the general structure of Bitfighter scripts before reading further.

void addItem(args)
- Adds an item to the game

Takes a variable number of arguments, and follows the same argument order as that used in level files.

For example:

-- Create a 10 x 10 block of RepairItems
for i = 0, 10 do
   for j = 0, 10 do
      levelgen:addItem("RepairItem", 1 + i * .2, 1 + j * .2)
   end
end
void addWall(wallsize, issolid, points)
- Adds a wall to the game. The wallsize param is the thickness of the wall, in the same units as used in the editor (the standard wall has a thickness of 50). The issolid parameter is not yet fully supported, so use "false" for this value for now. Finally, points is a Lua table containing 2 or more Points.

For example:

-- Create a U-shaped segment of wall.  To create a closed loop, 
-- repeat the first point at the end of the list.
levelgen:addWall(50, false, { Point(1,1), Point(1,5), Point(5,5), Point(5,1) } )
void addLevelLine(line)
- Feeds a raw level line to the level processor. You can use any line from a level definition file as an argument.
-- Some raw lines
levelgen:addLevelLine("LoadoutZone 0 4.8 4.2  7.1 3.9  7.2 4.8  4.8 4.5")
levelgen:addLevelLine("BarrierMaker 50 5.5 3  5.5 3.5")
void getGridSize()
- Returns the current level's gridsize
-- Create a 1x1 square of wall that is as thick as it is long
-- Use + 1 to make adjacent blocks overlap a tiny bit and thus appear
-- to merge.  Note that defining one long wall is MUCH better than creating
-- a series of many sorter segments.
levelgen:addWall(levelgen:getGridSize() + 1, false, { Point(0,0), Point(1,0) } )
void getPlayerCount()
- Returns the number of players currently on the server. Note that player counts may change during the game. Note also that when testing your level in the editor, the number of players will reported as 0. The best way to test different player configurations is to use a dummy player count instead of getPlayerCount() until you are ready to put your level into production.
-- Add an asteroid for each player at (10,10), (11, 11), etc.
local players = levelgen:getPlayerCount()  -- Replace with numbers for testing
for i = 1, players do
   levelgen:addItem("Asteroid", 10 + i, 10 + i)
end


void pointCanSeePoint(point1, point2)
- Returns true if there is an unimpeded line-of-sight between point1 and point2. Currently only considers walls impediments.
void setGameTime(time_in_minutes)
- Sets the game time for the level. Time is sepcified in minutes, fractional minutes are allowed.
levelgen:setGameTime(8.5)   -- 8 1/2 minute game