// setter void RigidCylinder::SetHeight(real height) { Cylinder::SetHeight(height); UpdateMass(); UpdateInertiaTensor(); }
void RigidCylinder::SetRadius(real radius) { Cylinder::SetRadius(radius); UpdateMass(); UpdateInertiaTensor(); }
Mass::Mass(Mesh * mesh, int lat, int lon, Globals * Consts, Field * Eta, Depth * Thickness) : Field(mesh, lat, lon) { consts = Consts; eta = Eta; thickness = Thickness; UpdateMass(); };
bool Ship::Jettison(Equip::Type t) { if (m_flightState != FLYING) return false; if (t == Equip::NONE) return false; Equip::Slot slot = EquipType::types[int(t)].slot; if (m_equipment.Count(slot, t) > 0) { m_equipment.Remove(t, 1); UpdateMass(); Aabb aabb; GetAabb(aabb); matrix4x4d rot; GetRotMatrix(rot); vector3d pos = rot * vector3d(0, aabb.min.y-5, 0); CargoBody *cargo = new CargoBody(t); cargo->SetFrame(GetFrame()); cargo->SetPosition(GetPosition()+pos); cargo->SetVelocity(GetVelocity()+rot*vector3d(0,-10,0)); Space::AddBody(cargo); Pi::luaOnJettison->Queue(this, cargo); return true; } else { return false; } }
void Ship::UpdateFuelStats() { m_stats.fuel_tank_mass_left = m_type->fuelTankMass * GetFuel(); Properties().Set("fuelMassLeft", m_stats.fuel_tank_mass_left); UpdateMass(); }
void RigidBody::EnableMassUpdate() { if (!enableMassUpdate_) { enableMassUpdate_ = true; UpdateMass(); } }
void Ship::Init() { const ShipType &stype = GetShipType(); SetModel(stype.lmrModelName.c_str()); SetMassDistributionFromModel(); UpdateMass(); m_stats.hull_mass_left = float(stype.hullMass); m_stats.shield_mass_left = 0; }
Player::Player(ShipType::Type shipType): Ship(shipType) { m_mouseActive = false; m_flightControlState = CONTROL_MANUAL; m_killCount = 0; m_knownKillCount = 0; UpdateMass(); m_accumTorque = vector3d(0,0,0); }
void Ship::UpdateFuelStats() { const ShipType &stype = GetShipType(); m_stats.fuel_tank_mass = stype.fuelTankMass; m_stats.fuel_use = GetFuelUseRate(); m_stats.fuel_tank_mass_left = m_stats.fuel_tank_mass * GetFuel(); UpdateMass(); }
Player::Player(ShipType::Type shipType): Ship(shipType) { m_mouseActive = false; m_invertMouse = false; m_flightControlState = CONTROL_MANUAL; m_killCount = 0; m_knownKillCount = 0; m_setSpeedTarget = 0; m_navTarget = 0; m_combatTarget = 0; UpdateMass(); float deadzone = Pi::config.Float("JoystickDeadzone"); m_joystickDeadzone = deadzone * deadzone; m_accumTorque = vector3d(0,0,0); }
void Ship::UpdateEquipStats() { const ShipType &stype = GetShipType(); m_stats.max_capacity = stype.capacity; m_stats.used_capacity = 0; m_stats.used_cargo = 0; for (int i=0; i<Equip::SLOT_MAX; i++) { for (int j=0; j<stype.equipSlotCapacity[i]; j++) { Equip::Type t = m_equipment.Get(Equip::Slot(i), j); if (t) m_stats.used_capacity += Equip::types[t].mass; if (Equip::Slot(i) == Equip::SLOT_CARGO) m_stats.used_cargo += Equip::types[t].mass; } } m_stats.free_capacity = m_stats.max_capacity - m_stats.used_capacity; m_stats.total_mass = m_stats.used_capacity + stype.hullMass; m_stats.shield_mass = TONS_HULL_PER_SHIELD * float(m_equipment.Count(Equip::SLOT_SHIELD, Equip::SHIELD_GENERATOR)); UpdateMass(); UpdateFuelStats(); Equip::Type fuelType = GetHyperdriveFuelType(); if (stype.equipSlotCapacity[Equip::SLOT_ENGINE]) { Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE); int hyperclass = Equip::types[t].pval; if (!hyperclass) { // no drive m_stats.hyperspace_range = m_stats.hyperspace_range_max = 0; } else { m_stats.hyperspace_range_max = Pi::CalcHyperspaceRangeMax(hyperclass, GetMass()/1000); m_stats.hyperspace_range = Pi::CalcHyperspaceRange(hyperclass, GetMass()/1000, m_equipment.Count(Equip::SLOT_CARGO, fuelType)); } } else { m_stats.hyperspace_range = m_stats.hyperspace_range_max = 0; } }
RigidCylinder::RigidCylinder(const vec3& position, real height, real radius) : RigidBody3(), Cylinder(position, height, radius) { UpdateMass(); UpdateInertiaTensor(); }
RigidCylinder::RigidCylinder(real x, real y, real z, real height, real radius) : RigidBody3(), Cylinder(vec3(x, y, z), height, radius) { UpdateMass(); UpdateInertiaTensor(); }
// constructors RigidCylinder::RigidCylinder(void) : RigidBody3(), Cylinder() { UpdateMass(); UpdateInertiaTensor(); }
void RigidBody::AddBodyToWorld() { if (!physicsWorld_) return; URHO3D_PROFILE(AddBodyToWorld); if (mass_ < 0.0f) mass_ = 0.0f; if (body_) RemoveBodyFromWorld(); else { // Correct inertia will be calculated below btVector3 localInertia(0.0f, 0.0f, 0.0f); body_ = new btRigidBody(mass_, this, shiftedCompoundShape_, localInertia); body_->setUserPointer(this); // Check for existence of the SmoothedTransform component, which should be created by now in network client mode. // If it exists, subscribe to its change events smoothedTransform_ = GetComponent<SmoothedTransform>(); if (smoothedTransform_) { SubscribeToEvent(smoothedTransform_, E_TARGETPOSITION, URHO3D_HANDLER(RigidBody, HandleTargetPosition)); SubscribeToEvent(smoothedTransform_, E_TARGETROTATION, URHO3D_HANDLER(RigidBody, HandleTargetRotation)); } // Check if CollisionShapes already exist in the node and add them to the compound shape. // Do not update mass yet, but do it once all shapes have been added PODVector<CollisionShape*> shapes; node_->GetComponents<CollisionShape>(shapes); for (PODVector<CollisionShape*>::Iterator i = shapes.Begin(); i != shapes.End(); ++i) (*i)->NotifyRigidBody(false); // Check if this node contains Constraint components that were waiting for the rigid body to be created, and signal them // to create themselves now PODVector<Constraint*> constraints; node_->GetComponents<Constraint>(constraints); for (PODVector<Constraint*>::Iterator i = constraints.Begin(); i != constraints.End(); ++i) (*i)->CreateConstraint(); } UpdateMass(); UpdateGravity(); int flags = body_->getCollisionFlags(); if (trigger_) flags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; else flags &= ~btCollisionObject::CF_NO_CONTACT_RESPONSE; if (kinematic_) flags |= btCollisionObject::CF_KINEMATIC_OBJECT; else flags &= ~btCollisionObject::CF_KINEMATIC_OBJECT; body_->setCollisionFlags(flags); body_->forceActivationState(kinematic_ ? DISABLE_DEACTIVATION : ISLAND_SLEEPING); if (!IsEnabledEffective()) return; btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld(); world->addRigidBody(body_, (short)collisionLayer_, (short)collisionMask_); inWorld_ = true; readdBody_ = false; if (mass_ > 0.0f) Activate(); else { SetLinearVelocity(Vector3::ZERO); SetAngularVelocity(Vector3::ZERO); } }
/* MarketAgent s***e */ void Player::Bought(Equip::Type t) { m_equipment.Add(t); UpdateMass(); }
void Ship::StaticUpdate(const float timeStep) { AITimeStep(timeStep); // moved to correct place, maybe if (GetHullTemperature() > 1.0) { Space::KillBody(this); } UpdateAlertState(); /* FUEL SCOOPING!!!!!!!!! */ if (m_equipment.Get(Equip::SLOT_FUELSCOOP) != Equip::NONE) { Body *astro = GetFrame()->m_astroBody; if (astro && astro->IsType(Object::PLANET)) { Planet *p = static_cast<Planet*>(astro); if (p->IsSuperType(SBody::SUPERTYPE_GAS_GIANT)) { double dist = GetPosition().Length(); double pressure, density; p->GetAtmosphericState(dist, &pressure, &density); double speed = GetVelocity().Length(); vector3d vdir = GetVelocity().Normalized(); matrix4x4d rot; GetRotMatrix(rot); vector3d pdir = -vector3d(rot[8], rot[9], rot[10]).Normalized(); double dot = vdir.Dot(pdir); if ((m_stats.free_capacity) && (dot > 0.95) && (speed > 2000.0) && (density > 1.0)) { double rate = speed*density*0.00001f; if (Pi::rng.Double() < rate) { m_equipment.Add(Equip::HYDROGEN); if (this == reinterpret_cast<Ship*>(Pi::player)) { Pi::Message(stringf(Lang::FUEL_SCOOP_ACTIVE_N_TONNES_H_COLLECTED, formatarg("quantity", m_equipment.Count(Equip::SLOT_CARGO, Equip::HYDROGEN)))); } UpdateMass(); } } } } } // Cargo bay life support if (m_equipment.Get(Equip::SLOT_CARGOLIFESUPPORT) != Equip::CARGO_LIFE_SUPPORT) { // Hull is pressure-sealed, it just doesn't provide // temperature regulation and breathable atmosphere // kill stuff roughly every 5 seconds if ((!m_dockedWith) && (5.0*Pi::rng.Double() < timeStep)) { Equip::Type t = (Pi::rng.Int32(2) ? Equip::LIVE_ANIMALS : Equip::SLAVES); if (m_equipment.Remove(t, 1)) { m_equipment.Add(Equip::FERTILIZER); if (this == reinterpret_cast<Ship*>(Pi::player)) { Pi::Message(Lang::CARGO_BAY_LIFE_SUPPORT_LOST); } } } } if (m_flightState == FLYING) m_launchLockTimeout -= timeStep; if (m_launchLockTimeout < 0) m_launchLockTimeout = 0; /* can't orient ships in SetDockedWith() because it gets * called from collision handler, and collision system gets a bit * weirded out if bodies are moved in the middle of collision detection */ if (m_dockedWith) m_dockedWith->OrientDockedShip(this, m_dockedWithPort); // lasers for (int i=0; i<ShipType::GUNMOUNT_MAX; i++) { m_gunRecharge[i] -= timeStep; float rateCooling = 0.01f; if (m_equipment.Get(Equip::SLOT_LASERCOOLER) != Equip::NONE) { rateCooling *= float(EquipType::types[ m_equipment.Get(Equip::SLOT_LASERCOOLER) ].pval); } m_gunTemperature[i] -= rateCooling*timeStep; if (m_gunTemperature[i] < 0.0f) m_gunTemperature[i] = 0; if (m_gunRecharge[i] < 0.0f) m_gunRecharge[i] = 0; if (!m_gunState[i]) continue; if (m_gunRecharge[i] > 0.0f) continue; if (m_gunTemperature[i] > 1.0) continue; FireWeapon(i); } if (m_ecmRecharge > 0.0f) { m_ecmRecharge = std::max(0.0f, m_ecmRecharge - timeStep); } if (m_stats.shield_mass_left < m_stats.shield_mass) { // 250 second recharge float recharge_rate = 0.004f; if (m_equipment.Get(Equip::SLOT_ENERGYBOOSTER) != Equip::NONE) { recharge_rate *= float(EquipType::types[ m_equipment.Get(Equip::SLOT_ENERGYBOOSTER) ].pval); } m_stats.shield_mass_left += m_stats.shield_mass * recharge_rate * timeStep; } m_stats.shield_mass_left = Clamp(m_stats.shield_mass_left, 0.0f, m_stats.shield_mass); if (m_wheelTransition) { m_wheelState += m_wheelTransition*0.3f*timeStep; m_wheelState = Clamp(m_wheelState, 0.0f, 1.0f); if (float_equal_exact(m_wheelState, 0.0f) || float_equal_exact(m_wheelState, 1.0f)) m_wheelTransition = 0; } if (m_testLanded) TestLanded(); if (m_equipment.Get(Equip::SLOT_HULLAUTOREPAIR) == Equip::HULL_AUTOREPAIR) { const ShipType &stype = GetShipType(); m_stats.hull_mass_left = std::min(m_stats.hull_mass_left + 0.1f*timeStep, float(stype.hullMass)); } // After calling StartHyperspaceTo this Ship must not spawn objects // holding references to it (eg missiles), as StartHyperspaceTo // removes the ship from Space::bodies and so the missile will not // have references to this cleared by NotifyDeleted() if (m_hyperspace.countdown > 0.0f) { m_hyperspace.countdown = m_hyperspace.countdown - timeStep; if (m_hyperspace.countdown <= 0.0f) { m_hyperspace.countdown = 0; m_hyperspace.now = true; } } if (m_hyperspace.now) { m_hyperspace.now = false; Space::StartHyperspaceTo(this, &m_hyperspace.dest); } }
void Player::Sold(Equip::Type t) { m_equipment.Remove(t, 1); UpdateMass(); }