From 751a95afe7d245da8864ce4cf88d8d384bd32ea2 Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Sun, 16 Dec 2018 18:26:31 -0600 Subject: [PATCH] Ai now has the same base speed as the player, and average speed is now displayed in the editor properly, also removed pointless artifact from old AI --- scripts/gui/microbe_editor.mjs | 13 ++++++++++++ scripts/gui/thrive_gui.html | 2 +- scripts/microbe_stage/configs.as | 2 ++ scripts/microbe_stage/microbe_ai.as | 9 ++++---- .../microbe_editor/microbe_editor.as | 21 +++++++++++++++++++ .../microbe_editor/microbe_editor_hud.as | 10 +++++++++ scripts/microbe_stage/species_system.as | 8 +++---- 7 files changed, 55 insertions(+), 10 deletions(-) diff --git a/scripts/gui/microbe_editor.mjs b/scripts/gui/microbe_editor.mjs index 56b4d10cfb9..1365212d161 100644 --- a/scripts/gui/microbe_editor.mjs +++ b/scripts/gui/microbe_editor.mjs @@ -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 @@ -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(){ diff --git a/scripts/gui/thrive_gui.html b/scripts/gui/thrive_gui.html index 07b47119eb9..c1a2357c938 100644 --- a/scripts/gui/thrive_gui.html +++ b/scripts/gui/thrive_gui.html @@ -400,7 +400,7 @@
SPECIES
Primum Thrivieum
GENERATION N/A
-
SPEED N/A
+
SPEED 2.0
SIZE N/A
diff --git a/scripts/microbe_stage/configs.as b/scripts/microbe_stage/configs.as index 407f780b966..e1a7f742b0e 100644 --- a/scripts/microbe_stage/configs.as +++ b/scripts/microbe_stage/configs.as @@ -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; diff --git a/scripts/microbe_stage/microbe_ai.as b/scripts/microbe_stage/microbe_ai.as index 89e8c65f5a1..9c8b32876a2 100644 --- a/scripts/microbe_stage/microbe_ai.as +++ b/scripts/microbe_stage/microbe_ai.as @@ -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 = {} @@ -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 { @@ -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 @@ -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; } @@ -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; } diff --git a/scripts/microbe_stage/microbe_editor/microbe_editor.as b/scripts/microbe_stage/microbe_editor/microbe_editor.as index f90881e6011..cfed404eebd 100644 --- a/scripts/microbe_stage/microbe_editor/microbe_editor.as +++ b/scripts/microbe_stage/microbe_editor/microbe_editor.as @@ -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 @@ -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(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 { diff --git a/scripts/microbe_stage/microbe_editor/microbe_editor_hud.as b/scripts/microbe_stage/microbe_editor/microbe_editor_hud.as index 24fd68d0bfe..fe22687cc1e 100644 --- a/scripts/microbe_stage/microbe_editor/microbe_editor_hud.as +++ b/scripts/microbe_stage/microbe_editor/microbe_editor_hud.as @@ -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 diff --git a/scripts/microbe_stage/species_system.as b/scripts/microbe_stage/species_system.as index d556b11c542..afe160031d8 100644 --- a/scripts/microbe_stage/species_system.as +++ b/scripts/microbe_stage/species_system.as @@ -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); }