Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How Does DF Calculate Dwarves' Ages?  (Read 389 times)

Antalia

  • Bay Watcher
    • View Profile
How Does DF Calculate Dwarves' Ages?
« on: March 09, 2012, 04:21:44 pm »

To calculate a creature's current age in years, normally I would take the current year, subtract the birth year, and then subtract one additional year if the birthday had not yet passed this year. Right?

DF doesn't seem to be doing this.

With DFHack I can obtain a creature's birth year and birth time. I can also get the current year and tick, which appear to be on the same scales. So, why are the values I get when I follow the algorithm above, often different from the age-related text on the unit screen in DF by one year? How does DF calculate the age value?

It's important to me to understand, because I am calculating and exporting dwarves' ages from DF, into an application that would like to filter juveniles. And I can't seem to get the ages I calculate to exactly match up with what DF itself reports on the unit screen.
Logged
Author of Saga of Nutscaves, a tale of unsafe working conditions, plague, and worse

Creator of Dwarf Organizer, a Java application to help assign labor in your fortress

thatkid

  • Bay Watcher
  • <Servibot> thatkid, swag percentiles: 94
    • View Profile
Re: How Does DF Calculate Dwarves' Ages?
« Reply #1 on: March 09, 2012, 05:35:43 pm »

I know that Birth DATE does not matter, only year.
What sort of incongruities are you seeing?
Logged
Fame is a vapor. The only earthly certainty is oblivion.

Dwarfu

  • Bay Watcher
  • Dwarven Advisor
    • View Profile
Re: How Does DF Calculate Dwarves' Ages?
« Reply #2 on: March 09, 2012, 05:49:30 pm »

Known bugs:

#1178, #2739, #3945
Logged

Antalia

  • Bay Watcher
    • View Profile
Re: How Does DF Calculate Dwarves' Ages?
« Reply #3 on: March 09, 2012, 05:58:09 pm »

If I had to guess, I think that DF is just subtracting the birth year from the current year, and stopping right there, without considering the birth date. Because the incongruities are like this one:

A creature is born in year value 4294967221. His birthday is in the 12th month of the year. The current year value is 4294967310, and it's the first month of the year right now. I'd expect the creature to be 88 years old right now, turning 89 in the 12th month. DF reports the age as 89 years on the unit screen.

My cases where the age I calculate is off by a year seem to follow that pattern, but I don't have a big enough sample size to be comfortably sure. (I haven't played the new version yet, and I don't have my old forts.) I'm wondering when DF draws the line with juveniles...do they stop being a juvenile during the year they'll be turning 13, or after their 13th birthday passes?

Edit: Uh oh! Those bugs probably mean that the problem isn't so simple....
« Last Edit: March 09, 2012, 06:00:06 pm by Antalia »
Logged
Author of Saga of Nutscaves, a tale of unsafe working conditions, plague, and worse

Creator of Dwarf Organizer, a Java application to help assign labor in your fortress