Skip to content

Commit

Permalink
Basic ship spawning queue (#2578)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

Not even a queue really. Basically it just prevents people from spawning
a ship while a ship is already spawning.

## Why It's Good For The Game

Multiple ships spawning is a recipe for disaster and lag.

## Changelog

:cl:
fix: Only one ship can spawn at a time.
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
  • Loading branch information
MarkSuckerberg authored Dec 12, 2023
1 parent ffde880 commit 5a6da28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion code/controllers/subsystem/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ SUBSYSTEM_DEF(overmap)
///The two-dimensional list that contains every single tile in the overmap as a sublist.
var/list/list/overmap_container

///Whether or not a ship is currently being spawned. Used to prevent multiple ships from being spawned at once.
var/ship_spawning //TODO: Make a proper queue for this

/datum/controller/subsystem/overmap/get_metrics()
. = ..()
var/list/cust = list()
Expand Down Expand Up @@ -227,13 +230,18 @@ SUBSYSTEM_DEF(overmap)
* Inteded for ship purchases, etc.
*/
/datum/controller/subsystem/overmap/proc/spawn_ship_at_start(datum/map_template/shuttle/template)
//Should never happen, but just in case. This'll delay the next spawn until the current one is done.
UNTIL(!ship_spawning)

var/ship_loc
if(template.space_spawn)
ship_loc = null
else
ship_loc = SSovermap.outposts[1]

return new /datum/overmap/ship/controlled(ship_loc, template)
ship_spawning = TRUE
. = new /datum/overmap/ship/controlled(ship_loc, template) //This statement SHOULDN'T runtime (not counting runtimes actually in the constructor) so ship_spawning should always be toggled.
ship_spawning = FALSE

/**
* Creates an overmap object for each ruin level, making them accessible.
Expand Down
7 changes: 7 additions & 0 deletions code/modules/mob/dead/new_player/ship_select.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
return

var/datum/map_template/shuttle/template = SSmapping.ship_purchase_list[params["name"]]
if(SSovermap.ship_spawning)
to_chat(spawnee, "<span class='danger'>A ship is currently spawning. Try again in a little while.</span>")
return
if(!SSovermap.player_ship_spawn_allowed())
to_chat(spawnee, "<span class='danger'>No more ships may be spawned at this time!</span>")
return
Expand Down Expand Up @@ -104,6 +107,10 @@
to_chat(spawnee, "<span class='danger'>Ship spawned, but you were unable to be spawned. You can likely try to spawn in the ship through joining normally, but if not, please contact an admin.</span>")
spawnee.new_player_panel()

/datum/ship_select/ui_data(mob/user)
. = list()
.["shipSpawning"] = SSovermap.ship_spawning

/datum/ship_select/ui_static_data(mob/user)
// tracks the number of existing ships of each template type so that their unavailability for purchase can be communicated to the user
var/list/template_num_lookup = list()
Expand Down
9 changes: 7 additions & 2 deletions tgui/packages/tgui/interfaces/ShipSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export const ShipSelect = (props, context) => {
(data.purchaseBanned &&
'You are banned from purchasing ships.') ||
(!data.shipSpawnAllowed &&
'No more ships may be spawned at this time.')
'No more ships may be spawned at this time.') ||
(data.shipSpawning &&
'A ship is currently spawning. Please wait.')
}
disabled={data.purchaseBanned}
onClick={() => {
Expand Down Expand Up @@ -254,10 +256,13 @@ export const ShipSelect = (props, context) => {
'There are too many ships of this type.') ||
(!data.autoMeet &&
data.playMin < template.minTime &&
'You do not have enough playtime to buy this ship.')
'You do not have enough playtime to buy this ship.') ||
(data.shipSpawning &&
'A ship is currently spawning. Please wait.')
}
disabled={
!data.shipSpawnAllowed ||
data.shipSpawning ||
template.curNum >= template.limit ||
(!data.autoMeet && data.playMin < template.minTime)
}
Expand Down

0 comments on commit 5a6da28

Please sign in to comment.