This repository was archived by the owner on Dec 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdayCycles.cs
More file actions
107 lines (84 loc) · 2.31 KB
/
Copy pathdayCycles.cs
File metadata and controls
107 lines (84 loc) · 2.31 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function getDayCycleTime() {
if (!$EnvGuiServer::DayCycleEnabled || !isObject(DayCycle)) {
error("ERROR: DayCycle not enabled.");
return -1;
}
%time = $Sim::Time / DayCycle.dayLength + DayCycle.dayOffset;
return %time - mFloor(%time);
}
function getDayCycleStage(%time) {
return mFloor(%time / 0.25);
}
function getDayCycleStageName(%stage) {
switch (%stage) {
case 0: return "dawn";
case 1: return "day";
case 2: return "dusk";
case 3: return "night";
default: return "error";
}
}
function getMSToNextDayCycleStage(%time) {
%cycles = (mFloor(%time / 0.25) + 1) * 0.25 - %time;
return mFloor(%cycles * DayCycle.dayLength * 1000);
}
function getDayCycleTimeString(%time, %mod12) {
%time = getTimeString(mFloor((%time * 86400) / 60));
if (!%mod12) {
if (strLen(%time) == 3) {
return 0 @ %time;
}
return %time;
}
%time = strReplace(%time, ":", " ");
%hour = getWord(%time, 0);
%mins = getWord(%time, 1);
if (%hour >= 13) {
return %hour - 12 @ ":" @ %mins SPC "PM";
}
return %hour @ ":" @ %mins SPC "AM";
}
function getSunVector() {
%azim = mDegToRad($EnvGuiServer::SunAzimuth);
if ($EnvGuiServer::DayCycleEnabled && isObject(DayCycle)) {
%time = getDayCycleTime();
%badspotIsWeird = 0.583;
if (%time < %badspotIsWeird) {
%elev = mDegToRad((%time / %badspotIsWeird) * 180);
}
else {
%elev = mDegToRad(180 + ((%time - %badspotIsWeird) / (1 - %badspotIsWeird)) * 180);
}
}
else {
%elev = mDegToRad($EnvGuiServer::SunElevation);
}
%h = mCos(%elev);
return %h * mSin(%azim) SPC %h * mCos(%azim) SPC mSin(%elev);
}
function isPointInShadow(%pos, %ignore) {
%ray = containerRayCast(%pos,
vectorAdd(%pos, vectorScale(getSunVector(), 250)),
$TypeMasks::StaticShapeObjectType |
$TypeMasks::FxBrickObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::ItemObjectType,
%ignore
);
return %ray !$= 0;
}
function syncDayCycle() {
if (!isObject(DayCycle)) {
error("ERROR: DayCycle does not exist.");
return;
}
if (DayCycle.dayLength != 86400) {
error("ERROR: DayCycle length is not 86400.");
return;
}
%all = strReplace(getWord(getDateTime(), 1), ":", " ");
%real = getWord(%all, 0) * 3600 + getWord(%all, 1) * 60 + getWord(%all, 2);
%curr = $Sim::Time / 86400;
DayCycle.setDayOffset(%real - (%curr - mFloor(%curr)));
}