1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2009 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "Interface.h"
27 #include "Variables.h"
29 Calendar::Calendar(void)
32 AutoTable
tab("months");
37 monthnamecount
= tab
->GetRowCount();
38 monthnames
= (int *) malloc(sizeof(int) * monthnamecount
);
39 days
= (int *) malloc(sizeof(int) * monthnamecount
);
41 for(i
=0;i
<monthnamecount
;i
++) {
42 days
[i
]=atoi(tab
->QueryField(i
,0));
44 monthnames
[i
]=atoi(tab
->QueryField(i
,1));
48 Calendar::~Calendar(void)
50 if (monthnames
) free(monthnames
);
54 void Calendar::GetMonthName(int dayandmonth
) const
58 for(int i
=0;i
<monthnamecount
;i
++) {
59 if (dayandmonth
<days
[i
]) {
62 core
->GetTokenDictionary()->SetAtCopy("DAY", dayandmonth
+1);
64 tmp
= core
->GetString( monthnames
[i
] );
65 core
->GetTokenDictionary()->SetAt("MONTHNAME",tmp
);
66 //must not free tmp, SetAt doesn't copy the pointer!
68 core
->GetTokenDictionary()->SetAtCopy("MONTH", month
);
72 //ignoring single days (they are not months)
73 if (days
[i
]!=1) month
++;
77 int Calendar::GetCalendarDay(int date
) const
82 if (!daysinyear
) return 0;
83 dayandmonth
= date
%daysinyear
;
84 for(int i
=0;i
<monthnamecount
;i
++) {
85 if (dayandmonth
<days
[i
]) {
89 //ignoring single days (they are not months)
90 if (days
[i
]!=1) month
++;