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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#include "KingSystem/World/worldShootingStarMgr.h"
#include <container/seadObjArray.h>
#include <random/seadGlobalRandom.h>
#include "KingSystem/ActorSystem/actActorCreator.h"
#include "KingSystem/ActorSystem/actBaseProcHeapMgr.h"
#include "KingSystem/ActorSystem/actInstParamPack.h"
#include "KingSystem/GameData/gdtManager.h"
#include "KingSystem/World/worldManager.h"
namespace ksys::world {
static bool sScheduled = true;
static struct {
int end = 3;
int start = 21;
int unk = 4;
} sHours;
static sead::Vector3f sStarProperty{};
ShootingStarMgr::ShootingStarMgr() = default;
ShootingStarMgr::~ShootingStarMgr() = default;
void ShootingStarMgr::init_(sead::Heap* heap) {
if (Manager::instance()->isDemo())
sScheduled = false;
else
initSchedule();
}
void ShootingStarMgr::initSchedule() {
const s32& start_hour = sHours.start;
const s32 end_hour = sHours.end - 1;
s32 fall_hour;
if (start_hour <= end_hour) {
// Time range is continuous.
fall_hour = sead::GlobalRandom::instance()->getS32Range(start_hour, end_hour);
} else {
// Time range is discontinuous.
// Fill an array with valid hours, shuffle it, and take the first.
sead::FixedObjArray<s32, 24> valid_hours;
for (int i = start_hour; i < 24; ++i) {
valid_hours.emplaceBack(i);
}
for (int i = 0; i < end_hour; ++i) {
valid_hours.emplaceBack(i);
}
valid_hours.shuffle();
fall_hour = *valid_hours[0];
}
mFallHour = fall_hour;
mFallMinute = sead::GlobalRandom::instance()->getU32(59);
mInitialised = true;
}
void ShootingStarMgr::calc_() {
if (Manager::instance() != nullptr) {
if (!mIsMainField)
return;
if (sScheduled) {
if (Manager::instance()->isDemo()) {
sScheduled = false;
return;
}
TimeMgr* tm = Manager::instance()->getTimeMgr();
if (tm != nullptr) {
int hour = tm->getHour();
if (mInitialised) {
if (hour == mFallHour && mFallMinute < tm->getMinute())
mNeedSpawnStar = true;
} else if (Manager::instance() != nullptr) {
if (isScheduledTime())
initSchedule();
}
}
}
}
if (mNeedSpawnStar && checkCamera()) {
spawnShootingStar();
mInitialised = false;
mNeedSpawnStar = false;
}
}
bool ShootingStarMgr::isScheduledTime() {
bool result = false;
if (Manager::instance() != nullptr) {
auto* tm = Manager::instance()->getTimeMgr();
if (tm != nullptr) {
int hour = tm->getHour();
if (sHours.start > sHours.unk) {
result = sHours.unk < hour && hour < sHours.start;
} else {
result = sHours.unk < hour || hour < sHours.start;
}
}
}
return result;
}
void ShootingStarMgr::resetStarPosition() {
if (gdt::Manager::instance() != nullptr)
gdt::Manager::instance()->setVec3f(sead::Vector3f::zero, "ShootingStarPosition");
}
void ShootingStarMgr::spawnStar() {
if (gdt::Manager::instance() == nullptr)
return;
if (!isStarPositionValid())
return;
act::InstParamPack pack;
sead::Vector3f pos;
tryGetStarPosition(&pos);
pack->addPosition(pos);
act::ActorCreator::instance()->requestCreateActor("FldObj_ShootingStar",
act::BaseProcHeapMgr::instance()->getHeap(),
nullptr, &pack, nullptr, 1);
}
bool ShootingStarMgr::isStarPositionValid() {
if (gdt::Manager::instance() == nullptr)
return false;
sead::Vector3f pos;
if (!gdt::Manager::instance()->getParam().get().getVec3f(&pos, "ShootingStarPosition"))
return false;
return !(pos.x == 0 && pos.y == 0 && pos.z == 0);
}
bool ShootingStarMgr::tryGetStarPosition(sead::Vector3f* out) const {
bool result = false;
if (gdt::Manager::instance())
result = gdt::Manager::instance()->getParam().get().getVec3f(out, "ShootingStarPosition");
return result;
}
void ShootingStarMgr::setStarPosition(f32 x, f32 y, f32 z) {
sead::Vector3f pos(x, y, z);
if (gdt::Manager::instance()) {
gdt::Manager::instance()->setVec3f(pos, "ShootingStarPosition");
}
}
void ShootingStarMgr::setScheduled(bool enable) {
sScheduled = enable;
}
void ShootingStarMgr::setShootingStarHours(int start, int end, int hr_unk) {
sHours.start = start;
sHours.end = end;
sHours.unk = hr_unk;
}
} // namespace ksys::world
|