Need some help with thaumaturgy code...

Everything about ToME 2.x.x. No spoilers, please

Moderator: Moderator

Post Reply
Message
Author
Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Need some help with thaumaturgy code...

#1 Post by Lord Estraven »

So I'm trying to modify the thaumaturgy code in 2.3.8 (in cmd7.c) to make thaumaturgy still useful in the late game without making it horribly overpowered early on. And I'm running into problems. Specifically, "->". There are "->"s all over the place, and I've no idea what they do. At first I thought they were like "=" in reverse, making the value of the right variable equal to that of the left one or somesuch, but the more I look the more their use seems ambiguous.

(Can you tell I've never done C before? :oops: )

Also, the damage of spells is of course determined by a damroll of dam_dice and dam_sides. Only, those two values don't seem to be derived from anything I can see. Where do they come from?

bigfoot
Thalore
Posts: 120
Joined: Thu Aug 20, 2009 3:26 pm

Re: Need some help with thaumaturgy code...

#2 Post by bigfoot »

Disclaimer: I know very little, almost nothing, about C.

I think that they are references.
-The Bigfoot

I really do exist.

budswell
Wyrmic
Posts: 292
Joined: Wed May 21, 2008 2:08 am

Re: Need some help with thaumaturgy code...

#3 Post by budswell »

-> Is a quick syntax for getting a field from a pointer to a struct.
i.e. ptr->fld is shorthand for (*ptr).fld

Code: Select all

typedef struct { int id; char* name } RecType;
RecType rec;
RecType* recPtr = &rec;
/* To get a value from a record*/
int id1 = rec.id;
/* To get a value from a record pointer...*/
int id2 = (*recPtr).id;
/* ... or use the shorthand -> notation. Another way opf writing the same thing as above */
int id3 = recPtr->id;
Hope that makes sense

Shoob
Reaper
Posts: 1535
Joined: Mon Jan 22, 2007 6:31 pm
Location: East of the sun, west of the moon

Re: Need some help with thaumaturgy code...

#4 Post by Shoob »

those dam_dice and dam_sides are part of the spell passed to it (hence the s_ptr, short for spell pointer or something, just like csp is short for current spell points)

but yeah bigfoot is right.
Oliphant am I, and I never lie.

bigfoot
Thalore
Posts: 120
Joined: Thu Aug 20, 2009 3:26 pm

Re: Need some help with thaumaturgy code...

#5 Post by bigfoot »

Haha! About the only thing I know. :D
-The Bigfoot

I really do exist.

Sorgath
Higher
Posts: 53
Joined: Thu Feb 26, 2004 3:24 am

Re: Need some help with thaumaturgy code...

#6 Post by Sorgath »

Lord Estraven wrote:So I'm trying to modify the thaumaturgy code in 2.3.8 (in cmd7.c) to make thaumaturgy still useful in the late game without making it horribly overpowered early on. And I'm running into problems. Specifically, "->". There are "->"s all over the place, and I've no idea what they do. At first I thought they were like "=" in reverse, making the value of the right variable equal to that of the left one or somesuch, but the more I look the more their use seems ambiguous.

(Can you tell I've never done C before? :oops: )

Also, the damage of spells is of course determined by a damroll of dam_dice and dam_sides. Only, those two values don't seem to be derived from anything I can see. Where do they come from?
As has been said the -> are for accessing things via a pointer. You should be able to google "C pointers" to find a decent explanation that tells you all you need to know. What changes do you want to make? If they're small enough I might be willing to do them for you. But personally I think thaumaturgy is pretty broken in general and would need a complete re-write to fix it.
------------
Sorgath
-Preserve our wildlife and pickle a squirrel today.

Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Re: Need some help with thaumaturgy code...

#7 Post by Lord Estraven »

Okay, for future reference what I was looking for - limits on thaum damage, damage for different spell types, etc. - was in spells1.c.

(Of particular note is a typo that makes ball spells use sides for dice and 1 for sides. That is a very very old bug.)

AnonymousHero
Spiderkin
Posts: 482
Joined: Sat Mar 18, 2006 12:48 pm

Re: Need some help with thaumaturgy code...

#8 Post by AnonymousHero »

Do you happen to have a patch or could you point to the typo? I'd like to get it fixed.

Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Re: Need some help with thaumaturgy code...

#9 Post by Lord Estraven »

This in spells1.c, starting on line 9281:

Code: Select all

	else if (chance < 76)
	{
		rspell->proj_flags |= PROJECT_STOP;
		rspell->radius = dice;
		rspell->dam_dice = sides;
		rspell->dam_sides = 1;
		ball_desc = TRUE;
	}
Presumably dam_sides should be dice or some derivative thereof, not 1. Also radius should probably be changed to something more sane, like half or even a third of the dice.

AnonymousHero
Spiderkin
Posts: 482
Joined: Sat Mar 18, 2006 12:48 pm

Re: Need some help with thaumaturgy code...

#10 Post by AnonymousHero »

Have you tried playing around with different values to see what works reasonably? I'd like to make a change, but I don't really have time for playtesting ATM.

Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Re: Need some help with thaumaturgy code...

#11 Post by Lord Estraven »

This works for me so far... From the contents of generate_spell():

Code: Select all

	random_spell* rspell;
	int dice, sides, chance, mana, power;
	bool destruc_gen = FALSE;
	bool simple_gen = TRUE;
	bool ball_desc = FALSE;

	if (spell_num == MAX_SPELLS) return;

	rspell = &random_spells[spell_num];

	power = rand_int(15);

	/* make spells weaker at start */
	dice = plev / 5;
	sides = plev;
	mana = plev;

	/* Make the spell more or less powerful. */
	dice += power;
	sides += power ;
	/* seriously reduce the mana involved */
	mana += (plev * power) / 15;

	/* Stay within reasonable bounds. */
	if (dice < 1) dice = 1;

	if (sides < 5) sides = 5;

	if (mana < 1) mana = 1;

	rspell->level = plev;
	rspell->mana = mana;
	rspell->untried = TRUE;

	/* Spells are always maximally destructive. */
	rspell->proj_flags = PROJECT_KILL | PROJECT_ITEM | PROJECT_GRID;

	chance = randint(100);

	/* Hack -- Always start with Magic Missile or derivative at lev. 1 */
	if (plev == 1 || chance < 25)
	{
		rspell->proj_flags |= PROJECT_STOP;
		/* swap dice and sides for better damage */
		rspell->dam_dice = sides;
		rspell->dam_sides = dice;
		rspell->radius = 0;
	}
	else if (chance < 50)
	{
		rspell->proj_flags |= PROJECT_BEAM;
		rspell->dam_dice = dice;
		rspell->dam_sides = sides;
		rspell->radius = 0;
	}
	else if (chance < 76)
	{
		rspell->proj_flags |= PROJECT_STOP;
		rspell->radius = dice / 3;
		rspell->dam_dice = dice;
		rspell->dam_sides = sides;
		ball_desc = TRUE;
	}
	else if (chance < 83)
	{
		rspell->proj_flags |= PROJECT_BLAST;
		rspell->radius = sides / 3;
		rspell->dam_dice = dice;
		rspell->dam_sides = sides;

		destruc_gen = TRUE;
		simple_gen = FALSE;
	}
	else if (chance < 90)
	{
		rspell->proj_flags |= PROJECT_METEOR_SHOWER;
		/* okay we need to make these way less powerful */
		rspell->dam_dice = dice / 5;
		rspell->dam_sides = sides / 5;
		rspell->radius = sides / 3;
		if (rspell->radius < 4) rspell->radius = 4;

		destruc_gen = TRUE;
	}
	else
	{
		rspell->proj_flags |= PROJECT_VIEWABLE;
		rspell->dam_dice = dice;
		/* view spells should do less damage */
		rspell->dam_sides = sides / 2;
	}
Basically it:
- Removes the upper damage limits so bolt, ball, and beam spells can be more useful
- Makes the spells scale better in terms of damage vs. mana and vs. school spell damage while still being reasonably weak at the start
- Makes bolt spells somewhat more powerful than ball and beam spells
- Severely nerfs Area spells and much less severely nerfs LoS ones

It may be imperfect and perhaps a little biased towards excess player power, but I've tested it a bit and it seems to do the job.

Lom
Wayist
Posts: 23
Joined: Mon Sep 05, 2005 12:13 am

Re: Need some help with thaumaturgy code...

#12 Post by Lom »

How would you say the bolt/beam thaum spells compare to Manathrust from 2.3.5 now? Just so I can sort of get a comparison in my mind. :)

Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Re: Need some help with thaumaturgy code...

#13 Post by Lord Estraven »

Probably roughly the same, maybe a bit weaker at high levels.

AnonymousHero
Spiderkin
Posts: 482
Joined: Sat Mar 18, 2006 12:48 pm

Re: Need some help with thaumaturgy code...

#14 Post by AnonymousHero »

After a little playtesting (not at high level though), I have applied and pushed your changes to the ToME 2 git repo. Thanks.

Lord Estraven
Uruivellas
Posts: 718
Joined: Tue Dec 13, 2005 12:35 am

Re: Need some help with thaumaturgy code...

#15 Post by Lord Estraven »

Yay! Thanks. :)

Post Reply