Temple of The Roguelike Forums

Game Discussion => Traditional Roguelikes (Turn-based) => Topic started by: Psiweapon on February 15, 2011, 12:42:20 PM

Title: ZAPM - some trouble
Post by: Psiweapon on February 15, 2011, 12:42:20 PM
Hello people. First post here.

Recently I've discovered ZAPM and I've more or less fallen in love with it :P

The problem is, I can't compile the sources, the compiler always get stuck with some classes declaration.

Any folks here got any clue about that? Has anyone compiled ZAPM successfully? Any general recommendations?
Title: Re: ZAPM - some trouble
Post by: Krice on February 15, 2011, 04:37:42 PM
Error messages with the copy of the line where the error is could help.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 12:18:35 AM
Aye Aye!

C:\zapmsource\Global.h|65|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'shMenu'|
C:\zapmsource\Global.h|66|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'shCreature'|
C:\zapmsource\Global.h|68|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'shMonster'|

and on and on... a gazillion errors more. The lines around that are

Code: [Select]

[...]

60 #define FULLTURN  1000
62 #define HALFTURN  500
63 #define QUICKTURN 250
64
65 struct shInterface;
66 class shMenu;
67 class shCreature;
68 struct shMonsterIlk;
69 class shMonster;
70 struct shObjectIlk;
71 struct shObject;

[...]


in global.h . Basically in every class line. Or is it the line before?

I'm using codeblocks, mingw32, and the version of the ZAPM source is 0.8.3 froom nethack.devnull.net

How do I compiled ZAPM ?  :'(

I suck ballz big tiem-.-
Title: Re: ZAPM - some trouble
Post by: Fenrir on February 16, 2011, 02:55:58 AM
I went to http://nethack.devnull.net (http://nethack.devnull.net), but I couldn't find the source. That doesn't mean much, as I may have just missed it, but, if you'll link to me the source, I'll have a go at compiling it.

The Win32 binary for version 0.8.2 is available at http://www.zapm.org (http://www.zapm.org) if you ever get tired of messing with it. You probably know already if you've played it already, but I figured that there would be no harm in mentioning it.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 03:10:07 AM

But of course  :)

http://nethack.devnull.net/software/zapm.tgz Labeled as "current"
http://nethack.devnull.net/software/zapm-083-src.tgz
http://nethack.devnull.net/software/zapm-082-src.tgz

let me know if it works well for youª
Title: Re: ZAPM - some trouble
Post by: Krice on February 16, 2011, 07:05:05 AM
The source comes with Visual C++ project file. It's compiling in VC++, just one warning (MOUSE_MOVED seems to be re-defined). If it's complaining about class, are you sure it's compiling in C++ mode?

By the way, running zapm was an interesting experience. I tried to type in my name (it was using computer's name by default) by pressing enter couple of times (nothing happened) and the game complained about "too many tries" and stopped. What the hell?
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 10:59:56 AM

Well I´ll be getting some tool that´s more vc++ specific and see if that helps...

I like this game so much I´m aching to tweak1 it.

About the name, it let´s me use the default name as well as typing one, that sounds weird.

And yes, I guess it was compiling in c++ mode since it asked me if it was a c or c++ project (and my answer was the later)



1 You might as well read "ruin" XD.
Title: Re: ZAPM - some trouble
Post by: Krice on February 16, 2011, 04:19:10 PM
Well I´ll be getting some tool that´s more vc++ specific and see if that helps...

Get VC++ Express, it's free. It's also the best IDE for Windows. Although the problem in zapm could possibly be VC++ only feature, which is bad programming. Writing standard portable C++ is of course possible in VC++ also. I'm developing code in VC++ and running final compile in GCC, because there is some .dll dependencies in VC++.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 04:58:02 PM
Yes, I have installed it already! But I don´t have time right now to try to compile it again, Ill post later if I have any success.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 06:05:05 PM

Well, I got to see the project file with VC++ and it does compile... but alas, it won't read the name input, what the hell?!
Title: Re: ZAPM - some trouble
Post by: Krice on February 16, 2011, 07:16:25 PM
but alas, it won't read the name input, what the hell?!

Yes, it's strange. It appears to be an older VC project file, so maybe there are differences let's say in Windows XP (possibly the platform zapm was programmed) and Windows 7 related to that input routine. Who knows. Just looking at global.h tells that zapm source code is poor quality.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 16, 2011, 08:27:17 PM

 I'm running winbugs XP too and it gives me the same bullshit XD

It really looks that bad? Perhaps that's why I can kind of understand some of it XD

I just love the theme and gameplay.

Thanks for the help man, the version I play is 0.8.2, I'll try to check if that compiles fine and then check the differences in the name-typing, or just switch to screw around with 0.8.2...
Title: Re: ZAPM - some trouble
Post by: Krice on February 17, 2011, 04:53:58 PM
Here's the epic code asking for player's name:

Code: [Select]
   if (!name) {
        int tries = 5;

        name = getenv ("USER");
        if (!name)
            name = getenv ("USERNAME");

        do {
            if (!tries--) {
                I->p ("Too many tries!");
                I->pause ();
                I->p ("");
                goto done;
            }
            I->p ("Welcome to ZAPM!");
            I->getStr (namebuf, HERO_NAME_LENGTH+1,
                       "What is your name?", name);
            I->pageLog ();
        } while (!nameOK (namebuf));
        name = namebuf;
    }

It could be simple but this guy has made it complicated. Also, great names for instances and functions. Interface class instance is 'I' and text output 'p'.
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 17, 2011, 05:29:13 PM
I had located it and somehow1 managed to get it to compile (perhaps I erased a typo or something, go figure) but then the game crashed as soon as a (b)arrel exploded. Way to go.







1 As in "I haven't the foggiest"
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 19, 2011, 08:04:15 PM
I ditched 0.8.3 and started screwing around with 0.8.2 (Which is the version I've played, anyway)

I've been able to add some stuffs and even got it to compile :D
Title: Re: ZAPM - some trouble
Post by: eit_cyrus on February 20, 2011, 11:14:40 PM
It appears to be an older VC project file, so maybe there are differences let's say in Windows XP (possibly the platform zapm was programmed) and Windows 7 related to that input routine. Who knows. Just looking at global.h tells that zapm source code is poor quality.

poor qaualalitiy??!!!!
poor qualiaity????  WHO DAERS to imppeach teh codding skillzz of EIT_CYRUS!?!?!   ZAPM was not intended to be complied by teh likes of GRIID BUGZ like yuo using soem tin can crock box hoem computter!!! 

I suggets yuo upgraed your computer to hthte to teh propar system requiremements!!  ZAPM is develeloped on  a REALL WORKSTAITION with SERIUOUS specificiations!!!!:]

[/size]
Title: Re: ZAPM - some trouble
Post by: Ex on February 21, 2011, 12:57:22 AM
Yeah guys, I have this exact setup, and it compiles just fine!  ;D
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 07:31:16 AM
I'm not sure if this causes the bug, but I think testing like

if (value)

or

if (!value)

should be used only with boolean type. Anyway, it's just a guess, could be something else. Maybe it's some kind of compiler dependent stuff and fails to work correctly in proper compilers like VC++.
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 08:03:12 AM
I had some time so I fixed the bug by refactoring that section of code. I also removed goto command, because those are bad. And added some comments. This code is in main.cpp.

Code: [Select]
I->showVersion ();

bool name_ok=true; //name is ok by default

//if no name was given yet
if (name==0)
{
for (int tries=0; tries<5; tries++)
{
//get computer's name as default name
name = getenv ("USER");
if (name==0) name = getenv ("USERNAME");

//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)==1)
{
name=namebuf;
name_ok=true;
break;
}
else name_ok=false; //set the name invalid and try again for five times
}
}

if (name_ok)
{
//load or play new game
if (0 == loadGame (name) || 0 == newGame (name))
{
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 ();
}
}
else
{
//failed to input a proper name
I->p ("Too many tries!");
I->pause ();
I->p ("");
}

    delete I;
Title: Re: ZAPM - some trouble
Post by: Ex on February 21, 2011, 09:57:06 AM
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:

Code: [Select]
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. :)
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 10:24:45 AM
And what counts as an invalid name?

nameOK function is checking the name. I didn't look at that carefully, but it doesn't matter, I trust it works. Also, I think you forgot (in your version) that 'name' can already be set from command line (check earlier code!). That's why the code starts with if (name==0) check and skips it entirely if name is set.
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 10:28:38 AM
Despite how it may look, this actually works fine

Didn't work fine in this case!
Title: Re: ZAPM - some trouble
Post by: Ex on February 21, 2011, 10:32:46 AM
Despite how it may look, this actually works fine

Didn't work fine in this case!
Where in this case?

EDIT: Ah, I found the problem :) Here's the fixed code, tested in game:

Code: [Select]
 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)) // Turns out that these return 0 on success
{
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;
It wasn't working because loadGame and newGame return 0 on success. Also, the original program shows the name editor screen even if given a name, so I updated that, too.
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 11:07:48 AM
Where in this case?

If you compile the original code the name input doesn't work (for some reason). I guess it must have something to do with those !checks with other than booleans, because with the refactored code I posted the input works and you can proceed to play the game.

ps. I think you "fixed" the code wrong again: the entire code section must be skipped if 'name' is given in command line. Also, the problem is not in the return values of newGame or loadGame which return int. Stop checking other than booleans with !.
Title: Re: ZAPM - some trouble
Post by: Ex on February 21, 2011, 11:17:40 AM
Where in this case?

If you compile the original code the name input doesn't work (for some reason). I guess it must have something to do with those !checks with other than booleans, because with the refactored code I posted the input works and you can proceed to play the game.

ps. I think you "fixed" the code wrong again: the entire code section must be skipped if 'name' is given in command line. Also, the problem is not in the return values of newGame or loadGame which return int. Stop checking other than booleans with !.
The fixed code works fine, my original fix wasn't working because newGame and loadGame needed ! to be checked. Checking stuff with ! is a time tested, tried, and true method of programming in C/C++. It is perfectly valid, and works fine in this case. Also, skipping the name editor if name is given at the command line is not totally nesssisary, but if you want it, then just put brackets around everything before the new/loadGame stuff. My code works fine, ! has nothing to do with it. In any event, my fix works. Don't tell me what to do when you clearly don't know C/C++ as well as I do.
Title: Re: ZAPM - some trouble
Post by: Krice on February 21, 2011, 12:21:57 PM
my original fix wasn't working because newGame and loadGame needed ! to be checked.

They return int, you use ! with booleans. Also, try to get that if you give the name from command line (using -u username) it's already check with nameOK. Scroll up to see the previous code. Now, if you don't skip the ENTIRE code section asking player's name it's going to ask the name AGAIN even if you entered it in command line. Try to get it, finally!
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 21, 2011, 03:59:59 PM
ZOMG TEH DRAMA!!!!

I´ll proceed to read the thread and   :D
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 21, 2011, 04:04:48 PM
Also I will check your fixes, I HOEP TEHY DONT SPLODE MY CAMPUTER!!!!7!!7
Title: Re: ZAPM - some trouble
Post by: Psiweapon on February 21, 2011, 04:12:52 PM
Fixes work nice, but 0.8.3 keeps crashing when a barrel explodes  ::)