Class Map
A map holds all of the data about a city, like its tiles, its objects and its roads. A map is split into MapSection objects which allows faster retrieval of objects in an area.
[DataContract]
public class Map : JsonTypeSafeGenericDataHolder, IGenericDataHolder
- Inheritance
-
JsonTypeSafeGenericDataHolderMap
- Implements
-
IGenericDataHolder
- Inherited Members
-
JsonTypeSafeGenericDataHolder.GetDataKeys()
- Extension Methods
Constructors
Map(Point)
Creates a new map with the given size
public Map(Point sizeInSections)
Parameters
sizeInSectionsPointThe size, in sections, of this map
Fields
AlphaTestEffect
An Microsoft.Xna.Framework.Graphics.Effect that skips drawing pixels that have very low alpha.
public static readonly Effect AlphaTestEffect
Field Value
- Effect
AppliedMigrations
The set of names of the Migration instances that have already been applied to objects on this map. When a new map is created, this collection is initialized with all migrations that exist, as new objects are expected to not need migration.
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public HashSet<string> AppliedMigrations
Field Value
DepthStencilCheck
The Microsoft.Xna.Framework.Graphics.DepthStencilState that is used as a response to the DepthStencilReplace state to draw only to parts of the screen that have been marked as "replaced" by the DepthStencilReplace state.
public static readonly DepthStencilState DepthStencilCheck
Field Value
- DepthStencilState
DepthStencilReplace
The Microsoft.Xna.Framework.Graphics.DepthStencilState that is used to replace the stencil buffer with a value of 1 in locations that are drawn to. The stencil state set by this state can be queried using the DepthStencilCheck state.
public static readonly DepthStencilState DepthStencilReplace
Field Value
- DepthStencilState
LightBlend
The Microsoft.Xna.Framework.Graphics.BlendState that is used for drawing to light maps.
public static readonly BlendState LightBlend
Field Value
- BlendState
MailToSend
A list of all Mail that needs to be sent by a mail carrier the next morning.
[DataMember]
public readonly List<Mail> MailToSend
Field Value
MaxFloor
The maximum floor, above the ground floor, that objects can be placed on in build mode. It is set to 1 in the demo and 4 in the full version of the game. For querying the maximum floor that the player can currently view, use CurrentMaxFloor.
public const int MaxFloor = 4
Field Value
MinFloor
The minimum floor, below the ground floor, that objects can be placed on in build mode. It is set to 0, but will likely change in the future, when basements are added to the game. For querying the minimum floor that the player can currently view, use CurrentMinFloor.
public const int MinFloor = 0
Field Value
NoTextureColorsEffect
An Microsoft.Xna.Framework.Graphics.Effect that draws textures in their regular shape, but with a solid color rather than the texture's actual colors.
public static readonly Effect NoTextureColorsEffect
Field Value
- Effect
OutlineEffect
An Microsoft.Xna.Framework.Graphics.Effect that only draws the outlines of the textures that are drawn with it in the passed color.
public static readonly Effect OutlineEffect
Field Value
- Effect
PathfindingDirtyNeighbors
A collection that is used in MarkDirtyForPathfinding(Point, int) which determines the set of "neighbor" positions that should additionally be marked dirty when a given position is marked as dirty. By default, this collection contains all neighboring positions (MLEM.Maths.Direction2Helper.AllExceptNone), as well as positions two tiles, and one floor, offset in adjacent directions for the purpose of Stairs pathfinding.
public static readonly List<(Point Offset, int FloorOffset)> PathfindingDirtyNeighbors
Field Value
- List<(Point Offset, int FloorOffset)>
RoadRadius
This field holds the radius that roads are required to have (in road tiles) excluding the center dotted line tiles. It is set to 2.
public const int RoadRadius = 2
Field Value
Properties
AdoptableChildren
A set of randomly generated children that can be adopted using AdoptChild. If this collection has children removed from it, it will automatically get repopulated until there are 12 children in it.
public List<Person> AdoptableChildren { get; }
Property Value
Info
This map's MapInfo, which includes its name and whether it is custom.
public MapInfo Info { get; }
Property Value
IsActive
Whether this map is active. An active map is one that is either current (IsCurrent), or that has members of the CurrentHousehold on it.
public bool IsActive { get; }
Property Value
IsCurrent
Whether this map is current. This returns whether this map is the same as CurrentMap.
public bool IsCurrent { get; }
Property Value
Neighborhood
The set of all maps that are loaded together as part of the same save, including this map. During gameplay, this collection is the same as CurrentMaps.
public Dictionary<string, Map> Neighborhood { get; }
Property Value
Size
The size in tiles that this map has. This is always SizeInSections multiplied by Size.
public Point Size { get; }
Property Value
- Point
SizeInSections
The size, in sections (not tiles) that this map has
[DataMember]
public Point SizeInSections { get; }
Property Value
- Point
StaticVersion
The static version of this map. When a new save file is created, a static version of each map is loaded and used as the save file's basis. If the static version of the save file is newer, their save file is updated to the new static map version, which causes all non-lot objects to be copied to the saved map.
[DataMember]
public int StaticVersion { get; }
Property Value
Time
This map's current in-game time, including the full day and time.
public TimeSpan Time { get; }
Property Value
Methods
AddHousehold(Lot, bool)
Adds a new household to this map by calling the Household constructor.
public Household AddHousehold(Lot lot, bool addedThroughPopulating = false)
Parameters
lotLotThe lot that the household should live on
addedThroughPopulatingboolWhether the household was added through random population rather than by a player.
Returns
- Household
The newly created household
AddLight(Light)
Adds the given light to the world at its Position
public Light AddLight(Light light)
Parameters
lightLightThe light to add
Returns
AddLot(Rectangle)
Adds a new lot with the given area to this map's lots
public Lot AddLot(Rectangle area)
Parameters
areaRectangleThe area that the new lot should have
Returns
- Lot
The newly created lot
AddLot(Lot)
Adds the given lot to this map's lots.
public void AddLot(Lot lot)
Parameters
lotLotThe lot to add.
AddObject(MapObject)
Adds the given object to this map. Note that, if the object's Id is already present on this map, this method will cause an exception.
public MapObject AddObject(MapObject obj)
Parameters
objMapObjectThe object to add to this map
Returns
AddRoad(Point)
Adds a road to the map at the given position. This doesn't actually add the road tiles, but it notifies the pathfinder that there is a road center at this location.
public void AddRoad(Point pos)
Parameters
posPointThe position to add a road to
AddRoof(Roof)
Adds the given roof to this map
public void AddRoof(Roof roof)
Parameters
roofRoofThe roof to add
AddStairs(Stairs)
Adds the given stairs to this map, additionally marking all involved locations dirty for pathfinding.
public void AddStairs(Stairs stairs)
Parameters
stairsStairsThe stairs to add.
AddWall(WallLike)
Adds the given wall to the given position. Optionally, the Room related to that wall is re-calculated.
public bool AddWall(WallLike wall)
Parameters
wallWallLikeThe wall to add
Returns
- bool
Whether the wall could be added successfully
ApplyCameraRotation(Vector2, bool, Direction2?)
Applies the game's current CameraRotation to the given position in world space
public Vector2 ApplyCameraRotation(Vector2 worldPos, bool borderOffset = false, Direction2? cameraRotation = null)
Parameters
worldPosVector2The position, in world space
borderOffsetboolWhether a border offset should be applied. This is useful for tiles and other objects that aren't centered in the middle of their tiles, but that use the top-left corner of a tile for positioning.
cameraRotationDirection2?An optional override camera rotation which should be used in favor of CameraRotation
Returns
- Vector2
The position in world space, but with camera rotation appplied
ApplyInverseCameraRotation(Vector2, Direction2?)
Applies the game's current CameraRotation to the given position in world space in reverse, undoing the action done by ApplyCameraRotation(Vector2, bool, Direction2?)
public Vector2 ApplyInverseCameraRotation(Vector2 worldPos, Direction2? cameraRotation = null)
Parameters
worldPosVector2The position, in world space
cameraRotationDirection2?An optional override camera rotation which should be used in favor of CameraRotation
Returns
- Vector2
The position in world space, but without camera rotation appplied
CanWalkBetween(PersonLike, Point, int, Point, int)
Returns whether the given person can walk between the two given positions.
Internally, this method only queries whether GetPathCost(MapObject, Point, int, Point, int) is lower than MaxValue or PositiveInfinity.
Note that, for this method to return a proper result, nextPos has to be directly or diagonally adjacent to currPos.
public bool CanWalkBetween(PersonLike person, Point currPos, int currFloor, Point nextPos, int nextFloor)
Parameters
personPersonLikeThe person to get the path cost for
currPosPointThe current position
currFloorintThe current position's floor.
nextPosPointThe next, neighboring position
nextFloorintThe next position's floor.
Returns
- bool
Whether the two locations can be walked between
ClampSectionPos(Point)
public Point ClampSectionPos(Point pos)
Parameters
posPoint
Returns
- Point
CollectPossiblePathNeighbors((Point Pos, int Floor), ISet<(Point Pos, int Floor)>)
Collects all possible next positions that can be walked to from the given position to the given set of neighbor positions. The set is not cleared beforehand, and only modified if there is a valid pathfinding node (GetPathfindingNode(Point, int, Func<Map, Point, int, bool>)) at the given position.
public void CollectPossiblePathNeighbors((Point Pos, int Floor) position, ISet<(Point Pos, int Floor)> neighbors)
Parameters
position(Point Pos, int Floor)The position, and floor, in world space.
neighborsISet<(Point Pos, int Floor)>The set of neighbors to collect possible path neighbors into.
Draw(GameTime, SpriteBatch, bool, RectangleF?, Matrix?, RenderTarget2D, bool)
Draws this map and all of its objects. Note that drawing in this manner uses multiple Microsoft.Xna.Framework.Graphics.RenderTarget2D objects, for things like the ground and the lightmaps.
public void Draw(GameTime time, SpriteBatch batch, bool selectionMode, RectangleF? visibleArea = null, Matrix? visibleMatrix = null, RenderTarget2D lightmap = null, bool ignoreObjectVisibility = false)
Parameters
timeGameTimeThe game's time
batchSpriteBatchThe sprite batch to use for drawing
selectionModeboolWhether we're drawing in selection mode ("ShowSelectionEffect" cheat displays this mode)
visibleAreaRectangleF?The area that is visible, in world space. If this is null, MLEM.Cameras.Camera.GetVisibleRectangle() is used to calculate the visible area.
visibleMatrixMatrix?A matrix that has a translation and scale that determines the visible area of the screenshot
lightmapRenderTarget2DThe light map to draw lighting data onto, or null to use the default light map
ignoreObjectVisibilityboolWhether object visibility should be ignored
GetAllLotEmployments()
Returns a set of all LotEmployment instances and their Lot on the map. Note that MapWideEmployments are also returned, with their Lot component being set to null.
public IEnumerable<(LotEmployment Employment, Lot EmploymentLot)> GetAllLotEmployments()
Returns
- IEnumerable<(LotEmployment Employment, Lot EmploymentLot)>
All lot employments on this map
GetAllPeople()
Returns all of the PersonLike objects that are on this map, including dead people stored in gravestones.
public IEnumerable<PersonLike> GetAllPeople()
Returns
- IEnumerable<PersonLike>
All people on this map.
GetClosestEmptyTile(Vector2, float, int, bool, bool, bool, bool, Predicate<Point>)
Returns the position of the closest tile that is empty. An empty tile is a tile that has no MapObject instances on it.
public Point? GetClosestEmptyTile(Vector2 pos, float floor, int radius = 2, bool ignorePeople = true, bool hasToBeOnLot = false, bool sameRoom = false, bool hasToBeNonnull = true, Predicate<Point> valid = null)
Parameters
posVector2The position to be close to
floorfloatThe floor to query tiles on.
radiusintThe radius to search for empty tiles in
ignorePeopleboolWhether or not people should be ignored. If this is true, the returned empty tile might currently be occupied by a PersonLike.
hasToBeOnLotboolWhether or not the returned tile position has to be part of a Lot
sameRoomboolWhether or not the returned tile position has to be in the same room as
poshasToBeNonnullboolWhether the tile has to be nonnull, ie air tiles on higher levels should not be included.
validPredicate<Point>A predicate that can optionally be used to check whether the returned tile matches additional conditions.
Returns
- Point?
The closest empty tile, or null if there isn't one
GetClosestFreeExitPoint(Vector2, OutOfTownIntention)
Returns the closest exit point on the map to the given position, out of all of the points returned by GetExitPoints().
Note that an OutOfTownDoor with the matching intention will always be preferred over an exit point on the map border. If there is no matching door, an exit point on the map border will always be returned, regardless of the passed intention.
public Point GetClosestFreeExitPoint(Vector2 position, OutOfTownIntention intention)
Parameters
positionVector2The position that the exit point should be close to.
intentionOutOfTownIntention
Returns
- Point
The closest exit point to the given position.
GetClosestRoads(Point, int)
Returns all road markers around the given pos in the given radius, ordered by their distance to the pos.
public IEnumerable<Point> GetClosestRoads(Point pos, int radius)
Parameters
posPointThe position to find the closest roads to
radiusintThe radius, in tiles, to search for roads in
Returns
- IEnumerable<Point>
The closest road points
GetClosestRoadsidePosition(Point, Vector2)
Returns the closest roadside position to the given road position, as well as the given pos.
public Point? GetClosestRoadsidePosition(Point road, Vector2 pos)
Parameters
roadPointThe road position.
posVector2The (non-road) position that the returned roadside position should be closest to.
Returns
- Point?
The closest roadside position, or null if there is none around.
GetDepth(Vector2, float, float, bool, bool, bool)
Gets the depth that should be used for drawing an object at the given position
public float GetDepth(Vector2 worldPos, float floor, float offset = 0, bool center = true, bool borderOffset = false, bool applyCameraRotation = true)
Parameters
worldPosVector2The position to get depth for, in tile coordinates
floorfloatThe floor to get depth for.
offsetfloatAn offset added to the depth value
centerboolWhether the position should be centered on the x axis
borderOffsetboolWhether the map border offset should be applied to the camera rotation using ApplyCameraRotation(Vector2, bool, Direction2?). This value only has an effect if
applyCameraRotationis trueapplyCameraRotationboolWhether the game's current CameraRotation should be applied using ApplyCameraRotation(Vector2, bool, Direction2?)
Returns
- float
The depth to pass to the draw call
GetExitPoints()
Returns a set of all exit points on the map, which are locations on the map's border that Tinies can exit from either on foot or using their car, as well as any OutOfTownDoor doors on the map.
public IEnumerable<(Point Position, OutOfTownIntention Intention)> GetExitPoints()
Returns
- IEnumerable<(Point Position, OutOfTownIntention Intention)>
All exit points on this map.
GetHousehold(PersonLike)
Returns the household that the given PersonLike lives in
public Household GetHousehold(PersonLike person)
Parameters
personPersonLikeThe person to query
Returns
- Household
The person's household, or null if there is none
GetHousehold(Lot)
Returns the household that lives on the given Lot
public Household GetHousehold(Lot lot)
Parameters
lotLotThe lot to query
Returns
- Household
The household that lives on the lot, or null if none lives there
GetHouseholds()
Returns a set of all of the Household instances that live on this map
public IEnumerable<Household> GetHouseholds()
Returns
- IEnumerable<Household>
This map's households
GetLot(Point)
Returns the lot that is present at the given position. The lot returned will always have its Area contain the passed position.
public Lot GetLot(Point pos)
Parameters
posPointThe position to query
Returns
- Lot
The lot at that position, or null if there is none
GetLot(Guid)
Returns the lot with the given id on this map. The returned lot's Id will equal the given id.
public Lot GetLot(Guid id)
Parameters
idGuidThe id that the lot should have
Returns
- Lot
The lot with the given id
GetLots()
Returns a set of all of the Lot objects on this map
public IEnumerable<Lot> GetLots()
Returns
- IEnumerable<Lot>
This map's lots
GetMapSampler()
Returns the Microsoft.Xna.Framework.Graphics.SamplerState to use when rendering the map. This value is determined by BlurZoomedOut, as well as the Camera's scale.
public static SamplerState GetMapSampler()
Returns
- SamplerState
The sampler state to use when rendering the map.
GetObject<T>(Guid)
Returns the object with the given id of the given type. If there is no object with that id, or its type does not match, null is returned.
public T GetObject<T>(Guid id) where T : MapObject
Parameters
idGuidThe id that the returned object should have
Returns
- T
The object, or null if there is no matching one
Type Parameters
TThe type that the object is expected to have
GetObjects<T>(RectangleF)
Returns a set of objects that are present in the given area.
public IEnumerable<T> GetObjects<T>(RectangleF area)
Parameters
areaRectangleFThe area, in tile coordinates
Returns
- IEnumerable<T>
A set of objects that match the criteria
Type Parameters
TThe type that the objects need to have
GetPathCost(MapObject, Point, int, Point, int)
Returns the cost to pathfind from the given current position to the given next position.
Note that, for this method to return a proper result, nextPos has to be directly or diagonally adjacent to currPos.
public float GetPathCost(MapObject obj, Point currPos, int currFloor, Point nextPos, int nextFloor)
Parameters
objMapObjectThe person to get the path cost for
currPosPointThe current position
currFloorintThe current position's floor.
nextPosPointThe next, neighboring position
nextFloorintThe next position's floor.
Returns
- float
The cost to path to this location
GetPeople()
Returns all of the PersonLike objects that are on this map, excluding dead people stored in gravestones.
public IEnumerable<PersonLike> GetPeople()
Returns
- IEnumerable<PersonLike>
This map's people
GetRandomTile(Random, Vector2, int, int, bool, bool, bool, Predicate<Point>)
Returns a random tile in the given radius that matches the given predicate. If no tile is found, an empty Nullable<T> is returned.
public Point? GetRandomTile(Random random, Vector2 pos, int floor, int radius = 32, bool hasToBeOnLot = false, bool sameRoom = false, bool hasToBeNonnull = true, Predicate<Point> valid = null)
Parameters
randomRandomThe random to use
posVector2The position that the radius should be centered on
floorintThe floor to query.
radiusintThe radius
hasToBeOnLotboolWhether the position returned has to be on a lot
sameRoomboolWhether the position returned has to be in the same room as the
pospassedhasToBeNonnullboolWhether the tile has to be nonnull, ie air tiles on higher levels should not be included.
validPredicate<Point>A predicate that determines whether tile should be included
Returns
- Point?
A random tile that matches the given conditions
GetRegularVisitors()
Returns the set of PersonLike instances in the world that are regular visitors. This method is a shorthand for GetPeople() and IsRegularVisitor. Note that dead regular visitors are not returned.
public IEnumerable<PersonLike> GetRegularVisitors()
Returns
- IEnumerable<PersonLike>
This map's regular visitors
GetRoads()
Returns a set of all of the road markers on this map
public IEnumerable<Point> GetRoads()
Returns
- IEnumerable<Point>
A set of all road markers on this map
GetRoof(Point, int)
Gets a Roof whose area contains the given position
public Roof GetRoof(Point pos, int floor)
Parameters
posPointThe position to find a roof at
floorintThe floor to find a roof at.
Returns
- Roof
The roof at that position, or null if there is none
GetRoofs(RectangleF)
Returns the roofs that intersect the given area.
Note that this method performs rather badly on a large scale, and its usage should be avoided if GetRoof(Point, int) is more convenient.
public IEnumerable<Roof> GetRoofs(RectangleF area)
Parameters
areaRectangleFThe area to search for roofs in.
Returns
- IEnumerable<Roof>
The roofs in the given area.
GetRoom(Point, int)
Returns the room that the given pos is contained in.
If the position is out of bounds (IsInBounds(Point)), null is returned.
public Room GetRoom(Point pos, int floor)
Parameters
posPointThe position to query
floorintThe floor to query.
Returns
- Room
The room at that location, or null if there is none
GetRooms(RectangleF)
Returns all rooms that are contained in, or intersect with, the given area.
Note that this method performs rather badly on a large scale, and its usage should be avoided if GetRoom(Point, int) is more convenient.
public IEnumerable<Room> GetRooms(RectangleF area)
Parameters
areaRectangleFThe area to search for rooms in.
Returns
- IEnumerable<Room>
The rooms in the area.
GetSection(Point, bool)
Returns the MapSection at the given tile position
public MapSection GetSection(Point pos, bool clamp = false)
Parameters
posPointThe tile position
clampboolWhether the
posshould be clamped into the valid Size of the map.
Returns
- MapSection
The section at that position
GetSectionPos(Point)
public static Point GetSectionPos(Point pos)
Parameters
posPoint
Returns
- Point
GetSections(RectangleF, int)
Returns a set of sections that are contained in (or intersect with) the given area
public IEnumerable<MapSection> GetSections(RectangleF area, int radiusIncrease = 0)
Parameters
areaRectangleFThe area to find sections in, in tile coordinates
radiusIncreaseintThe radius, in sections, that the search area should be extended by
Returns
- IEnumerable<MapSection>
A set of sections covered by this area
GetSections(Point, int)
Returns a set of sections that are contained in (or intersect with) the given area
public IEnumerable<MapSection> GetSections(Point point, int radiusIncrease = 0)
Parameters
pointPointThe position to find the section for, in tile coordinates
radiusIncreaseintThe radius, in sections, that the search area should be extended by
Returns
- IEnumerable<MapSection>
A set of sections covered by this area
GetStairs(RectangleF, bool)
Returns all of the stairs in the given area, including stairs that partly intersect, on all floors.
public IEnumerable<Stairs> GetStairs(RectangleF area, bool includeEntryPositions = false)
Parameters
areaRectangleFThe area.
includeEntryPositionsboolWhether the entry positions of the stairs should be included, rather than just the Area.
Returns
- IEnumerable<Stairs>
The stairs in the area.
GetStaticMaps()
Returns information about all static maps that are currently loadable by the game, including default maps, modded maps, and custom maps. This method also invokes the OnGetStaticMaps event, which allows mods to add their own static maps to the list. To load a static map, use LoadStaticMap(MapInfo) or AddMapToSave(MapInfo, Action).
public static IEnumerable<(string Path, string Description, Texture2D Icon, bool Custom, bool Hidden)> GetStaticMaps()
Returns
- IEnumerable<(string Path, string Description, Texture2D Icon, bool Custom, bool Hidden)>
Information about all static maps that can be loaded by the game.
GetStoredDeadPeople()
Returns a set of all of the dead people that are stored in IContainerObject<T> furniture that stores PersonLike objects (like Gravestone objects), both on this map and in the household storages of any of this map's households.
public IEnumerable<(IContainerObject<PersonLike> Gravestone, PersonLike Person)> GetStoredDeadPeople()
Returns
- IEnumerable<(IContainerObject<PersonLike> Gravestone, PersonLike Person)>
The stored dead people on this map.
GetTile(Point, int)
Returns the tile at the given position on this map. Note that, if the floor is not the ground floor 0, this method can return null.
public Tile GetTile(Point pos, int floor)
Parameters
posPointThe position to query
floorintThe floor.
Returns
- Tile
The tile at that position
GetTileInstance(Point, int)
Returns the tile instance at the given position on this map. Note that, if the floor is not the ground floor 0, this method can return null.
public TileInstance GetTileInstance(Point pos, int floor)
Parameters
posPointThe position to query
floorintThe floor.
Returns
- TileInstance
The tile instance at that position
GetTilesAround(Vector2, float, int, bool, bool, bool, Predicate<Point>)
Returns a set of tiles around the given position that match the given conditions
public IEnumerable<Point> GetTilesAround(Vector2 pos, float floor, int radius, bool hasToBeOnLot = false, bool sameRoom = false, bool hasToBeNonnull = true, Predicate<Point> valid = null)
Parameters
posVector2The position
floorfloatThe floor to query.
radiusintThe radius, in tiles
hasToBeOnLotboolWhether the returned positions have to be on a lot
sameRoomboolWhether the returned positions have to be in the same room as the
pospassedhasToBeNonnullboolWhether the tile has to be nonnull, ie air tiles on higher levels should not be included.
validPredicate<Point>A function that determines whether a position should be returned. If this is null, all valid positions are returned.
Returns
- IEnumerable<Point>
A set of positions that match the given conditions
GetVisibleWorldArea(RectangleF)
Returns a rectangle, in world space, that encompasses all tile positions on a Map that are currently visible, based on the passed cameraArea, which is expected to be the value of a camera's MLEM.Cameras.Camera.GetVisibleRectangle().
Note that, due to the fact that maps are in isometric perspective, the returned rectangle contains additional tile positions in each corner of the cameraArea that aren't actually visible.
public static RectangleF GetVisibleWorldArea(RectangleF cameraArea)
Parameters
cameraAreaRectangleFThe camera area, in camera space.
Returns
- RectangleF
The visible area, in world space.
GetVisitPriority(PersonLike)
Returns the visitation priority for this map for the given PersonLike.
The returned value is based on whether the person is on the same map, and the results of the OnGetVisitPriority event.
public float GetVisitPriority(PersonLike person)
Parameters
personPersonLikeThe person visiting a lot on this map.
Returns
- float
The priority, as a weight.
GetWallBetween<T>(Point, Point, int)
Returns the wall between the pos and secondPos.
A wall is between two positions if its Positions are exactly those two positions, ignoring their order.
public T GetWallBetween<T>(Point pos, Point secondPos, int floor) where T : WallLike
Parameters
posPointThe first position
secondPosPointThe second position
floorintThe floor.
Returns
- T
The wall between the two positions, or null if there is none
Type Parameters
T
GetWalls<T>(RectangleF)
Returns a set of walls in the given area. All WallLike objects for which at least one Positions entry is contained in the area are returned.
public IEnumerable<T> GetWalls<T>(RectangleF area) where T : WallLike
Parameters
areaRectangleFThe area to query for walls
Returns
- IEnumerable<T>
A set of walls in the area
Type Parameters
T
IsFreeSpot(Point, int)
Returns whether or not the given position on the given map is free for a PersonLike to stand in
public bool IsFreeSpot(Point pos, int floor)
Parameters
posPointThe position to query
floorintThe floor to query.
Returns
- bool
Whether this position is free to stand on
IsInBounds(Point)
Returns whether the given position is in bounds of this map's Size
public bool IsInBounds(Point pos)
Parameters
posPointThe position to query
Returns
- bool
true if the position is in bounds, false otherwise
IsLotHidden(Lot)
Whether the given lot is hidden from the camera.
Note that the result of this method will be different from IsLotVisible(Lot), since this method also checks for the ShowAllLots cheat.
For ease of use, this method returns true if lot is null, in which case walls and roofs generally stay up for buildings that act as "set dressing".
If TinyLife.Debug.ShowAllLots is true, this method always returns false.
public static bool IsLotHidden(Lot lot)
Parameters
lotLot
Returns
IsRoad(Point)
Returns whether the given position contains a road. This doesn't query road tiles, but it queries for road markers added by AddRoad(Point).
public bool IsRoad(Point pos)
Parameters
posPoint
Returns
LoadStaticMap(MapInfo)
Loads a static map with the given name from the game's content directory. Note that no validation steps (ValidateEarly(MapInfo, Dictionary<string, Map>, Action<string>, Action<float>), Validate(bool, Action<string>, Action<float>), PostValidate(Action<string>, Action<float>)) have taken place when the map is returned.
public static Map LoadStaticMap(MapInfo info)
Parameters
Returns
- Map
The static map that was loaded.
MarkDirtyForPathfinding(Point, int)
Marks the given position dirty for pathfinding purposes. When a path is found again close to this position, its cost (GetPathCost(MapObject, Point, int, Point, int)) will be re-calculated. This method is called by Furniture when it is placed for removed.
public void MarkDirtyForPathfinding(Point pos, int floor)
Parameters
posPointThe position to mark dirty
floorintThe floor that the position is on.
MarkGroundTileDirtyForDrawing(Point, Point?)
Marks the given position dirty for drawing, which causes the underlying MLEM.Graphics.StaticSpriteBatch to re-render the tile. This method is used automatically by SetTile(Point, int, Tile) and AutoTile.
public void MarkGroundTileDirtyForDrawing(Point pos, Point? sectionPos = null)
Parameters
posPointThe position to mark dirty.
sectionPosPoint?The section position that
posis expected to be in, or null to determine the section position automatically.
MarkObjectDirtyForDrawing(MapObject, MapSection, bool)
Marks the given MapObject dirty for drawing, which causes the underlying MLEM.Graphics.StaticSpriteBatch to re-render the object if its visibility is Static. This method is used automatically by AddObject(MapObject) and RemoveObject(MapObject), as well as when a static object's Position changes.
public void MarkObjectDirtyForDrawing(MapObject obj, MapSection section = null, bool removedFromSection = false)
Parameters
objMapObjectThe object to mark dirty.
sectionMapSectionThe section that the object is expected to be in, or null to determine the section automatically.
removedFromSectionboolWhether the object was removed, and should not be redrawn in the
section.
MoveEverything(Point, Rectangle, bool, Tile)
Moves all of the objects, walls, tiles and roofs in the given area in the world, optionally moving the lots as well
public void MoveEverything(Point offset, Rectangle area, bool moveLots, Tile defaultTile = null)
Parameters
offsetPointThe offset to move things by
areaRectangleThe area to move
moveLotsboolWhether lots should be moved as well. The content of lots will be moved regardless of this parameter
defaultTileTileThe default tile to replace the moved ground with.
OnCameraRotationChanged(Direction2, Direction2)
A method that is called when CameraRotation is changed. When changing camera rotation manually, this method should be called along with the change.
public void OnCameraRotationChanged(Direction2 oldRotation, Direction2 newRotation)
Parameters
oldRotationDirection2newRotationDirection2
OnCurrentGameMapChanged(Map, Map)
This method is invoked when the game's CurrentMap is changed, ie when the camera is moved to a different map.
public void OnCurrentGameMapChanged(Map oldMap, Map newMap)
Parameters
PlaySound(SoundEffect, Vector2, float, float, float, bool, bool)
Plays a sound at the given location (in world space) statically. If the sound should move while being played, use PlaySound(SoundEffect, MapAudioEmitter, float, float, bool, bool) instead. Note that the returned Microsoft.Xna.Framework.Audio.SoundEffectInstance does not need to be disposed when it is finished playing.
public SoundEffectInstance PlaySound(SoundEffect sound, Vector2 pos, float floor, float volume = 1, float pitch = 0, bool loop = false, bool applyWorldSoundVolume = true)
Parameters
soundSoundEffectThe sound effect to play
posVector2The position, in world space, to play the sound at
floorfloatThe floor to play the sound based on.
volumefloatThe sound's volume, between 0 and 1 (default)
pitchfloatThe sound's pitch, between -1, 0 (default) and 1
loopboolWhether or not the sound should loop
applyWorldSoundVolumeboolWhether the WorldSoundVolume should be applied to the passed
volume
Returns
- SoundEffectInstance
The sound effect instance that is responsible for playing this sound, which can be stopped or paused
PlaySound(SoundEffect, MapAudioEmitter, float, float, bool, bool)
Plays a sound at the given location (in world space) with the given MapAudioEmitter, whose WorldPosition can be updated by the caller. If the sound should move in a static location, use PlaySound(SoundEffect, Vector2, float, float, float, bool, bool) instead. Note that the returned Microsoft.Xna.Framework.Audio.SoundEffectInstance does not need to be disposed when it is finished playing.
public SoundEffectInstance PlaySound(SoundEffect sound, MapAudioEmitter emitter, float volume = 1, float pitch = 0, bool loop = false, bool applyWorldSoundVolume = true)
Parameters
soundSoundEffectThe sound effect to play
emitterMapAudioEmitterThe audio emitter, whose WorldPosition should be set by the caller
volumefloatThe sound's volume, between 0 and 1 (default)
pitchfloatThe sound's pitch, between -1, 0 (default) and 1
loopboolWhether or not the sound should loop
applyWorldSoundVolumeboolWhether the WorldSoundVolume should be applied to the passed
volume
Returns
- SoundEffectInstance
The sound effect instance that is responsible for playing this sound, which can be stopped or paused
PlaySound(DefaultSound, Vector2, float, float, float, bool, bool)
Plays a sound at the given location (in world space) statically. If the sound should move while being played, use PlaySound(SoundEffect, MapAudioEmitter, float, float, bool, bool) instead. Note that the returned Microsoft.Xna.Framework.Audio.SoundEffectInstance does not need to be disposed when it is finished playing.
public SoundEffectInstance PlaySound(DefaultSound sound, Vector2 pos, float floor, float volume = 1, float pitch = 0, bool loop = false, bool applyWorldSoundVolume = true)
Parameters
soundDefaultSoundThe default sound to play
posVector2The position, in world space, to play the sound at
floorfloatThe floor to play the sound based on.
volumefloatThe sound's volume, between 0 and 1 (default)
pitchfloatThe sound's pitch, between -1, 0 (default) and 1
loopboolWhether or not the sound should loop
applyWorldSoundVolumeboolWhether the WorldSoundVolume should be applied to the passed
volume
Returns
- SoundEffectInstance
The sound effect instance that is responsible for playing this sound, which can be stopped or paused
PlaySound(DefaultSound, MapAudioEmitter, float, float, bool, bool)
Plays a sound at the given location (in world space) with the given MapAudioEmitter, whose WorldPosition can be updated by the caller. If the sound should move in a static location, use PlaySound(SoundEffect, Vector2, float, float, float, bool, bool) instead. Note that the returned Microsoft.Xna.Framework.Audio.SoundEffectInstance does not need to be disposed when it is finished playing.
public SoundEffectInstance PlaySound(DefaultSound sound, MapAudioEmitter emitter, float volume = 1, float pitch = 0, bool loop = false, bool applyWorldSoundVolume = true)
Parameters
soundDefaultSoundThe default sound to play
emitterMapAudioEmitterThe audio emitter, whose WorldPosition should be set by the caller
volumefloatThe sound's volume, between 0 and 1 (default)
pitchfloatThe sound's pitch, between -1, 0 (default) and 1
loopboolWhether or not the sound should loop
applyWorldSoundVolumeboolWhether the WorldSoundVolume should be applied to the passed
volume
Returns
- SoundEffectInstance
The sound effect instance that is responsible for playing this sound, which can be stopped or paused
PopulateLots()
Populates a subset of empty residential lots on this map with loaded exported households, or with randomly generated households. This method is automatically invoked every few in-game days if the PopulateLots option is enabled.
public void PopulateLots()
PostValidate(Action<string>, Action<float>)
This method is called when this object is loaded from disk, after Validate(bool, Action<string>, Action<float>) has already been called. When called on a map, post-load preloads like pathfinding pre-generation occurs.
public void PostValidate(Action<string> setState, Action<float> setProgress)
Parameters
setStateAction<string>An action that accepts the current state of the loading process.
setProgressAction<float>An action that accepts the progress of the current state of the loading process.
PrepareForPermanentRemoval()
Prepares this map for permanent removal, moving all people on this map to their original positions (including their home location if it is on another map and their lot employment map if they have one), and calls PrepareForPermanentRemoval() on all remaining people.
public void PrepareForPermanentRemoval()
RemoveHousehold(Household)
Removes the given household from this map
public void RemoveHousehold(Household household)
Parameters
householdHouseholdThe household to remove
RemoveLight(Light)
Removes the given light from the world
public bool RemoveLight(Light light)
Parameters
lightLightThe light to remove
Returns
RemoveLot(Lot)
Removes the given lot from this map's lots
public void RemoveLot(Lot lot)
Parameters
lotLotThe lot to remove
RemoveObject(MapObject)
Removes the given object from this map and its underlying MapSection. This also calls OnRemoved().
public void RemoveObject(MapObject obj)
Parameters
objMapObjectThe object to remove
Remarks
When removing a Furniture object from the world entirely, including when putting it into furniture storage, RemoveAndUnlink() should be used instead, or UnlinkParentsAndChildren() should be called in addition to this method. As all of those methods also sever the relationships between furniture items and their parents (which is equivalent to calling UnlinkParentsAndChildren()), they are usually preferred over this method, since parent-child relationships should not persist in many cases.
RemoveRoof(Roof)
Removes the given Roof from this map
public void RemoveRoof(Roof roof)
Parameters
roofRoofThe roof to remove
RemoveStairs(Stairs)
Removes the given stairs from this map entirely, additionally marking all involved locations dirty for pathfinding.
public bool RemoveStairs(Stairs stairs)
Parameters
stairsStairsThe stairs to remove.
Returns
- bool
Whether the stairs existed on the map, and were successfully removed.
RemoveWall(WallLike)
Removes the given wall from the map
public bool RemoveWall(WallLike wall)
Parameters
wallWallLikeThe wall to remove
Returns
- bool
Whether the wall was present on the map and could be removed
SetTile(Point, int, Tile)
Sets the tile at the given position to the given tile
public TileInstance SetTile(Point pos, int floor, Tile tile)
Parameters
Returns
SummonSpecialVisitor(Guid, Lot)
Summons a special visitor with the given personId to this map, and optionally to the given lotToVisit. If a special visitor with the given id does not already exist, they are imported from the exported households if found.
public PersonLike SummonSpecialVisitor(Guid personId, Lot lotToVisit = null)
Parameters
personIdGuidThe Id of the person to summon. This id should match the person's Id or one of the entries in their TinyLife.Objects.PersonLike.IdHistory.
lotToVisitLotThe lot that the summoned person should visit, or null to make them visit a random lot.
Returns
- PersonLike
The summoned person, or null if no person with the given id exists on this map or any of its Neighborhood maps, and no person with the given id exists in the set of exported households.
Update(GameTime, TimeSpan, float)
Updates this map, its MapSection objects and its Households.
public void Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)
Parameters
timeGameTimeThe game's time
passedInGameTimeSpanThe amount of time that has passed in game
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
UpdateExternalPeople(ICollection<Map>, Action<string>, Action<float>)
Updates the given maps' regular visitors based on the MaxRegularVisitors value, assigns random people to empty LotEmployment slots, and clears duplicate households that have not been played (HasBeenPlayed).
This method is called automatically in various locations.
public static void UpdateExternalPeople(ICollection<Map> maps, Action<string> setState = null, Action<float> setProgress = null)
Parameters
Validate(bool, Action<string>, Action<float>)
This method is called when this object is loaded from disk, between ValidateEarly(MapInfo, Dictionary<string, Map>, Action<string>, Action<float>) and PostValidate(Action<string>, Action<float>). When called on a map, it causes all objects to be validated, roads to be generated, outdated information to be removed, and more.
public void Validate(bool localize, Action<string> setState, Action<float> setProgress)
Parameters
localizeboolWhether this map's data should be localized upon validation, which is only used for builtin maps and not custom ones.
setStateAction<string>An action that accepts the current state of the loading process.
setProgressAction<float>An action that accepts the progress of the current state of the loading process.
ValidateEarly(MapInfo, Dictionary<string, Map>, Action<string>, Action<float>)
This method is called when this object is loaded from disk, before Validate(bool, Action<string>, Action<float>) is called. When called on a map, early section and object validation occurs.
public void ValidateEarly(MapInfo info, Dictionary<string, Map> neighborhood, Action<string> setState, Action<float> setProgress)
Parameters
infoMapInfoThe MapInfo to assign to this map.
neighborhoodDictionary<string, Map>The Neighborhood to assign to this map.
setStateAction<string>An action that accepts the current state of the loading process.
setProgressAction<float>An action that accepts the progress of the current state of the loading process.
ValidateRooms(Point, int)
Adds new Room objects to the given positions if there are valid rooms present, and validates additional rooms, checking for whether they should still exist.
public Room ValidateRooms(Point position, int floor)
Parameters
positionPointThe position that should be inspected for possible rooms.
floorintThe floor that should be inspected for possible rooms.
Returns
Events
OnDraw
An event that is invoked during various phases of this map being drawn. The Phase field determines which phase this event is invoked in for each invocation. This event can be subscribed to using OnEventsAttachable.
public event Action<Map.DrawEventArgs> OnDraw
Event Type
OnEventsAttachable
An event that is invoked when non-static events for a Map are ready to be attached to. This event is invoked in PostValidate(Action<string>, Action<float>).
public static event Action<Map> OnEventsAttachable
Event Type
OnGetStaticMaps
An event that is invoked in OnGetStaticMaps, which mods can use to add custom static maps to the game. If this event is subscribed to and one or more custom maps are added to the list, the OnLoadStaticMap event should also be subscribed to to handle actually loading these maps.
public static event Action<List<(string Path, string Description, Texture2D Icon, bool Hidden)>> OnGetStaticMaps
Event Type
OnGetVisitPriority
An event that is invoked when the visitation priority for this map for a PersonLike is evaluated in GetVisitPriority(PersonLike). The visitation priority for any given person can be modified using this event. This event can be subscribed to using OnEventsAttachable.
public event Map.VisitPriorityDelegate OnGetVisitPriority
Event Type
OnLoadStaticMap
An event that is invoked in LoadStaticMap(MapInfo), which mods can use to load custom static maps into the game. If this event is subscribed to, OnGetStaticMaps should also be subscribed to to return the information about the custom maps that are loadable by mods.
public static event Map.LoadStaticMapDelegate OnLoadStaticMap
Event Type
OnObjectAdded
An event that is invoked when a MapObject is added to this map using AddObject(MapObject) This event can be subscribed to using OnEventsAttachable.
public event Action<MapObject> OnObjectAdded
Event Type
OnObjectRemoved
An event that is invoked when a MapObject is removed from this map using RemoveObject(MapObject) This event can be subscribed to using OnEventsAttachable.
public event Action<MapObject> OnObjectRemoved
Event Type
OnPathfindingNodeConstruct
An event that is invoked when a new pathfinding node is constructed after a position was marked as dirty using MarkDirtyForPathfinding(Point, int). This event can be used to make pathfinding for a given position cheaper or more expensive based on mod factors. This event can be subscribed to using OnEventsAttachable.
public event Map.PathfindingNodeConstructDelegate OnPathfindingNodeConstruct
Event Type
OnPrepareForPermanentRemoval
public event Action<EventPhase> OnPrepareForPermanentRemoval
Event Type
OnUpdate
An event that is invoked when this map is updated in Update(GameTime, TimeSpan, float). This event can be subscribed to using OnEventsAttachable.
public event Map.UpdateDelegate OnUpdate
Event Type
OnUpdateExternalPeople
An event that is invoked in UpdateExternalPeople(ICollection<Map>, Action<string>, Action<float>), which can optionally be used to add or remove modded external people.
public static event Map.UpdateExternalPeopleDelegate OnUpdateExternalPeople
Event Type
OnUpdateObjects
public event Map.UpdateObjectsDelegate OnUpdateObjects