Talk:Gem
Jump to navigation
Jump to search
This is the program I wrote to generate the table of gems. -- Killian 08:52, 19 October 2006 (UTC)
#include <stdio.h> #include <string.h> #include <stdlib.h> #define GEM(name,desc,prob,wt,gval,nutr,mohs,glass,color) \ printrow(name,desc,prob,wt,gval,nutr,mohs,glass,color) #define ROCK(name,desc,kn,prob,wt,gval,sdam,ldam,mgc,nutr,mohs,glass,color) \ printrow(name,desc,prob,wt,gval,nutr,mohs,glass,color) #define GEMSTONE "gemstone" #define GLASS "glass" #define MINERAL "mineral" #define CLR_WHITE "white" #define CLR_RED "red" #define CLR_ORANGE "orange" #define CLR_BLUE "blue" #define CLR_BLACK "black" #define CLR_GREEN "green" #define CLR_YELLOW "yellow" #define CLR_MAGENTA "magenta" #define CLR_BROWN "brown" #define CLR_GRAY "gray" /* 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(name, "flint")) { return " stone"; } if (!strcmp(material, "glass")) { return ""; } if (!strcmp(material, "mineral")) { 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", "luckstone", "loadstone", "touchstone", "flint", "rock", 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 *gem(char *name, char *material) { if (!strcmp(name, "rock")) { return ""; } if (!strcmp(material, "mineral")) { return " stone"; } return " gem"; } char *hard(int mohs) { return (mohs >= 8) ? "HARD" : "soft"; } typedef char *S; typedef int I; void pre(void) { printf("<!-- This table was generated by a program; see the talk page. -->\r\n"); printf("{| class=\"prettytable\"\r\n"); printf("! * !! Name !! Description !! Cost !! Weight !! Hardness !! Material\r\n"); } void printrow(S name, S desc, I prob, I wt, I gval, I nutr, I mohs, S glass, S color) { printf("|-\r\n"); printf("| {{%s|*}} ", color); printf("|| '''%s%s%s%s''' ", openlink(name), name, stone(name, glass), closelink(name)); printf("|| %s %s ", (desc ? desc : name), gem(name, glass)); printf("|| %i [[zm]] ", gval); printf("|| [[weight|%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("<!-- End generated table. -->\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), mid(); ROCK("luckstone", "gray", 0, 10, 10, 60, 3, 3, 1, 10, 7, MINERAL, CLR_GRAY), ROCK("loadstone", "gray", 0, 10, 500, 1, 3, 3, 1, 10, 6, MINERAL, CLR_GRAY), ROCK("touchstone", "gray", 0, 8, 10, 45, 3, 3, 1, 10, 6, MINERAL, CLR_GRAY), ROCK("flint", "gray", 0, 10, 10, 1, 6, 6, 0, 10, 7, MINERAL, CLR_GRAY), ROCK("rock", (char *)0, 1,100, 10, 0, 3, 3, 0, 10, 7, MINERAL, CLR_GRAY), post(); }