Angband Forums

Angband Forums (http://angband.oook.cz/forum/index.php)
-   Development (http://angband.oook.cz/forum/forumdisplay.php?f=10)
-   -   Vanilla Code Questions (http://angband.oook.cz/forum/showthread.php?t=9905)

DavidMedley March 16, 2020 01:57

Vanilla Code Questions
 
I'm hacking around with vanilla at the moment. I'm going to post some questions as they come up.

My background: I don't have a lot of experience with C but I have 15+ years experience as a professional software developer. I'm more familiar with Perl than any other language.

DavidMedley March 16, 2020 02:15

Where do things like PLAYER_LEVEL from class.txt get interpreted? I only find that string in text files and player-spell.c.
Code:

expression_base_value_f spell_value_base_by_name(const char *name)
{
        static const struct value_base_s {
                const char *name;
                expression_base_value_f function;
        } value_bases[] = {
                { "SPELL_POWER", spell_value_base_spell_power },
                { "PLAYER_LEVEL", spell_value_base_player_level },
                { "DUNGEON_LEVEL", spell_value_base_dungeon_level },
                { "MAX_SIGHT", spell_value_base_max_sight },
                { "WEAPON_DAMAGE", spell_value_base_weapon_damage },
                { "PLAYER_HP", spell_value_base_player_hp },
                { "MONSTER_PERCENT_HP_GONE", spell_value_base_monster_percent_hp_gone },
                { NULL, NULL },
        };
        const struct value_base_s *current = value_bases;

        while (current->name != NULL && current->function != NULL) {
                if (my_stricmp(name, current->name) == 0)
                        return current->function;

                current++;
        }

        return NULL;
}

When I saw this I thought "Jackpot!" But when I try to put in things like WEAPON_DAMAGE into class.txt, angband gives me a parse error when I run it. I tried PLAYER_HP and DUNGEON_LEVEL as well and they give the same error, though MONSTER_PERCENT_HP_GONE obviously works since it's part of the Necro class.

So where are these codes, such as PLAYER_LEVEL and MONSTER_PERCENT_HP_GONE interpretted?

DavidMedley March 16, 2020 02:29

Confirming: "s32b" means "signed 32 bit integer"? Example:
Code:

        s32b new_mana, new_mana_frac;
If so, why use this construction instead of "signed long int"? Or just "long" for brevity?

wobbly March 16, 2020 04:54

Quote:

Originally Posted by DavidMedley (Post 143649)
Where do things like PLAYER_LEVEL from class.txt get interpreted? I only find that string in text files and player-spell.c.
Code:

expression_base_value_f spell_value_base_by_name(const char *name)
{
        static const struct value_base_s {
                const char *name;
                expression_base_value_f function;
        } value_bases[] = {
                { "SPELL_POWER", spell_value_base_spell_power },
                { "PLAYER_LEVEL", spell_value_base_player_level },
                { "DUNGEON_LEVEL", spell_value_base_dungeon_level },
                { "MAX_SIGHT", spell_value_base_max_sight },
                { "WEAPON_DAMAGE", spell_value_base_weapon_damage },
                { "PLAYER_HP", spell_value_base_player_hp },
                { "MONSTER_PERCENT_HP_GONE", spell_value_base_monster_percent_hp_gone },
                { NULL, NULL },
        };
        const struct value_base_s *current = value_bases;

        while (current->name != NULL && current->function != NULL) {
                if (my_stricmp(name, current->name) == 0)
                        return current->function;

                current++;
        }

        return NULL;
}

When I saw this I thought "Jackpot!" But when I try to put in things like WEAPON_DAMAGE into class.txt, angband gives me a parse error when I run it. I tried PLAYER_HP and DUNGEON_LEVEL as well and they give the same error, though MONSTER_PERCENT_HP_GONE obviously works since it's part of the Necro class.

So where are these codes, such as PLAYER_LEVEL and MONSTER_PERCENT_HP_GONE interpretted?

look in init.c for Initialize player classes

backwardsEric March 16, 2020 05:41

Quote:

Originally Posted by DavidMedley (Post 143650)
Confirming: "s32b" means "signed 32 bit integer"? Example:
Code:

        s32b new_mana, new_mana_frac;
If so, why use this construction instead of "signed long int"? Or just "long" for brevity?

Yes, it means a 32-bit signed integer. If one uses long, you don't have a guarantee about the size. For instance, when compiling 64-bit applications on Linux or Mac OS, a long is a 64-bit signed integer. There's a standard way of referring to integers with a known number of bits (int32_t, uint32_t, ....), and you'll see that used in h-basic.h to define what s32b is. But those types were introduced after Angband was originally written, and it's understandable that Angband adopted its own convention.

wobbly March 16, 2020 05:52

Quote:

Originally Posted by DavidMedley (Post 143649)
When I saw this I thought "Jackpot!" But when I try to put in things like WEAPON_DAMAGE into class.txt, angband gives me a parse error when I run it. I tried PLAYER_HP and DUNGEON_LEVEL as well and they give the same error, though MONSTER_PERCENT_HP_GONE obviously works since it's part of the Necro class.

Changing:

Code:

spell:Magic Missile:1:1:22:4
effect:BOLT_OR_BEAM:MISSILE:0:-10
dice:$Dd4
expr:D:PLAYER_LEVEL:- 1 / 5 + 3
desc:Fires a magic missile that always hits its target and does
desc: unresistable damage.
desc:  Sometimes a beam is fired instead that hurts each monster
desc: in its path.
desc:  The chance to get a beam goes up with your character level.

to

Code:

spell:Magic Missile:1:1:22:4
effect:BOLT_OR_BEAM:MISSILE:0:-10
dice:$Dd4
expr:D:WEAPON_DAMAGE:- 1 / 5 + 3
desc:Fires a magic missile that always hits its target and does
desc: unresistable damage.
desc:  Sometimes a beam is fired instead that hurts each monster
desc: in its path.
desc:  The chance to get a beam goes up with your character level.

is working for me, & gives me a magic missile damage based on the dice of my weapon.

What parser error are you getting?

DavidMedley March 16, 2020 06:38

Quote:

Originally Posted by wobbly (Post 143660)
is working for me

Hmm ok
Code:

expr:D:WEAPON_DAMAGE: #<--doesn't parse
expr:D:WEAPON_DAMAGE:+ 0 #<-- does parse

Thanks!

DavidMedley March 16, 2020 06:40

Quote:

Originally Posted by backwardsEric (Post 143659)
those types were introduced after Angband was originally written

Makes sense. Thanks, Eric!

DavidMedley March 16, 2020 06:43

Quote:

Originally Posted by wobbly (Post 143652)
look in init.c for Initialize player classes

OK. Now that we have the other thing figured out, hopefully I won't have to make any changes in here!

DavidMedley March 16, 2020 08:37

OK, this is a pretty big ask, but I'll put it out into the universe and see what happens.

I want to create a spell that includes a melee blow as one of its effects. I've looked at
Code:

static bool py_attack_real(struct player *p, struct loc grid, bool *fear)
/**Attack the monster at the given location with a single blow.*/

And that seems to be perfect for what I have in mind, so I shouldn't have to write a whole new attack sequence.

But when I look at
Code:

bool spell_cast(int spell_index, int dir) {
...
        effect_do(spell->effect, source_player(), NULL, ident, true, dir, beam, 0)
...
}

It's really abstract and hard to follow. This probably makes it very flexible and powerful and (I'm hoping) pretty easy to get it to do what I want.

So can anyone provide me with hints or examples of how to do this?


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

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