Eufloria > Eufloria Classic Support

Bug: PlantDysonTree and PlantDefenseTree allow illegal planting

<< < (2/4) > >>

threephi:
The workaround code is rather simple, but I'm pointing it out because it's clearly not how it's supposed to work.  For one thing, it's contrary to the function description given in the lua reference (although that description does contain a subtle error discussed below).  You're not supposed to have asteroids with trees belonging to two (or more) different factions, and when it happens it can really mess things up.

Given a = asteroid in question; f = faction whose tree you want to plant:


--- Code: ---if a:AvailableStructureSpace() and (a.IsBarren() or a.owner == f) then
        PlantDysonTree(f)
end
--- End code ---

In looking into this bug I did gain an appreciation of the subtleties involved in planting a tree so it's not so straightforward as a simple owner check.


--- Quote from: annikk.exe on June 04, 2011, 11:01:28 PM ---
--- Quote from: Aino on June 04, 2011, 07:54:27 PM ---Well, why bother so much of this? And this actually allows more stuff to be done, to prevent it; just check if the owner is themself else that there is noone that have been planting one it...

--- End quote ---

That alone won't work, two different empires can plant on an asteroid at the same time.  The asteroid doesn't actually change owners until the roots reach the center.

--- End quote ---
Exactly.  You can have legitimate situations where two different factions can legally plant a tree at roughly the same time. If you have a virgin asteroid with zero existing trees (and room for trees of course), the new owner will be whoever gets their roots to touch the center first, in which case all the trees will become theirs.  Once there is one root system that touches the center, the rules are different.

Here's the subtle omission in the function description I mentioned above:

--- Quote ---   Attempt to plant a Dyson tree using the seedlings present at the asteroid; if nothing can be done (all tree slots are taken, or there are not enough seedlings or the asteroi [sic] is owned by some other faction than team 0 or the given faction) the function does nothing and returns nil. Otherwise the function returns a Structure, which is the base type of the trees in Dyson.
--- End quote ---
Any faction can plant on any asteroid with zero existing tree roots so long as there are tree slots, no matter which faction is designated as the owner.

Aino:
Mhm...

A tree/owner/root check will do the trick, cause if a tree is planted, it will immediatly be added to the amount of trees on the roid. Just tested to plant a tree, just after the tree was PLANTED, it was already counted as a tree on the asteroid.

So if you're using a custom AI, just add a root array and make it change to true for the asteroid if there is an existing tree on the roid and the root array is false for the roid. then if it is false it'll be allowed to plant :)

annikk.exe:
You don't need an array to check for it.

Aino:
Maybe not, but thats how I did it :P

threephi:
That's kind of exactly what AvailableStructureSpace() does... true if there is room to plant a tree, false if not.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version