A simple mechanism to markup mud output |
A mechanism to markup mud outputIt looks a bit like HTML You are in a [fairy]huge[/fairy] cavern. [day]Shafts of light descend from an opening high in the cavern ceiling.[/day]... This implementation does support ==, && (and), || (or) logic, though it's subtle. [fairy][mage]Show to fairy mage[/mage][/fairy] --> (race == fairy && class == mage) [fairy]Show to fairy[/fairy][elf]Show to elf[/elf] --> (race == fairy || race == elf) ...but not integral value tests or intergral comparison tests. (age > 25) (level == 1) It can be easily extended to do things like that: [dwarf][age 25+]Something for old dwarves[/age][/dwarf] --> (race == dwarf && age >= 25) [level 1]Welcome newbie.[/level] --> (level == 1) [detect hidden 50]something really secret[/detect hidden] --> (skill_check("detect hidden", 50) == true) [evil]a view from the dark side[/evil] --> (alignment <= -350) I think it's a good example of creating an interface that tries its damndest to not turn builders into coders. I suspect trying to convert them often makes them unhappy and disgruntled. I don't know if that's really true or not. Ahh the power of regular expressions. |
int termwidth[] = {40,60,80}; string sex[] = {"male", "female"}; string race[] = {"human", "elf", "fairy"}; string tod[] = {"day", "night"}; |
int Termwidth[] = {40,60,80}; string Sex[] = {"male", "female"}; string Race[] = {"human", "elf", "fairy"}; string TOD[] = {"day", "night"}; |
vector<int> Termwidth; vector<string> Sex; vector<string> Race; vector<string> TOD; |
string show(string s, Player* p) { |
string show(string s, Player& p) { |
sprintf(tws,"%d",p->tw); |
string pat; for(vector<string>::iterator i = p->pf.begin(); i != p->pf.end(); i++) { pat = "\\[" + *i + "\\](.*?)\\[\\/" + *i + "\\]"; RE(pat, RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).GlobalReplace?("\\1",&str); |
for(vector<string>::iterator i = p.pf.begin(); i != p.pf.end(); i++) { RE("\\[" + *i + "\\](.*?)\\[\\/" + *i + "\\]", RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).GlobalReplace?("\\1",&str); |
pat = "\\[" + *i + "\\].*?\\[\\/" + *i + "\\]"; RE(pat, RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).GlobalReplace?("",&str); |
RE("\\[" + *i + "\\].*?\\[\\/" + *i + "\\]", RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).GlobalReplace?("",&str); |
pat = "\\S{" + string(tws) + "})(?=\\S)"; RE(pat).GlobalReplace?("\\1", &str); pat = "(.{1," + string(tws) + "})(?:\\s+|$)"; RE(pat).GlobalReplace?("\\1\n", &str); |
sprintf(tws,"%d",p.tw); RE("\\S{" + string(tws) + "})(?=\\S)").GlobalReplace?("\\1", &str); RE("(.{1," + string(tws) + "})(?:\\s+|$)").GlobalReplace?("\\1\n", &str); |
Termwidth.assign(termwidth, termwidth+3); Sex.assign(sex, sex+2); Race.assign(race, race+3); TOD.assign(tod, tod+2); Keywords.insert(Keywords.end(), Sex.begin(), Sex.end()); Keywords.insert(Keywords.end(), Race.begin(), Race.end()); Keywords.insert(Keywords.end(), TOD.begin(), TOD.end()); for(int i=0; i<5; i++) { Player* p = new Player( Sex[rand() % Sex.size()], Race[rand() % Race.size()], TOD[rand() % TOD.size()], Termwidth[rand() % Termwidth.size()] |
Keywords.insert(Keywords.end(), Sex, Sex+2); Keywords.insert(Keywords.end(), Race, Race+3); Keywords.insert(Keywords.end(), TOD, TOD+2); for(int i=0; i<10; i++) { Player p( Sex[rand() % 2], Race[rand() % 3], TOD[rand() % 2], Termwidth[rand() % 3] |
cout << "Sex:" << p->sex << " Race:" << p->race << " TOD:" << p->tod << " TW:" << p->tw << endl; |
cout << "Sex:" << p.sex << " Race:" << p.race << " TOD:" << p.tod << " TW:" << p.tw << endl; |