Map

A map is a single area that can be any size and contain any amount of tiles, including Entities and TilePic’s.

Most of these map settings are also available in the editor under Map Properties.

If the map is saved (by defaults maps auto-save and are persistent), changes made are remembered.

A game may have an unlimited number of maps.

Each map contains its own LayerManager which can be accessed to see what kind of layers it has.

See also

MapManager

LayerManager

Summary
MapA map is a single area that can be any size and contain any amount of tiles, including Entities and TilePic’s.
Member Functions
SetPersistent
GetPersistent
SetAutoSave
GetAutoSave
GetName
GetWorldRect
SetWorldRect
ComputeWorldRect
GetLayerManager
BuildLocalNavGraph
GetCollisionByRay
GetTilesByRect
Related Constants
C_RAY_CONSTANTSUsed with Map::GetCollisionByRay.
C_RAY_ENTITIESThe ray will hit only entities.
C_RAY_TILE_PICThe ray will hit only tile pics.
C_RAY_EVERYTHINGThe ray will hit entities as well as tile pics.
C_RAY_DEBUGThe rays will be visually drawn on the screen, helps to figure out problems.

Member Functions

SetPersistent

nil SetPersistent(boolean bPersistent)

By default, maps are persistent, meaning all changes are remembered and automatically saved in the player’s profile.  (the original is not changed, only the player’s modified version of it)

This only has meaning when a player profile is active.

Parameters

bPersistantTrue if the map should be persistent and changes remembered, false if not

GetPersistent

boolean GetPersistent()

Returns

True if the map is persistent and changes will be remembered on a per-player-profile basis.

SetAutoSave

nil SetAutoSave(boolean bAutoSave)

This only applies when a user profile is not yet loaded.

For title screens, auto-save is usually turned off because no player profile is loaded, yet we don’t want to save after we mess up the screen.

Parameters

bAutoSaveTrue if the map should automatically be saved without needing to choose “Save map now” from the editor.

GetAutoSave

boolean GetAutoSave()

Returns

True if auto-save is currently enabled.

GetName

string GetName()

Returns

The map name.  (the name of its directory)

GetWorldRect

Rectf GetWorldRect()

Returns

The exact size of the map in world coordinates, based on visual data.  Will be computed the first time it is needed.  If chunks of the map are erased, you must call ComputeWorldRect yourself if you want this to be updated.

Returns

a Rectf containing the location of the used map.

SetWorldRect

nil SetWorldRect(Rectf viewArea)

Allows you to manually set the map view rect, allowing more control when the camera is setup to respect these boundries.

Parameters

viewAreaa Rectf object containing the boundries of this map in world coordinates.

ComputeWorldRect

Rect ComputeWorldRect(number reserved)

Computes the actual size of the entire map in world coordinates by looking at the size of each entity/tile.  Slow.  GetWorldRect will now return this cached data.

Parameters

reservedReserved for future features, you must always pass it 0.

Returns

a Rect containing the location of the used map.

GetLayerManager

LayerManager GetLayerManager()

Returns

This map’s LayerManager, containing all information about its layers and layer settings.

BuildLocalNavGraph

nil BuildLocalNavGraph()

Rebuilds the navigational graph for this map.

In general, this isn’t needed, as navigational graphs are grown/destroyed fluidly on the fly as the map changes.

GetCollisionByRay

Zone GetCollisionByRay(Vector2 vStartPos, Vector2 vDir, number rayRange, number raySpread,
Entity entToIgnore, number mode, boolean bIgnoreCreatures)

Allows you to shoot a ray from any point in this map and see what it hits.

The returned Zone object’s vPos member will contain the exact position of the hit, its other values will contain additional information about the collision.

Usage

//let's shoot a ray in front of this entity and see if it detects any other entities)

local rayRange = 80;
local raySpread = 8; //causes 5 rays to be shot in a spread formation 8 units apart, easier to detect hits. 0 to use
//1 ray only
local entToIgnore = this;
local hitZone = this:GetMap():GetCollisionByRay(this:GetPos(), this:GetVectorFacing(), rayRange, raySpread,
entToIgnore, C_RAY_ENTITIES, false);

if (hitZone.entityID != C_ENTITY_NONE) then
//we have an entity in front of us!

local ent = GetEntityByID(hitZone.entityID);
LogMsg("Entity " .. tostring(ent) .. " is sitting in front of us.");

end

Parameters

vStartPosA Vector2 object containing the start position of the ray.
vDirA unit vector containing the direction of the ray.
rayRangeHow far the ray can reach.
raySpread0 for a single ray, otherwise will shoot five rays in a spread formation, this distance apart from each one.
entToIgnoreAn Entity we should ignore during the check, otherwise nil
modeOne of the C_RAY_CONSTANTS.  Use C_RAY_DEBUG to visually see the rays being shot.
bIgnoreCreatureIf true, creatures are ignored during the check.

Returns

A Zone object containing information on what was hit.  The Zone’s materialID will be C_MATERIAL_TYPE_NONE if no collision occured.

GetTilesByRect

TileList GetTilesByRect(Rect rect, LayerList layers, boolean bWithCollisionOnly)

This allows you to grab a list of all the entities and tiles in a rectangular area of the map.

You can later cycle through the list examining each one, or move or copy the list to a new place.  (well, the moving/pasting as a group isn’t accessible yet in script, coming soon?)

Usage

//grab all tiles/entities we're touching

local layerList = this:GetMap():GetLayerManager():GetVisibleLayers(); //what layers we'll scan
local tileList = this:GetMap():GetTilesByRect( Rect(this:GetWorldCollisionRect()), layerList, false); //grab them

LogMsg("Found " .. tileList:GetCount() .. " tiles after scanning the " .. layerList:GetCount() .. " layers.");

//ok, now we have our list and need to run through and look at each one

local tile;

while true do

tile = tileList:GetNext();
if (tile == nil) then break; end;

LogMsg("Found tile type " .. tile:GetType());

if (tile:GetType() == C_TILE_TYPE_ENTITY and tile:GetAsEntity():GetID() != this:GetID()) then
LogMsg("We are standing near an entity that isn't us! Its ID is " .. tile:GetAsEntity():GetID());
end
end

Parameters

rectA Rect object containing the area we should grab tiles from.  Any tile/entity that overlays this area will be included.
layersA LayerList object containing which layers should be included for the search.
bWidthCollisionOnlyIf true, entities/tiles without collision information will be ignored.

Returns

A TileList object containing handles to all the tiles/entities found.  If TileList::GetCount is 0, nothing was found.

Related Constants

Summary
C_RAY_CONSTANTSUsed with Map::GetCollisionByRay.
C_RAY_ENTITIESThe ray will hit only entities.
C_RAY_TILE_PICThe ray will hit only tile pics.
C_RAY_EVERYTHINGThe ray will hit entities as well as tile pics.
C_RAY_DEBUGThe rays will be visually drawn on the screen, helps to figure out problems.

C_RAY_CONSTANTS

C_RAY_ENTITIES

The ray will hit only entities.

C_RAY_TILE_PIC

The ray will hit only tile pics.

C_RAY_EVERYTHING

The ray will hit entities as well as tile pics.

C_RAY_DEBUG

The rays will be visually drawn on the screen, helps to figure out problems.  Slow, so don’t leave this on.  Hits everything.

The Entity object.
TilePics are the simplest form of visual.
Every Map contains its own LayerManager which contains information about its layers.
Handles loading and unloading maps.
The Rectf object.
The Rect object.
A simple object that contains information about a collision.
The Vector2 object.
Used with Map::GetCollisionByRay.
The rays will be visually drawn on the screen, helps to figure out problems.
Means invalid material.
Contains a list of layerID’s.
Contains a list of tiles.
class_< vector<unsigned int> >(
   "LayerList"
) .def(constructor<>()) .def("Add", &vector<unsigned int>::push_back) .def("GetCount", &vector<unsigned int>::size) .def("Get", &NumberGet) .def("__tostring", &LayerListToString) ]