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 1: | Line 1: | ||
− | This page explains the game's process behind spawning enemies in a cave. This is obtained through | + | This page explains the game's process behind spawning enemies in a cave. This is obtained through observation, and is subject to have some parts incorrect. |
− | {{ | + | {{note|Until further notice, this only applies to spawning enemies.}} |
− | == | + | ==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. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | ===Main algorithm=== |
− | + | # For each <code>TekiInfo</code> entry in the [[Cave definition file|sublevel's configuration]], in order... | |
+ | ## Run the [[#Spawn algorithm|spawn algorithm]] using this entry's class, minimum spawn amount, and spawn coordinate type. | ||
+ | # If the number of enemies hasn't reached <code>{f002}</code> yet... | ||
+ | ## For each <code>TekiInfo</code> entry in the sublevel's configuration... | ||
+ | ### Grab its random distribution weight and add it to a list. | ||
+ | ## While the number of enemies hasn't reached <code>{f002}</code>... | ||
+ | ### Randomly decide what enemy to spawn next, using the weighted list built in the previous step. | ||
+ | ### Store the enemy's type. | ||
+ | ### Store the spawn coordinate type. | ||
+ | ### Run the [[#Spawn algorithm|spawn algorithm]] using this entry's class, amount of 1, and this entry's spawn coordinate type. | ||
+ | # Remove every spawned object that is not meant to be there (collected treasures, Candypop Buds that disappear when you have 20+, etc.) | ||
− | === | + | ===Spawn algorithm=== |
− | + | This algorithm takes as parameters an object class, a spawn amount, and a spawn coordinate type. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | # While the intended amount of enemies hasn't been spawned yet... | |
− | + | ## Pick a [[#Coordinate check|valid spawn coordinate]] randomly. | |
+ | ## If there is no valid spawn coordinate remaining, leave this algorithm. | ||
+ | ## Mark this spawn coordinate as used. | ||
+ | ## Decide how many objects to spawn here, picking randomly between the spawn coordinate's amount limits. | ||
+ | ## For each one in that amount... | ||
+ | ### If the number of objects spawned here surpasses the intended amount, leave this algorithm. | ||
+ | ### Spawn that object in these coordinates (randomly translated inside the circle decided by the spawn coordinate's radius). | ||
− | + | ===Coordinate check=== | |
− | + | A spawn coordinate is valid if all of the following are true: | |
− | + | # It is not in a dead end cave unit. | |
− | # | + | # It is of the intended spawn coordinate type (Enemy Group A, Plant, etc.) |
− | # | + | # It is in-bounds. |
− | # | + | # It has not been used already. |
− | # | + | # It is farther than 300 units from the ship's pod. |
− | # | ||
− | + | ===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. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{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" |