On map init use a hashtable to save the terrain type at every x/y in 64 unit intervals or something, and periodically check to see if the unit has moved to a new tile, and if so revert the old terrain changes done and make the new.
Why don't you post a question like this in JASS help, instead, though?
Why don't you post a question like this in JASS help, instead, though?