From 9ff472d7047420d6bc400ec110c5c76f4fd9f3ec Mon Sep 17 00:00:00 2001 From: 1n48yg <37918520+1n48yg@users.noreply.github.com> Date: Sat, 11 May 2019 11:59:07 -0700 Subject: [PATCH 1/2] Merged parts of spawnMicrobe and spawnBacteria Removed unused code and removed a duplicate function that somehow exists Removed spawnbacteria entirely and combined everything into spawnMicrobe Removed random comment No idea how this got here Combined the duplicated mutation code into one function As suggested by Untrustedlife Ran ruby reformatting script Made requested changes --- scripts/microbe_stage/microbe_operations.as | 70 +++------ scripts/microbe_stage/species_system.as | 161 +++++++------------- 2 files changed, 73 insertions(+), 158 deletions(-) diff --git a/scripts/microbe_stage/microbe_operations.as b/scripts/microbe_stage/microbe_operations.as index 9b5902f25b5..2d90f864679 100644 --- a/scripts/microbe_stage/microbe_operations.as +++ b/scripts/microbe_stage/microbe_operations.as @@ -895,10 +895,8 @@ bool validPlacement(CellStageWorld@ world, ObjectID microbeEntity, const Organel return touching; } -// speciesName decides the template to use, while individualName is -// used for referencing the instance ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in speciesName, - bool aiControlled) + bool aiControlled, bool partOfColony = false) { assert(world !is null); assert(speciesName != ""); @@ -906,10 +904,9 @@ ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in specie if(pos.Y != 0) LOG_WARNING("spawnMicrobe: spawning at y-coordinate: " + pos.Y); - // Create microbeEntity with correct template, physics and species name auto microbeEntity = _createMicrobeEntity(world, aiControlled, speciesName, - // in_editor + //in editor false); // Teleport the cell to the right position @@ -918,67 +915,36 @@ ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in specie microbePos.Marked = true; auto physics = world.GetComponent_Physics(microbeEntity); - physics.JumpTo(microbePos); - - // Try setting the position immediately as well (as otherwise it - // takes until the next tick for this to take effect) - auto node = world.GetComponent_RenderNode(microbeEntity); - - if(IsInGraphicalMode()) - node.Node.setPosition(pos); auto speciesEntity = findSpeciesEntityByName(world, speciesName); auto species = world.GetComponent_SpeciesComponent(speciesEntity); - // TODO: Why is this here with the separate spawnBacteria function existing? - // Bacteria get scaled to half size - if(species.isBacteria){ - node.Scale = Float3(0.5, 0.5, 0.5); - node.Marked = true; + if (species.isBacteria) + { + physics.Body.SetMass(physics.Body.Mass * 10); } - return microbeEntity; -} - -// TODO: merge common parts with spawnMicrobe -ObjectID spawnBacteria(CellStageWorld@ world, Float3 pos, const string &in speciesName, - bool aiControlled, bool partOfColony) -{ - assert(world !is null); - assert(speciesName != ""); - - if(pos.Y != 0) - LOG_WARNING("spawnBacteria: spawning at y-coordinate: " + pos.Y); - - // Create microbeEntity with correct template, physics and species name - auto microbeEntity = _createMicrobeEntity(world, aiControlled, speciesName, - // in_editor - false); - - // Teleport the cell to the right position - auto microbePos = world.GetComponent_Position(microbeEntity); - microbePos._Position = pos; - microbePos.Marked = true; - - auto physics = world.GetComponent_Physics(microbeEntity); - physics.Body.SetMass(physics.Body.Mass * 10); physics.JumpTo(microbePos); // Try setting the position immediately as well (as otherwise it // takes until the next tick for this to take effect) auto node = world.GetComponent_RenderNode(microbeEntity); - node.Node.setPosition(pos); - // Bacteria get scaled to half size - node.Scale = Float3(0.5, 0.5, 0.5); - node.Marked = true; + if(IsInGraphicalMode()) + node.Node.setPosition(pos); - // Need to set bacteria spawn and it needs to be squared like it - // is in the spawn system. code, if part of colony but not - // directly spawned give a spawned component - if (partOfColony){ - world.Create_SpawnedComponent(microbeEntity, BACTERIA_SPAWN_RADIUS * + // Checks if the cell is a bacteria/prokaryote + if(species.isBacteria){ + node.Scale = Float3(0.5, 0.5, 0.5); + node.Marked = true; + + // Need to set bacteria spawn and it needs to be squared like it + // is in the spawn system. code, if part of colony but not + // directly spawned give a spawned component + if (partOfColony){ + world.Create_SpawnedComponent(microbeEntity, BACTERIA_SPAWN_RADIUS * BACTERIA_SPAWN_RADIUS); + } } return microbeEntity; diff --git a/scripts/microbe_stage/species_system.as b/scripts/microbe_stage/species_system.as index b0d0dc0ccd0..b99c85d0a22 100644 --- a/scripts/microbe_stage/species_system.as +++ b/scripts/microbe_stage/species_system.as @@ -337,66 +337,72 @@ class Species{ { this.isBacteria = parent.isBacteria; LOG_INFO("Gene Code Is:"+parent.stringCode); + if (!isBacteria) { name = randomSpeciesName(); + } + else { + name = randomBacteriaName(); + } - //Mutate the epithet - if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ - epithet = mutateWord(parent.epithet); - } - else { + //Mutate the epithet + if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ + epithet = mutateWord(parent.epithet); + } + else { epithet = generateNameSection(); - } - genus = parent.genus; - colour=parent.colour; - mutateBehavior(parent); + } + genus = parent.genus; + colour=parent.colour; + mutateBehavior(parent); - // Make sure not over or under our scales - cleanPersonality(); + // Make sure not over or under our scales + cleanPersonality(); - // Subtly mutate color - this.colour = Float4(parent.colour.X + randomMutationColourChannel(), - parent.colour.Y + randomMutationColourChannel(), - parent.colour.Z + randomMutationColourChannel(), - parent.colour.W + randomMutationColourChannel()); + // Subtly mutate color + this.colour = Float4(parent.colour.X + randomMutationColourChannel(), + parent.colour.Y + randomMutationColourChannel(), + parent.colour.Z + randomMutationColourChannel(), + parent.colour.W + randomMutationColourChannel()); - LOG_INFO("X:"+parent.colour.X+" Y:"+parent.colour.Y+" Z:"+parent.colour.Z+" W:"+parent.colour.W); - LOG_INFO("X:"+colour.X+" Y:"+colour.Y+" Z:"+colour.Z+" W:"+colour.W); - // Chance of new color needs to be low - if (GetEngine().GetRandom().GetNumber(0,100) <= MUTATION_CHANGE_GENUS) + LOG_INFO("X:"+parent.colour.X+" Y:"+parent.colour.Y+" Z:"+parent.colour.Z+" W:"+parent.colour.W); + LOG_INFO("X:"+colour.X+" Y:"+colour.Y+" Z:"+colour.Z+" W:"+colour.W); + // Chance of new color needs to be low + if (GetEngine().GetRandom().GetNumber(0,100) <= MUTATION_CHANGE_GENUS) + { + if (!isBacteria) { LOG_INFO("New Genus"); - // We can do more fun stuff here later - if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ - genus = mutateWord(parent.genus); - } - else { - genus = generateNameSection(); - } - // New genuses get to double their color change - this.colour = Float4(parent.colour.X + randomMutationColourChannel(), - parent.colour.Y + randomMutationColourChannel(), - parent.colour.Z + randomMutationColourChannel(), - parent.colour.W + randomMutationColourChannel()); + }else { + LOG_INFO("New Genus of Bacteria"); + } + + // We can do more fun stuff here later + if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ + genus = mutateWord(parent.genus); } + else { + genus = generateNameSection(); + } + // New genuses get to double their color change + this.colour = Float4(parent.colour.X + randomMutationColourChannel(), + parent.colour.Y + randomMutationColourChannel(), + parent.colour.Z + randomMutationColourChannel(), + parent.colour.W + randomMutationColourChannel()); + } - this.stringCode = mutateMicrobe(parent.stringCode,false); + this.stringCode = mutateMicrobe(parent.stringCode,false); - generateMembranes(parent); + generateMembranes(parent); - commonConstructor(world); + commonConstructor(world); - this.setupSpawn(world); - } - else - { - mutateBacteria(parent,world); - } + this.setupSpawn(world); } private void generateMembranes(SpeciesComponent@ parent){ @@ -509,7 +515,7 @@ class Species{ //dont spawn them on top of each other because it //causes them to bounce around and lag - MicrobeOperations::spawnBacteria(world, pos + curSpawn, this.name, true, true); + MicrobeOperations::spawnMicrobe(world, pos + curSpawn, this.name, true, true); curSpawn = curSpawn + Float3(GetEngine().GetRandom().GetNumber(-7, 7), 0, GetEngine().GetRandom().GetNumber(-7, 7)); } @@ -528,7 +534,7 @@ class Species{ // Dont spawn them on top of each other because it // Causes them to bounce around and lag - MicrobeOperations::spawnBacteria(world, pos+curSpawn, this.name, true, true); + MicrobeOperations::spawnMicrobe(world, pos+curSpawn, this.name, true, true); curSpawn = curSpawn + Float3(lineX + GetEngine().GetRandom().GetNumber(-2, 2), 0, linez + GetEngine().GetRandom().GetNumber(-2, 2)); } @@ -560,7 +566,7 @@ class Species{ // Add a litlle organicness to the look curSpawn.Z += GetEngine().GetRandom().GetNumber(-2, 2); - MicrobeOperations::spawnBacteria(world, pos + curSpawn, this.name, + MicrobeOperations::spawnMicrobe(world, pos + curSpawn, this.name, true, true); } } @@ -573,7 +579,7 @@ class Species{ curSpawn.Z += GetEngine().GetRandom().GetNumber(5,7); // Add a litlle organicness to the look curSpawn.X += GetEngine().GetRandom().GetNumber(-2,2); - MicrobeOperations::spawnBacteria(world, pos+curSpawn, this.name, true, + MicrobeOperations::spawnMicrobe(world, pos+curSpawn, this.name, true, true); } } @@ -590,7 +596,7 @@ class Species{ curSpawn.X -= GetEngine().GetRandom().GetNumber(5, 7); // Add a litlle organicness to the look curSpawn.Z -= GetEngine().GetRandom().GetNumber(-2, 2); - MicrobeOperations::spawnBacteria(world, pos + curSpawn, this.name, + MicrobeOperations::spawnMicrobe(world, pos + curSpawn, this.name, true, true); } } @@ -606,7 +612,7 @@ class Species{ curSpawn.Z -= GetEngine().GetRandom().GetNumber(5, 7); //add a litlle organicness to the look curSpawn.X -= GetEngine().GetRandom().GetNumber(-2, 2); - MicrobeOperations::spawnBacteria(world, pos+curSpawn, this.name, true, + MicrobeOperations::spawnMicrobe(world, pos+curSpawn, this.name, true, true); } } @@ -622,14 +628,14 @@ class Species{ // Causes them to bounce around and lag curSpawn.Z += GetEngine().GetRandom().GetNumber(5, 7); curSpawn.X += GetEngine().GetRandom().GetNumber(5, 7); - MicrobeOperations::spawnBacteria(world, pos + curSpawn, this.name, + MicrobeOperations::spawnMicrobe(world, pos + curSpawn, this.name, true, true); } } } } - return MicrobeOperations::spawnBacteria(world, pos, this.name, true, false); + return MicrobeOperations::spawnMicrobe(world, pos, this.name, true); } // Sets up the spawn of the species @@ -657,63 +663,6 @@ class Species{ BACTERIA_SPAWN_RADIUS); } - void mutateBacteria(SpeciesComponent@ parent, CellStageWorld@ world) - { - name = randomBacteriaName(); - genus = parent.genus; - colour=parent.colour; - //Mutate the epithet - if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ - epithet = mutateWord(parent.epithet); - } - else { - epithet = generateNameSection(); - } - - - mutateBehavior(parent); - - // Make sure not over or under our scales - cleanPersonality(); - - // Subtly mutate color - this.colour = Float4(parent.colour.X + randomMutationColourChannel(), - parent.colour.Y + randomMutationColourChannel(), - parent.colour.Z + randomMutationColourChannel(), - parent.colour.W + randomMutationColourChannel()); - - - LOG_INFO("X:"+parent.colour.X+" Y:"+parent.colour.Y+" Z:"+parent.colour.Z+" W:"+parent.colour.W); - LOG_INFO("X:"+colour.X+" Y:"+colour.Y+" Z:"+colour.Z+" W:"+colour.W); - - if (GetEngine().GetRandom().GetNumber(0,100) <= MUTATION_CHANGE_GENUS) - { - LOG_INFO("New Genus of bacteria"); - - // We can do more fun stuff here later - //Mutate the genus - if (GetEngine().GetRandom().GetNumber(0, 100) < MUTATION_WORD_EDIT){ - genus = mutateWord(parent.genus); - } - else { - genus = generateNameSection(); - } - - // New genuses get to double color change - this.colour = Float4(parent.colour.X + randomMutationColourChannel(), - parent.colour.Y + randomMutationColourChannel(), - parent.colour.Z + randomMutationColourChannel(), - parent.colour.W + randomMutationColourChannel()); - } - - this.stringCode = mutateMicrobe(parent.stringCode,true); - - generateMembranes(parent); - - commonConstructor(world); - this.setupSpawn(world); - } - //! updates the population count of the species void updatePopulation() { From f54e1e159bb0ee342c593ba792d66ed88c05f1a8 Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Mon, 13 May 2019 20:06:11 -0500 Subject: [PATCH 2/2] mutateCode now takes in isBacteria commented out setMass code for now. It was hacky anyway. ai no longer has speed boost (the x10 was what was causing the issue previously) just got rid of redundant if statement completely --- scripts/microbe_stage/configs.as | 2 +- scripts/microbe_stage/microbe_operations.as | 5 ----- scripts/microbe_stage/species_system.as | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/microbe_stage/configs.as b/scripts/microbe_stage/configs.as index 3930895c47a..6ec8c24bf70 100644 --- a/scripts/microbe_stage/configs.as +++ b/scripts/microbe_stage/configs.as @@ -112,7 +112,7 @@ const auto FLAGELLA_BASE_FORCE = 0.7f; const auto CELL_BASE_THRUST = 1.6f; // is set by this and modified by applyCellMovement like the player later -const auto AI_BASE_MOVEMENT = 1.6f; +const auto AI_BASE_MOVEMENT = 1.0f; const auto AI_FOCUSED_MOVEMENT = 1.0f; //! The drag force is calculated by taking the current velocity and multiplying it by this. diff --git a/scripts/microbe_stage/microbe_operations.as b/scripts/microbe_stage/microbe_operations.as index 2d90f864679..eb69cdac8b1 100644 --- a/scripts/microbe_stage/microbe_operations.as +++ b/scripts/microbe_stage/microbe_operations.as @@ -919,11 +919,6 @@ ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in specie auto speciesEntity = findSpeciesEntityByName(world, speciesName); auto species = world.GetComponent_SpeciesComponent(speciesEntity); - if (species.isBacteria) - { - physics.Body.SetMass(physics.Body.Mass * 10); - } - physics.JumpTo(microbePos); // Try setting the position immediately as well (as otherwise it diff --git a/scripts/microbe_stage/species_system.as b/scripts/microbe_stage/species_system.as index b99c85d0a22..6eb50d18349 100644 --- a/scripts/microbe_stage/species_system.as +++ b/scripts/microbe_stage/species_system.as @@ -393,7 +393,7 @@ class Species{ parent.colour.W + randomMutationColourChannel()); } - this.stringCode = mutateMicrobe(parent.stringCode,false); + this.stringCode = mutateMicrobe(parent.stringCode,isBacteria); generateMembranes(parent);