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

Method addObject

source/game/StarSystemWorldServer.cpp:174–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174bool SystemWorldServer::addObject(SystemObjectPtr object, bool doRangeCheck) {
175 if (doRangeCheck) {
176 CelestialCoordinate system = CelestialCoordinate(m_location);
177 CelestialCoordinate outer = system.child(m_celestialDatabase->childOrbits(system).sorted().last());
178 List<pair<float, float>> orbitDistances;
179 for (auto planet : planets()) {
180 orbitDistances.append({planetOrbitDistance(planet), clusterSize(planet) / 2.0});
181 }
182 for (auto o : m_objects.values()) {
183 if (o->permanent())
184 orbitDistances.append({o->position().magnitude(), 0.0});
185 }
186
187 float maxRange = planetOrbitDistance(outer) + (clusterSize(outer) / 2.0) + systemConfig().clientObjectSpawnPadding;
188 // Allow objectSpawnPadding of room outside the farthest orbit to have an object placed in it
189 maxRange += systemConfig().clientObjectSpawnPadding;
190 float minRange = (planetSize(system) / 2.0) + systemConfig().clientObjectSpawnPadding;
191 float radius = object->position().magnitude();
192 if (radius > maxRange || radius < minRange)
193 return false;
194 for (pair<float, float> p : orbitDistances) {
195 if (abs(radius - p.first) < p.second + systemConfig().clientObjectSpawnPadding)
196 return false;
197 }
198 }
199
200 m_objects.set(object->uuid(), object);
201
202 auto objectStore = object->netStore();
203 for (auto clientId : m_clientShips.keys()) {
204 m_outgoingPackets[clientId].append(make_shared<SystemObjectCreatePacket>(objectStore));
205 }
206
207 m_triggerStorage = true;
208 return true;
209}
210
211void SystemWorldServer::update(float dt) {
212 for (auto p : m_ships)

Callers

nothing calls this directly

Calls 14

CelestialCoordinateClass · 0.85
childMethod · 0.80
childOrbitsMethod · 0.80
permanentMethod · 0.80
lastMethod · 0.45
sortedMethod · 0.45
appendMethod · 0.45
valuesMethod · 0.45
magnitudeMethod · 0.45
positionMethod · 0.45
setMethod · 0.45
uuidMethod · 0.45

Tested by

no test coverage detected