Sign in to follow this  
Darkavenger

Help Tree Growth

Recommended Posts

Hello,

I'd like to implement a mod for argos modloader which behaves similar to the creatureage mod but with trees. I play on a server with my friend and the server is turned off if we aren't playing. And planted tree sprout seem to never grow actually.

 

So i digged into the server code and discovered the TilePoller class in which the PollNextTile Method which works on a global variable in this class which seems to be set from the outside before the poll next tile method is called; as observed from the poll gm action in the TileBehaviour class.

 

The pollNextTile method calls the checkEffects methods after some more calls which checks if this tile is a tree then checks for age restrictions and calculates a chance at which the tree may grow age++.

This seems like the time constant in which a tree may grow is not determined in the poll call but in another loop where this method is called to only execute the tree growth.

 

This behaviour is observed when a gm calls the poll method on a tree tile as it grows immediately.

 

Now i'm searching for the code which determines the time span after which a tree tile is polled... This seems to happen in Server.run but my decompiler is not able to decompile this method properly and neither was i able to locate any constants which represent the growth times for the different tree types.

 

Is there maybe a more experienced modder which can enlighten me with the workings of tree growth

Share this post


Link to post
Share on other sites

Are you using the server 'tree growth' option?  Trees was not expanding at all at release, that option fixed it.   Seems logical that the same option would control individual tree growth as well as forest expansion.

Share this post


Link to post
Share on other sites

 

Hello, 

I tried extremely high and extremely low values neither motivated my trees to grow. Neither did i set it to 0 as this stops growing and despawns sapplings,  i have seen this in the code too. And it seems that this value controls tree spreading.

 

And an extreme groeth rate would cause that the trees would be overaged fast

 

The effevt which im aiming is to have trees grow with a reduced tick till a certain age then with the worh the normal rate. Just like the creatureage mod

 

Share this post


Link to post
Share on other sites

When i asked Taufiq he said that editing the actual speed of growth would be a fairly involved process

 

Have you had a look at each of the items class files? as the growth time might be included there as each tree has a specific grow time (ie, oaks grow alot slower) 

Share this post


Link to post
Share on other sites

in TilePoller.class,  checkForTreeGrowth() method is this line:

final int chance = TilePoller.entryServer ? Server.rand.nextInt(20) : Server.rand.nextInt(225);

 

What this is doing is increasing the tree growth chance for "entry server" aka Golden Valley. Wurm had greatly buffed the rate trees grow so the noob servers wouldn't run out of trees.

I think one solution here is to use byte code manipulation to change that 225 something much smaller.


edit1

A better alternative might be to use Javassist to inject a new method. The method would return an integer that we put in "chance". The purpose of the method would be to control the growth chance based on different input parameters. One case is we want to quickly accelerate growth the first 12 ages stages and have very old, very old sprouting, and overaged stages last longer.

 

Use bytecode to add the new method call into checkForTreeGrowth(), void out the line I posted above (NOP), in place of the chance line.

Edited by joedobo

Share this post


Link to post
Share on other sites

So this check treeGrowth is a special implementation and not the usual time based Treeaging, i guess. Do we have informations about how often each tile is polled by the server. Or does someone now how to display a debug message here to see if a tree is polled maybe get the first time a tree is polled save the tile and put out a debug message each time the saved tile is polled again...

 

So i may implement a method which generates a chance value of 1 if the tree is below desired age and a timebase has passed... only questions is where to save this timebase for each tree there should be an database entry for eacht tree last growth i guess ... is the tile data synced with the database or is it pkaced in ram an batch saved at an intervall to the database?

 

 

Share this post


Link to post
Share on other sites

Tree data is in the mesh files. Look at common.jar, package "com.wurmonline.mesh". Although, tree age is already available in checkForTreeGrowth(). Instead of trying to keep track of a timebase consider just using an RNG algorithm. Just decreasing the chance value until growth rate seems right should work. I'm not sure how fast trees would grow would be if that 225 was a 1. I guess if that is not fast enough you'll need to look into increasing the tile polling frequency. I believe this process cycles through all tiles in the game so it might be a resource intensive change.

 

I think the checkForTreeGrowth() method is the main implementation that grows trees. I suggested one way to alter it so trees at different ages can produced different growth chances. 

 

All you'd need to do is pass the tree age into the method and then run some logic to return different chances(integers used in the line below it) based on tree age. A different RNG algorithm for each stage would help. so...

1, 2, 3, young ages: chance returned 1

4, 5, 6 mature stages: chance returned 1

7, mature sprouting: chance returned I like 80% and by default it is at 36% (82/225) Any random numbers between 1 and 81( from (16-age)^2 ) will result in success. Thus a random value between 1-101 would work.

int chance = (new Double(Math.max(Math.round(Server.rand.nextFloat()*101),1)).intValue());

8 and 10 old: chance returned 1

9 and 11 old sprouting: chance returned I like 60% and by default its at 21%,11% . Any RNG value between 1 and 49, 25 will give a success. Do a range between 1 and 82,42.

int chance = (new Double(Math.max(Math.round(Server.rand.nextFloat()*82),1)).intValue());

12 very old: chance returned I like 40% and by default its 7%. Any RNG value between 1 and 16 will give  a success. Use a range of 1 to 40.

13 very old sprouting: chance returned I like the default of 4% chance. Values between 1 and 9 are success. Use a range of 1 to 225

14 overaged: chance returned returned I like 1%, default  is 1.77%. values between 1 and 4 are success. use a range between 1 and 400.

 

- I need advise if all those Math processes are going to cause performance issues.

- It might be better to replace these two lines and have the new method return a boolean instead of what was done above.

final int chance = TilePoller.entryServer ? Server.rand.nextInt(20) : Server.rand.nextInt(225);
if (chance <= (16 - age) * (16 - age)) {

 

 

I wouldn't mess with tile poll frequency. I don't' know how either. The thing is here that the server is already polling the tiles multiple times and only doing something some of the time. It seems inefficient to me to attempt to make the server poll more frequently. Instead reduce the number of time the server does nothing during a poll.

Share this post


Link to post
Share on other sites

I am searching for a solution for the tree growth too... I run a small one-player server, and the trees don't grow very fast (they do not seem to grow at all to be honest).

I think the issue does not come from the "chance" parameter, but comes from the way the tile are polled. It seems the PollNext function polls X tiles per tick so that every tile is polled once a day. But if my server runs one or two hours a day, some tilles are never polled.

 

My ideas so far:

- Increasing the number of polled tiles is not a solution, because it may affect the performances of the server

- I planned to patch (with javassist) the function that loads the map in order to force PollNext to run many times in order to poll the whole map, but I did not manage to find the right way to do it (and I fear it will be quite resource-consuming)

- my current idea: use an "offline" approach, with a small script that directly updates the mesh file. I can then run the script just before launching the server.

 

Time to dive into the mesh file structure! ;-)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this