I'm working on a 2D game on the same vein as Tower Defense games but with a large world, seemless world.
The player(s) will have to react to attacks from different areas of the world and sometimes defend multiple fronts at once.
The problem I have is the idea of hundreds (potentially thousands) of "towers" trying to acquire targets. Also to avoid unnecessary checks when there are no targets within the maximum range. Line-of-Sight is NOT an issue, only whether the target fits within it's range. (some shoot directly forward, some can aim in a cone, etc)
I have been told that Quadtrees might allow me to optimize this system of target acquisition.
Is this true? Are there any articles I should read? Any pitfalls or alternatives?
Additionally, to prevent unnecessary checks, I had the idea that when a hostile unit enters the world, it "activates" all the defenses within a certain radius. And when there are no enemy units around, the defenses shut-down and go into a kind of "sleep" mode. Any thoughts on this?
You can combine both of your above ideas. In a quad tree, you'd often implement a function that takes a volume (usually a rectangle, but you could concievably have a circle or some swept shape), and returns all of the objects that are around that volume by returning the contents of all the nodes with which the circle intersects. So, an enemy can have its own volume (probably a circle with some detection radius), and it might query the tree with that circle to get the list of nearby towers. Then, you can tell those towers to do their thing (is the enemy within range? can we shoot it?...). This would probably give you the efficiency you need.
If you have a dynamic, node-based implementation of the tree, the recursive query function is very simple.
Check this out: http://www.kyleschou...ource-included/