Spawn points don't guarantee distribution

Bug #1030507 reported by Erik Ogenvik
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cyphesis
Fix Committed
Undecided
Erik Ogenvik

Bug Description

When spawning into a spawn point, the entity should be placed within a random place within the are use by the spawn point.

The main issue is however that since there's no good way to get a random position within an arbitrary WFMath shape, the code has to use a more naive solution whereby it tries to generate a random position ten times, and check if any of these positions are contained within the shape.

For the path that the settlers are set to use this will in almost all cases fail (since the 2d box area of the path is way much larger than the area itself). The result is that settlers pretty much always are created at the same position.

Fixing this is non trivial. It would be possible to use a better way of generating a random position within the area, but that depends on WFMath having methods through which we could get the location of a collision (i.e. we could probe the area with lines or vectors from different directions to better figure out where to place the entity). Such methods are however lacking, and I don't foresee us having the resources to put any work into adding such methods.
One option further on is to revisit this issue if and when we decide to replace WFMath with a math library which is more actively maintained, and provide at least the same features, and more.

Another option would be to not use a shape such as the rather elongated path, instead defining something more square as the spawn point.

Revision history for this message
Al Riddoch (alriddoch) wrote :

I have suddenly worked out why some of my spawn locations are so confusing. I didn't realise that the spawn area was defined by such a long, odd shaped area.

Obviously an immediate fix in the default world would be to switch to something with a more reasonable shape, but I'd also like to create a general solution that does allow for this. The "try ten times, and hope to eventually get an intersect" algorithm never felt right, but I had to get it done before my 6 month sabatical, and six months later I'd forgotten about it.

Al Riddoch (alriddoch)
Changed in cyphesis:
assignee: nobody → Al Riddoch (alriddoch)
Revision history for this message
Erik Ogenvik (erik-ogenvik) wrote :

The world defined in https://github.com/worldforge/worlds/tree/master/mason/island has a more circular "landing area". I've also put some thought into having the landing area more game play friendly. Now, I haven't really done any work on that world in quite a time. Mainly because I've been preoccupied with other WF work.

Revision history for this message
Erik Ogenvik (erik-ogenvik) wrote :

Given any polygon there are ways of picking a random position within it. Usually by decomposing the polygon into triangles.
We shouldn't need to reinvent the wheel here; this might help. http://www.cgal.org/

Changed in cyphesis:
assignee: Al Riddoch (alriddoch) → Erik Ogenvik (erik-ogenvik)
status: New → Confirmed
Changed in cyphesis:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.