Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old March 16, 2020, 01:57   #1
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
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.

Last edited by DavidMedley; March 16, 2020 at 02:31.
DavidMedley is offline   Reply With Quote
Old March 16, 2020, 02:15   #2
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
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 is offline   Reply With Quote
Old March 16, 2020, 02:29   #3
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
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?

Last edited by DavidMedley; March 16, 2020 at 02:56.
DavidMedley is offline   Reply With Quote
Old March 16, 2020, 04:54   #4
wobbly
Veteran
 
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,246
wobbly is on a distinguished road
Quote:
Originally Posted by DavidMedley View Post
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
wobbly is offline   Reply With Quote
Old March 16, 2020, 05:41   #5
backwardsEric
Scout
 
Join Date: Aug 2019
Posts: 30
backwardsEric is on a distinguished road
Quote:
Originally Posted by DavidMedley View Post
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.
backwardsEric is online now   Reply With Quote
Old March 16, 2020, 05:52   #6
wobbly
Veteran
 
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,246
wobbly is on a distinguished road
Quote:
Originally Posted by DavidMedley View Post
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?
wobbly is offline   Reply With Quote
Old March 16, 2020, 06:38   #7
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
Quote:
Originally Posted by wobbly View Post
is working for me
Hmm ok
Code:
expr:D:WEAPON_DAMAGE: #<--doesn't parse
expr:D:WEAPON_DAMAGE:+ 0 #<-- does parse
Thanks!
DavidMedley is offline   Reply With Quote
Old March 16, 2020, 06:40   #8
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
Quote:
Originally Posted by backwardsEric View Post
those types were introduced after Angband was originally written
Makes sense. Thanks, Eric!
DavidMedley is offline   Reply With Quote
Old March 16, 2020, 06:43   #9
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
Quote:
Originally Posted by wobbly View Post
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 is offline   Reply With Quote
Old March 16, 2020, 08:37   #10
DavidMedley
Swordsman
 
Join Date: Oct 2019
Posts: 405
DavidMedley is on a distinguished road
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?
DavidMedley is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a code? jozmon Development 19 August 4, 2014 00:38
Questions regarding vanilla inscriptions Avenger Vanilla 8 December 13, 2013 21:15
Questions regarding vanilla dungeon design Cazliostro Vanilla 23 October 11, 2010 12:05
code help please will_asher Variants 22 March 15, 2010 19:00
Looking through the code K.I.L.E.R Vanilla 5 July 11, 2007 08:01


All times are GMT +1. The time now is 09:15.


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