Angband Forums

Angband Forums (
-   Vanilla (
-   -   Game cannot handle more than 255 terrain types (

PowerWyrm April 8, 2019 13:58

Game cannot handle more than 255 terrain types
Reported by Tangar in this post:

This is PWMAngband so I checked why this happened. The reason is obvious: the terrain "floor d hills" is exactly number 256 in the f_info feature array. This means there is somewhere where feature is coded on a "byte" and doesn't allow more than 255 terrain types. And I found the culprit:


struct square {
        byte feat;
        bitflag *info;
        int light;
        s16b mon;
        struct object *obj;
        struct trap *trap;

Everywhere else, feature index is coded on an integer. Vanilla code has the same "struct square", so it must also happen in V.

Nick April 8, 2019 14:53

Yes, it's like that partly because (a) tradition and (b) there's nowhere near 256 different terrain types in V. But the reason for byte instead of int is that for portability of savefiles you need to only save things of a fixed length, and int is platform dependent.

So this can be fixed; the way to do it is
  1. Change the type for feat in struct square to u16b;
  2. Change the saving and loading functions - wr_dungeon_aux() and rd_dungeon_aux() - so that the terrain piece uses u16b instead of byte.

As you say, I suspect ints are used pretty much everywhere else, but there may be the odd other occurrence to look out for. There has been a move for about the last ten years, though, to remove the special fixed length types and replace them with ints unless there's a good reason (like savefiles) not to.

So you can just to do this in PWMangband; there's no actual need to do it in V, but I probably will at some stage, if only to keep the two aligned as much as possible :)

All times are GMT +1. The time now is 15:53.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.