Limit number of fleets & spawn specified number when entering system #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature: This implements a feature requested by @Zitchas: limit the number of fleets that spawn in a system. It does a bit more than that, too.
This is identical to PR endless-sky#8082 to endless-sky master
Previously, @RisingLeaf attempted this in #7167
As noted in the comments, there's a PR #8074, still in progress, which I may be able to use to expand this functionality. That PR isn't working yet, as of this writing, so I can't be certain, but at this point it looks like they could go into master in either order. If 8074 goes in first, I'll add functionality to this PR. If this PR goes in first, I can do another PR later to add functionality.That PR has been closed and orphaned.Feature Details
You can:
Syntax:
All arguments are optional, except the fleet name. The default category is "fleet name@system" so the limits and initial counts only apply to that fleet in that system if you give it no category.
The Engine will keep track of fleets as they despawn. However, disabled ships have not despawned, so if there's a
limit
of 10 fleets and 10 fleets are sitting in the system disabled, no more will come. To avoid this, usenon-disabled limit
which skips fleets whose ships are all disabled.Usage Examples
If the period, limit, and initial count, are connected to conditions, then we can do this:
Testing Done
Put this somewhere in the data directory:
limittest.txt
Load this save:
Friction Diction~3024-05-02 test limit.txt
Your flagship has afterburners and a cloak. Don't forget that! You'll need them.
Example 1: Solo ship vs a replenishing fleet of consistent size.
It's the fight we've all been waiting for: Drak vs. Pug.
Notice the non-stop flow of Pug Arfectas. Despite the arrival period of 100, the number never gets out of hand. That's because there's a limit of 12 fleets of 6 Arfectas. Also, there's always exactly one Archon.
Example 2: multi-system guard ship
Somebody has been farming the Korath to extinction, so the Drak have placed an Archon in the Korath Exile systems.
The first time you enter one of these systems, an Archon will be there to greet you. If you leave the system, it'll take at least 1000 frames for the Archon to arrive. That's because it takes 1000 frames to despawn after you leave the system, and then has a 500 frame arrival period.
If, by some miracle, you managed to destroy the Archon, another one would show up soon after.
Example 3: Fleet counts include disabled fleets
Here, the Remnant and Korath are battling. Eventually, the Korath will stop sending new fleets because they've hit their maximum due to all of their fleets being disabled. If you destroy some of the disabled Korath ships, new Korath fleets will arrive. The fighters are part of the fleet, so you'll have to destroy those too.
Notice both remnant fleets have the same category. That means their fleet counts are combined into one. Each has its own limit, though, and that limit is compared against the combined count when deciding whether to spawn ships.
Also, notice the remnant fleet initial counts are higher than the limits. When initially spawning fleets, the initial count ignores the limit.
The Heron fleet will only spawn if the Remnant run out of ships. This is it has no initial count and doesn't spawn during the 5 second system entry loop, so the system will already be filled with ships in the "remnant" category.
Example 4: Fleet counts that do NOT include disabled ships
As with the third example, the Remnant and Korath are battling, but this time both sides will keep sending ships no matter how many are disabled. This is because they use
non-disabled limit
instead oflimit
.Automated Tests Added
There is an integration test for the new txt file functionality.
I did not add any for LimitedEvents since it's just a few pieces of data with set/get functions. If people want unit tests for that, let me know and I'll add some.
Performance Impact
Negligible.