Editing Cave spawning
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
{{credits|JHawk}} | {{credits|JHawk}} | ||
− | + | ==Process== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == Process == | ||
Some time after the cave is built out of its [[Cave unit list file|available units]], the game will run this "main algorithm" in order to spawn objects. Note that this outline will only include information about which objects spawn, and how many. It does not have information on ''where'' they spawn, using the "score" mechanic. | Some time after the cave is built out of its [[Cave unit list file|available units]], the game will run this "main algorithm" in order to spawn objects. Note that this outline will only include information about which objects spawn, and how many. It does not have information on ''where'' they spawn, using the "score" mechanic. | ||
− | === Main algorithm === | + | ===Main algorithm=== |
+ | {{todo|Document the algorithms that are linked here, but don't exist in the page.}} | ||
# Run the [[#Main category allocation algorithm|main category allocation algorithm]] to figure out how many "main" category entries of each spawn type will be spawned. | # Run the [[#Main category allocation algorithm|main category allocation algorithm]] to figure out how many "main" category entries of each spawn type will be spawned. | ||
# Run the [[#Spawn type 5, 8, 1 algorithm|spawn type 5, 8, 1 algorithm]] to spawn all "main" category objects of type 5 (seams). | # Run the [[#Spawn type 5, 8, 1 algorithm|spawn type 5, 8, 1 algorithm]] to spawn all "main" category objects of type 5 (seams). | ||
Line 25: | Line 13: | ||
# Run the [[#Spawn type 5, 8, 1 algorithm|same algorithm]] to spawn all "main" category objects of type 1 ("hard" enemies). | # Run the [[#Spawn type 5, 8, 1 algorithm|same algorithm]] to spawn all "main" category objects of type 1 ("hard" enemies). | ||
# Run the [[#Spawn type 0 algorithm|spawn type 0 algorithm]] to spawn all "main" category objects of type 0 ("easy" enemies). | # Run the [[#Spawn type 0 algorithm|spawn type 0 algorithm]] to spawn all "main" category objects of type 0 ("easy" enemies). | ||
− | # Run the [[#Spawn | + | # Run the [[#Spawn type 6 algorithm|spawn type 6 algorithm]] to spawn all "decorative" category objects. |
# Run the [[#Spawn treasure algorithm|spawn treasure algorithm]] to spawn all "treasure" category objects. | # Run the [[#Spawn treasure algorithm|spawn treasure algorithm]] to spawn all "treasure" category objects. | ||
− | # Run the [[#Spawn | + | # Run the [[#Spawn dead end algorithm|spawn dead end algorithm]] to spawn all "dead end" category objects. |
− | |||
− | |||
− | |||
=== Main category allocation algorithm === | === Main category allocation algorithm === | ||
Line 37: | Line 22: | ||
# Save the number of allocations of spawn type 0 ("easy" enemies) as 0. Repeat for types 1 ("hard" enemies), 5 (seams), and 8 ("special" enemies). | # Save the number of allocations of spawn type 0 ("easy" enemies) as 0. Repeat for types 1 ("hard" enemies), 5 (seams), and 8 ("special" enemies). | ||
# Save the weight of each spawn type as 0. | # Save the weight of each spawn type as 0. | ||
− | # For each "main" category entry in the [[Cave definition file|sublevel's configuration]] | + | # For each "main" category entry in the [[Cave definition file|sublevel's configuration]]... |
## Add the minimum amount of that entry to the number of allocations of the relevant spawn type. | ## Add the minimum amount of that entry to the number of allocations of the relevant spawn type. | ||
## Add the weight of that entry to the weight of the relevant spawn type. | ## Add the weight of that entry to the weight of the relevant spawn type. | ||
Line 50: | Line 35: | ||
## Pick a free spawn point of the given type. | ## Pick a free spawn point of the given type. | ||
### For type 5, this means picking a free seam. Note that not all seams have the same chance of being picked. | ### For type 5, this means picking a free seam. Note that not all seams have the same chance of being picked. | ||
− | ### For types 8 or 1, this means a standard spawn point. Note that some points cannot | + | ### For types 8 or 1, this means a standard spawn point. Note that some points cannot be picked due to being too close to important gameplay features. |
− | ## Run the [[# | + | ## Run the [[#Entry picking algorithm|entry picking algorithm]] with all entries of this type, and the number of spawned objects of this type so far. |
## If there is no spawn point or entry that can be picked, finish now. | ## If there is no spawn point or entry that can be picked, finish now. | ||
## Spawn one object of that entry on that spawn point. | ## Spawn one object of that entry on that spawn point. | ||
Line 60: | Line 45: | ||
# Repeat n times, n being the number of allocations for spawn type 0. | # Repeat n times, n being the number of allocations for spawn type 0. | ||
− | ## Pick a free spawn point of type 0. Note that some points cannot | + | ## Pick a free spawn point of type 0. Note that some points cannot be picked due to being too close to important gameplay features. |
− | ## Run the [[# | + | ## Run the [[#Entry picking algorithm|entry picking algorithm]] with all entries of type 0, and the number of spawned objects type 0 so far. |
## If we picked an entry because we still have minimum amounts to fill, then: | ## If we picked an entry because we still have minimum amounts to fill, then: | ||
### Save the number of candidates as the number of objects we still have left to spawn of the given entry to meet its minimum. | ### Save the number of candidates as the number of objects we still have left to spawn of the given entry to meet its minimum. | ||
Line 78: | Line 63: | ||
## Mark that spawn point as used. | ## Mark that spawn point as used. | ||
− | === | + | === Entry picking algorithm === |
− | This algorithm | + | This algorithm picks an object entry from a given set, and chooses an object to spawn. It checks how many of this type have been spawned so far to decide which one to pick next. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | # If we haven't spawned all necessary minimum amounts for objects of the given type, then: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | # If we haven't spawned all necessary minimum amounts for objects of the | ||
## Pick an entry whose minimum amounts haven't been met yet. Prioritize the order in the sublevel configuration file. | ## Pick an entry whose minimum amounts haven't been met yet. Prioritize the order in the sublevel configuration file. | ||
− | # Otherwise, if | + | # Otherwise, if there are entries of that type with any weight, then: |
− | ## Pick an entry | + | ## Pick an entry of that type using [[#Weighted distribution|weighted randomness]], using the weights of the entries of that type. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# Otherwise: | # Otherwise: | ||
− | |||
## Pick none. | ## Pick none. | ||
− | === Notes === | + | ===Notes=== |
* If a spawn coordinate has a radius of 0, all objects to spawn will be placed in the same spot, and will physically push each other apart. Otherwise, the objects will be forced to maintain a fixed minimum distance from one another, even if that distance will push them beyond the spawn coordinate's radius. | * If a spawn coordinate has a radius of 0, all objects to spawn will be placed in the same spot, and will physically push each other apart. Otherwise, the objects will be forced to maintain a fixed minimum distance from one another, even if that distance will push them beyond the spawn coordinate's radius. | ||
− | * | + | * A spawn coordinate is valid if all of the following are true: |
− | + | *# It is not in a dead end cave unit. | |
− | *# It is in a | + | *# It is of the intended spawn coordinate type (Enemy Group A, Plant, etc.) |
+ | *# It is in-bounds. | ||
*# It has not been used already. | *# It has not been used already. | ||
− | *# It is far enough away from the ship's pod (300 units). | + | *# It is far enough away from the ship's pod (300 units for Enemy Group A, B, and C). |
− | *# It is far enough away from the hole ( | + | *# It is far enough away from the hole (200 units for Enemy Group A, 150 units for Enemy Group C, not applicable for Enemy Group B). |
− | *# It is far enough away from the geyser ( | + | *# It is far enough away from the geyser (200 units for Enemy Group A, 150 units for Enemy Group C, not applicable for Enemy Group B). |
{{credits|[[User:Espyo|Espyo]], [[User:Jimble|Jimble]]}} | {{credits|[[User:Espyo|Espyo]], [[User:Jimble|Jimble]]}} | ||
− | == Weighted distribution == | + | ==Weighted distribution== |
− | Some types of object may come up more often than others. For instance, a developer could want a cave where the enemy slots are filled randomly, with each one having a 90% chance of being a Red Bulborb, and 10% chance of being a Wollywog. This is known as weighted random distribution. The way ''Pikmin 2'' does this is that every object | + | Some types of object may come up more often than others. For instance, a developer could want a cave where the enemy slots are filled randomly, with each one having a 90% chance of being a Red Bulborb, and 10% chance of being a Wollywog. This is known as weighted random distribution. The way ''Pikmin 2'' does this is that every object definition has a weight number that goes from 0 to 9. Any object definition with a weight of 0 will not be picked, though. |
− | To know what the chances are of the game picking a given | + | To know what the chances are of the game picking a given object, all of the weight numbers are summed up, and the chance of that object is <code><object's weight> / <sum></code>. So for example, if you have the following list: |
{| class="wikitable" | {| class="wikitable" |