-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathseasons.cpp
More file actions
86 lines (74 loc) · 2.45 KB
/
Copy pathseasons.cpp
File metadata and controls
86 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// openSAM: open source SAM emulator for X Plane
//
// Copyright (C) 2024, 2025, 2026 Holger Teutsch
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
// USA
//
#include "XPLMDataAccess.h"
#include "seasons.h"
#include "log_msg.h"
// support for legacy SAM seasons
namespace Seasons {
int auto_season;
int nh; // on northern hemisphere
int season; // 0-3
static const char* dr_name[] = {"sam/season/winter", "sam/season/spring", "sam/season/summer", "sam/season/autumn"};
static XPLMDataRef date_day_dr;
// Accessor for the "sam/season/*" datarefs
static int ReadSeasonAcc(void* ref) {
int s = (long long)ref;
int val = (s == season);
return val;
}
void InitDataRefs() {
date_day_dr = XPLMFindDataRef("sim/time/local_date_days");
for (int i = 0; i < 4; i++)
XPLMRegisterDataAccessor(dr_name[i], xplmType_Int, 0, ReadSeasonAcc, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, (void*)(long long)i, NULL);
}
void SetAuto() {
if (!auto_season)
return;
int day = XPLMGetDatai(date_day_dr);
if (nh) {
if (day <= 80) {
season = 0;
} else if (day <= 172) {
season = 1;
} else if (day <= 264) {
season = 2;
} else if (day <= 355) {
season = 3;
} else if (day) {
season = 0;
}
} else {
if (day <= 80) {
season = 2;
} else if (day <= 172) {
season = 3;
} else if (day <= 264) {
season = 0;
} else if (day <= 355) {
season = 1;
} else if (day) {
season = 2;
}
}
LogMsg("nh: %d, day: %d, season: %d", nh, day, season);
}
} // namespace Seasons