[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  int str2 = (int) (str * 0.25 + 10);

int str2 = (int) (str * 0.25 + 10);

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


Pages: 1 2  

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Wed 14 Jul 2004 02:59 AM (UTC)

Amended on Wed 14 Jul 2004 06:32 AM (UTC) by Mike Scherling

Message
***EDIT*** Making this easier for anyone looking at it.. ill update this part so you can see what changes I make etc.. etc..

Thanks a TON for working with me so far.. cant wait till this small error is fixed, then I can move onto the rest of y mud...

---If you think logging onto the mud to evaluate parts otf this would helpp, leave a message and i can get you the ip and port


void status_update (CCharacter *ch)
{
ASSERT (ch);
if (! ch->IsNpc())
CClassData *pClass = ClassTable.GetClassData (ch->GetClass ());
{
int str = (int) ch->GetCurrentStrength();
short str2 = (int) (str * 0.25 + 10);
int dex = (int) ch->GetDexterity ();
short dex2 = (int) (dex * 0.25 + 10);
int Newbie = ClassTable.GetClass ("Newbie");
if (ch->GetClass() == Newbie)
{
int hpupdate = 300 + (level * (40 + con - 20));
int fpupdate = 300 + (level * (40 + (intm - 20) / 2 + (wis - 20) / 2));
ch->SetMaxHp (hpupdate);
ch->SetMaxMana (fpupdate);
ch->SetDamroll(str2);
ch->SetHitroll(dex2);
}
}

mset self str 75
and
( STR: 75 ) ( DAM: 30 )

mset self str 76
and
( STR: 76 ) ( DAM: 127 ) <----Daroll bumps up to 127 ;\


damage also jumps into the negatives (I have damage shown on each attack) when i set the str to 76... damage is just fine on 75 strength though

Can you tell me -why- everything up to strength 75 works, then suddely at 76 it bumps up to 127.. maybe some of you can give this a try, Ive searched high, low, and everythign in between, ive disabled ALL stat bonus's related to strength and damroll, so only this equation will affect damroll

Any help would be appreciated =) thanks.. heh


P.S I know a bti about the code, but this one problem has had me stumped for days.. spending late nights pickign through it to find out what could be causing this problem





***EDIT***
I fixed teh damage message part, I accidntly set it to show damage on the miss/dodge/parry as well as the hit, so that would show a negative number.. one moment, i will copy a string of what the combat looks like

You dodge the chadoyn's attack.
You dodge the chadoyn's attack.
You brush the chadoyn. -[44]-
You brush the chadoyn. -[44]-
The chadoyn brushes you. -[1]-

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 14 Jul 2004 03:26 AM (UTC)
Message
What do GetCurrentStrength and SetDamroll do?

Why are you casting the return value to int? You shouldn't do that without a good reason.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #2 on Wed 14 Jul 2004 03:33 AM (UTC)

Amended on Wed 14 Jul 2004 03:35 AM (UTC) by Mike Scherling

Message
the value was origionally short, but seeing the numbers im using.. it didnt really matter whether i used short or int (i switched to int to see if it would fix the negative number problem)


int and short didnt affect anything




And --> What do GetCurrentStrength and SetDamroll do?

Thats calling for what the players current strength is, and it setdamroll is setting the players damroll to what the equation is that i gave above

they are very self explanitory



***EDIT*** If you are talking about the (int) then that is setting the number to be a full number, and not a decimal.. hence the reason i am using it, multiplying by .25 is causing it so every 4 strength it will go up 1 damroll, if it didnt have (int) it would return it as a decimal number

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #3 on Wed 14 Jul 2004 04:15 AM (UTC)
Message
If you simply dont want decimals, it would seem to me to be simpler to use ((str*3)/4)+10 instead of multiplying by .25 and forcing an int cast.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #4 on Wed 14 Jul 2004 04:22 AM (UTC)
Message
well, either way.. its working just the same =)


So... anyone have a fix for why my hitroll and damage roll keep shooting up when my str hits 76? I adjusted all stat values.. went into #Define and adjusted the hitroll and damroll there to my equation, still no work

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #5 on Wed 14 Jul 2004 04:29 AM (UTC)
Message
Can you paste the code that calculates it? There might be something in there that a second(or 20) set of eyes will be able to spot.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #6 on Wed 14 Jul 2004 04:30 AM (UTC)
Message
Without seeing all the changes and comparing to the original formulae, it's really hard to say why it might be doing that. Could be an obscure call in the original code, could be a typo in the revised, could be some wierd unexpected combination of old and new.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 14 Jul 2004 05:28 AM (UTC)
Message
Quote:

Thats calling for what the players current strength is, and it setdamroll is setting the players damroll


Yes, I sort of guessed that GetCurrentStrength would get the player's current strength, I meant "what does the code look like?".

127 is one of those "critical" numbers that should ring alarm bells. Also, when things "go negative" that is another alarm bell.

The numbers that a signed char (not short or int) will hold are -128 to +127. Thus, if you somehow force your calculation to be a char it might have that affect.

Similarly, if a calculation uses a short for its variables, and the number being calculated goes over 32767, it will become negative (shorts being -32768 to +32767).

As for the casts, in a line like this:

int str = (int) ch->GetCurrentStrength();

The cast to int doesn't achieve much, as the compiler is stuffing the result into an int anyway (int str). If you start getting into the habit of throwing in casts in the hope of fixing problems you may well cause them.

Quote:

multiplying by .25 is causing it so every 4 strength it will go up 1 damroll, if it didnt have (int) it would return it as a decimal number


Yes, but you are putting it into an int, so the compiler must convert it into an int to achieve that. Did you do that to eliminate a compiler warning?


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #8 on Wed 14 Jul 2004 06:05 AM (UTC)

Amended on Wed 14 Jul 2004 06:13 AM (UTC) by Mike Scherling

Message
A code snippet from what I am doing

void status_update (CCharacter *ch)
{
ASSERT (ch);
if (! ch->IsNpc())
CClassData *pClass = ClassTable.GetClassData (ch->GetClass ());
{
int str = (int) ch->GetCurrentStrength();
short str2 = (int) (str * 0.25 + 10);
int dex = (int) ch->GetDexterity ();
short dex2 = (int) (dex * 0.25 + 10);
int Newbie = ClassTable.GetClass ("Newbie");
if (ch->GetClass() == Newbie)
{
int hpupdate = 300 + (level * (40 + con - 20));
int fpupdate = 300 + (level * (40 + (intm - 20) / 2 + (wis - 20) / 2));
ch->SetMaxHp (hpupdate);
ch->SetMaxMana (fpupdate);
ch->SetDamroll(str2);
ch->SetHitroll(dex2);
}
}


EDIT:: Changed the int values to short (from reading what you wrote above) going to see what happens -starts testing-




***************************************
This is a snippet from teh code string I have, it all follows the same definitions, calls for a status update every time prompt is shown, it allws me to give a character complete flexibility on there stats, persay if a character has a buff cast on them that raises the Con stat, it would also raise their life... or lower it if a curse of sorts is put on them.

Everything works perfectly, the only problem is the jump that happens beween 75 strength, and 76 strength affecting the damroll...



---This also happens with dexterity, which follows the same equation as strength, but affects hitroll

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #9 on Wed 14 Jul 2004 06:16 AM (UTC)
Message
We ( well, at least me ) were refering to the code for GetCurrentStrength() and SetDamroll(). The problem is most likely in SetDamroll(), because the strength function seems to set it properly, and as Nick points out, perhaps it has an internal variable defined as a char instead of an int or short (for whatever reason).

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #10 on Wed 14 Jul 2004 06:22 AM (UTC)

Amended on Wed 14 Jul 2004 06:26 AM (UTC) by Mike Scherling

Message
#define GET_DAMROLL(ch) (ch->GetDamroll() \
+ str_app [ch->GetCurrentStrength()].tohit \
+ (2-(abs(ch->GetMentalState ())* 0)))
#define GET_HITROLL(ch) (ch->GetHitroll() \
+ str_app [ch->GetCurrentStrength()].tohit \
+ (2-(abs(ch->GetMentalState ())* 0)))




These 2 values are in my SMAUG.H I Believe that thi is where the problem is coming from, since i have 2 values trying to update my stats... is there a way for my to cancel this out effectivly (voiding it wont work) so it pulls the value from my settings there?

I am planning on having each if ch->GetClass to have its own set of values for hitroll and damroll



EDIT:::


#define GET_HITROLL(ch) (ch->GetHitroll() \
+ (int) (str_app [ch->GetDexterity()].tohit * 0.25))
#define GET_DAMROLL(ch) (ch->GetDamroll() \
+ (int) (str_app [ch->GetCurrentStrength()].tohit * 0.25))

I tried setting these values, and then voiding out the ones in teh character set, but still no ado.. brought me to -24000 or so when i set my strength to 76

BTW, thanks a -ton- for giving me some somewhat active support on this, its been happenign for gdays and ive been adjusting readjusting, then putting back everyhign i thought coudl be the problem


-Mike

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #11 on Wed 14 Jul 2004 06:30 AM (UTC)
Message

Character.h
int GetDamroll () { return m_Damroll; }
void SetDamroll (int d) { m_Damroll = d; }
void AddDamroll (int d) { m_Damroll += d; }


That is the only other value for setdamroll that has any signifigance i coudl find, maybe somethign here needs changed? doesnt look like it to me, but i may not be experienced enough to know this part

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #12 on Wed 14 Jul 2004 06:40 AM (UTC)

Amended on Wed 14 Jul 2004 06:44 AM (UTC) by Greven

Message
K, so when your talking about it here:

( STR: 76 ) ( DAM: 127 ) <----Daroll bumps up to 127 ;\

Your printing GET_DAMROLL or GetDamroll()? Also I notice that in GET_DAMROLL, its using .tohit, the same as in GET_HITROLL? Is that intentional? Why not just divide by four instead of multiplying by .25? Exact same thing without the cast to int. If your only dividing by four, it discards any decimal values automatically.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Mike Scherling   USA  (20 posts)  [Biography] bio
Date Reply #13 on Wed 14 Jul 2004 06:47 AM (UTC)

Amended on Wed 14 Jul 2004 06:49 AM (UTC) by Mike Scherling

Message
GET_DAMROLL(ch) is what I am calling for in my score


Also I notice that in GET_DAMROLL, its using .tohit, the same as in GET_HITROLL?

It was forced, the #define doesnt work without it, gives a poop load of errors when I go to compile
.tohit however doesnt have any relevance to the hitroll, Im not sure exacly what it does, Ill tae a quick look at it though

EDIT:
D:\Program Files\BuiltByRustry\SmaugWizard Builder\HANDLER.CPP(63) : error C2679: binary '+' : no operator defined which takes a right-hand operand of type 'const struct str_app_type' (or there is no acceptable conversion)

is the error i get when removing the .tohit, AND i ran a search through all files, .tohit is only valid in those 2 places, for #define hitroll and damroll..
It isnt only in the Handler.cpp, it is located in about 10 or 11 other files as well

The source is all around us...
in the food you eat...
in the air you breath...
in your tooth... yes, your tooth...
any questions?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #14 on Wed 14 Jul 2004 06:51 AM (UTC)
Message
I think its supposed to be calling .todam instead, and looking at mine for 30 slots, the difference might be it. You also might have a number from for slot 76 in the str_app table. Perhaps its like 50 instead of 30 or something. I dunno. You can check the table, its in const.c for my own

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] 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.


42,050 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]