Welcome to the Builder Academy

Question New age code, pls read and comment and help fix it

More
06 Apr 2013 22:26 - 08 Apr 2013 12:01 #1820 by JTP
// TBAMUD STOCK AGE:

struct time_info_data *age(struct char_data *ch)
{
static struct time_info_data player_age;

player_age = *mud_time_passed(time(0), ch->player.time.birth);

player_age.year += 17; /* All players start at 17 */

return (&player_age);
}



// MY AGE CODE:
Code:
struct time_info_data *age(struct char_data *ch) { static struct time_info_data player_age; player_age = *mud_time_passed(time(0), ch->player.time.birth); switch (GET_RACE(ch)) { case RACE_HALF_GIANT: player_age.year += 58; break; case RACE_HALFLING: player_age.year += 75; break; case RACE_DWARF: player_age.year += 100; break; case RACE_ELF: player_age.year += 118; break; case RACE_GNOME: player_age.year += 80; break; case RACE_HUMAN: default: player_age.year += 18; break; } return (&player_age); }
.

Firstly with the thamud code setting people ages works fine they start as age 17 and if i with set changed to 25 it will be 25.


As you can see in my code i only added cases for each race like:
case RACE_DWARF:
player_age.year += 58; // this line is like the one in TBAMUD code just 58 instead of 17.
break; // break and on to next case


With my code people start with the age i specified BUT THEN if i with set change from dwarfs start age 58 to lets say 65 it will be set to 66.

BIG question is why ?

Should i remove:
default:
in case RACE_HUMAN ?
Last edit: 08 Apr 2013 12:01 by JTP.

Please Log in or Create an account to join the conversation.

More
06 Apr 2013 22:39 #1821 by Fizban
I see no reason it'd be adding 1 to the number you specify, the cause is likely in the set code, and not in that section, though that last bit is rather messy, but shouldn't be related.

Default cases aren't always necessary, they're typically considered good coding practice though, but when used they shouldn't be used like that, either of the following would be better:
Code:
- case RACE_HUMAN: ! default: // The Player is a human. player_age.year += 18; break;
Code:
case RACE_HUMAN: - default: player_age.year += 18; break; + default: + player_age.year += 18; + break;

Please Log in or Create an account to join the conversation.

More
06 Apr 2013 22:48 - 06 Apr 2013 23:14 #1822 by JTP
Now i tryed this:

struct time_info_data *age(struct char_data *ch)
{
static struct time_info_data player_age;

player_age = *mud_time_passed(time(0), ch->player.time.birth);
switch (GET_RACE(ch))
{
case RACE_HUMAN:
player_age.year += 18;
break;

case RACE_ELF:
player_age.year += 118;
break;

case RACE_GNOME:
player_age.year += 80;
break;

case RACE_DWARF:
player_age.year += 58;
break;

default:
player_age.year += 17;
break;
}

return (&player_age);
}

Now i tried the code like this:
I made a gnome with age 80 so far so good, then i set age in game to 100 BUT now the player got to be 163 ???????????????? wtf
Last edit: 06 Apr 2013 23:14 by JTP.

Please Log in or Create an account to join the conversation.

More
06 Apr 2013 23:27 #1823 by thomas
do_set:
Code:
case 2: /* age */ if (value < 2 || value > 200) { /* Arbitrary limits. */ send_to_char(ch, "Ages 2 to 200 accepted.\r\n"); return (0); } /* NOTE: May not display the exact age specified due to the integer * division used elsewhere in the code. Seems to only happen for * some values below the starting age (17) anyway. -gg 5/27/98 */ vict->player.time.birth = time(0) - ((value - 17) * SECS_PER_MUD_YEAR); break;
your age:

(100-17)+80 = 163...

Please Log in or Create an account to join the conversation.

More
21 Apr 2013 18:01 #1978 by JTP
After trying above age code i went back to stock age code, but now suddently people dont seem to age, they stay at 17 :(

Whats up with that ?

Please Log in or Create an account to join the conversation.

More
21 Apr 2013 19:22 #1980 by thomas
I'm going to assume you have a some kind of source code versioning system in place. Have you tried diff'ing the code versions?

Please Log in or Create an account to join the conversation.

Time to create page: 0.190 seconds