Skip to content

Commit

Permalink
Merge pull request #187 from Revolutionary-Games/159-mutation-points
Browse files Browse the repository at this point in the history
Working mutation points
  • Loading branch information
jjonj committed Jul 30, 2014
2 parents fd8ab94 + 586de44 commit a11a98c
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 17 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ install(DIRECTORY
PATTERN "*.xml"
)

# Create directory tree that thrive requires
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin/creations)
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin/creations/microbe)
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin/creations/multicellular)

# Install Runtime Libraries
if(WIN32)

Expand Down
2 changes: 1 addition & 1 deletion assets/definitions/processes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Output compound="atp" amount="36"/>
</Outputs>
</Process>
<Process name="ReproductaseSynthesis" speedFactor="0.2" energyCost="6">
<Process name="ReproductaseSynthesis" speedFactor="0.3" energyCost="6">
<Inputs>
<Input compound="aminoacids" amount="6"/>
<Input compound="glucose" amount="6"/>
Expand Down
28 changes: 20 additions & 8 deletions scripts/microbe_editor/microbe_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function MicrobeEditor:__init(hudSystem)
self.hudSystem = hudSystem
self.nextMicrobeEntity = nil
self.lockedMap = nil
self.mutationPoints = 100
self.placementFunctions = {["nucleus"] = MicrobeEditor.createNewMicrobe,
["flagelium"] = MicrobeEditor.addMovementOrganelle,
["mitochondria"] = MicrobeEditor.addProcessOrganelle,
Expand All @@ -35,6 +36,7 @@ function MicrobeEditor:activate()
Engine:playerData():setBool("edited_microbe", true)
Engine:playerData():setActiveCreature(self.nextMicrobeEntity.id, GameState.MICROBE_EDITOR)
end
self.mutationPoints = 100
end

function MicrobeEditor:update(milliseconds)
Expand All @@ -55,6 +57,16 @@ function MicrobeEditor:update(milliseconds)
organelle:_updateHexColours()
end
end
self.hudSystem:updateMutationPoints()
end

function MicrobeEditor:takeMutationPoints(amount)
if amount <= self.mutationPoints then
self.mutationPoints = self.mutationPoints - amount
return true
else
return false
end
end

function MicrobeEditor:performLocationAction()
Expand Down Expand Up @@ -82,7 +94,7 @@ function MicrobeEditor:removeOrganelle()
local q, r = self:getMouseHex()
if not (q == 0 and r == 0) then -- Don't remove nucleus
local organelle = self.currentMicrobe:getOrganelleAt(q,r)
if organelle then
if organelle and self:takeMutationPoints(10) then
self.currentMicrobe:removeOrganelle(organelle.position.q ,organelle.position.r )
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
Expand All @@ -94,7 +106,7 @@ end
function MicrobeEditor:addStorageOrganelle(organelleType)
-- self.currentMicrobe = Microbe(Entity("working_microbe", GameState.MICROBE))
local q, r = self:getMouseHex()
if self.currentMicrobe:getOrganelleAt(q, r) == nil then
if self.currentMicrobe:getOrganelleAt(q, r) == nil and self:takeMutationPoints(Organelle.mpCosts["vacuole"]) then
self.currentMicrobe:addOrganelle(q, r, OrganelleFactory.make_vacuole({}))
self.organelleCount = self.organelleCount + 1
end
Expand All @@ -104,7 +116,7 @@ end
function MicrobeEditor:addMovementOrganelle(organelleType)
local q, r = self:getMouseHex()
local data = {["q"]=q, ["r"]=r}
if self.currentMicrobe:getOrganelleAt(q, r) == nil then
if self.currentMicrobe:getOrganelleAt(q, r) == nil and self:takeMutationPoints(Organelle.mpCosts["flagellum"]) then
self.currentMicrobe:addOrganelle(q,r, OrganelleFactory.make_flagellum(data))
self.organelleCount = self.organelleCount + 1
end
Expand All @@ -114,12 +126,10 @@ function MicrobeEditor:addProcessOrganelle(organelleType)
local q, r = self:getMouseHex()
if self.currentMicrobe:getOrganelleAt(q, r) == nil then

if organelleType == "mitochondria" then
if organelleType == "mitochondria" and self:takeMutationPoints(Organelle.mpCosts["mitochondrion"]) then
self.currentMicrobe:addOrganelle(q,r, OrganelleFactory.make_mitochondrion({}))
elseif organelleType == "chloroplast" then
elseif organelleType == "chloroplast" and self:takeMutationPoints(Organelle.mpCosts["chloroplast"]) then
self.currentMicrobe:addOrganelle(q,r, OrganelleFactory.make_chloroplast({}))
else
assert(false, "organelleType did not exist")
end
end
self.organelleCount = self.organelleCount + 1
Expand All @@ -128,7 +138,7 @@ end
function MicrobeEditor:addAgentVacuole(organelleType)
if organelleType == "toxin" then
local q, r = self:getMouseHex()
if self.currentMicrobe:getOrganelleAt(q, r) == nil then
if self.currentMicrobe:getOrganelleAt(q, r) == nil and self:takeMutationPoints(Organelle.mpCosts["oxytoxy"]) then
self.currentMicrobe:addOrganelle(q, r, OrganelleFactory.make_oxytoxy({}))
self.organelleCount = self.organelleCount + 1
end
Expand All @@ -152,6 +162,7 @@ function MicrobeEditor:loadMicrobe(entityId)
self.currentMicrobe.sceneNode.transform:touch()
self.currentMicrobe.collisionHandler:addCollisionGroup("powerupable")
Engine:playerData():setActiveCreature(entityId, GameState.MICROBE_EDITOR)
self.mutationPoints = 0
end

function MicrobeEditor:createNewMicrobe()
Expand All @@ -165,5 +176,6 @@ function MicrobeEditor:createNewMicrobe()
self.currentMicrobe.sceneNode.transform:touch()
self.currentMicrobe.collisionHandler:addCollisionGroup("powerupable")
self:addNucleus()
self.mutationPoints = 100
Engine:playerData():setActiveCreature(self.currentMicrobe.entity.id, GameState.MICROBE_EDITOR)
end
8 changes: 8 additions & 0 deletions scripts/microbe_editor/microbe_editor_hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function MicrobeEditorHudSystem:init(gameState)
sceneNode.meshName = "hex.mesh"
self.hoverHex:addComponent(sceneNode)
local root = gameState:rootGUIWindow()
self.mpLabel = root:getChild("BottomSection"):getChild("MutationPoints"):getChild("MPBar"):getChild("NumberLabel")
self.mpProgressBar = root:getChild("BottomSection"):getChild("MutationPoints"):getChild("MPBar")
local nucleusButton = root:getChild("EditorTools"):getChild("NucleusItem")
local flageliumButton = root:getChild("EditorTools"):getChild("FlageliumItem")
local mitochondriaButton = root:getChild("EditorTools"):getChild("MitochondriaItem")
Expand Down Expand Up @@ -139,6 +141,12 @@ function MicrobeEditorHudSystem:update(milliseconds)
end


function MicrobeEditorHudSystem:updateMutationPoints()
self.mpProgressBar:progressbarSetProgress(self.editor.mutationPoints/100)
self.mpLabel:setText("" .. self.editor.mutationPoints)
end


-- Event handlers
function nucleusClicked()
if global_activeMicrobeEditorHudSystem.activeButton ~= nil then
Expand Down
2 changes: 2 additions & 0 deletions scripts/microbe_stage/agent_vacuole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function AgentVacuole:load(storage)
self.process = process
end

Organelle.mpCosts["oxytoxy"] = 40

-- factory functions
function OrganelleFactory.make_oxytoxy(data)
local agentVacuole = AgentVacuole(CompoundRegistry.getCompoundId("oxytoxy"), global_processMap["OxyToxySynthesis"])
Expand Down
2 changes: 1 addition & 1 deletion scripts/microbe_stage/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ class 'MicrobeCameraSystem' (System)

function MicrobeCameraSystem:__init()
System.__init(self)
-- The offset from player microbe to camera
self.camera = nil
self.cameraScenenode = nil
end

function MicrobeCameraSystem:activate()
local camera = Entity(CAMERA_NAME)
self.camera = camera:getComponent(OgreCameraComponent.TYPE_ID)
-- The offset from player microbe to camera
self.camera.properties.offset = Vector3(0, 0, 30)
self.camera.properties:touch()
self.cameraScenenode = camera:getComponent(OgreSceneNodeComponent.TYPE_ID)
Expand Down
4 changes: 3 additions & 1 deletion scripts/microbe_stage/microbe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ end

-- Copies this microbe. The new microbe will not have the stored compounds of this one.
function Microbe:reproduce()

copy = Microbe.createMicrobeEntity(nil, true)
for _, organelle in pairs(self.microbe.organelles) do
local organelleStorage = organelle:storage()
Expand All @@ -731,6 +730,9 @@ function Microbe:reproduce()
copy.microbe:updateSafeAngles()
copy.microbe:_resetCompoundPriorities()
copy.entity:addComponent(SpawnedComponent())
if self.microbe.isPlayerMicrobe then
showReproductionDialog()
end
end


Expand Down
10 changes: 10 additions & 0 deletions scripts/microbe_stage/microbe_stage_hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
global_if_already_displayed = false

function HudSystem:activate()
global_activeMicrobeStageHudSystem = self -- Global reference for event handlers
lockedMap = Engine:playerData():lockedMap()
if lockedMap ~= nil and not lockedMap:isLocked("Toxin") and not ss and not global_if_already_displayed then
showMessage("'E' Releases Toxin")
Expand All @@ -30,16 +31,20 @@ function HudSystem:init(gameState)
local menuButton = self.rootGuiWindow:getChild("BottomSection"):getChild("MenuButton")
local helpButton = self.rootGuiWindow:getChild("BottomSection"):getChild("HelpButton")
local editorButton = self.rootGuiWindow:getChild("MenuPanel"):getChild("EditorButton")
local editorButton2 = self.rootGuiWindow:getChild("ReproductionPanel"):getChild("EditorButton")
local returnButton = self.rootGuiWindow:getChild("MenuPanel"):getChild("ReturnButton")
local returnButton2 = self.rootGuiWindow:getChild("HelpPanel"):getChild("ReturnButton")
local returnButton3 = self.rootGuiWindow:getChild("MessagePanel"):getChild("ReturnButton")
local returnButton4 = self.rootGuiWindow:getChild("ReproductionPanel"):getChild("ReturnButton")
local quitButton = self.rootGuiWindow:getChild("MenuPanel"):getChild("QuitButton")
menuButton:registerEventHandler("Clicked", menuButtonClicked)
helpButton:registerEventHandler("Clicked", helpButtonClicked)
editorButton:registerEventHandler("Clicked", editorButtonClicked)
editorButton2:registerEventHandler("Clicked", editorButtonClicked)
returnButton:registerEventHandler("Clicked", returnButtonClicked)
returnButton2:registerEventHandler("Clicked", returnButtonClicked)
returnButton3:registerEventHandler("Clicked", returnButtonClicked)
returnButton4:registerEventHandler("Clicked", returnButtonClicked)
quitButton:registerEventHandler("Clicked", quitButtonClicked)
self.rootGuiWindow:getChild("MenuPanel"):getChild("MainMenuButton"):registerEventHandler("Clicked", menuMainMenuClicked)
end
Expand Down Expand Up @@ -83,6 +88,10 @@ function HudSystem:update(milliseconds)
offset.z = newZVal
end

function showReproductionDialog()
global_activeMicrobeStageHudSystem.rootGuiWindow:getChild("ReproductionPanel"):show()
end

function showMessage(msg)
local messagePanel = Engine:currentGameState():rootGUIWindow():getChild("MessagePanel")
messagePanel:getChild("MessageLabel"):setText(msg)
Expand Down Expand Up @@ -115,6 +124,7 @@ function returnButtonClicked()
if Engine:currentGameState():name() == "microbe" then
Engine:currentGameState():rootGUIWindow():getChild("HelpPanel"):hide()
Engine:currentGameState():rootGUIWindow():getChild("MessagePanel"):hide()
Engine:currentGameState():rootGUIWindow():getChild("ReproductionPanel"):hide()
elseif Engine:currentGameState():name() == "microbe_editor" then
Engine:currentGameState():rootGUIWindow():getChild("SaveLoadPanel"):hide()
end
Expand Down
2 changes: 2 additions & 0 deletions scripts/microbe_stage/movement_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function MovementOrganelle:update(microbe, milliseconds)
self:_moveMicrobe(microbe, milliseconds)
end

Organelle.mpCosts["flagellum"] = 25

-- factory functions
function OrganelleFactory.make_flagellum(data)
-- Calculate the momentum of the movement organelle based on angle towards nucleus
Expand Down
2 changes: 2 additions & 0 deletions scripts/microbe_stage/organelle.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-- Base class for microbe organelles
class 'Organelle'

Organelle.mpCosts = {}

-- Factory function for organelles
function Organelle.loadOrganelle(storage)
local className = storage:get("className", "")
Expand Down
3 changes: 3 additions & 0 deletions scripts/microbe_stage/process_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ end
-------------------------------------------
-- factory functions for process organelles

Organelle.mpCosts["chloroplast"] = 20
Organelle.mpCosts["mitochondrion"] = 20

function OrganelleFactory.make_mitochondrion(data)
local mito = ProcessOrganelle()
mito:addProcess(global_processMap["Respiration"])
Expand Down
1 change: 0 additions & 1 deletion scripts/microbe_stage/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local function setupBackground()
local skyplane = SkyPlaneComponent()
skyplane.properties.plane.normal = Vector3(0, 0, 2000)
skyplane.properties.materialName = "background/blue_01"
skyplane.properties.tiling = 7
skyplane.properties:touch()

entity:addComponent(skyplane)
Expand Down
1 change: 1 addition & 0 deletions scripts/microbe_stage/storage_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function StorageOrganelle:onRemovedFromMicrobe(microbe, q, r)
microbe:removeStorageOrganelle(self)
end

Organelle.mpCosts["vacuole"] = 15

function OrganelleFactory.make_vacuole(data)
local vacuole = StorageOrganelle(100.0)
Expand Down

0 comments on commit a11a98c

Please sign in to comment.