quote:Perhaps to minimize the number of squares (if your map is huge and largely unoccupied), use larger squares for areas that have no one in them. Then, if a unit walks into this large square, it (the large square) is subdivided into smaller squares. Squares that a moving unit can no longer see are subsumed into larger squares again.
Maybe what you can do is for every map square you have a list of pointers to units that can see that square. This way, when a unit enters the square you wake the surrounding units of its presence. Now you don''t have check every unit to see if he sees something in all his squares. This would mean that only moving the units that are moving need to be actively processed. And only the enemies units would trigger the squares, thus only moving enemies would trigger your stationary units.
When the order to move is given to a unit, a pathfinding algorithm finds all or part of a path, and the squares the unit will be able to see during this route add the unit to their lists. Perhaps the subdivision is done at this time. Perhaps the path is divided into parts, and then this (adding to the list and/or subdividing/subsuming) is done only on the first part.