code deduplication

code thanks to https://github.com/sgrunt/GruntHack/commit/e7afc1b022dd5e1b39dd2c69db077b533e66f3f4

improves code of r519 of UnNetHack