PDA

View Full Version : Help decrypting the effect_list ?


PaulBlay
May 24, 2009, 15:06
/* Use a slightly unusual include method to create effect_list[] */
static const char *effect_list[] =
{
#define EFFECT(x, y, r, z) #x,
#include "list-effects.h"
#undef EFFECT
};

EFFECT(XXX, FALSE, 0, NULL)
EFFECT(POISON, FALSE, 0, "poisons you for 2d7+10 turns")
EFFECT(BLIND, FALSE, 0, "blinds you for 4d25+75 turns")
EFFECT(SCARE, FALSE, 0, "induces fear in you for 1d10+10 turns")

Basically I'm currently (attempting to) make Angband place nicely with Unicode.

My problem is that I don't know exactly what "#define EFFECT(x, y, r, z) #x," does and I need to change it because the "XXX" etc. are being treated as narrow text strings (8bit) and I either need to make them wide (16bit) or work out how to get it to compile while they are still narrow.

So I'd really like to know what the "slightly unusual include method" is. :)

takkaria
May 24, 2009, 15:22
/* Use a slightly unusual include method to create effect_list[] */
static const char *effect_list[] =
{
#define EFFECT(x, y, r, z) #x,
#include "list-effects.h"
#undef EFFECT
};

EFFECT(XXX, FALSE, 0, NULL)
EFFECT(POISON, FALSE, 0, "poisons you for 2d7+10 turns")
EFFECT(BLIND, FALSE, 0, "blinds you for 4d25+75 turns")
EFFECT(SCARE, FALSE, 0, "induces fear in you for 1d10+10 turns")

Basically I'm currently (attempting to) make Angband place nicely with Unicode.

My problem is that I don't know exactly what "#define EFFECT(x, y, r, z) #x," does and I need to change it because the "XXX" etc. are being treated as narrow text strings (8bit) and I either need to make them wide (16bit) or work out how to get it to compile while they are still narrow.

So I'd really like to know what the "slightly unusual include method" is. :)

#x in an macro "stringifies" x. So, what that #define is just making EFFECT(XXX) into "XXX", or EFFECT(POISON) into "POISON", etc.

(And can't you just use UTF-8 instead of UTF-16? It's much nicer... :))

PaulBlay
May 24, 2009, 16:10
(And can't you just use UTF-8 instead of UTF-16? It's much nicer... :))

Now, now, you know it's only fun if everybody gets to make their own mistakes.

Thanks for the #x info. Unfortunately I think the necessary changes would break that cute bit of coding so I'm re-doing it with extra redundancy for now.