ALMaSS Partridge ODdox  1.1
The partridge model description following ODdox protocol
Calendar Class Reference

#include <calendar.h>

Public Member Functions

void Reset (void)
 
bool TickMinute (void)
 
bool TickMinute10 (void)
 
bool TickHour (void)
 
void Tick (void)
 
long Date (void)
 
int DayInYear (void)
 
long OldDays (void)
 
long GlobalDate (int a_day, int a_month, int a_year)
 
int DayLength (void)
 
int DayLength (int a_day_in_year)
 
int GetFirstYear (void)
 
int GetLastYear (void)
 
int GetYear (void)
 
int GetYearNumber (void)
 
int GetMonth (void)
 
int GetMinute (void)
 
int GetHour (void)
 
int GetDayInMonth (void)
 
double GetDaylightProportion (void)
 
bool JanFirst (void)
 
bool MarchFirst (void)
 
void SetFirstYear (int a_year)
 
void SetLastYear (int a_year)
 
bool ValidDate (int a_day, int a_month)
 
int DayInYear (int a_day, int a_month)
 
 Calendar (void)
 

Private Attributes

long m_date
 
long m_olddays
 
int m_firstyear
 
int m_lastyear
 
int m_day_in_month
 
int m_day_in_year
 
int m_month
 
int m_year
 
int m_simulationyear
 
int m_todayslength
 
double m_daylightproportion
 
int m_minutes
 
int m_hours
 
bool m_janfirst
 
bool m_marchfirst
 

Static Private Attributes

static int m_daylength []
 The length of the day between sun up and sun down im minutes (DK - Jutland) More...
 

Detailed Description

Definition at line 38 of file calendar.h.

Constructor & Destructor Documentation

◆ Calendar()

Calendar::Calendar ( void  )

Definition at line 55 of file calendar.cpp.

56 {
57  Reset();
58 }

References Reset().

Member Function Documentation

◆ Date()

◆ DayInYear() [1/2]

int Calendar::DayInYear ( int  a_day,
int  a_month 
)

Definition at line 96 of file calendar.cpp.

97 {
98  const int m_monthsum[12] = {
99  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
100 
101  return m_monthsum[ a_month - 1 ] + a_day - 1;
102 }

◆ DayInYear() [2/2]

◆ DayLength() [1/2]

int Calendar::DayLength ( int  a_day_in_year)

Definition at line 67 of file calendar.cpp.

68 {
69  if ( a_day_in_year<0 || a_day_in_year>364 ) {
70  g_msg->Warn( WARN_BUG, "Calendar::DayLength(): Day outside a year!",
71  "" );
72  exit(1);
73  }
74  return m_daylength[ a_day_in_year ];
75 }

References g_msg, m_daylength, MapErrorMsg::Warn(), and WARN_BUG.

◆ DayLength() [2/2]

int Calendar::DayLength ( void  )
inline

Definition at line 63 of file calendar.h.

63 { return m_todayslength; }

References m_todayslength.

Referenced by Landscape::SupplyDaylength().

◆ GetDayInMonth()

int Calendar::GetDayInMonth ( void  )
inline

Definition at line 72 of file calendar.h.

72 { return m_day_in_month; }

References m_day_in_month.

Referenced by Landscape::SupplyDayInMonth(), and Landscape::Tick().

◆ GetDaylightProportion()

double Calendar::GetDaylightProportion ( void  )
inline

Definition at line 73 of file calendar.h.

73 { return m_daylightproportion; }

References m_daylightproportion.

Referenced by Landscape::SupplyDaylightProp(), and Landscape::SupplyNightProp().

◆ GetFirstYear()

int Calendar::GetFirstYear ( void  )
inline

Definition at line 65 of file calendar.h.

65 { return m_firstyear; }

References m_firstyear.

◆ GetHour()

int Calendar::GetHour ( void  )
inline

Definition at line 71 of file calendar.h.

71 { return m_hours; }

References m_hours.

Referenced by LargeRoad::GetTrafficLoad(), SmallRoad::GetTrafficLoad(), and Landscape::SupplyHour().

◆ GetLastYear()

int Calendar::GetLastYear ( void  )
inline

Definition at line 66 of file calendar.h.

66 { return m_lastyear; }

References m_lastyear.

Referenced by Weather::Weather().

◆ GetMinute()

int Calendar::GetMinute ( void  )
inline

Definition at line 70 of file calendar.h.

70 { return m_minutes; }

References m_minutes.

Referenced by Landscape::SupplyMinute().

◆ GetMonth()

int Calendar::GetMonth ( void  )
inline

◆ GetYear()

int Calendar::GetYear ( void  )
inline

Definition at line 67 of file calendar.h.

67 { return m_year; }

References m_year.

Referenced by PesticideMap::DumpPMap(), Landscape::SupplyYear(), and Landscape::VegDump().

◆ GetYearNumber()

◆ GlobalDate()

long Calendar::GlobalDate ( int  a_day,
int  a_month,
int  a_year 
)

Definition at line 61 of file calendar.cpp.

62 {
63  return m_olddays + DayInYear( a_day, a_month) + a_year*365;
64 }

References DayInYear(), and m_olddays.

◆ JanFirst()

bool Calendar::JanFirst ( void  )
inline

◆ MarchFirst()

bool Calendar::MarchFirst ( void  )
inline

Definition at line 75 of file calendar.h.

75 { return m_marchfirst; }

References m_marchfirst.

Referenced by Landscape::Tick().

◆ OldDays()

long Calendar::OldDays ( void  )
inline

Definition at line 60 of file calendar.h.

60 { return m_olddays; }

References m_olddays.

Referenced by Landscape::DumpMapInfoByArea().

◆ Reset()

void Calendar::Reset ( void  )

Definition at line 40 of file calendar.cpp.

41 {
42  m_date = 0;
43  m_olddays = 0;
44  m_day_in_month = 1;
45  m_minutes = 0;
46  m_hours = 0;
47  m_day_in_year = 0; // [0..364]
48  m_month = 0; // [0..11]
50  m_simulationyear = 0;
51  m_janfirst = true;
52  m_marchfirst = false;
53 }

References m_date, m_day_in_month, m_day_in_year, m_firstyear, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, and m_year.

Referenced by Calendar(), Landscape::Landscape(), and Weather::Weather().

◆ SetFirstYear()

void Calendar::SetFirstYear ( int  a_year)
inline

Definition at line 76 of file calendar.h.

76 { m_firstyear = a_year; }

References m_firstyear.

Referenced by Weather::Weather().

◆ SetLastYear()

void Calendar::SetLastYear ( int  a_year)
inline

Definition at line 77 of file calendar.h.

77 { m_lastyear = a_year; }

References m_lastyear.

Referenced by Weather::Weather().

◆ Tick()

void Calendar::Tick ( void  )

Definition at line 141 of file calendar.cpp.

142 {
143  const int m_monthlength[12] = {
144  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
145  const int m_maxmonth = 11;
146 
147  m_minutes = 0;
148  m_hours = 0;
149  m_date++;
150  m_day_in_year++;
151  m_day_in_month++;
152  m_janfirst = false;
153  m_marchfirst = false;
154 
155  if ( m_day_in_month > m_monthlength[ m_month ])
156  {
157  m_day_in_month = 1;
158  m_month++;
159  if ( m_month == 2 )
160  // March 1st.
161  m_marchfirst = true;
162  }
163 
164  if ( m_month > m_maxmonth )
165  {
166  m_month = 0;
167  m_year++;
169  m_olddays += 365;
170  m_janfirst = true;
171  m_day_in_year = 0;
172  }
175 }

References m_date, m_day_in_month, m_day_in_year, m_daylength, m_daylightproportion, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, m_todayslength, and m_year.

Referenced by Landscape::Tick().

◆ TickHour()

bool Calendar::TickHour ( void  )

Definition at line 128 of file calendar.cpp.

129 {
130  bool dotick = false;
131 
132  if ( ++m_hours > 23 ) {
133  m_minutes = 0;
134  m_hours = 0;
135  dotick = true;
136  }
137  return dotick;
138 }

References m_hours, and m_minutes.

◆ TickMinute()

bool Calendar::TickMinute ( void  )

Definition at line 106 of file calendar.cpp.

107 {
108  bool dotick = false;
109 
110  if (m_minutes++ > 59) {
111  m_minutes = 0;
112  dotick = true;
113  }
114  return dotick;
115 }

References m_minutes.

◆ TickMinute10()

bool Calendar::TickMinute10 ( void  )

Definition at line 117 of file calendar.cpp.

118 {
119  bool dotick = false;
120  m_minutes += 10;
121  if (m_minutes > 59) {
122  m_minutes = 0;
123  dotick = true;
124  }
125  return dotick;
126 }

References m_minutes.

◆ ValidDate()

bool Calendar::ValidDate ( int  a_day,
int  a_month 
)

Definition at line 79 of file calendar.cpp.

80 {
81  const int m_monthlength[12] = {
82  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
83 
84  if ( a_month < 1 ||
85  a_month > 12 ||
86  a_day < 1 ||
87  a_day > m_monthlength[ a_month - 1 ] ) {
88  return false;
89  } else {
90  return true;
91  }
92 }

Member Data Documentation

◆ m_date

long Calendar::m_date
private

Definition at line 86 of file calendar.h.

Referenced by Date(), Reset(), and Tick().

◆ m_day_in_month

int Calendar::m_day_in_month
private

Definition at line 90 of file calendar.h.

Referenced by GetDayInMonth(), Reset(), and Tick().

◆ m_day_in_year

int Calendar::m_day_in_year
private

Definition at line 91 of file calendar.h.

Referenced by DayInYear(), Reset(), and Tick().

◆ m_daylength

int Calendar::m_daylength
staticprivate

The length of the day between sun up and sun down im minutes (DK - Jutland)

Definition at line 102 of file calendar.h.

Referenced by DayLength(), and Tick().

◆ m_daylightproportion

double Calendar::m_daylightproportion
private

Definition at line 96 of file calendar.h.

Referenced by GetDaylightProportion(), and Tick().

◆ m_firstyear

int Calendar::m_firstyear
private

Definition at line 88 of file calendar.h.

Referenced by GetFirstYear(), Reset(), and SetFirstYear().

◆ m_hours

int Calendar::m_hours
private

Definition at line 98 of file calendar.h.

Referenced by GetHour(), Reset(), Tick(), and TickHour().

◆ m_janfirst

bool Calendar::m_janfirst
private

Definition at line 99 of file calendar.h.

Referenced by JanFirst(), Reset(), and Tick().

◆ m_lastyear

int Calendar::m_lastyear
private

Definition at line 89 of file calendar.h.

Referenced by GetLastYear(), and SetLastYear().

◆ m_marchfirst

bool Calendar::m_marchfirst
private

Definition at line 100 of file calendar.h.

Referenced by MarchFirst(), Reset(), and Tick().

◆ m_minutes

int Calendar::m_minutes
private

Definition at line 97 of file calendar.h.

Referenced by GetMinute(), Reset(), Tick(), TickHour(), TickMinute(), and TickMinute10().

◆ m_month

int Calendar::m_month
private

Definition at line 92 of file calendar.h.

Referenced by GetMonth(), Reset(), and Tick().

◆ m_olddays

long Calendar::m_olddays
private

Definition at line 87 of file calendar.h.

Referenced by GlobalDate(), OldDays(), Reset(), and Tick().

◆ m_simulationyear

int Calendar::m_simulationyear
private

Definition at line 94 of file calendar.h.

Referenced by GetYearNumber(), Reset(), and Tick().

◆ m_todayslength

int Calendar::m_todayslength
private

Definition at line 95 of file calendar.h.

Referenced by DayLength(), and Tick().

◆ m_year

int Calendar::m_year
private

Definition at line 93 of file calendar.h.

Referenced by GetYear(), Reset(), and Tick().


The documentation for this class was generated from the following files:
Calendar::m_marchfirst
bool m_marchfirst
Definition: calendar.h:100
Calendar::m_hours
int m_hours
Definition: calendar.h:98
Calendar::m_daylightproportion
double m_daylightproportion
Definition: calendar.h:96
WARN_BUG
Definition: maperrormsg.h:34
Calendar::m_firstyear
int m_firstyear
Definition: calendar.h:88
Calendar::m_day_in_year
int m_day_in_year
Definition: calendar.h:91
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
Calendar::m_minutes
int m_minutes
Definition: calendar.h:97
Calendar::Reset
void Reset(void)
Definition: calendar.cpp:40
Calendar::m_todayslength
int m_todayslength
Definition: calendar.h:95
Calendar::m_olddays
long m_olddays
Definition: calendar.h:87
Calendar::m_day_in_month
int m_day_in_month
Definition: calendar.h:90
Calendar::m_daylength
static int m_daylength[]
The length of the day between sun up and sun down im minutes (DK - Jutland)
Definition: calendar.h:102
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
Calendar::m_month
int m_month
Definition: calendar.h:92
Calendar::m_simulationyear
int m_simulationyear
Definition: calendar.h:94
Calendar::m_lastyear
int m_lastyear
Definition: calendar.h:89
Calendar::DayInYear
int DayInYear(void)
Definition: calendar.h:58
Calendar::m_date
long m_date
Definition: calendar.h:86
Calendar::m_janfirst
bool m_janfirst
Definition: calendar.h:99
Calendar::m_year
int m_year
Definition: calendar.h:93