// Move the stellar objects to their positions on the given date. void System::SetDate(const Date &date) { double now = date.DaysSinceEpoch(); for(StellarObject &object : objects) { // "offset" is used to allow binary orbits; the second object is offset // by 180 degrees. object.angle = Angle(now * object.speed + object.offset); object.position = object.angle.Unit() * object.distance; // Because of the order of the vector, the parent's position has always // been updated before this loop reaches any of its children, so: if(object.parent >= 0) object.position += objects[object.parent].position; if(object.position) object.angle = Angle(object.position); if(object.planet) object.planet->ResetDefense(); } }
// Get the number of days between the two given dates. int Date::operator-(const Date &other) const { return DaysSinceEpoch() - other.DaysSinceEpoch(); }