| 152 | } |
| 153 | |
| 154 | String 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 | |
| 203 | String CommandProcessor::timewarp(ConnectionId connectionId, String const& argumentsString) { |
| 204 | if (auto errorMsg = adminCheck(connectionId, "do the time warp again")) |
nothing calls this directly
no test coverage detected