Dynamic factory tile edges

done in a hackish and unreadable way, but I really don't feel like
cleaning it up at the moment. Might want to modularize this code for use
by lava caves, etc