castlewars additions and fixes for overstepping array bounds