That's a good version, Krice. The original code is a little strange, for instance, why do we check for the name 5 times? Is the user going to endlessly try to type in invalid names? And what counts as an invalid name? The only invalid name I can think of is one that is below or above a certain size. Anyway, here's what I was thinking:
I->showVersion ();
//get computer's name as default name
if(!name) //Thanks Krice! :D
if(getenv("USER"))
name=getenv("USER");
else if(getenv("USERNAME"))
name=getenv("USERNAME");
while(true) {
//input player's name
I->p ("Welcome to ZAPM!");
I->getStr (namebuf, HERO_NAME_LENGTH+1, "What is your name?", name);
I->pageLog ();
//check if the name is valid
if (nameOK(namebuf))
{
name=namebuf;
break;
}
}
//load or play new game
if (!loadGame (name) || !newGame (name)) //This originally assumed that loadGame and newGame return a non-zero value on success, which wasn't the case.
{
I->p ("Welcome to \"ZapM\". Press '?' for help.");
I->p ("Please submit bug reports at http://zapm.org/bb/");
if (GodMode) I->p ("God Mode is on.");
gameLoop ();
}
delete I;
Also, in response to the questions, ! will work with things that you wouldn't expect it to, because ! checks to see whether or not the operand is 0 (which is particularly useful since NULL = 0). If the operand is 0, then ! returns true. If the operand is non-zero, then ! returns false. For instance, !0 is true, while !1, !2, !3, !'a', and !"hello" are all false.
In C/C++, the if operator functions similarly: zero is false, non-zero is true. This allows for things like if( this_string_pointer_isnt_null ) printf("%s",the_string_mentioned_before); Despite how it may look, this actually works fine whether the string pointer is NULL or not (provided that if the pointer is not NULL that it points to a valid memory location, of course).
EDIT: I just downloaded ZAPM to see what problems might come up in compiling it, but it compiled just fine. There were less warnings than I see on my own code. I use MSVC++ 2008 Express, which is free. Even the name prompt works. Mingw32 might not like that ZAPM is defining classes without declaring what they are. If that's the case, you should just be able to delete those lines and move the class definitions around to get it to work.
EDIT 2: Thanks Krice! Fixed.