World Class
Manages entities, rooms, and the date.
Method Index
- addObjectToTile(object, x, y)
- adjustZoom(delta)
- afterLoad(old, new)
- calculateSpawnTiles()
- checkWinningConditions(player_no)
- clearCaches()
- createEarthquake()
- createMapObjects(objects)
- debugDisableSalaryRaise(mode)
- destroyEntity(entity)
- determineWinningConditions()
- dumpGameLog()
- findAllObjectsNear(x, y, distance, object_type_name)
- findFreeObjectNearToUse(humanoid, object_type_name, which, current_object)
- findObjectNear(humanoid, object_type_name, distance, callback)
- findRoomNear(humanoid, room_type_id, distance, mode)
- gameLog(message)
- getAnimLength(anim)
- getCurrentMonthLength()
- getCurrentSpeed()
- getDate()
- getFreeBench(x, y, distance)
- getIdleTile(x, y, idx)
- getLocalPlayerHospital()
- getObject(x, y, id)
- getObjectToNotifyOfOccupants(x, y)
- getObjects(x, y)
- getObjectsById(id)
- getPath(x, y, dest_x, dest_y)
- getPathDistance(x1, y1, x2, y2)
- getRoom(x, y)
- getRoomNameAndRequiredStaffName(room_id)
- getWallDirFromBlockId(block_id)
- getWallIdFromBlockId(block_id)
- getWallSetFromBlockId(block_id)
- initCompetitors()
- initFromPreviousLevel(carry)
- initLevel(app)
- initRooms()
- initStaff()
- isCurrentSpeed(speed)
- isTilePartOfNearbyObject(x, y, distance)
- loseGame(player_no, reason, limit)
- makeAvailableStaff(month)
- markRoomAsBuilt(room)
- newEntity(class, animation)
- newFloatingDollarSign(patient, amount)
- newObject(id, ...)
- newRoom(x, y, w, h, room_info, ...)
- nextEarthquake()
- nextEmergency()
- nextVip()
- notifyObjectOfOccupants(x, y, object)
- notifyRoomRemoved(room)
- objectPlaced(entity, id)
- onEndDay()
- onEndMonth()
- onEndYear()
- onTick()
- pauseOrUnpause()
- previousSpeed()
- registerRoomBuildCallback(callback)
- registerRoomRemoveCallback(callback)
- removeObjectFromTile(object, x, y)
- resetAnimations()
- resetSideObjects()
- setEndMonth()
- setEndYear()
- setPlotOwner(parcel, owner)
- setSpeed(speed)
- setUI(ui)
- spawnPatient(hospital)
- spawnVIP(name)
- speedUp()
- tickEarthquake()
- toggleInformation()
- unregisterRoomBuildCallback(callback)
- unregisterRoomRemoveCallback(callback)
- updateSpawnDates()
- winGame(player_no)
Member Index
- active_earthquake
- anim_length_cache
- animation_manager
- anims
- autosave_next_tick
- available_diseases
- available_rooms
- available_staff
- cheat_announcements
- currentX
- currentY
- current_map_earthquake
- current_tick_entity
- day
- debug_disable_salary_raise
- delayed_map_objects
- dispatcher
- earthquake_size
- earthquake_stop_day
- entities
- floating_dollars
- free_build_mode
- game_log
- goals
- hospitals
- hour
- hours_per_day
- hours_per_tick
- idle_cache
- level_criteria
- map
- month
- monthly_spawn_increase
- next_earthquake_day
- next_earthquake_month
- next_emergency_day
- next_emergency_month
- next_emergency_no
- next_vip_day
- next_vip_month
- object_counts
- object_id_by_thob
- object_types
- objects
- objects_notify_occupants
- original_savegame_version
- pathfinder
- prev_speed
- randomX
- randomY
- room_build_callbacks
- room_built
- room_information_dialogs_off
- room_remove_callbacks
- rooms
- savegame_version
- spawn_dates
- spawn_hours
- spawn_points
- spawn_rate
- tick_rate
- tick_timer
- ui
- user_actions_allowed
- wall_dir_by_block_id
- wall_id_by_block_id
- wall_set_by_block_id
- wall_types
- winning_goal_count
- year
function World:World(app)
Parameters:
Name | Type | Description |
---|---|---|
app | ? | ? |
Declared on: line 47 of Lua/world.lua.
function World:addObjectToTile(object, x, y)
Notify the world of a new object being placed somewhere in the world
See also `World:removeObjectFromTile`
Parameters:
Name | Type | Description |
---|---|---|
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 |
Declared on: line 1920 of Lua/world.lua.
function World:adjustZoom(delta)
Parameters:
Name | Type | Description |
---|---|---|
delta | ? | ? |
Declared on: line 190 of Lua/world.lua.
function 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:
Name | Type | Description |
---|---|---|
old | ? | The old version of the save game. |
new | ? | The current version of the save game format. |
Declared on: line 2065 of Lua/world.lua.
function World:calculateSpawnTiles()
Identify the tiles on the map suitable for spawning `Humanoid`s from.
Declared on: line 446 of Lua/world.lua.
function World:checkWinningConditions(player_no)
(reputation, balance, percentage_killed) and a number limit which
corresponds to the limit the player passed.
Parameters:
Name | Type | Description |
---|---|---|
player_no | ? | The index of the player to check in the world's list of hospitals |
Declared on: line 1390 of Lua/world.lua.
function World:clearCaches()
Clear all internal caches which are dependant upon map state / object position
Declared on: line 848 of Lua/world.lua.
function World:createEarthquake()
Declared on: line 553 of Lua/world.lua.
function World:createMapObjects(objects)
Parameters:
Name | Type | Description |
---|---|---|
objects | ? | ? |
Declared on: line 746 of Lua/world.lua.
function World:debugDisableSalaryRaise(mode)
Parameters:
Name | Type | Description |
---|---|---|
mode | ? | ? |
Declared on: line 692 of Lua/world.lua.
function World:destroyEntity(entity)
Parameters:
Name | Type | Description |
---|---|---|
entity | ? | ? |
Declared on: line 1820 of Lua/world.lua.
function World:determineWinningConditions()
Load goals to win and lose from the map, and store them in 'self.goals'.
Also set 'self.winning_goal_count'.
Declared on: line 298 of Lua/world.lua.
function World:dumpGameLog()
Dump the contents of the game log into a file.
This is automatically done on each error.
Declared on: line 2039 of Lua/world.lua.
function World:findAllObjectsNear(x, y, distance, object_type_name)
Returns a set of all objects near the given position but if supplied only of the given object type.
Parameters:
Name | Type | Description |
---|---|---|
x | ? | The x-coordinate at which to originate the search |
y | ? | The y-coordinate |
distance | ? | The number of tiles away from the origin to search |
object_type_name | ? | The name of the objects that are being searched for |
Declared on: line 1620 of Lua/world.lua.
function World:findFreeObjectNearToUse(humanoid, object_type_name, which, current_object)
Parameters:
Name | Type | Description |
---|---|---|
humanoid | ? | ? |
object_type_name | ? | ? |
which | ? | ? |
current_object | ? | ? |
Declared on: line 1713 of Lua/world.lua.
function World:findObjectNear(humanoid, object_type_name, distance, callback)
Find all objects of the given type near the humanoid.
Note that regardless of distance, only the room which the humanoid is in
is searched (or the corridor if the humanoid is not in a room).
When no callback is specified then the first object found is returned,
along with its usage tile position. This may return an object already being
used - if you want to find an object not in use (in order to use it),
then call findFreeObjectNearToUse instead.
Parameters:
Name | Type | Description |
---|---|---|
humanoid | ? | The humanoid to search around |
object_type_name | ? | The objects to search for |
distance | ? | Maximum L1 distance to search from humanoid. If nil then everywhere in range will be searched. |
callback | ? | Function to call for each result. If it returns true then the search will be ended. -- |
Declared on: line 1651 of Lua/world.lua.
function World:findRoomNear(humanoid, room_type_id, distance, mode)
Parameters:
Name | Type | Description |
---|---|---|
humanoid | ? | ? |
room_type_id | ? | ? |
distance | ? | ? |
mode | ? | ? |
Declared on: line 1753 of Lua/world.lua.
function World:gameLog(message)
Append a message to the game log.
Parameters:
Name | Type | Description |
---|---|---|
message | string | The message to add. |
Declared on: line 2029 of Lua/world.lua.
function World:getAnimLength(anim)
Parameters:
Name | Type | Description |
---|---|---|
anim | ? | ? |
Declared on: line 784 of Lua/world.lua.
function World:getCurrentMonthLength()
Return the length of the current month
Declared on: line 909 of Lua/world.lua.
function World:getCurrentSpeed()
Return the name of the current speed, relating to a key in tick_rates.
Declared on: line 930 of Lua/world.lua.
function World:getDate()
Declared on: line 892 of Lua/world.lua.
function World:getFreeBench(x, y, distance)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
distance | ? | ? |
Declared on: line 1589 of Lua/world.lua.
function World:getIdleTile(x, y, idx)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
idx | ? | ? |
Declared on: line 1561 of Lua/world.lua.
function World:getObject(x, y, id)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
id | ? | ? |
Declared on: line 1948 of Lua/world.lua.
function World:getObjectToNotifyOfOccupants(x, y)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
Declared on: line 740 of Lua/world.lua.
function World:getObjects(x, y)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
Declared on: line 1943 of Lua/world.lua.
function World:getObjectsById(id)
Parameters:
Name | Type | Description |
---|---|---|
id | ? | ? |
Declared on: line 1970 of Lua/world.lua.
function World:getPath(x, y, dest_x, dest_y)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
dest_x | ? | ? |
dest_y | ? | ? |
Declared on: line 1557 of Lua/world.lua.
function World:getPathDistance(x1, y1, x2, y2)
Calculate the distance of the shortest path (along passable tiles) between
the two given map tiles. This operation is commutative (swapping (x1, y1)
with (x2, y2) has no effect on the result) if both tiles are passable.
Parameters:
Name | Type | Description |
---|---|---|
x1 | integer | X-cordinate of first tile's Lua tile co-ordinates. |
y1 | integer | Y-cordinate of first tile's Lua tile co-ordinates. |
x2 | integer | X-cordinate of second tile's Lua tile co-ordinates. |
y2 | integer | Y-cordinate of second tile's Lua tile co-ordinates. |
Declared on: line 1544 of Lua/world.lua.
function World:getRoom(x, y)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
Declared on: line 1997 of Lua/world.lua.
function World:getRoomNameAndRequiredStaffName(room_id)
Returns localized name of the room, internal required staff name
and localized name of staff required.
Parameters:
Name | Type | Description |
---|---|---|
room_id | ? | ? |
Declared on: line 2001 of Lua/world.lua.
function World:getWallDirFromBlockId(block_id)
Parameters:
Name | Type | Description |
---|---|---|
block_id | ? | ? |
Declared on: line 869 of Lua/world.lua.
function World:getWallIdFromBlockId(block_id)
Parameters:
Name | Type | Description |
---|---|---|
block_id | ? | ? |
Declared on: line 853 of Lua/world.lua.
function World:getWallSetFromBlockId(block_id)
Parameters:
Name | Type | Description |
---|---|---|
block_id | ? | ? |
Declared on: line 861 of Lua/world.lua.
function World:initCompetitors()
Declared on: line 414 of Lua/world.lua.
function World:initFromPreviousLevel(carry)
Initializes variables carried from previous levels
Parameters:
Name | Type | Description |
---|---|---|
carry | ? | ? |
Declared on: line 425 of Lua/world.lua.
function World:initLevel(app)
Parameters:
Name | Type | Description |
---|---|---|
app | ? | ? |
Declared on: line 210 of Lua/world.lua.
function World:initRooms()
Declared on: line 363 of Lua/world.lua.
function World:initStaff()
Declared on: line 244 of Lua/world.lua.
function World:isCurrentSpeed(speed)
Return if the selected speed the same as the current speed.
Parameters:
Name | Type | Description |
---|---|---|
speed | ? | ? |
Declared on: line 924 of Lua/world.lua.
function World:isTilePartOfNearbyObject(x, y, distance)
This helper function checks if the given tile is part of a nearby object (walkable tiles count as part of the object)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
distance | ? | ? |
Declared on: line 1608 of Lua/world.lua.
function World:loseGame(player_no, reason, limit)
Cause the player with the player number player_no to lose.
Parameters:
Name | Type | Description |
---|---|---|
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. |
Declared on: line 1508 of Lua/world.lua.
function World:makeAvailableStaff(month)
Parameters:
Name | Type | Description |
---|---|---|
month | ? | ? |
Declared on: line 702 of Lua/world.lua.
function World:markRoomAsBuilt(room)
Called when a room has been completely built and is ready to use
Parameters:
Name | Type | Description |
---|---|---|
room | ? | ? |
Declared on: line 828 of Lua/world.lua.
function World:newEntity(class, animation)
Parameters:
Name | Type | Description |
---|---|---|
class | ? | ? |
animation | ? | ? |
Declared on: line 1811 of Lua/world.lua.
function World:newFloatingDollarSign(patient, amount)
Setup an animated floating money amount above a patient.
Parameters:
Name | Type | Description |
---|---|---|
patient | ? | Patient to float above. |
amount | ? | Amount of money to display. |
Declared on: line 1784 of Lua/world.lua.
function World:newObject(id, ...)
Creates a new object by finding the object_type from the "id" variable and
calls its class constructor.
Parameters:
Name | Type | Description |
---|---|---|
id | string | The unique id of the object to be created. |
... | ? | ? |
Declared on: line 1830 of Lua/world.lua.
function World:newRoom(x, y, w, h, room_info, ...)
Parameters:
Name | Type | Description |
---|---|---|
x | ? | ? |
y | ? | ? |
w | ? | ? |
h | ? | ? |
room_info | ? | ? |
... | ? | ? |
Declared on: line 814 of Lua/world.lua.
function World:nextEarthquake()
Called when it is time to have another earthquake
Declared on: line 1346 of Lua/world.lua.
function World:nextEmergency()
Called when it is time to determine what the
next emergency should look like.
Declared on: line 1260 of Lua/world.lua.
function World:nextVip()
Called when it is time to have another VIP
Declared on: line 1322 of Lua/world.lua.
function World:notifyObjectOfOccupants(x, y, object)
Register a callback for when `Humanoid`s enter or leave a given tile.
Note that only one callback may be registered to each tile.
Parameters:
Name | Type | Description |
---|---|---|
x | integer | The 1-based X co-ordinate of the tile to monitor. |
y | integer | The 1-based Y co-ordinate of the tile to monitor. |
object | Object | Something with an `onOccupantChange` method, which will be called whenever a `Humanoid` enters or leaves the given tile. The method will recieve one argument (after `self`), which will be `1` for an enter event and `-1` for a leave event. |
Declared on: line 726 of Lua/world.lua.
function World:notifyRoomRemoved(room)
Called when a room has been deactivated (crashed or edited)
Parameters:
Name | Type | Description |
---|---|---|
room | ? | ? |
Declared on: line 840 of Lua/world.lua.
function World:objectPlaced(entity, id)
Notifies the world that an object has been placed, notifying
interested entities in the vicinity of the new arrival.
Parameters:
Name | Type | Description |
---|---|---|
entity | Entity | The entity that was just placed. |
id | string | That entity's id. |
Declared on: line 1852 of Lua/world.lua.
function World:onEndDay()
Called immediately prior to the ingame day changing.
Declared on: line 1109 of Lua/world.lua.
function World:onEndMonth()
Called immediately prior to the ingame month changing.
returns true if the game was killed due to the player losing
Declared on: line 1196 of Lua/world.lua.
function World:onEndYear()
Called immediately prior to the ingame year changing.
Declared on: line 1526 of Lua/world.lua.
function 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.
Declared on: line 990 of Lua/world.lua.
function World:pauseOrUnpause()
Dedicated function to allow unpausing by pressing 'p' again
Declared on: line 964 of Lua/world.lua.
function World:previousSpeed()
Declared on: line 918 of Lua/world.lua.
function World:registerRoomBuildCallback(callback)
Register a function to be called whenever a room is built.
Parameters:
Name | Type | Description |
---|---|---|
callback | function | A function taking one argument: a `Room`. |
Declared on: line 788 of Lua/world.lua.
function World:registerRoomRemoveCallback(callback)
Register a function to be called whenever a room has been deactivated (crashed or edited).
Parameters:
Name | Type | Description |
---|---|---|
callback | function | A function taking one argument: a `Room`. |
Declared on: line 801 of Lua/world.lua.
function World:removeObjectFromTile(object, x, y)
Notify the world of an object being removed from a tile
See also `World:addObjectToTile`
Parameters:
Name | Type | Description |
---|---|---|
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 |
Declared on: line 1895 of Lua/world.lua.
function 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.
Declared on: line 2057 of Lua/world.lua.
function World:resetSideObjects()
There is a problem with room editing in that it resets all the partial passable flags
(travelNorth, travelSouth etc.) in the corridor, a workaround is calling this function
after the room was edited so that all edge only objects, that set partial passable flags set
those flags again
Declared on: line 2319 of Lua/world.lua.
function World:setEndMonth()
Declared on: line 1099 of Lua/world.lua.
function World:setEndYear()
Declared on: line 1104 of Lua/world.lua.
function World:setPlotOwner(parcel, owner)
Parameters:
Name | Type | Description |
---|---|---|
parcel | ? | ? |
owner | ? | ? |
Declared on: line 771 of Lua/world.lua.
function World:setSpeed(speed)
Set the (approximate) number of seconds per tick.
Parameters:
Name | Type | Description |
---|---|---|
speed | string | One of: "Pause", "Slowest", "Slower", "Normal", "Max speed", or "And then some more". |
Declared on: line 939 of Lua/world.lua.
function World:setUI(ui)
Register key shortcuts for controling the world (game speed, etc.)
Parameters:
Name | Type | Description |
---|---|---|
ui | ? | ? |
Declared on: line 174 of Lua/world.lua.
function World:spawnPatient(hospital)
Parameters:
Name | Type | Description |
---|---|---|
hospital | ? | ? |
Declared on: line 478 of Lua/world.lua.
function World:spawnVIP(name)
Parameters:
Name | Type | Description |
---|---|---|
name | ? | ? |
Declared on: line 532 of Lua/world.lua.
function World:speedUp()
Declared on: line 914 of Lua/world.lua.
function World:tickEarthquake()
Declared on: line 596 of Lua/world.lua.
function World:toggleInformation()
Declared on: line 240 of Lua/world.lua.
function World:unregisterRoomBuildCallback(callback)
Unregister a function from being called whenever a room is built.
Parameters:
Name | Type | Description |
---|---|---|
callback | function | A function previously passed to `registerRoomBuildCallback`. |
Declared on: line 794 of Lua/world.lua.
function World:unregisterRoomRemoveCallback(callback)
Unregister a function from being called whenever a room has been deactivated (crashed or edited).
Parameters:
Name | Type | Description |
---|---|---|
callback | function | A function previously passed to `registerRoomRemoveCallback`. |
Declared on: line 807 of Lua/world.lua.
function World:updateSpawnDates()
Called when a month ends. Decides on which dates patients arrive
during the coming month.
Declared on: line 1245 of Lua/world.lua.
function World:winGame(player_no)
Parameters:
Name | Type | Description |
---|---|---|
player_no | ? | ? |
Declared on: line 1443 of Lua/world.lua.