Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Revolutionary-Games/Thrive
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyyrylainen committed Jun 4, 2017
2 parents 1c19d60 + 6735f4d commit bd63584
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
10 changes: 10 additions & 0 deletions scripts/microbe_stage/organelle_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -35,6 +38,7 @@ organelleTable = {
["nucleus"] = {
mass = 0.7,
gene = "N",
chanceToCreate = 0, -- Not randomly generated.

components = {
["NucleusOrganelle"] = {}
Expand Down Expand Up @@ -74,6 +78,7 @@ organelleTable = {

mass = 0.1,
gene = "Y",
chanceToCreate = 1,
mpCost = 5,
mesh = nil, --it's an empty hex
hexes = {
Expand Down Expand Up @@ -102,6 +107,7 @@ organelleTable = {

mass = 0.4,
gene = "H",
chanceToCreate = 2,
mpCost = 20,
mesh = "chloroplast.mesh",
hexes = {
Expand Down Expand Up @@ -131,6 +137,7 @@ organelleTable = {

mass = 0.3,
gene = "T",
chanceToCreate = 1,
mpCost = 40,
mesh = "oxytoxy.mesh",
hexes = {
Expand All @@ -157,6 +164,7 @@ organelleTable = {

mass = 0.3,
gene = "M",
chanceToCreate = 3,
mpCost = 20,
mesh = "mitochondrion.mesh",
hexes = {
Expand All @@ -180,6 +188,7 @@ organelleTable = {

mass = 0.4,
gene = "V",
chanceToCreate = 3,
mpCost = 15,
mesh = "vacuole.mesh",
hexes = {
Expand All @@ -203,6 +212,7 @@ organelleTable = {

mass = 0.3,
gene = "F",
chanceToCreate = 3,
mpCost = 25,
mesh = "flagellum.mesh",
hexes = {
Expand Down
57 changes: 36 additions & 21 deletions scripts/microbe_stage/procedural_microbes.lua
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -45,44 +60,44 @@ 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
return q, r, rotation
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
Expand All @@ -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)],
Expand Down

0 comments on commit bd63584

Please sign in to comment.