-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEcosystem.cs
187 lines (135 loc) · 4.82 KB
/
Ecosystem.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*************************************************************************
Ecosystem Main Class
Copyright (C), SBland.co.uk
-------------------------------------------------------------------------
Date:09/11/13
Description: Initializes Ecosystem
------------------------------------------------------------------------
History:30/12/13 - Transfered to C#
Rewriting Ecosystem
*************************************************************************/
using UnityEngine;
using System.Collections;
using System.Xml;
using System.IO;
public class Ecosystem : MonoBehaviour {
//Input (User)
public int updateRate = 500;
public double initialOxygen = 10;
public double initialCo = 10;
public double initialTemperature = 27;
public double initialHumidity = 45;
public Rigidbody treeModel;
public Rigidbody humanModel;
public Rigidbody cowModel;
public Transform spawnPlane;
public string saveLocation = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\\Ecosystem";
//properties
public int updateCount = 0;
GameObject[] humanList;
GameObject[] cowList;
string dir;
//objects
//--------------------------------------------------------------------------------------------------------
// Use this for initialization
void Start () {
Initialization ();
EntityCounts();
File.WriteAllText (dir, "Trees, Humans, Cow, Oxygen, CO2 \r\n"); //Write column headers
}//End Start()--------------------------------------------------------------------------------------------------------
// Update is called once per frame
void Update () {
//EntityCounts();
if (this.updateCount == this.updateRate)
{
EcosystemCalculations();
EcosystemConsoleLog();
EcosystemDataLog();
this.updateCount = 0;
}
this.updateCount++;
}//End Update()--------------------------------------------------------------------------------------------------------
/// <summary>
/// Initialize ecosystem variables to user in/put;
/// </summary>
private void Initialization()
{
//set values to user input
EcosystemAtmosphere.Oxygen = initialOxygen;
EcosystemAtmosphere.Co = initialCo;
EcosystemEnvironment.Temperature = initialTemperature;
EcosystemEnvironment.Humidity = initialHumidity;
dir = saveLocation + "\\saveTest_" + System.DateTime.Now.ToString("HHmm_d_M_yy") + ".txt";
}//End Initialization()--------------------------------------------------------------------------------------------------------
// Get entity counts
private void EntityCounts()
{
EcosystemEntityTree.EcoUpdate ();
EcosystemEntityHuman.EcoUpdate ();
EcosystemEntityCow.EcoUpdate ();
}
/// <summary>
/// Ecosystems the calculations.
/// </summary>
void EcosystemCalculations()
{
EcosystemAtmosphere.Oxygen += EcosystemAtmosphere.OxygenCalc;
EcosystemAtmosphere.Co += EcosystemAtmosphere.CoCalc;
humanList = GameObject.FindGameObjectsWithTag ("ecosystemHuman");
cowList = GameObject.FindGameObjectsWithTag ("ecosystemCow");
EcosystemPostCalculations();
}//End EcosystemCalculations()--------------------------------------------------------------------------------------------------------
/// <summary>
/// Ecosystems the post calculations.
/// </summary>
void EcosystemPostCalculations()
{
EcosystemEntityTree tree = new EcosystemEntityTree();
EcosystemEntityHuman human = new EcosystemEntityHuman();
EcosystemEntityCow cow = new EcosystemEntityCow();
//Create Tree
if (EcosystemAtmosphere.Co > 90) {
tree.Create();
}
//Create Human
if (EcosystemAtmosphere.Oxygen > 90) {
human.Create();
}
//Create Cow
if (EcosystemAtmosphere.Oxygen > 140) {
cow.Create();
}
//Destroy Tree
if (EcosystemAtmosphere.Co < 8) {
tree.Remove();
}
//Destroy Human
if (EcosystemAtmosphere.Oxygen < 8) {
human.Remove();
}
//Destroy Cow
if (EcosystemAtmosphere.Oxygen < 15) {
cow.Remove();
}
}// End EcosystemPostCalculations()--------------------------------------------------------------------------------------------------------
/// <summary>
/// Ecosystems the console log.
/// </summary>
void EcosystemConsoleLog()
{
}// End EcosystemConsoleLog()--------------------------------------------------------------------------------------------------------
/// <summary>
/// Ecosystem data Log
/// -Logs data to an xml file
/// </summary>
void EcosystemDataLog()
{
//File Write Test]
//string dir = saveLocation + "\\saveTest.txt";
string[] printme = {EcosystemEntityTree.Count + "", ", " + EcosystemEntityHuman.Count, ", "+ EcosystemEntityCow.Count, ", " + EcosystemAtmosphere.Oxygen, ", " + EcosystemAtmosphere.Co + "\r\n"};
for (int i = 0; i<printme.Length; i++)
{
File.AppendAllText(dir, printme[i]);
}
}// End EcosystemDataLog()--------------------------------------------------------------------------------------------------------
}