MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / warpRandom

Method warpRandom

source/game/StarCommandProcessor.cpp:154–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154String CommandProcessor::warpRandom(ConnectionId connectionId, String const& typeName) {
155 if (auto errorMsg = adminCheck(connectionId, "warp to random world"))
156 return *errorMsg;
157
158 Vec2I size = {2, 2};
159 auto& celestialDatabase = m_universe->celestialDatabase();
160 Maybe<CelestialCoordinate> target = {};
161
162 auto validPlanet = [&celestialDatabase, &typeName](CelestialCoordinate const& p) {
163 if (auto celestialParams = celestialDatabase.parameters(p)) {
164 if (auto visitableParams = celestialParams->visitableParameters()) {
165 if (visitableParams->typeName == typeName)
166 return true;
167 }
168 }
169 return false;
170 };
171
172 while (target.isNothing()) {
173 RectI region = RectI::withSize(Vec2I(Random::randi32(), Random::randi32()), size);
174
175 while (!celestialDatabase.scanRegionFullyLoaded(region)) {
176 celestialDatabase.scanSystems(region);
177 }
178 auto systems = celestialDatabase.scanSystems(region);
179 for (auto s : systems) {
180 for (auto planet : celestialDatabase.children(s)) {
181 if (validPlanet(planet))
182 target = planet;
183 if (target.isNothing()) {
184 for (auto moon : celestialDatabase.children(planet)) {
185 if (validPlanet(moon)) {
186 target = moon;
187 break;
188 }
189 }
190 }
191 }
192 }
193
194 if (size.magnitude() > 1024)
195 return "could not find a matching world";
196 size *= 2;
197 }
198
199 m_universe->clientWarpPlayer(connectionId, WarpToWorld(CelestialWorldId(*target)));
200 return strf("warping to {}", *target);
201}
202
203String CommandProcessor::timewarp(ConnectionId connectionId, String const& argumentsString) {
204 if (auto errorMsg = adminCheck(connectionId, "do the time warp again"))

Callers

nothing calls this directly

Calls 12

randi32Function · 0.85
WarpToWorldClass · 0.85
strfFunction · 0.85
celestialDatabaseMethod · 0.80
visitableParametersMethod · 0.80
isNothingMethod · 0.80
scanRegionFullyLoadedMethod · 0.80
scanSystemsMethod · 0.80
childrenMethod · 0.80
clientWarpPlayerMethod · 0.80
parametersMethod · 0.45
magnitudeMethod · 0.45

Tested by

no test coverage detected