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; } }
static void MiningLaserSpawnTastyStuff(Frame *f, const SBody *asteroid, const vector3d &pos) { Equip::Type t; if (20*Pi::rng.Fixed() < asteroid->m_metallicity) { t = Equip::PRECIOUS_METALS; } else if (8*Pi::rng.Fixed() < asteroid->m_metallicity) { t = Equip::METAL_ALLOYS; } else if (Pi::rng.Fixed() < asteroid->m_metallicity) { t = Equip::METAL_ORE; } else if (Pi::rng.Fixed() < fixed(1,2)) { t = Equip::WATER; } else { t = Equip::RUBBISH; } CargoBody *cargo = new CargoBody(t); cargo->SetFrame(f); cargo->SetPosition(pos); cargo->SetVelocity(Pi::rng.Double(100.0,200.0)*vector3d(Pi::rng.Double()-.5, Pi::rng.Double()-.5, Pi::rng.Double()-.5)); Pi::game->GetSpace()->AddBody(cargo); }
static void MiningLaserSpawnTastyStuff(Frame *f, const SystemBody *asteroid, const vector3d &pos) { Equip::Type t; if (20*Pi::rng.Fixed() < asteroid->GetMetallicity()) { t = Equip::PRECIOUS_METALS; } else if (8*Pi::rng.Fixed() < asteroid->GetMetallicity()) { t = Equip::METAL_ALLOYS; } else if (Pi::rng.Fixed() < asteroid->GetMetallicity()) { t = Equip::METAL_ORE; } else if (Pi::rng.Fixed() < fixed(1,2)) { t = Equip::WATER; } else { t = Equip::RUBBISH; } CargoBody *cargo = new CargoBody(t); cargo->SetFrame(f); cargo->SetPosition(pos); const double x = Pi::rng.Double(); vector3d dir = pos.Normalized(); dir.ArbRotate(vector3d(x, 1-x, 0), Pi::rng.Double()-.5); cargo->SetVelocity(Pi::rng.Double(100.0,200.0) * dir); Pi::game->GetSpace()->AddBody(cargo); }
/* * Attribute: type * * The type of cargo contained within this cargo body, as a * <Constants.EquipType> constant. * * Availability: * * alpha 10 * * Status: * * experimental */ static int l_cargobody_attr_type(lua_State *l) { CargoBody *b = LuaCargoBody::GetFromLua(1); lua_pushstring(l, LuaConstants::GetConstantString(l, "EquipType", b->GetCargoType())); return 1; }
/* * Attribute: type * * The type of cargo contained within this cargo body, as a * <Constants.EquipType> constant. * * Availability: * * alpha 10 * * Status: * * experimental */ static int l_cargobody_attr_type(lua_State *l) { CargoBody *b = LuaObject<CargoBody>::CheckFromLua(1); lua_pushstring(l, EnumStrings::GetString("EquipType", b->GetCargoType())); return 1; }