1. Is there a script that removes a tree (and all connecting branches and such) from a map? As in, I target a location or a tree id (I don't know, do tree's have individual ids?) and it will be erased?
2. Similarly, a script that does the same for bushes/shrubs/any growths?
3. Is milo christiansen's script still the best way to get a tile's material using lua?
1) Not that I know of, but it wouldn't be hard to write one...
2) I have a script that forcibly removes surface saplings. Actually if you look back a few pages in this thread I posted an early version of my sapling elimination code.
Speaking of my sapling deletion script I need to get that tested... The script is supposed to be an answer to "the jungle problem" (trees growing super thick on every map regardless of biome). Basically if surface trees go over a set limit it deletes all surface saplings until trees go under the limit again
Well when I look at the information for a given tree I find
[lua]# ~df.plant.find(2114)
<plant: 0x18452340>
flags = <plant_flags: 0x18452340>
material = 153
pos = <coord: 0x18452344>
grow_counter = 19982037
damage_flags = <plant.T_damage_flags: 0x18452350>
hitpoints = 400000
update_order = 9
site_id = -1
srb_id = -1
contaminants = <vector<spatter_common*>: 0x18452364>
tree_info = <plant_tree_info: 0x185d0a30>
Note that this is the same as just going ~df.global.world.plants.all[2114], the 2114 was just picked at random and then I went to look at that spot on the map. What is growing here is a large three story tree. My efforts to remove it were as follows;
1. Set hitpoints to 0 and then to -1. I was really hoping this would just take care of the tree, but nothing seemed to happen.
2. Set grow counter to 0 and then to -1. Again, no visible effect.
3. Set all damage_flags to true. No change.
4. Change material just to make sure you can actually have an affect. Material of tree did change.
5. Remove the entry for the tree from the plant list. No change.
6. Change the tiletype to that of the adjacent grass square. Tile changed to grass, but rest of tree (the above trunks and branches and twigs) still remain.
Now 4 and 5 together might be necessary to remove the tree (didn't try 5 without 4) but what I can't figure out is how to find all of the tiles for the tree. The plant entry only lists the base trunk, but changing the material of the base trunk changes the material of the entire tree, so they must be connected. Now I could just iterate over all of the squares next to the base of the tree and see which ones are also TREE tile types, but what if two trees are right next to eachother? How do you determine which branches belong to which tree?
Also, I can't think of a slick way to determine the id of a tree at a given location. It's possible to just brute force it and go through the position of all the plants on the df.global.world.plants.all list, but that could be several thousand even on a small map. And also you may be looking at not the main tree trunk but a different part of the tree, in which case you would need to look for the main trunk first and then look for the id.
All of these issues definitely can be dealt with brute force style. Just wondering if anyone else can think of a more elegant way to go about it.