Tuesday 7 September 2010

Roguelike MUD progress #4

Previous post: Roguelike MUD progress #3

Almost no progress on the game today. Instead, I was distracted by two different problems with my code reloading framework. Link to SVN revision.

  1. Use of slots:
    class Tile(object):
    __slots__ = [ "character", "fgColour", "bgColour", "flags" ]
    This also seems to be an unsolved problem in the xreload module, which was written for normal Python namespaces.

    TypeError: descriptor 'flags' for 'Tile' objects doesn't apply to 'Tile' object

    I've not got any better ideas, and I am only using __slots__ for the sake of it. So the solution is to stop using them.

  2. File-local instances of the classes it defines:
    START_TILE = Tile("x", isMarker=True)
    SPAWN_TILE = Tile("s", isMarker=True)
    WALL_TILE = Tile("X", isPassable=False, isOpaque=True)
    WALL1_TILE = Tile("1", isPassable=False, isOpaque=True)
    WALL2_TILE = Tile("2", isPassable=False, isOpaque=True)
    DOOR_TILE = Tile("D")
    FLOOR_TILE = Tile(" ")

    mapTilesByCharacter = {}
    def IndexTiles():
    for k, v in globals().iteritems():
    if k.endswith("_TILE"):
    mapTilesByCharacter[v.character] = v
    IndexTiles()

    CHAR_TILE_TEMPLATE = Tile("@", isPassable=False)
    DRAGON_TILE = Tile("&", isPassable=False)
    I've had to use a custom framework that has xreload-based code reloading, and encountered this same scenario there. In that case, it was because the class was registered with a external factory and subsequently used to churn out bad instances. These then hit the following error.

    unbound method BLAH must be called with BLAH instance as first argument (got BLAH instead)

    Solving that leaked class problem was simple, through locating the references to the throwaway new class, and substituting the old reference for them. Replacing instances though, is a little more complicated.

    This error has gone away in 3.x I am told, which is a pity. As it serves as a good indication that there instances or class references have leaked outside of the code reloading system.
Chances are that I am going to have to try and solve these cases for xreload, as well as in my custom framework.

Next post: Roguelike MUD progress #5

Sunday 5 September 2010

Roguelike MUD progress #3

Previous post: Roguelike MUD progress #2.

Field of view emphasis is now row based, rather than tile based. However, I've also added the ability for tiles to have attached foreground and background colours. Really, the rendering needs to break all this down and minimise the number of switches made using different escape codes. For now, use of colour is limited, so updating the display does not seem slow or flickery like it was in the past before I batched updates.

I've also added simple NPCs, in this case three small green dragons that wander around the dungeon. For now, that's all they do, but they're good at highlighting rendering bugs.



Current TODO list:

  1. Add bursts of fire, using different tiles and colours to make use of a wide range of colours than the basic eight through dithering. It might be a good idea to write the tile/colour choosing logic in a way that can optionally use the xterm 256 colour mode, if the client can be detected as supporting it.
  2. Add option for NPCs to choose to attack, rather than move, when they are ticked.
  3. Add option for players to attack, rather than move.
  4. At the moment, player keypresses are executed as they come in from the client. They should instead be queued and executed at a fixed rate.


Next post: Roguelike MUD progress #4