Skip to content

Commit

Permalink
Merge pull request Revolutionary-Games#786 from Revolutionary-Games/6…
Browse files Browse the repository at this point in the history
…25-Reduce-Bacteria-Codedupe

Merged parts of spawnMicrobe and spawnBacteria
  • Loading branch information
hhyyrylainen authored May 14, 2019
2 parents b04eb71 + f54e1e1 commit 2497a77
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 159 deletions.
2 changes: 1 addition & 1 deletion scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
65 changes: 13 additions & 52 deletions scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -895,21 +895,18 @@ 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 != "");

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
Expand All @@ -918,6 +915,10 @@ ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in specie
microbePos.Marked = true;

auto physics = world.GetComponent_Physics(microbeEntity);

auto speciesEntity = findSpeciesEntityByName(world, speciesName);
auto species = world.GetComponent_SpeciesComponent(speciesEntity);

physics.JumpTo(microbePos);

// Try setting the position immediately as well (as otherwise it
Expand All @@ -927,58 +928,18 @@ ObjectID spawnMicrobe(CellStageWorld@ world, Float3 pos, const string &in specie
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
// Checks if the cell is a bacteria/prokaryote
if(species.isBacteria){
node.Scale = Float3(0.5, 0.5, 0.5);
node.Marked = true;
}

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;

// 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 *
// 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;
Expand Down
161 changes: 55 additions & 106 deletions scripts/microbe_stage/species_system.as
Original file line number Diff line number Diff line change
Expand Up @@ -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,isBacteria);


generateMembranes(parent);
generateMembranes(parent);


commonConstructor(world);
commonConstructor(world);


this.setupSpawn(world);
}
else
{
mutateBacteria(parent,world);
}
this.setupSpawn(world);
}

private void generateMembranes(SpeciesComponent@ parent){
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit 2497a77

Please sign in to comment.