Skip to content

Commit

Permalink
Merge pull request Revolutionary-Games#297 from Revolutionary-Games/1…
Browse files Browse the repository at this point in the history
…91-basic-population-dynamics

A large refactoring project, adding proper species handling, and a model for handling populations.

Also refactored:

Spawning functions heavily simplified
Editor organelle placement heavily simplified
Fixes Revolutionary-Games#191
Fixes Revolutionary-Games#270
  • Loading branch information
Moopli committed Feb 22, 2015
2 parents 2693f12 + dc11eb0 commit ec58ae8
Show file tree
Hide file tree
Showing 15 changed files with 786 additions and 416 deletions.
94 changes: 47 additions & 47 deletions assets/definitions/compounds.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<?xml version="1.0" ?>
<Compounds>
<Compound name="atp" weight="1">
<Display text="ATP">
<Model file="ATP.mesh" size="0.1" />
</Display>
</Compound>
<Compound name="oxygen" weight="1">
<Display text="Oxygen" >
<Model file="molecule.mesh" size="0.3" />
</Display>
</Compound>
<Compound name="reproductase" weight="1">
<Display text="Reproductase" >
<Model file="reproductase.mesh" size="0.09" />
</Display>
</Compound>
<Compound name="aminoacids" weight="1">
<Display text="Amino Acids">
<Model file="aminoacid.mesh" size="0.2" />
</Display>
</Compound>
<Compound name="ammonia" weight="1">
<Display text="Ammonia" >
<Model file="ammonia.mesh" size="0.16" />
</Display>
</Compound>
<Compound name="glucose" weight="1">
<Display text="Glucose" >
<Model file="glucose.mesh" size="0.3" />
</Display>
</Compound>
<Compound name="co2" weight="1">
<Display text="CO2" >
<Model file="co2.mesh" size="0.16" />
</Display>
</Compound>

<AgentCompounds>
<Agent name="oxytoxy" weight="1">
<Display text="OxyToxy NT" >
<Model file="oxytoxy.mesh" size="0.3" />
</Display>
<Effect function="oxytoxyEffect" />
</Agent>
</AgentCompounds>
</Compounds>
<?xml version="1.0" ?>
<Compounds>
<Compound name="atp" weight="1">
<Display text="ATP">
<Model file="ATP.mesh" size="0.1" />
</Display>
</Compound>
<Compound name="oxygen" weight="1">
<Display text="Oxygen" >
<Model file="molecule.mesh" size="0.3" />
</Display>
</Compound>
<Compound name="reproductase" weight="1">
<Display text="Reproductase" >
<Model file="reproductase.mesh" size="0.09" />
</Display>
</Compound>
<Compound name="aminoacids" weight="1">
<Display text="Amino Acids">
<Model file="aminoacid.mesh" size="0.2" />
</Display>
</Compound>
<Compound name="ammonia" weight="1">
<Display text="Ammonia" >
<Model file="ammonia.mesh" size="0.16" />
</Display>
</Compound>
<Compound name="glucose" weight="1">
<Display text="Glucose" >
<Model file="glucose.mesh" size="0.3" />
</Display>
</Compound>
<Compound name="co2" weight="1">
<Display text="CO2" >
<Model file="co2.mesh" size="0.16" />
</Display>
</Compound>

<AgentCompounds>
<Agent name="oxytoxy" weight="1">
<Display text="OxyToxy NT" >
<Model file="oxytoxy.mesh" size="0.3" />
</Display>
<Effect function="oxytoxyEffect" />
</Agent>
</AgentCompounds>
</Compounds>
109 changes: 23 additions & 86 deletions scripts/microbe_editor/microbe_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function MicrobeEditor:__init(hudSystem)
self.gridVisible = true
self.mutationPoints = 100
self.placementFunctions = {["nucleus"] = MicrobeEditor.createNewMicrobe,
["flagelium"] = MicrobeEditor.addMovementOrganelle,
["mitochondrion"] = MicrobeEditor.addProcessOrganelle,
["chloroplast"] = MicrobeEditor.addProcessOrganelle,
["toxin"] = MicrobeEditor.addAgentVacuole,
["flagellum"] = MicrobeEditor.addOrganelle,
["mitochondrion"] = MicrobeEditor.addOrganelle,
["chloroplast"] = MicrobeEditor.addOrganelle,
["oxytoxy"] = MicrobeEditor.addOrganelle,

["vacuole"] = MicrobeEditor.addStorageOrganelle,
["vacuole"] = MicrobeEditor.addOrganelle,
-- ["aminosynthesizer"] = MicrobeEditor.addProcessOrganelle,
["remove"] = MicrobeEditor.removeOrganelle}
self.actionHistory = nil
Expand Down Expand Up @@ -54,6 +54,7 @@ function MicrobeEditor:activate()
end

function MicrobeEditor:update(renderTime, logicTime)
-- self.nextMicrobeEntity being a temporary used to pass the microbe from game to editor
if self.nextMicrobeEntity ~= nil then
self.currentMicrobe = Microbe(self.nextMicrobeEntity)
self.currentMicrobe.sceneNode.transform.orientation = Quaternion(Radian(Degree(180)), Vector3(0, 0, 1))-- Orientation
Expand Down Expand Up @@ -154,110 +155,49 @@ function MicrobeEditor:getMouseHex()
return qr, rr
end

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
local storage = organelle:storage()
self:enqueueAction{
cost = 10,
redo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
end,
undo = function()
self.currentMicrobe:addOrganelle(q, r, Organelle.loadOrganelle(storage))
self.organelleCount = self.organelleCount + 1
end
}
end
end
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
self:enqueueAction{
cost = Organelle.mpCosts["vacuole"],
redo = function()
self.currentMicrobe:addOrganelle(q, r, OrganelleFactory.make_vacuole({}))
self.organelleCount = self.organelleCount + 1
end,
undo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
end
}
end
end


function MicrobeEditor:addMovementOrganelle(organelleType)
function MicrobeEditor:addOrganelle(organelleType)
local q, r = self:getMouseHex()
if self.currentMicrobe:getOrganelleAt(q, r) == nil then
self:enqueueAction{
cost = Organelle.mpCosts["flagellum"],
local data = {["name"]=organelleType, ["q"]=q, ["r"]=r}
self:enqueueAction({
cost = Organelle.mpCosts[organelleType],
redo = function()
self.currentMicrobe:addOrganelle(q,r, OrganelleFactory.make_flagellum{["q"]=q, ["r"]=r})
self.currentMicrobe:addOrganelle(q,r, OrganelleFactory.makeOrganelle(data))
self.organelleCount = self.organelleCount + 1
end,
undo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
end
}
})
end
end

function MicrobeEditor:addProcessOrganelle(organelleType)
function MicrobeEditor:removeOrganelle()
local q, r = self:getMouseHex()

if organelleType and self.currentMicrobe:getOrganelleAt(q, r) == nil then
local data = { ["name"] = organelleType }

self:enqueueAction{
cost = Organelle.mpCosts[data.name],
redo = function()
self.currentMicrobe:addOrganelle(q, r, OrganelleFactory.makeOrganelle(data))
self.organelleCount = self.organelleCount + 1
end,
undo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
end
}
end
end

function MicrobeEditor:addAgentVacuole(organelleType)
if organelleType == "toxin" then
local q, r = self:getMouseHex()
if self.currentMicrobe:getOrganelleAt(q, r) == nil then
if not (q == 0 and r == 0) then -- Don't remove nucleus
local organelle = self.currentMicrobe:getOrganelleAt(q,r)
if organelle then
local storage = organelle:storage()
self:enqueueAction{
cost = Organelle.mpCosts["oxytoxy"],
cost = 10,
redo = function()
self.currentMicrobe:addOrganelle(q, r, OrganelleFactory.make_oxytoxy({}))
self.organelleCount = self.organelleCount + 1
end,
undo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
end,
undo = function()
self.currentMicrobe:addOrganelle(q, r, Organelle.loadOrganelle(storage))
self.organelleCount = self.organelleCount + 1
end
}
end
end
end

function MicrobeEditor:addNucleus()
local nucleusOrganelle = OrganelleFactory.make_nucleus({})
local nucleusOrganelle = OrganelleFactory.makeOrganelle({["name"]="nucleus"})
self.currentMicrobe:addOrganelle(0, 0, nucleusOrganelle)
end

Expand All @@ -270,7 +210,6 @@ function MicrobeEditor:loadMicrobe(entityId)
self.currentMicrobe.entity:stealName("working_microbe")
self.currentMicrobe.sceneNode.transform.orientation = Quaternion(Radian(Degree(180)), Vector3(0, 0, 1))-- Orientation
self.currentMicrobe.sceneNode.transform:touch()
self.currentMicrobe.collisionHandler:addCollisionGroup("powerupable")
Engine:playerData():setActiveCreature(entityId, GameState.MICROBE_EDITOR)
self.mutationPoints = 0
-- resetting the action history - it should not become entangled with the local file system
Expand All @@ -289,7 +228,6 @@ function MicrobeEditor:createNewMicrobe()
self.currentMicrobe.entity:stealName("working_microbe")
self.currentMicrobe.sceneNode.transform.orientation = Quaternion(Radian(Degree(180)), Vector3(0, 0, 1))-- Orientation
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)
Expand All @@ -310,7 +248,6 @@ function MicrobeEditor:createNewMicrobe()
self.currentMicrobe.entity:stealName("working_microbe")
self.currentMicrobe.sceneNode.transform.orientation = Quaternion(Radian(Degree(180)), Vector3(0, 0, 1))-- Orientation
self.currentMicrobe.sceneNode.transform:touch()
self.currentMicrobe.collisionHandler:addCollisionGroup("powerupable")
for position,storage in pairs(organelleStorage) do
local q, r = decodeAxial(position)
self.currentMicrobe:addOrganelle(q, r, Organelle.loadOrganelle(storage))
Expand Down
16 changes: 8 additions & 8 deletions scripts/microbe_editor/microbe_editor_hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ function MicrobeEditorHudSystem:init(gameState)
-- self.mpProgressBar = root:getChild("BottomSection"):getChild("MutationPoints"):getChild("MPBar")
self.organelleScrollPane = root:getChild("scrollablepane");
local nucleusButton = root:getChild("NewMicrobe")
local flageliumButton = root:getChild("scrollablepane"):getChild("AddFlagellum")
local flagellumButton = root:getChild("scrollablepane"):getChild("AddFlagellum")
local mitochondriaButton = root:getChild("scrollablepane"):getChild("AddMitochondria")
local vacuoleButton = root:getChild("scrollablepane"):getChild("AddVacuole")
local toxinButton = root:getChild("scrollablepane"):getChild("AddToxinVacuole")
local chloroplastButton = root:getChild("scrollablepane"):getChild("AddChloroplast")
self.organelleButtons["nucleus"] = nucleusButton
self.organelleButtons["flagelium"] = flageliumButton
self.organelleButtons["flagellum"] = flagellumButton
self.organelleButtons["mitochondrion"] = mitochondriaButton
self.organelleButtons["chloroplast"] = chloroplastButton
self.organelleButtons["vacuole"] = vacuoleButton
self.organelleButtons["Toxin"] = toxinButton
self.activeButton = nil
nucleusButton:registerEventHandler("Clicked", function() self:nucleusClicked() end)
flageliumButton:registerEventHandler("Clicked", function() self:flageliumClicked() end)
flagellumButton:registerEventHandler("Clicked", function() self:flagellumClicked() end)
mitochondriaButton:registerEventHandler("Clicked", function() self:mitochondriaClicked() end)
chloroplastButton:registerEventHandler("Clicked", function() self:chloroplastClicked() end)
vacuoleButton:registerEventHandler("Clicked", function() self:vacuoleClicked() end)
Expand Down Expand Up @@ -134,7 +134,7 @@ function MicrobeEditorHudSystem:update(renderTime, logicTime)
self.editor:performLocationAction()
end
elseif keyCombo(kmp.flagellum) then
self:flageliumClicked()
self:flagellumClicked()
self.editor:performLocationAction()
elseif keyCombo(kmp.mitochondrion) then
self:mitochondriaClicked()
Expand Down Expand Up @@ -241,13 +241,13 @@ function MicrobeEditorHudSystem:nucleusClicked()
self:setActiveAction("nucleus")
end

function MicrobeEditorHudSystem:flageliumClicked()
function MicrobeEditorHudSystem:flagellumClicked()
if self.activeButton ~= nil then
self.activeButton:enable()
end
self.activeButton = self.organelleButtons["flagelium"]
self.activeButton = self.organelleButtons["flagellum"]
self.activeButton:disable()
self:setActiveAction("flagelium")
self:setActiveAction("flagellum")
end

function MicrobeEditorHudSystem:mitochondriaClicked()
Expand Down Expand Up @@ -292,7 +292,7 @@ function MicrobeEditorHudSystem:toxinClicked()
end
self.activeButton = self.organelleButtons["Toxin"]
self.activeButton:disable()
self:setActiveAction("toxin")
self:setActiveAction("oxytoxy")
end


Expand Down
2 changes: 2 additions & 0 deletions scripts/microbe_stage/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ microbe.lua
camera.lua
microbe_control.lua
spawn_system.lua
species_system.lua
patch_system.lua
switch_game_state_system.lua

// Organelles
Expand Down
Loading

0 comments on commit ec58ae8

Please sign in to comment.