MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / Initialize

Method Initialize

Source/Game/level.cpp:112–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void Level::Initialize(SceneGraph* scenegraph, GUI* gui) {
113 Dispose();
114
115 this->scenegraph = scenegraph;
116
117 Engine::Instance()->GetASNetwork()->RegisterASNetworkCallback(this);
118
119 Path script_path = FindFilePath(script_dir_path + "level.as", kDataPaths | kModPaths);
120
121 HookedASContext hasc;
122 hasc.path = script_path;
123 hasc.context_name = "main_level_script";
124 as_contexts_.push_back(hasc);
125
126 if (!level_specific_script_.empty()) {
127 Path level_specific_script_path = FindScript(level_specific_script_);
128 if (level_specific_script_path.isValid() == false) {
129 DisplayError("Couldn't find file", "Couldn't find player script file, default will be used", ErrorType::_ok);
130 LOGE << "Could not find file specified in <Script> in level: " << level_specific_script_ << std::endl;
131 }
132
133 if (level_specific_script_path.isValid()) {
134 HookedASContext hasc;
135 hasc.path = level_specific_script_path;
136 hasc.context_name = "level_specific";
137 as_contexts_.push_back(hasc);
138 }
139 }
140
141 if (!pc_script_.empty()) {
142 Path pc_script_path = FindScript(pc_script_);
143 while (!pc_script_path.isValid() && DisplayError("Couldn't find file", "Couldn't find player script file, default will be used instead", ErrorType::_ok_cancel_retry) == ErrorResponse::_retry) {
144 pc_script_path = FindScript(pc_script_);
145 LOGE << "Could not find file specified in <PCScript> in level: " << pc_script_ << std::endl;
146 }
147
148 if (!pc_script_path.isValid())
149 pc_script_ = "";
150 }
151
152 if (!npc_script_.empty()) {
153 Path npc_script_path = FindScript(npc_script_);
154 while (!npc_script_path.isValid() && DisplayError("Couldn't find file", "Couldn't find enemy script file, default will be used instead", ErrorType::_ok_cancel_retry) == ErrorResponse::_retry) {
155 npc_script_path = FindScript(npc_script_);
156 LOGE << "Could not find file specified in <NPCScript> in level: " << npc_script_ << std::endl;
157 }
158
159 if (!npc_script_path.isValid())
160 npc_script_ = "";
161 }
162
163 if (!npc_script_.empty()) {
164 for (auto& movement_object : scenegraph->movement_objects_) {
165 MovementObject* obj = (MovementObject*)movement_object;
166 if (obj->GetNPCObjectScript().empty()) {
167 obj->ChangeControlScript(npc_script_);
168 }
169 }

Callers

nothing calls this directly

Calls 15

FindFilePathFunction · 0.85
AttachASNetworkFunction · 0.85
AttachUIQueriesFunction · 0.85
AttachActiveCameraFunction · 0.85
AttachScreenWidthFunction · 0.85
AttachPhysicsFunction · 0.85
AttachEngineFunction · 0.85
AttachScenegraphFunction · 0.85
AttachMessagesFunction · 0.85
AttachStringConvertFunction · 0.85
AttachLevelFunction · 0.85

Tested by

no test coverage detected