Module CorsixTH.CorsixTH.Lua.world
Manages entities, rooms, and the date.
Functions
| World:_createMapObject (object) | Internal function for placing an object from the map file. |
| World:addObjectToTile (object, x, y) | Notify the world of a new object being placed somewhere in the world See also `World:removeObjectFromTile` |
| World:afterLoad (old, new) | Let the world react to and old save game. |
| World:calculateSpawnTiles () | Identify the tiles on the map suitable for spawning `Humanoid`s from. |
| World:checkWinningConditions (player_no) | Checks if all goals have been achieved or if the player has lost. |
| World:clearCaches () | Clear all internal caches which are dependent upon map state / object position |
| World:computeNextEmergencyDates (emergency) | Generate the dates for the next emergency |
| World:createMapObjects (objects) | Place objects from a map file onto the map. |
| World:date () | Get todays date. |
| World:debugDisableSalaryRaise (mode) | Enable or disable salary raise events. |
| World:determineWinningConditions () | Load goals to win and lose from the map, and store them in 'self.goals'. |
| World:dumpGameLog () | Dump the contents of the game log into a file. |
| World:gameLog (message) | Append a message to the game log. |
| World:getAvailableRooms () | Find the rooms available at the level. |
| World:getCampaignData () | Collect the settings that should be reused in the next world |
| World:getCampaignWinningText (player_no) | Finds what text the winning fax should contain, and which choices the player has. |
| World:getCurrentSpeed () | Return the name of the current speed, relating to a key in tick_rates. |
| World:getHospital (x, y) | Get the hospital at a given tile location. |
| World:getLocalPlayerHospital () | Get the hospital controlled by the (single) player. |
| World:getObject (x, y, id) | Retrieve one object from a given position. |
| World:getObjects (x, y) | Retrieve all objects from a given position. |
| World:getReputationImpact (hospital) | Computes the impact of hospital reputation on the spawn rate. |
| World:getRoom (x, y) | Get the room at a given tile location. |
| World:getRoomNameAndRequiredStaffName (room_id) | Returns localized name of the room, internal required staff name and localized name of staff required. |
| World:initLevel (app, avail_rooms) | Initialize the game level (available diseases, winning conditions). |
| World:isCurrentSpeed (speed) | Return true if the given speed the same as the current speed. |
| World:isFootprintTileBuildableOrPassable (x, y, tile, footprint, requirement_flag, player_id) | A footprint tile will either need to be buildable or passable so this function checks if its buildable/passable using the tile's appropriate flag and then returns this flag's boolean value or false if the tile isn't valid. |
| World:isOnMap (x, y) | Test whether the given coordinate is on the map. |
| World:isSystemPauseActive () | Reports the system pause status |
| World:isTilePartOfNearbyObject (x, y, distance) | Checks whether the given tile is part of a nearby object (walkable tiles count as part of the object) |
| World:isUserActionProhibited () | Function to check if player can perform actions when paused |
| World:localiseInitial (profile) | Change the staff name first letter to one from the current language from the seed (generated here or in staff_profile.lua) |
| World:loseGame (player_no, reason, limit) | Cause the player with the player number player_no to lose. |
| World:markRoomAsBuilt (room) | Called when a room has been completely built and is ready to use. |
| World:newFloatingDollarSign (patient, amount) | Setup an animated floating money amount above a patient. |
| World:newObject (id, x, y, flags, name) | Creates a new object by finding the object_type from the "id" variable and calls its class constructor. |
| World:nextEmergency () | Called when it is time to determine when the next emergency should happen |
| World:notifyRoomRemoved (room) | Called when a room has been deactivated (crashed or edited) |
| World:objectPlaced (entity, id) | Notifies the world that an object has been placed, notifying interested entities in the vicinity of the new arrival. |
| World:onTick () | World ticks are translated to game ticks (or hours) depending on the current speed of the game. |
| World:pauseOrUnpause () | Dedicated function to allow unpausing by pressing 'p' again |
| World:prepareFootprintTilesForBuild (object_footprint, x, y) | Prepare all tiles of the footprint for build of an object. |
| World:prepareRectangleTilesForBuild (x, y, w, h) | Prepare all tiles in the given rectangle for building a room. |
| World:removeAllLitter (x, y) | Remove all cleanable litter from a given tile. |
| World:removeObjectFromTile (object, x, y) | Notify the world of an object being removed from a tile See also `World:addObjectToTile` |
| World:resetAnimations () | Because the save file only saves one thob per tile if they are more that information will be lost. |
| World:scheduleRandomEmergency (control) | If a level file specifies random emergencies we make the next one as defined by the mean/variance given |
| World:setCampaignData (campaign_data) | Restore the settings from the previous world |
| World:setEndMonth () | Change the date of the game to the last hour of this month. |
| World:setEndYear () | Change the date of the game to the last hour of this year. |
| World:setPlotOwner (parcel, owner) | Change owner of a plot. |
| World:setSystemPause (state) | Sets the system_pause parameter |
| World:setUI (ui) | Register key shortcuts for controlling the world (game speed, etc.) |
| World:spawnPatient (hospital) | Spawn a patient from a spawn point for the given hospital. |
| World:tickEarthquake () | Perform actions to simulate an active earthquake. |
| World:updateInitialsCache () | Refresh cache of letters in current language to be used for staff member's initials |
| World:wasEmergencySkipped (prev_date, new_date) | Checks if a time jump caused an emergency to be missed |
| World:willObjectsFootprintTileBeWithinItsAllowedRoomIfLocatedAt (x, y, object, allowed_rooms_id_parameter) | |
| World:winGame (player_no) | Process that the given player number won the game. |
| World:wouldNonSideObjectBreakPathfindingIfSpawnedAt (x, y, object, objects_orientation, spawn_rooms_id) | Check that pathfinding still works, i.e. |
Functions
- World:_createMapObject (object)
-
Internal function for placing an object from the map file.
Parameters:
- object Object to place.
- World:addObjectToTile (object, x, y)
-
Notify the world of a new object being placed somewhere in the world
See also `World:removeObjectFromTile`
Parameters:
- object (Object) The object being placed
- x (integer) The X-coordinate of the tile being placed upon
- y (integer) The Y-coordinate of the tile being placed upon
- World:afterLoad (old, new)
-
Let the world react to and old save game. First it gets the chance to
do things for itself, and then it calls corresponding functions for
the hospitals, entities and rooms in that order.
Parameters:
- old The old version of the save game.
- new The current version of the save game format.
- World:calculateSpawnTiles ()
- Identify the tiles on the map suitable for spawning `Humanoid`s from.
- World:checkWinningConditions (player_no)
-
Checks if all goals have been achieved or if the player has lost.
Returns a table that always contains a state string ("win", "lose" or "nothing").
If the state is "lose", the table also contains a reason string,
which corresponds to the criterion name the player lost to
(reputation, balance, percentage_killed) and a number limit which
corresponds to the limit the player passed.
Parameters:
- player_no The index of the player to check in the world's list of hospitals
- World:clearCaches ()
- Clear all internal caches which are dependent upon map state / object position
- World:computeNextEmergencyDates (emergency)
-
Generate the dates for the next emergency
Parameters:
- emergency The next scheduled emergency to take place
Returns:
-
(boolean) true if emergency successfully scheduled
- World:createMapObjects (objects)
-
Place objects from a map file onto the map.
Parameters:
- objects Objects to place.
- World:date ()
-
Get todays date.
Returns:
-
(Date) Current game date.
- World:debugDisableSalaryRaise (mode)
-
Enable or disable salary raise events.
Parameters:
- mode (boolean) If true, do not create salary raise events.
- World:determineWinningConditions ()
- Load goals to win and lose from the map, and store them in 'self.goals'. Also set 'self.winning_goal_count'.
- World:dumpGameLog ()
- Dump the contents of the game log into a file. This is automatically done on each error.
- World:gameLog (message)
-
Append a message to the game log.
Parameters:
- message (string) The message to add.
- World:getAvailableRooms ()
-
Find the rooms available at the level.
Returns:
-
(list) Available rooms, with discovery state at start, and build_cost.
- World:getCampaignData ()
-
Collect the settings that should be reused in the next world
Returns:
-
(table) world and hospital campaign data
- World:getCampaignWinningText (player_no)
-
Finds what text the winning fax should contain, and which choices the player has.
Parameters:
- player_no (integer) Which player that will see the message.
Returns:
-
(string, string, string) Text to show in the fax, text that accompanies
the "continue"-choice the player has, and whether it is the "return_to_main_menu"
choice or the "accept_new_level" choice.
- World:getCurrentSpeed ()
- Return the name of the current speed, relating to a key in tick_rates.
- World:getHospital (x, y)
-
Get the hospital at a given tile location.
Parameters:
- x (int) X position of the queried tile.
- y (int) Y position of the queried tile.
Returns:
-
(Hospital) Hospital at the given location or 'nil'.
- World:getLocalPlayerHospital ()
-
Get the hospital controlled by the (single) player.
Returns:
-
(Hospital) The hospital controlled by the (single) player.
- World:getObject (x, y, id)
-
Retrieve one object from a given position.
Parameters:
- x (int) X position of the object to retrieve.
- y (int) Y position of the object to retrieve.
- id Id to search, nil gets first object, string gets first object with that id, set of strings gets first object that matches an entry in the set.
Returns:
-
(Object or nil) The found object, or nil if the object is not found.
- World:getObjects (x, y)
-
Retrieve all objects from a given position.
Parameters:
- x (int) X position of the object to retrieve.
- y (int) Y position of the object to retrieve.
- World:getReputationImpact (hospital)
-
Computes the impact of hospital reputation on the spawn rate.
The relation between reputation and its impact is linear.
Returns a percentage (as a float):
1% if reputation < 253
60% if reputation == 400
100% if reputation == 500
140% if reputation == 600
180% if reputation == 700
300% if reputation == 1000
Parameters:
- hospital (hospital): the hospital used to compute the reputation impact
- World:getRoom (x, y)
-
Get the room at a given tile location.
Parameters:
- x (int) X position of the queried tile.
- y (int) Y position of the queried tile.
Returns:
-
(Room) Room of the tile, or 'nil'.
- World:getRoomNameAndRequiredStaffName (room_id)
-
Returns localized name of the room, internal required staff name
and localized name of staff required.
Parameters:
- room_id
- World:initLevel (app, avail_rooms)
-
Initialize the game level (available diseases, winning conditions).
Parameters:
- app Game application.
- avail_rooms (list) Available rooms in the level.
- World:isCurrentSpeed (speed)
-
Return true if the given speed the same as the current speed.
Parameters:
- speed
- World:isFootprintTileBuildableOrPassable (x, y, tile, footprint, requirement_flag, player_id)
-
A footprint tile will either need to be buildable or passable so this function
checks if its buildable/passable using the tile's appropriate flag and then returns this
flag's boolean value or false if the tile isn't valid.
Parameters:
- x
- y
- tile
- footprint
- requirement_flag
- player_id
- World:isOnMap (x, y)
-
Test whether the given coordinate is on the map.
Parameters:
- x (int) X position of the coordinate to test.
- y (int) Y position of the coordinate to test.
Returns:
-
(boolean) Whether the provided position is on the map.
- World:isSystemPauseActive ()
-
Reports the system pause status
Returns:
-
(bool) true is system pause is active, else false
- World:isTilePartOfNearbyObject (x, y, distance)
-
Checks whether the given tile is part of a nearby object (walkable tiles
count as part of the object)
Parameters:
- x X position of the given tile.
- y Y position of the given tile.
- distance The number of tiles away from the tile to search.
Returns:
-
(boolean) Whether the tile is part of a nearby object.
- World:isUserActionProhibited ()
-
Function to check if player can perform actions when paused
Returns:
-
(bool) Returns true if player hasn't allowed editing while paused
- World:localiseInitial (profile)
-
Change the staff name first letter to one from the current language
from the seed (generated here or in staff_profile.lua)
Parameters:
- profile (table) The profile of the staff member
- World:loseGame (player_no, reason, limit)
-
Cause the player with the player number player_no to lose.
Parameters:
- player_no (number) The number of the player which should lose.
- reason (string) [optional] The name of the criterion the player lost to.
- limit (number) [optional] The number the player went over/under which caused him to lose.
- World:markRoomAsBuilt (room)
-
Called when a room has been completely built and is ready to use.
Parameters:
- room (Room) The new room.
- World:newFloatingDollarSign (patient, amount)
-
Setup an animated floating money amount above a patient.
Parameters:
- patient Patient to float above.
- amount Amount of money to display.
- World:newObject (id, x, y, flags, name)
-
Creates a new object by finding the object_type from the "id" variable and
calls its class constructor.
Parameters:
- id (string) The unique id of the object to be created.
- x X position of the new object.
- y Y position of the new object.
- flags Flags of the new object.
- name Name of the new object.
Returns:
-
The created object.
- World:nextEmergency ()
- Called when it is time to determine when the next emergency should happen
- World:notifyRoomRemoved (room)
-
Called when a room has been deactivated (crashed or edited)
Parameters:
- room
- World:objectPlaced (entity, id)
-
Notifies the world that an object has been placed, notifying
interested entities in the vicinity of the new arrival.
Parameters:
- entity (Entity) The entity that was just placed.
- id (optional string) That entity's id.
- World:onTick ()
- World ticks are translated to game ticks (or hours) depending on the current speed of the game. There are 50 hours in a TH day.
- World:pauseOrUnpause ()
- Dedicated function to allow unpausing by pressing 'p' again
- World:prepareFootprintTilesForBuild (object_footprint, x, y)
-
Prepare all tiles of the footprint for build of an object.
Parameters:
- object_footprint Footprint of the object being build.
- x (int) X position of the object
- y (int) Y position of the object
- World:prepareRectangleTilesForBuild (x, y, w, h)
-
Prepare all tiles in the given rectangle for building a room.
Parameters:
- x (int) Start x position of the area.
- y (int) Start y position of the area.
- w (int) Number of tiles in x direction.
- h (int) Number of tiles in y direction.
- World:removeAllLitter (x, y)
-
Remove all cleanable litter from a given tile.
Parameters:
- x (int) X position of the tile to clean.
- y (int) Y position of the tile to clean.
- World:removeObjectFromTile (object, x, y)
-
Notify the world of an object being removed from a tile
See also `World:addObjectToTile`
Parameters:
- object (Object) The object being removed.
- x (integer) The X-coordinate of the tile which the object was on
- y (integer) The Y-coordinate of the tile which the object was on
- World:resetAnimations ()
- Because the save file only saves one thob per tile if they are more that information will be lost. To solve this after a load we need to set again all the thobs on each tile.
- World:scheduleRandomEmergency (control)
-
If a level file specifies random emergencies we make the next one as defined by the mean/variance given
Parameters:
- control (table) Contains emergency information from level file
- World:setCampaignData (campaign_data)
-
Restore the settings from the previous world
Parameters:
- campaign_data (table) world and hospital campaign data
- World:setEndMonth ()
- Change the date of the game to the last hour of this month.
- World:setEndYear ()
- Change the date of the game to the last hour of this year.
- World:setPlotOwner (parcel, owner)
-
Change owner of a plot.
Parameters:
- parcel (int) Plot to change.
- owner (int) New owner (may be 0).
- World:setSystemPause (state)
-
Sets the system_pause parameter
Parameters:
- state (bool)
- World:setUI (ui)
-
Register key shortcuts for controlling the world (game speed, etc.)
Parameters:
- ui
- World:spawnPatient (hospital)
-
Spawn a patient from a spawn point for the given hospital.
Parameters:
- hospital (Hospital) Hospital that the new patient should visit.
Returns:
-
(Patient entity) The spawned patient, or 'nil' if no patient spawned.
- World:tickEarthquake ()
- Perform actions to simulate an active earthquake.
- World:updateInitialsCache ()
- Refresh cache of letters in current language to be used for staff member's initials
- World:wasEmergencySkipped (prev_date, new_date)
-
Checks if a time jump caused an emergency to be missed
Parameters:
- prev_date (Date) Original game date before jump
- new_date (Date) Game date after time jump
Returns:
-
(boolean) true if emergency has been skipped
- World:willObjectsFootprintTileBeWithinItsAllowedRoomIfLocatedAt (x, y, object, allowed_rooms_id_parameter)
-
Parameters:
- x (int) X position of the coordinate to test.
- y (int) Y position of the coordinate to test.
- object (table) the object to test
- allowed_rooms_id_parameter Should be nil when the object is allowed to be placed in any room.
Returns:
-
{within_room, roomId}
- World:winGame (player_no)
-
Process that the given player number won the game.
Parameters:
- player_no (integer) Number of the player who just won.
- World:wouldNonSideObjectBreakPathfindingIfSpawnedAt (x, y, object, objects_orientation, spawn_rooms_id)
-
Check that pathfinding still works, i.e. that placing the object
wouldn't disconnect one part of the hospital from another. To do
this, we provisionally mark the footprint as unpassable (as it will
become when the object is placed), and then check that the cells
surrounding the footprint have not had their connectedness changed.
Parameters:
- x
- y
- object
- objects_orientation
- spawn_rooms_id