Angband Forums

Angband Forums (http://angband.oook.cz/forum/index.php)
-   Idle chatter (http://angband.oook.cz/forum/forumdisplay.php?f=6)
-   -   Roguelike development practice (http://angband.oook.cz/forum/showthread.php?t=1515)

PaulBlay February 18, 2009 18:30

Roguelike development practice
 
I've attempted (and mostly failed ;-) to gain experience with C++ and the *band builds in various ways and here I go again.

This time I'm going to keep it simple (if I can) - just produce code to add one feature to the latest Angband code.

Code:

^T  Talk    Attempt to strike up conversation with an adjacent monster.
            (Monster will reply with single line based on its type)

If I get it to work I'll take suggestions of appropriate lines for monsters in the game. :D

pav February 18, 2009 21:09

Ogres need to have a line 'Heee did it.'

bio_hazard February 19, 2009 01:59

Quote:

Originally Posted by pav (Post 15718)
Ogres need to have a line 'Heee did it.'

"That's Brimstone."

PaulBlay February 19, 2009 15:14

Well, I got close this time, but it looks like no cigar for me. :(

I thought I'd added everything I needed for an extra parameter in the monster text, but now it is no longer recognizing the D: line! (Which I don't think I've touched)

Error at line 121 of 'monster.txt'.
Record 1 contains a 'undefined directive' error.
Parsing 'D:He looks squalid and thoroughly revolting.'.


Code:

        /* Process 'D' for "Description" */
        if (buf[0] == 'D')
        {
                /* Store the text */
                if (!add_text(&(r_ptr->text), head, buf+2))
                        return (PARSE_ERROR_OUT_OF_MEMORY);
        }

        /* Process 'T' for "Talk" */
        if (buf[0] == 'T')
        {
                /* Store the line of speech */
                if (!add_text(&(r_ptr->talk), head, buf+2))
                        return (PARSE_ERROR_OUT_OF_MEMORY);
        }

Oh well, better luck next scheme.

takkaria February 19, 2009 15:18

Quote:

Originally Posted by PaulBlay (Post 15787)
Well, I got close this time, but it looks like no cigar for me. :(

I thought I'd added everything I needed for an extra parameter in the monster text, but now it is no longer recognizing the D: line! (Which I don't think I've touched)

Error at line 121 of 'monster.txt'.
Record 1 contains a 'undefined directive' error.
Parsing 'D:He looks squalid and thoroughly revolting.'.


Code:

        /* Process 'D' for "Description" */
        if (buf[0] == 'D')
        {
                /* Store the text */
                if (!add_text(&(r_ptr->text), head, buf+2))
                        return (PARSE_ERROR_OUT_OF_MEMORY);
        }

        /* Process 'T' for "Talk" */
        if (buf[0] == 'T')
        {
                /* Store the line of speech */
                if (!add_text(&(r_ptr->talk), head, buf+2))
                        return (PARSE_ERROR_OUT_OF_MEMORY);
        }

Oh well, better luck next scheme.

That second 'if' should be 'else if'. Follow through the code and you'll see why.

PaulBlay February 19, 2009 15:49

Quote:

Originally Posted by takkaria (Post 15788)
That second 'if' should be 'else if'. Follow through the code and you'll see why.

That improved things - although it looks like I broke it elsewhere. :p

Obviously I need more practice.

Pete Mack February 19, 2009 15:54

@paul --
Do you have a working debugger? I assume from what you are saying, that you are using MSDEV. Even the free version has a line-by-line stepping debugger/IDE. You can put "breakpoints" in and stop the program at any point, then step from there. It can be very useful. (It can also be a huge time-waster.)

PaulBlay February 19, 2009 16:13

Quote:

Originally Posted by Pete Mack (Post 15791)
@paul --
Do you have a working debugger?

Presumably. :D

I haven't actually tried it yet though. Basically it's been decades since I sort-of-knew what I was doing with this stuff and I'm very slowly getting back up to speed.

Quote:

I assume from what you are saying, that you are using MSDEV. Even the free version has a line-by-line stepping debugger/IDE. You can put "breakpoints" in and stop the program at any point, then step from there. It can be very useful. (It can also be a huge time-waster.)
I'm familiar with breakpoints and stepping from Visual Basic. I'm not sure whether I've ever tried it with a C++ debugger. :o

What I did so far required changes to:
cmd0.c
cmds.h
cmd3.c
monster.txt
init1.c
init2.c
init.h
and
monster/types.h

Everything seems to be spread out to heck and gone.

Pete Mack February 19, 2009 17:46

Debugging with a C compiler isn't any harder. The tough part is setting up the compile environment from scratch :/

And your changes aren't really spread out "to heck and gone." I could have told you what files would need modifying.

For the record:

Adding a new command:
cmds.h to add the new command declaration
* [ED: this is broken, since some of them are also in externs.h]
cmd0.c, to add a new command to the command m enus & list.
* [pre-3.0.8: was dungeon.c, and was that ever a lousy place!]

cmd[1-3].c to add the new command implementation, depending on what type it is. (This depends on which menu in cmd0.c)
(cmd4.c is for meta-commands like options and knowledge)


To change the behavior of individual monsters: (NOT by monster "genus", like 'T', 'o', 'D', etc.)

monster.txt: to add the new flag/descriptor to the individual monster data field.
monster/types.h to add the new field in the basic monster type.
init1.c to add to the tokens (string constants) tables for initialization.
Also, the spoken strings may go here too.
init2.c to add to the monster.txt parser.
init.h to add the appropriate #defines for token_ids.

PaulBlay February 19, 2009 18:00

Quote:

Originally Posted by Pete Mack (Post 15802)
And your changes aren't really spread out "to heck and gone." I could have told you what files would need modifying.

In other words somebody who already knows where to go can find stuff. For somebody coming to the whole thing from scratch working out which bit does what is rather more of an uphill struggle.


All times are GMT +1. The time now is 07:27.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.