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