Skip to content

Commit

Permalink
Allow player character names to contain all non-reserved ASCII charac…
Browse files Browse the repository at this point in the history
…ters. Partially addresses #1138.
  • Loading branch information
ianestrachan committed Aug 20, 2013
1 parent f7eb335 commit bd0ffcc
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int set_profession(WINDOW* w, game* g, player *u, character_type type, int &poin
int set_skills(WINDOW* w, game* g, player *u, character_type type, int &points);
int set_description(WINDOW* w, game* g, player *u, character_type type, int &points);

bool is_char_allowed(char ch);
int random_skill();

int calc_HP(int strength, bool tough);
Expand Down Expand Up @@ -1144,8 +1145,7 @@ int set_description(WINDOW* w, game* g, player *u, character_type type, int &poi
} else if (ch == '\t') {
line = 2;
mvwprintz(w, 6, namebar_pos + utf8_width(u->name.c_str()), c_ltgray, "_");
} else if (((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
ch == ' ') && utf8_width(u->name.c_str()) < 30) {
} else if (is_char_allowed(ch) && utf8_width(u->name.c_str()) < 30) {
u->name.push_back(ch);
}
else if(ch==KEY_F(2)) {
Expand Down Expand Up @@ -1176,6 +1176,27 @@ int set_description(WINDOW* w, game* g, player *u, character_type type, int &poi
} while (true);
}

/**
* Returns whether or not the given (ASCII) character is usable in a (player)
* character's name. Only printable symbols not reserved by the filesystem are
* permitted.
* @param ch The char to check.
* @return true if the char is allowed in a name, false if not.
*/
bool is_char_allowed(char ch) {

//Allow everything EXCEPT the following reserved characters:
return (ch > 31 //0-31 are control characters
&& ch < 127 //DEL character
&& ch != '/' && ch != '\\' //Path separators
&& ch != '?' && ch != '*' && ch != '%' //Wildcards
&& ch != ':' //Mount point/drive marker
&& ch != '|' //Output pipe
&& ch != '"' //Filename (with spaces) marker
&& ch != '>' && ch != '<'); //Input/output redirection

}

int player::random_good_trait()
{
return rng(1, PF_SPLIT - 1);
Expand Down

0 comments on commit bd0ffcc

Please sign in to comment.