Talk:Gem

This is the program I wrote to generate the table of gems. -- Killian 08:52, 19 October 2006 (UTC)


 * 1) include 
 * 2) include 
 * 3) include 

gem(name,desc,prob,wt,gval,nutr,mohs,glass,color)
 * 1) define GEM(name,desc,prob,wt,gval,nutr,mohs,glass,color) \


 * 1) define GEMSTONE "gemstone"
 * 2) define GLASS "glass"


 * 1) define CLR_WHITE "white"
 * 2) define CLR_RED "red"
 * 3) define CLR_ORANGE "orange"
 * 4) define CLR_BLUE "blue"
 * 5) define CLR_BLACK "black"
 * 6) define CLR_GREEN "green"
 * 7) define CLR_YELLOW "yellow"
 * 8) define CLR_MAGENTA "magenta"
 * 9) define CLR_BROWN "brown"

/* Don't display "stone" after the name. */ char *NO_STONE[] = { "dilithium crystal", "ruby", "diamond", "sapphire", "black opal", "emerald", "opal", NULL };

/* Returns " stone" if it should be appended, or else "". */ char *stone(char *name, char *material) { char **i;

if (!strcmp(material, "glass")) { return ""; }

for (i = NO_STONE; *i != NULL; i++) { if (!strcmp(name, *i)) { return ""; }	}	return " stone"; }

/* Name should be a wikilink. */ char *LINK_NAME[] = { "dilithium crystal", NULL };

int link(char *name) { char **i; for (i = LINK_NAME; *i != NULL; i++) { if (!strcmp(name, *i)) { return 1; }	}	return 0; }

char *openlink(char *name) { return link(name) ? "" : ""; } char *closelink(char *name) {	return link(name) ? "" : ""; }

char *hard(int mohs) { return (mohs >= 8) ? "HARD" : "soft"; }

typedef char *S; typedef int I;

void pre(void) { printf("\r\n"); printf("{| class=\"prettytable\"\r\n"); printf("! * !! Name !! Description !! Cost !! Weight !! Hardness !! Material\r\n"); }

void gem(S name, S desc, I prob, I wt, I gval, I nutr, I mohs, S glass, S color) { printf("|-\r\n"); printf("| ", color); printf("|| %s%s%s%s ", openlink(name), name, stone(name, glass), closelink(name)); printf("|| %s gem ", desc); printf("|| %i zm ", gval); printf("|| %i ", wt); printf("|| %s ", hard(mohs)); printf("|| %s ", glass); printf("\r\n"); }

void mid(void) { printf("|-\r\n"); printf("| colspan=7 |\r\n"); }

void post(void) { printf("|}\r\n"); printf("\r\n"); }

int main {

pre;

GEM("dilithium crystal", "white",     2,  1, 4500, 15,  5, GEMSTONE, CLR_WHITE), GEM("diamond", "white",               3,  1, 4000, 15, 10, GEMSTONE, CLR_WHITE), GEM("ruby", "red",                    4,  1, 3500, 15,  9, GEMSTONE, CLR_RED), GEM("jacinth", "orange",              3,  1, 3250, 15,  9, GEMSTONE, CLR_ORANGE), GEM("sapphire", "blue",               4,  1, 3000, 15,  9, GEMSTONE, CLR_BLUE), GEM("black opal", "black",            3,  1, 2500, 15,  8, GEMSTONE, CLR_BLACK), GEM("emerald", "green",               5,  1, 2500, 15,  8, GEMSTONE, CLR_GREEN), GEM("turquoise", "green",             6,  1, 2000, 15,  6, GEMSTONE, CLR_GREEN), GEM("citrine", "yellow",              4,  1, 1500, 15,  6, GEMSTONE, CLR_YELLOW), GEM("aquamarine", "green",            6,  1, 1500, 15,  8, GEMSTONE, CLR_GREEN), GEM("amber", "yellowish brown",       8,  1, 1000, 15,  2, GEMSTONE, CLR_BROWN), GEM("topaz", "yellowish brown",      10,  1,  900, 15,  8, GEMSTONE, CLR_BROWN), GEM("jet", "black",                   6,  1,  850, 15,  7, GEMSTONE, CLR_BLACK), GEM("opal", "white",                 12,  1,  800, 15,  6, GEMSTONE, CLR_WHITE), GEM("chrysoberyl", "yellow",          8,  1,  700, 15,  5, GEMSTONE, CLR_YELLOW), GEM("garnet", "red",                 12,  1,  700, 15,  7, GEMSTONE, CLR_RED), GEM("amethyst", "violet",            14,  1,  600, 15,  7, GEMSTONE, CLR_MAGENTA), GEM("jasper", "red",                 15,  1,  500, 15,  7, GEMSTONE, CLR_RED), GEM("fluorite", "violet",            15,  1,  400, 15,  4, GEMSTONE, CLR_MAGENTA), GEM("obsidian", "black",              9,  1,  200, 15,  6, GEMSTONE, CLR_BLACK), GEM("agate", "orange",               12,  1,  200, 15,  6, GEMSTONE, CLR_ORANGE), GEM("jade", "green",                 10,  1,  300, 15,  6, GEMSTONE, CLR_GREEN),

mid;

GEM("worthless piece of white glass", "white",  77, 1, 0, 6, 5, GLASS, CLR_WHITE), GEM("worthless piece of blue glass", "blue",    77, 1, 0, 6, 5, GLASS, CLR_BLUE), GEM("worthless piece of red glass", "red",      77, 1, 0, 6, 5, GLASS, CLR_RED), GEM("worthless piece of yellowish brown glass", "yellowish brown", 77, 1, 0, 6, 5, GLASS, CLR_BROWN), GEM("worthless piece of orange glass", "orange", 76, 1, 0, 6, 5, GLASS, CLR_ORANGE), GEM("worthless piece of yellow glass", "yellow", 77, 1, 0, 6, 5, GLASS, CLR_YELLOW), GEM("worthless piece of black glass", "black",  76, 1, 0, 6, 5, GLASS, CLR_BLACK), GEM("worthless piece of green glass", "green",  77, 1, 0, 6, 5, GLASS, CLR_GREEN), GEM("worthless piece of violet glass", "violet", 77, 1, 0, 6, 5, GLASS, CLR_MAGENTA),

post; }