diff --git a/scripts/microbe_stage/organelle_table.lua b/scripts/microbe_stage/organelle_table.lua index 4f5ed5e8fed..7b489c2f5f4 100644 --- a/scripts/microbe_stage/organelle_table.lua +++ b/scripts/microbe_stage/organelle_table.lua @@ -21,6 +21,9 @@ Organelle atributes: gene: The letter that will be used by the auto-evo system to identify this organelle. + chanceToCreate: The (relative) chance this organelle will appear in a randomly + generated or mutated microbe (to do roulette selection). + processes: A table with all the processes this organelle does, and the capacity of the process (the amount of process that can be made in one second). @@ -35,6 +38,7 @@ organelleTable = { ["nucleus"] = { mass = 0.7, gene = "N", + chanceToCreate = 0, -- Not randomly generated. components = { ["NucleusOrganelle"] = {} @@ -74,6 +78,7 @@ organelleTable = { mass = 0.1, gene = "Y", + chanceToCreate = 1, mpCost = 5, mesh = nil, --it's an empty hex hexes = { @@ -102,6 +107,7 @@ organelleTable = { mass = 0.4, gene = "H", + chanceToCreate = 2, mpCost = 20, mesh = "chloroplast.mesh", hexes = { @@ -131,6 +137,7 @@ organelleTable = { mass = 0.3, gene = "T", + chanceToCreate = 1, mpCost = 40, mesh = "oxytoxy.mesh", hexes = { @@ -157,6 +164,7 @@ organelleTable = { mass = 0.3, gene = "M", + chanceToCreate = 3, mpCost = 20, mesh = "mitochondrion.mesh", hexes = { @@ -180,6 +188,7 @@ organelleTable = { mass = 0.4, gene = "V", + chanceToCreate = 3, mpCost = 15, mesh = "vacuole.mesh", hexes = { @@ -203,6 +212,7 @@ organelleTable = { mass = 0.3, gene = "F", + chanceToCreate = 3, mpCost = 25, mesh = "flagellum.mesh", hexes = { diff --git a/scripts/microbe_stage/procedural_microbes.lua b/scripts/microbe_stage/procedural_microbes.lua index baccc787ce0..397fc63e314 100644 --- a/scripts/microbe_stage/procedural_microbes.lua +++ b/scripts/microbe_stage/procedural_microbes.lua @@ -1,27 +1,42 @@ ---limits the size of the initial stringCodes +-- Limits the size of the initial stringCodes local MIN_INITIAL_LENGTH = 5 local MAX_INITIAL_LENGTH = 15 +local MAX_CHANCE_SCORE = 0 organelleLetters = {} -VALID_LETTERS = {} +VALID_ORGANELLES = {} ---Getting the organelle letters from the organelle table. for organelleName, organelleInfo in pairs(organelleTable) do + -- Getting the organelle letters from the organelle table. organelleLetters[organelleInfo.gene] = organelleName if organelleInfo.components.NucleusOrganelle == nil then - table.insert(VALID_LETTERS, organelleInfo.gene) + table.insert(VALID_ORGANELLES, organelleName) + + -- Getting the max chance score for the roulette selection. + MAX_CHANCE_SCORE = MAX_CHANCE_SCORE + organelleInfo.chanceToCreate end end ---returns a random organelle letter +-- Returns a random organelle letter function getRandomLetter() - return VALID_LETTERS[math.random(1, #VALID_LETTERS)] + i = math.random(0, MAX_CHANCE_SCORE) + + for _, organelleName in pairs(VALID_ORGANELLES) do + i = i - organelleTable[organelleName].chanceToCreate + + if i <= 0 then + return organelleTable[organelleName].gene + end + end + + -- Just in case + return organelleTable["cytoplasm"].gene end ---checks whether an organelle in a certain position would fit within a list of other organelles. +-- Checks whether an organelle in a certain position would fit within a list of other organelles. function isValidPlacement(organelleName, q, r, rotation, organelleList) - --this is super hacky :/ + -- This is super hacky :/ local data = { ["name"] = organelleName, ["q"] = q, @@ -45,14 +60,14 @@ function isValidPlacement(organelleName, q, r, rotation, organelleList) return true end ---finds a valid position to place the organelle and returns it ---maybe the values should be saved? +-- Finds a valid position to place the organelle and returns it +-- Maybe the values should be saved? function getPosition(organelleName, organelleList) local q = 0 local r = 0 - --Checks whether the center is free. + -- Checks whether the center is free. for j = 0, 5 do rotation = 360 * j / 6 if isValidPlacement(organelleName, q, r, rotation, organelleList) then @@ -60,29 +75,29 @@ function getPosition(organelleName, organelleList) end end - --Moving the center one hex to the bottom. - --This way organelles are "encouraged" to be on the bottom, rather than on the top, - --which in turn means the flagellum are more likely to be on the back side of the cell. + -- Moving the center one hex to the bottom. + -- This way organelles are "encouraged" to be on the bottom, rather than on the top, + -- which in turn means the flagellum are more likely to be on the back side of the cell. q = q + HEX_NEIGHBOUR_OFFSET[HEX_SIDE.BOTTOM][1] r = r + HEX_NEIGHBOUR_OFFSET[HEX_SIDE.BOTTOM][2] - --Spiral search for space for the organelle + -- Spiral search for space for the organelle local radius = 1 while true do - --Moves into the ring of radius "radius" and center (0, -1) + -- Moves into the ring of radius "radius" and center (0, -1) q = q + HEX_NEIGHBOUR_OFFSET[HEX_SIDE.BOTTOM_LEFT][1] r = r + HEX_NEIGHBOUR_OFFSET[HEX_SIDE.BOTTOM_LEFT][2] - --Iterates in the ring - for side = 1, 6 do --necesary due to lua not ordering the tables. + --I terates in the ring + for side = 1, 6 do -- Necesary due to lua not ordering the tables. local offset = HEX_NEIGHBOUR_OFFSET[side] - --Moves "radius" times into each direction + -- Moves "radius" times into each direction for i = 1, radius do q = q + offset[1] r = r + offset[2] --print(q, r) - --Checks every possible rotation value. + -- Checks every possible rotation value. for j = 0, 5 do rotation = 360 * j / 6 if isValidPlacement(organelleName, q, r, rotation, organelleList) then @@ -95,7 +110,7 @@ function getPosition(organelleName, organelleList) end end ---creates a list of organelles from the stringCode. +-- Creates a list of organelles from the stringCode. function positionOrganelles(stringCode) local organelleList = {{ ["name"] = organelleLetters[string.sub(stringCode, 1, 1)],