Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Energy (mana) drain code snippet -dbsaga

Energy (mana) drain code snippet -dbsaga

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Angelicus   USA  (5 posts)  Bio
Date Thu 09 Apr 2009 05:51 PM (UTC)
Message
I recently found a copy of DBSaga (Smaug based) on one of my back up disks and decided to try my hand at learning C in my spare time. Unfortunately the small community that DBSaga had went away a while ago and I cannot find any of the code snippets that some of the others had done.

First on my list as adding an energy(mana) drain for the Super Saiyan transformations so the players would not be able to indefinitely stay in their transformed state, at least not a first.

I started by mimicing the code for energy drain related to a different skill at that went smooth so this is my attempt at basing it on skill level instead of the players PL(experience).

I plan on adding it in tonight but I was wondering if anyone here could look it over and see if there are any glaring errors or holes in the code.
Top

Posted by Angelicus   USA  (5 posts)  Bio
Date Reply #1 on Thu 09 Apr 2009 05:52 PM (UTC)
Message
Here is the code:

void ssj_drain(CHAR_DATA *ch)
{
    int drain;
	/* This is so when they sleep they don't lose energy trying to sustain the transformation or in the future gain skill */
	if (ch->position <= POS_SLEEPING)
	{
		act( AT_RED, "Your hair flashes back to its original color as you lose conciseness.", ch, NULL, NULL, TO_CHAR );
		act( AT_RED, "$n's hair flashes back to its original color as $e loses conciseness.", ch, NULL, NULL, TO_NOTVICT );
		if (xIS_SET((ch)->affected_by, AFF_SSJ)
			|| xIS_SET((ch)->affected_by, AFF_SSJ2)
			|| xIS_SET((ch)->affected_by, AFF_SSJ3)
			|| xIS_SET((ch)->affected_by, AFF_SSJ4))
	    {
			if (xIS_SET((ch)->affected_by, AFF_USSJ))
				xREMOVE_BIT((ch)->affected_by, AFF_USSJ);
			if (xIS_SET((ch)->affected_by, AFF_USSJ2))
				xREMOVE_BIT((ch)->affected_by, AFF_USSJ2);
			if (xIS_SET((ch)->affected_by, AFF_SSJ))
				xREMOVE_BIT((ch)->affected_by, AFF_SSJ);
			if (xIS_SET((ch)->affected_by, AFF_SSJ2))
				xREMOVE_BIT((ch)->affected_by, AFF_SSJ2);
			if (xIS_SET((ch)->affected_by, AFF_SSJ3))
				xREMOVE_BIT((ch)->affected_by, AFF_SSJ3);
			if (xIS_SET((ch)->affected_by, AFF_SSJ4))
				xREMOVE_BIT((ch)->affected_by, AFF_SSJ4);
				ch->pl = ch->exp;
				transStatRemove(ch);
					if( !IS_NPC( ch ) )
					{
					  ch->pcdata->haircolor = ch->pcdata->orignalhaircolor;
					  ch->pcdata->eyes      = ch->pcdata->orignaleyes;
					}
		}
		return;
	}
	/* 4 if checks one for each of the different levels of Super Saiyan Transformations to determine how much energy to drain */
	if (xIS_SET(ch->affected_by, AFF_SSJ)
		&& !xIS_SET(ch->affected_by, AFF_SSJ2)
		&& !xIS_SET(ch->affected_by, AFF_SSJ3)
		&& !xIS_SET(ch->affected_by, AFF_SSJ4))
		{
		if (( ch->pcdata->learned[gsn_ssj] > 0 ) && ( ch->pcdata->learned[gsn_ssj] < 20 ))
			drain = 100;
		else if (( ch->pcdata->learned[gsn_ssj] > 20 ) && ( ch->pcdata->learned[gsn_ssj] < 50 ))
			drain = 80;
		else if (( ch->pcdata->learned[gsn_ssj] > 50 ) && ( ch->pcdata->learned[gsn_ssj] < 70 ))
			drain = 40;
		else if (( ch->pcdata->learned[gsn_ssj] > 70 ) && ( ch->pcdata->learned[gsn_ssj] < 90 ))
			drain = 20;
		else if (( ch->pcdata->learned[gsn_ssj] > 90 )
			drain = 0;
		}
	if (!xIS_SET(ch->affected_by, AFF_SSJ)
		&& xIS_SET(ch->affected_by, AFF_SSJ2)
		&& !xIS_SET(ch->affected_by, AFF_SSJ3)
		&& !xIS_SET(ch->affected_by, AFF_SSJ4))
		{
		if (( ch->pcdata->learned[gsn_ssj2] > 0 ) && ( ch->pcdata->learned[gsn_ssj] < 20 ))
			drain = 200;
		else if (( ch->pcdata->learned[gsn_ssj2] > 20 ) && ( ch->pcdata->learned[gsn_ssj] < 50 ))
			drain = 150;
		else if (( ch->pcdata->learned[gsn_ssj2] > 50 ) && ( ch->pcdata->learned[gsn_ssj] < 70 ))
			drain = 100;
		else if (( ch->pcdata->learned[gsn_ssj2] > 70 ) && ( ch->pcdata->learned[gsn_ssj] < 90 ))
			drain = 50;
		else if (( ch->pcdata->learned[gsn_ssj2] > 90 )
			drain = 0;
		}
	if (!xIS_SET(ch->affected_by, AFF_SSJ)
		&& !xIS_SET(ch->affected_by, AFF_SSJ2)
		&& xIS_SET(ch->affected_by, AFF_SSJ3)
		&& !xIS_SET(ch->affected_by, AFF_SSJ4))
		{
		if (( ch->pcdata->learned[gsn_ssj3] > 0 ) && ( ch->pcdata->learned[gsn_ssj] < 20 ))
			drain = 300;
		else if (( ch->pcdata->learned[gsn_ssj3] > 20 ) && ( ch->pcdata->learned[gsn_ssj] < 50 ))
			drain = 200;
		else if (( ch->pcdata->learned[gsn_ssj3] > 50 ) && ( ch->pcdata->learned[gsn_ssj] < 70 ))
			drain = 100;
		else if (( ch->pcdata->learned[gsn_ssj3] > 70 ) && ( ch->pcdata->learned[gsn_ssj] < 90 ))
			drain = 50;
		else if (( ch->pcdata->learned[gsn_ssj3] > 90 )
			drain = 0;
		}
	if (!xIS_SET(ch->affected_by, AFF_SSJ)
		&& !xIS_SET(ch->affected_by, AFF_SSJ2)
		&& !xIS_SET(ch->affected_by, AFF_SSJ3)
		&& xIS_SET(ch->affected_by, AFF_SSJ4))
		{
		if (( ch->pcdata->learned[gsn_ssj4] > 0 ) && ( ch->pcdata->learned[gsn_ssj] < 20 ))
			drain = 400;
		else if (( ch->pcdata->learned[gsn_ssj4] > 20 ) && ( ch->pcdata->learned[gsn_ssj] < 50 ))
			drain = 300;
		else if (( ch->pcdata->learned[gsn_ssj4] > 50 ) && ( ch->pcdata->learned[gsn_ssj] < 70 ))
			drain = 200;
		else if (( ch->pcdata->learned[gsn_ssj4] > 70 ) && ( ch->pcdata->learned[gsn_ssj] < 90 ))
			drain = 100;
		else if (( ch->pcdata->learned[gsn_ssj4] > 90 )
			drain = 0;
		}


	/* actual drain function, would like to add a possibilty for a skill increase in this if possible */
	if (ch->mana - drain < 0)
	{
		drain = drain - ch->mana;
		ch->mana = 0;
	}
	else
		ch->mana -= drain;

	if (drain != 0 && ch->mana == 0)
	{
		act( AT_RED, "Your hair and eyes return to their original color as you can no longer sustain your Super Saiyan state.", ch, NULL, NULL, TO_CHAR );
		act( AT_RED, "$n's hair and eyes return to their original color as $e can no longer sustain the Super Saiyan state.", ch, NULL, NULL, TO_NOTVICT );

		if (xIS_SET((ch)->affected_by, AFF_SSJ)
					|| xIS_SET((ch)->affected_by, AFF_SSJ2)
					|| xIS_SET((ch)->affected_by, AFF_SSJ3)
					|| xIS_SET((ch)->affected_by, AFF_SSJ4))
				{
					if (xIS_SET((ch)->affected_by, AFF_USSJ))
						xREMOVE_BIT((ch)->affected_by, AFF_USSJ);
					if (xIS_SET((ch)->affected_by, AFF_USSJ2))
						xREMOVE_BIT((ch)->affected_by, AFF_USSJ2);
					if (xIS_SET((ch)->affected_by, AFF_SSJ))
						xREMOVE_BIT((ch)->affected_by, AFF_SSJ);
					if (xIS_SET((ch)->affected_by, AFF_SSJ2))
						xREMOVE_BIT((ch)->affected_by, AFF_SSJ2);
					if (xIS_SET((ch)->affected_by, AFF_SSJ3))
						xREMOVE_BIT((ch)->affected_by, AFF_SSJ3);
					if (xIS_SET((ch)->affected_by, AFF_SSJ4))
						xREMOVE_BIT((ch)->affected_by, AFF_SSJ4);
						ch->pl = ch->exp;
						transStatRemove(ch);
							if( !IS_NPC( ch ) )
							{
							  ch->pcdata->haircolor = ch->pcdata->orignalhaircolor;
							  ch->pcdata->eyes      = ch->pcdata->orignaleyes;
							}
				}

	}
	return;
}
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #2 on Thu 09 Apr 2009 07:55 PM (UTC)
Message
The best thing to do would be attempt a compile and test it in-game.

We don't know what structs/pointers/etc the MUD has so it can be hard to say if it'll work or not.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Angelicus   USA  (5 posts)  Bio
Date Reply #3 on Thu 09 Apr 2009 08:17 PM (UTC)

Amended on Thu 09 Apr 2009 08:19 PM (UTC) by Angelicus

Message
I was thinking along the lines of general structure. I have a habit of forgetting a bracket or semicolon. As it is it looks right to me though I do wonder if I overlapped the the skill checks correctly.

Luckily I found the code in update.c that controls the regular mana recovery so I should be able to turn that off while testing.

edit:
I'll definitly post back if it doesn't compile and I can't figure out why.
Top

Posted by Angelicus   USA  (5 posts)  Bio
Date Reply #4 on Fri 10 Apr 2009 03:44 PM (UTC)
Message
I had a few parse errors but I managed to get rid of those. It compiles in Cygwin but i get the following warning:
new_fun.c: In function 'ssj_drain':
new_fun.c:934: warning: 'ssjdrain' might be used uninitialized in this function


here is lines 932-934:
void ssj_drain(CHAR_DATA *ch)
{
	int ssjdrain; 


So it should be initialized right?
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #5 on Fri 10 Apr 2009 05:30 PM (UTC)
Message
No, it is declared, or in other words, the variable has been said to exist. It is not initialized, or in other words, given a value. Try: int ssjdrain = 0; to initialize it to 0.
Top

Posted by Angelicus   USA  (5 posts)  Bio
Date Reply #6 on Fri 10 Apr 2009 07:28 PM (UTC)
Message
Thanks Worstje. That fixed the compile warnings.

Turns out I also had to reverse my affect checks. appearantly the ssj affects stack so I had to start with the highest and work my way down.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


25,201 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.