Skip to content

Commit

Permalink
Ai now has the same base speed as the player, and average speed is no…
Browse files Browse the repository at this point in the history
…w displayed in the editor properly, also removed pointless artifact from old AI
  • Loading branch information
Untrustedlife committed Dec 17, 2018
1 parent 21e3a67 commit 751a95a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
13 changes: 13 additions & 0 deletions scripts/gui/microbe_editor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ export function setupMicrobeEditor(){
updateGeneration(vars.generation);
});

// Event for speed update
Leviathan.OnGeneric("SpeedUpdated", (event, vars) => {
// Apply the new values
updateSpeed(vars.speed);
});

// Event for undo setting
Leviathan.OnGeneric("EditorUndoButtonStatus", (event, vars) => {
// Apply the new values
Expand Down Expand Up @@ -277,6 +283,13 @@ function updateGeneration(generation){
generation;
}

//! Updates generation points in GUI
function updateSpeed(speed){
document.getElementById("speedLabel").textContent =
speed.toFixed(2);
}



function onResumeClickedEditor(){

Expand Down
2 changes: 1 addition & 1 deletion scripts/gui/thrive_gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<div id="species">SPECIES <div id="speciesNameBox" class="TextBox">
<span id="speciesName">Primum Thrivieum</span></div></div>
<div id="generation">GENERATION <span id="generationLabel">N/A</span></div>
<div id="speed">SPEED <span id="speedLabel">N/A</span></div>
<div id="speed">SPEED <span id="speedLabel">2.0</span></div>
<div id="size">SIZE <span id="sizeLabel">N/A</span></div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const auto REGENERATION_RATE = 1.0f;
const auto FLAGELLA_ENERGY_COST = 7.0f;
const auto FLAGELLA_BASE_FORCE = 0.5f;
const auto CELL_BASE_THRUST = 2.0f;
// is set by this and modified by applyCellMovement like the player later
const auto AI_BASE_MOVEMENT = 1.0f;
//! The drag force is calculated by taking the current velocity and multiplying it by this.
//! This must be negative!
const auto CELL_DRAG_MULTIPLIER = -0.1f;
Expand Down
9 changes: 4 additions & 5 deletions scripts/microbe_stage/microbe_ai.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const int OXYGEN_SEARCH_THRESHHOLD = 8;
const int GLUCOSE_SEARCH_THRESHHOLD = 5;
const float AI_MOVEMENT_SPEED = 0.5;

// microbes_number = {}

Expand Down Expand Up @@ -393,7 +392,7 @@ class MicrobeAISystem : ScriptSystem{
//Always set target Position, for use later in AI
if (aiComponent.speciesAggression+GetEngine().GetRandom().GetNumber(-100.0f,100.0f) > aiComponent.speciesActivity)
{
microbeComponent.movementDirection = Float3(0, 0, -AI_MOVEMENT_SPEED);
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
}
else
{
Expand Down Expand Up @@ -493,7 +492,7 @@ class MicrobeAISystem : ScriptSystem{
auto vec = (aiComponent.targetPosition - position._Position);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
microbeComponent.movementDirection = Float3(0, 0, -AI_MOVEMENT_SPEED);
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
aiComponent.hasTargetPosition = true;
}
else
Expand Down Expand Up @@ -540,7 +539,7 @@ class MicrobeAISystem : ScriptSystem{
auto vec = (aiComponent.targetPosition - position._Position);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
microbeComponent.movementDirection = Float3(0, 0, -AI_MOVEMENT_SPEED);
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
aiComponent.hasTargetPosition = true;

}
Expand Down Expand Up @@ -689,7 +688,7 @@ class MicrobeAISystem : ScriptSystem{
auto vec = (aiComponent.targetPosition - position._Position);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
microbeComponent.movementDirection = Float3(0, 0, -AI_MOVEMENT_SPEED);
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
aiComponent.hasTargetPosition = true;

}
Expand Down
21 changes: 21 additions & 0 deletions scripts/microbe_stage/microbe_editor/microbe_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ class MicrobeEditor{
actionHistory.insertAt(actionIndex,action);
actionIndex++;

//Only called when an action happens, because its an expensive method
hudSystem.updateSpeed();

}

//! \todo Clean this up
Expand Down Expand Up @@ -886,6 +889,24 @@ class MicrobeEditor{
{
return editedMicrobe.length();
}

// Make sure this is only called when you add organelles, as it is an expensive
double getMicrobeSpeed() const
{
double finalSpeed = 0;
int flagCount=0;
double lengthMicrobe = double(editedMicrobe.length());
for(uint i = 0; i < editedMicrobe.length(); ++i){
auto organelle = cast<PlacedOrganelle>(editedMicrobe[i]);
auto name = organelle.organelle.name;
if (name=="flagellum"){
flagCount++;
}
}
//This is complex, i Know
finalSpeed= CELL_BASE_THRUST+((flagCount/lengthMicrobe)*FLAGELLA_BASE_FORCE)-(CELL_DRAG_MULTIPLIER+(CELL_SIZE_DRAG_MULTIPLIER*lengthMicrobe));
return finalSpeed;
}
// Maybe i should do this in the non-editor code instead, to make sure its more decoupled from the player
int getMicrobeGeneration() const
{
Expand Down
10 changes: 10 additions & 0 deletions scripts/microbe_stage/microbe_editor/microbe_editor_hud.as
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ class MicrobeEditorHudSystem : ScriptSystem{
GetEngine().GetEventHandler().CallEvent(event);
}

void updateSpeed()
{
// Number of Flagella / total number of organelles
GenericEvent@ event = GenericEvent("SpeedUpdated");
NamedVars@ vars = event.GetNamedVars();

vars.AddValue(ScriptSafeVariableBlock("speed", editor.getMicrobeSpeed()));
GetEngine().GetEventHandler().CallEvent(event);
}

MicrobeEditorWorld@ world
{
get
Expand Down
8 changes: 4 additions & 4 deletions scripts/microbe_stage/species_system.as
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,19 @@ class Species{
}
if (GetEngine().GetRandom().GetNumber(0,100) < 50) {
this.speciesMembraneType = MEMBRANE_TYPE::WALL;

} else if (GetEngine().GetRandom().GetNumber(0,100) < 50) {
this.speciesMembraneType = MEMBRANE_TYPE::CHITIN;
this.colour.W = randomOpacityChitin();

} else if (GetEngine().GetRandom().GetNumber(0,100) < 50) {
this.speciesMembraneType = MEMBRANE_TYPE::MEMBRANE;

} else {
this.speciesMembraneType = MEMBRANE_TYPE::DOUBLEMEMBRANE;
this.colour.W = randomOpacityChitin();
}

commonConstructor(world);
this.setupSpawn(world);
}
Expand Down

0 comments on commit 751a95a

Please sign in to comment.