-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMembrane.cpp
82 lines (59 loc) · 2.4 KB
/
Membrane.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Membrane.h"
#include "Cell.h"
#include "NeuralNetwork.h"
#include "ChemicalContainer.h"
#include "Chunk.h"
#include "World.h"
#include "DNA.h"
Membrane::Membrane(Cell* parentCell, DNA* dna, int startingPos) : pCell(parentCell)
{
surfaceArea = pCell->GetSurfaceArea();
neuralNet = pCell->GetNeuralNetwork();
dna->SetCurrentPosition(startingPos);
for (int i = 0; i < contains_amount; i++)
{
outputNodeArr[i] = dna->GetGeneInt(0, pCell->GetNeuralNetwork()->GetOutputLayerCount());
modifierArrCellToChunk[i] = dna->GetGeneFloat(0, 20.0f);
modifierArrChunkToCell[i] = dna->GetGeneFloat(0, 20.0f);
modifierArrPassiveMovement[i] = dna->GetGeneFloat(0, 1);
}
swellingModifier = dna->GetGeneFloat(0, 1);
swellingOutputNode = dna->GetGeneInt(0, pCell->GetNeuralNetwork()->GetOutputLayerCount());
pCell->SetMembraneStatus(true);
pCell->AddToDNAColourX(Filter_SplittingMembrane, 0.75);
}
float Membrane::Tick(int t)
{
totalATPCost = pCell->GetChemCon()->DiffuseFromAndTo(pCell->GetCurrentChunk()->GetChemCon(), t, this);
//swelling
double swellingChange = pCell->LimitATPUsage(Swell_Speed_Factor * neuralNet->GetOutputNode(swellingOutputNode) * t * swellingModifier * surfaceArea / pCell->GetChemCon()->GetVolume(), surfaceArea);;
totalATPCost += abs(swellingChange * Swell_Cost_Factor);
pCell->AddToSwellPercent(swellingChange);
if (isnan(totalATPCost) || isinf(totalATPCost))
{
OutputDebugString("oh no");
}
return -1 * totalATPCost * Membrane_ATP_Cost_Modfier;
}
string Membrane::GetOutputString()
{
string buffer = "\n Membrane:\n";
buffer += " LastATPCost: " + to_string(totalATPCost) + "\n";
buffer += " Swelling modifier: " + to_string(swellingModifier) + "\n";
buffer += " Swelling OutputNode: " + to_string(swellingOutputNode) + "/" + to_string(neuralNet->GetOutputNode(swellingOutputNode)) + "\n\n";
buffer += " Passive Transport:\n";
for (int i = 0; i < contains_amount; i++)
{
buffer += " " + writtenSubstances[i] + " " + to_string(modifierArrPassiveMovement[i]) + "\n";
}
buffer += "\n Active Transport:\n";
for (int i = 0; i < contains_amount; i++)
{
buffer += " " + writtenSubstances[i] + " " + to_string(modifierArrCellToChunk[i]) + "/" + to_string(modifierArrChunkToCell[i]) + " (" + to_string((outputNodeArr[i])) + "/" + to_string(pCell->GetNeuralNetwork()->GetOutputNode(outputNodeArr[i])) + ")\n";
}
buffer += "\n";
return buffer;
}
Membrane::~Membrane()
{
}