diff options
author | Jeff Ames | 2008-05-01 14:31:30 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-01 14:31:30 +0000 |
commit | d51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch) | |
tree | d3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/World/TreePopulator | |
parent | * Looks like I had the bamboo build right in the first place - it was just th... (diff) | |
download | opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2 opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz |
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/TreePopulator')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs | 500 |
1 files changed, 250 insertions, 250 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs index f144444..32e45b7 100644 --- a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs +++ b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs | |||
@@ -1,251 +1,251 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Timers; | 31 | using System.Timers; |
32 | using Axiom.Math; | 32 | using Axiom.Math; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using log4net; | 34 | using log4net; |
35 | using Nini.Config; | 35 | using Nini.Config; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Region.Environment.Interfaces; | 37 | using OpenSim.Region.Environment.Interfaces; |
38 | using OpenSim.Region.Environment.Scenes; | 38 | using OpenSim.Region.Environment.Scenes; |
39 | 39 | ||
40 | namespace OpenSim.Region.Environment.Modules | 40 | namespace OpenSim.Region.Environment.Modules |
41 | { | 41 | { |
42 | /// <summary> | 42 | /// <summary> |
43 | /// Version 2.0 - Very hacky compared to the original. Will fix original and release as 0.3 later. | 43 | /// Version 2.0 - Very hacky compared to the original. Will fix original and release as 0.3 later. |
44 | /// </summary> | 44 | /// </summary> |
45 | public class TreePopulatorModule : IRegionModule | 45 | public class TreePopulatorModule : IRegionModule |
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | private Scene m_scene; | 48 | private Scene m_scene; |
49 | 49 | ||
50 | public double m_tree_density = 50.0; // Aim for this many per region | 50 | public double m_tree_density = 50.0; // Aim for this many per region |
51 | public double m_tree_updates = 1000.0; // MS between updates | 51 | public double m_tree_updates = 1000.0; // MS between updates |
52 | private List<LLUUID> m_trees; | 52 | private List<LLUUID> m_trees; |
53 | 53 | ||
54 | #region IRegionModule Members | 54 | #region IRegionModule Members |
55 | 55 | ||
56 | public void Initialise(Scene scene, IConfigSource config) | 56 | public void Initialise(Scene scene, IConfigSource config) |
57 | { | 57 | { |
58 | try | 58 | try |
59 | { | 59 | { |
60 | m_tree_density = config.Configs["Trees"].GetDouble("tree_density", m_tree_density); | 60 | m_tree_density = config.Configs["Trees"].GetDouble("tree_density", m_tree_density); |
61 | } | 61 | } |
62 | catch (Exception) | 62 | catch (Exception) |
63 | { | 63 | { |
64 | } | 64 | } |
65 | 65 | ||
66 | m_trees = new List<LLUUID>(); | 66 | m_trees = new List<LLUUID>(); |
67 | m_scene = scene; | 67 | m_scene = scene; |
68 | 68 | ||
69 | m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole); | 69 | m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole); |
70 | 70 | ||
71 | Timer CalculateTrees = new Timer(m_tree_updates); | 71 | Timer CalculateTrees = new Timer(m_tree_updates); |
72 | CalculateTrees.Elapsed += new ElapsedEventHandler(CalculateTrees_Elapsed); | 72 | CalculateTrees.Elapsed += new ElapsedEventHandler(CalculateTrees_Elapsed); |
73 | CalculateTrees.Start(); | 73 | CalculateTrees.Start(); |
74 | m_log.Debug("[TREES]: Initialised tree module"); | 74 | m_log.Debug("[TREES]: Initialised tree module"); |
75 | } | 75 | } |
76 | 76 | ||
77 | public void PostInitialise() | 77 | public void PostInitialise() |
78 | { | 78 | { |
79 | } | 79 | } |
80 | 80 | ||
81 | public void Close() | 81 | public void Close() |
82 | { | 82 | { |
83 | } | 83 | } |
84 | 84 | ||
85 | public string Name | 85 | public string Name |
86 | { | 86 | { |
87 | get { return "TreePopulatorModule"; } | 87 | get { return "TreePopulatorModule"; } |
88 | } | 88 | } |
89 | 89 | ||
90 | public bool IsSharedModule | 90 | public bool IsSharedModule |
91 | { | 91 | { |
92 | get { return false; } | 92 | get { return false; } |
93 | } | 93 | } |
94 | 94 | ||
95 | #endregion | 95 | #endregion |
96 | 96 | ||
97 | private void EventManager_OnPluginConsole(string[] args) | 97 | private void EventManager_OnPluginConsole(string[] args) |
98 | { | 98 | { |
99 | if (args[0] == "tree") | 99 | if (args[0] == "tree") |
100 | { | 100 | { |
101 | m_log.Debug("[TREES]: New tree planting"); | 101 | m_log.Debug("[TREES]: New tree planting"); |
102 | CreateTree(new LLVector3(128.0f, 128.0f, 0.0f)); | 102 | CreateTree(new LLVector3(128.0f, 128.0f, 0.0f)); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | private void growTrees() | 106 | private void growTrees() |
107 | { | 107 | { |
108 | foreach (LLUUID tree in m_trees) | 108 | foreach (LLUUID tree in m_trees) |
109 | { | 109 | { |
110 | if (m_scene.Entities.ContainsKey(tree)) | 110 | if (m_scene.Entities.ContainsKey(tree)) |
111 | { | 111 | { |
112 | SceneObjectPart s_tree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; | 112 | SceneObjectPart s_tree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; |
113 | 113 | ||
114 | // 100 seconds to grow 1m | 114 | // 100 seconds to grow 1m |
115 | s_tree.Scale += new LLVector3(0.1f, 0.1f, 0.1f); | 115 | s_tree.Scale += new LLVector3(0.1f, 0.1f, 0.1f); |
116 | s_tree.SendFullUpdateToAllClients(); | 116 | s_tree.SendFullUpdateToAllClients(); |
117 | //s_tree.ScheduleTerseUpdate(); | 117 | //s_tree.ScheduleTerseUpdate(); |
118 | } | 118 | } |
119 | else | 119 | else |
120 | { | 120 | { |
121 | m_trees.Remove(tree); | 121 | m_trees.Remove(tree); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | private void seedTrees() | 126 | private void seedTrees() |
127 | { | 127 | { |
128 | foreach (LLUUID tree in m_trees) | 128 | foreach (LLUUID tree in m_trees) |
129 | { | 129 | { |
130 | if (m_scene.Entities.ContainsKey(tree)) | 130 | if (m_scene.Entities.ContainsKey(tree)) |
131 | { | 131 | { |
132 | SceneObjectPart s_tree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; | 132 | SceneObjectPart s_tree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; |
133 | 133 | ||
134 | if (s_tree.Scale.X > 0.5) | 134 | if (s_tree.Scale.X > 0.5) |
135 | { | 135 | { |
136 | if (Util.RandomClass.NextDouble() > 0.75) | 136 | if (Util.RandomClass.NextDouble() > 0.75) |
137 | { | 137 | { |
138 | SpawnChild(s_tree); | 138 | SpawnChild(s_tree); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | else | 142 | else |
143 | { | 143 | { |
144 | m_trees.Remove(tree); | 144 | m_trees.Remove(tree); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | private void killTrees() | 149 | private void killTrees() |
150 | { | 150 | { |
151 | foreach (LLUUID tree in m_trees) | 151 | foreach (LLUUID tree in m_trees) |
152 | { | 152 | { |
153 | double killLikelyhood = 0.0; | 153 | double killLikelyhood = 0.0; |
154 | 154 | ||
155 | if (m_scene.Entities.ContainsKey(tree)) | 155 | if (m_scene.Entities.ContainsKey(tree)) |
156 | { | 156 | { |
157 | SceneObjectPart selectedTree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; | 157 | SceneObjectPart selectedTree = ((SceneObjectGroup) m_scene.Entities[tree]).RootPart; |
158 | double selectedTreeScale = Math.Sqrt(Math.Pow(selectedTree.Scale.X, 2) + | 158 | double selectedTreeScale = Math.Sqrt(Math.Pow(selectedTree.Scale.X, 2) + |
159 | Math.Pow(selectedTree.Scale.Y, 2) + | 159 | Math.Pow(selectedTree.Scale.Y, 2) + |
160 | Math.Pow(selectedTree.Scale.Z, 2)); | 160 | Math.Pow(selectedTree.Scale.Z, 2)); |
161 | 161 | ||
162 | foreach (LLUUID picktree in m_trees) | 162 | foreach (LLUUID picktree in m_trees) |
163 | { | 163 | { |
164 | if (picktree != tree) | 164 | if (picktree != tree) |
165 | { | 165 | { |
166 | SceneObjectPart pickedTree = ((SceneObjectGroup) m_scene.Entities[picktree]).RootPart; | 166 | SceneObjectPart pickedTree = ((SceneObjectGroup) m_scene.Entities[picktree]).RootPart; |
167 | 167 | ||
168 | double pickedTreeScale = Math.Sqrt(Math.Pow(pickedTree.Scale.X, 2) + | 168 | double pickedTreeScale = Math.Sqrt(Math.Pow(pickedTree.Scale.X, 2) + |
169 | Math.Pow(pickedTree.Scale.Y, 2) + | 169 | Math.Pow(pickedTree.Scale.Y, 2) + |
170 | Math.Pow(pickedTree.Scale.Z, 2)); | 170 | Math.Pow(pickedTree.Scale.Z, 2)); |
171 | 171 | ||
172 | double pickedTreeDistance = Math.Sqrt(Math.Pow(Math.Abs(pickedTree.AbsolutePosition.X - selectedTree.AbsolutePosition.X), 2) + | 172 | double pickedTreeDistance = Math.Sqrt(Math.Pow(Math.Abs(pickedTree.AbsolutePosition.X - selectedTree.AbsolutePosition.X), 2) + |
173 | Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Y - selectedTree.AbsolutePosition.Y), 2) + | 173 | Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Y - selectedTree.AbsolutePosition.Y), 2) + |
174 | Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Z - selectedTree.AbsolutePosition.Z), 2)); | 174 | Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Z - selectedTree.AbsolutePosition.Z), 2)); |
175 | 175 | ||
176 | killLikelyhood += (selectedTreeScale / (pickedTreeScale * pickedTreeDistance)) * 0.1; | 176 | killLikelyhood += (selectedTreeScale / (pickedTreeScale * pickedTreeDistance)) * 0.1; |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | if (Util.RandomClass.NextDouble() < killLikelyhood) | 180 | if (Util.RandomClass.NextDouble() < killLikelyhood) |
181 | { | 181 | { |
182 | m_scene.RemoveEntity(selectedTree.ParentGroup); | 182 | m_scene.RemoveEntity(selectedTree.ParentGroup); |
183 | m_trees.Remove(selectedTree.ParentGroup.UUID); | 183 | m_trees.Remove(selectedTree.ParentGroup.UUID); |
184 | 184 | ||
185 | m_scene.ForEachClient(delegate(IClientAPI controller) | 185 | m_scene.ForEachClient(delegate(IClientAPI controller) |
186 | { | 186 | { |
187 | controller.SendKillObject(m_scene.RegionInfo.RegionHandle, | 187 | controller.SendKillObject(m_scene.RegionInfo.RegionHandle, |
188 | selectedTree.LocalId); | 188 | selectedTree.LocalId); |
189 | }); | 189 | }); |
190 | 190 | ||
191 | break; | 191 | break; |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0); | 195 | selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | else | 198 | else |
199 | { | 199 | { |
200 | m_trees.Remove(tree); | 200 | m_trees.Remove(tree); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | private void SpawnChild(SceneObjectPart s_tree) | 205 | private void SpawnChild(SceneObjectPart s_tree) |
206 | { | 206 | { |
207 | LLVector3 position = new LLVector3(); | 207 | LLVector3 position = new LLVector3(); |
208 | 208 | ||
209 | position.X = s_tree.AbsolutePosition.X + (1 * (-1 * Util.RandomClass.Next(1))); | 209 | position.X = s_tree.AbsolutePosition.X + (1 * (-1 * Util.RandomClass.Next(1))); |
210 | if (position.X > 255) | 210 | if (position.X > 255) |
211 | position.X = 255; | 211 | position.X = 255; |
212 | if (position.X < 0) | 212 | if (position.X < 0) |
213 | position.X = 0; | 213 | position.X = 0; |
214 | position.Y = s_tree.AbsolutePosition.Y + (1 * (-1 * Util.RandomClass.Next(1))); | 214 | position.Y = s_tree.AbsolutePosition.Y + (1 * (-1 * Util.RandomClass.Next(1))); |
215 | if (position.Y > 255) | 215 | if (position.Y > 255) |
216 | position.Y = 255; | 216 | position.Y = 255; |
217 | if (position.Y < 0) | 217 | if (position.Y < 0) |
218 | position.Y = 0; | 218 | position.Y = 0; |
219 | 219 | ||
220 | double randX = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3); | 220 | double randX = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3); |
221 | double randY = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3); | 221 | double randY = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3); |
222 | 222 | ||
223 | position.X += (float) randX; | 223 | position.X += (float) randX; |
224 | position.Y += (float) randY; | 224 | position.Y += (float) randY; |
225 | 225 | ||
226 | CreateTree(position); | 226 | CreateTree(position); |
227 | } | 227 | } |
228 | 228 | ||
229 | private void CreateTree(LLVector3 position) | 229 | private void CreateTree(LLVector3 position) |
230 | { | 230 | { |
231 | position.Z = (float) m_scene.Heightmap[(int) position.X, (int) position.Y]; | 231 | position.Z = (float) m_scene.Heightmap[(int) position.X, (int) position.Y]; |
232 | 232 | ||
233 | SceneObjectGroup tree = | 233 | SceneObjectGroup tree = |
234 | m_scene.AddTree(new LLVector3(0.1f, 0.1f, 0.1f), | 234 | m_scene.AddTree(new LLVector3(0.1f, 0.1f, 0.1f), |
235 | LLQuaternion.Identity, | 235 | LLQuaternion.Identity, |
236 | position, | 236 | position, |
237 | Tree.Cypress1, | 237 | Tree.Cypress1, |
238 | false); | 238 | false); |
239 | 239 | ||
240 | m_trees.Add(tree.UUID); | 240 | m_trees.Add(tree.UUID); |
241 | tree.SendGroupFullUpdate(); | 241 | tree.SendGroupFullUpdate(); |
242 | } | 242 | } |
243 | 243 | ||
244 | private void CalculateTrees_Elapsed(object sender, ElapsedEventArgs e) | 244 | private void CalculateTrees_Elapsed(object sender, ElapsedEventArgs e) |
245 | { | 245 | { |
246 | growTrees(); | 246 | growTrees(); |
247 | seedTrees(); | 247 | seedTrees(); |
248 | killTrees(); | 248 | killTrees(); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | } \ No newline at end of file | 251 | } \ No newline at end of file |