// ok, need thing to step down through bodies and find closest approach // modify targpos directly to aim short of dangerous bodies static bool ParentSafetyAdjust(Ship *ship, Frame *targframe, const vector3d &posoff, vector3d &targpos) { Body *body = 0; Frame *frame = targframe->IsRotatingFrame() ? targframe->m_parent : targframe; while (frame) { double sdist = ship->GetPositionRelTo(frame).Length(); // ship position in that frame if (sdist < frame->GetRadius()) break; while (frame && !(body = frame->GetBodyFor())) frame = frame->m_parent; if (!frame) return false; frame = body->GetFrame()->m_parent; if (body->HasDoubleFrame()) frame = frame->m_parent; } if (!body) return false; // ok, so if body != 0, aim for zero velocity at distance to surface of that body // still along path to target vector3d targpos2 = targpos - ship->GetPosition(); double targdist = targpos2.Length(); double bodydist = body->GetPositionRelTo(ship).Length() - MaxEffectRad(body, ship)*1.5; if (targdist < bodydist) return false; targpos -= (targdist - bodydist) * targpos2 / targdist; // printf("Adjusted targpos for safety from %s: old = %.1f, new = %.1f\n", // body->GetLabel().c_str(), targdist, (targpos-ship->GetPosition()).Length()); return true; }
/* * Attribute: frameBody * * The non-dynamic body attached to the frame this dynamic body is in. * * Only valid for dynamic <Bodies>. For non-dynamic bodies <frameBody> will be * nil. * * <frameBody> can also be nil if this dynamic body is in a frame with no * non-dynamic body. This most commonly occurs when the player is in * hyperspace. * * Availability: * * alpha 12 * * Status: * * experimental */ static int l_body_attr_frame_body(lua_State *l) { Body *b = LuaBody::GetFromLua(1); if (!b->IsType(Object::DYNAMICBODY)) { lua_pushnil(l); return 1; } Frame *f = b->GetFrame(); LuaBody::PushToLua(f->GetBodyFor()); return 1; }