void SpaceStation::DoLawAndOrder() { Sint64 fine, crimeBitset; Polit::GetCrime(&crimeBitset, &fine); bool isDocked = static_cast<Ship*>(Pi::player)->GetDockedWith() ? true : false; if (Pi::player->GetFlightState() != Ship::DOCKED && m_numPoliceDocked && (fine > 1000) && (GetPositionRelTo(static_cast<Body*>(Pi::player)).Length() < 100000.0)) { int port = GetFreeDockingPort(); if (port != -1) { m_numPoliceDocked--; // Make police ship intent on killing the player Ship *ship = new Ship(ShipType::LADYBIRD); ship->AIKill(Pi::player); ship->SetFrame(GetFrame()); ship->SetDockedWith(this, port); Space::AddBody(ship); { // blue and white thang ShipFlavour f; f.type = ShipType::LADYBIRD; strncpy(f.regid, "POLICE", 16); f.price = ship->GetFlavour()->price; LmrMaterial m; m.diffuse[0] = 0.0f; m.diffuse[1] = 0.0f; m.diffuse[2] = 1.0f; m.diffuse[3] = 1.0f; m.specular[0] = 0.0f; m.specular[1] = 0.0f; m.specular[2] = 1.0f; m.specular[3] = 1.0f; m.emissive[0] = 0.0f; m.emissive[1] = 0.0f; m.emissive[2] = 0.0f; m.emissive[3] = 0.0f; m.shininess = 50.0f; f.primaryColor = m; m.shininess = 0.0f; m.diffuse[0] = 1.0f; m.diffuse[1] = 1.0f; m.diffuse[2] = 1.0f; m.diffuse[3] = 1.0f; f.secondaryColor = m; ship->ResetFlavour(&f); } ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::PULSECANNON_DUAL_1MW); ship->m_equipment.Add(Equip::SHIELD_GENERATOR); ship->m_equipment.Add(Equip::LASER_COOLING_BOOSTER); ship->m_equipment.Add(Equip::ATMOSPHERIC_SHIELDING); ship->UpdateMass(); } } }
/* Method: SetShipType * * Replaces the ship with a new ship of the specified type. * * > ship:SetShipType(newtype) * * Parameters: * * newtype - the name of the ship * * Example: * * > ship:SetShipType('sirius_interdictor') * * Availability: * * alpha 15 * * Status: * * experimental */ static int l_ship_set_type(lua_State *l) { LUA_DEBUG_START(l); Ship *s = LuaObject<Ship>::CheckFromLua(1); const char *type = luaL_checkstring(l, 2); if (! ShipType::Get(type)) luaL_error(l, "Unknown ship type '%s'", type); ShipFlavour f(type); s->ResetFlavour(&f); s->m_equipment.Set(Equip::SLOT_ENGINE, 0, ShipType::types[f.id].hyperdrive); s->UpdateStats(); LUA_DEBUG_END(l, 0); return 0; }
// XXX this whole thing should be done by Lua void SpaceStation::DoLawAndOrder(const double timeStep) { Sint64 fine, crimeBitset; Polit::GetCrime(&crimeBitset, &fine); if (Pi::player->GetFlightState() != Ship::DOCKED && m_numPoliceDocked && (fine > 1000) && (GetPositionRelTo(Pi::player).Length() < 100000.0)) { int port = GetFreeDockingPort(); // at 60 Hz updates (ie, 1x time acceleration), // this spawns a police ship with probability ~0.83% each frame // This makes it unlikely (but not impossible) that police will spawn on top of each other // the expected number of game-time seconds between spawns: 120 (2*60 Hz) // variance is quite high though if (port != -1 && 2.0*Pi::rng.Double() < timeStep) { m_numPoliceDocked--; // Make police ship intent on killing the player Ship *ship = new Ship(ShipType::POLICE); ship->AIKill(Pi::player); ship->SetFrame(GetFrame()); ship->SetDockedWith(this, port); Pi::game->GetSpace()->AddBody(ship); { ShipFlavour f; f.id = ShipType::POLICE; f.regid = Lang::POLICE_SHIP_REGISTRATION; f.price = ship->GetFlavour()->price; ship->ResetFlavour(&f); } ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::PULSECANNON_DUAL_1MW); ship->m_equipment.Add(Equip::LASER_COOLING_BOOSTER); ship->m_equipment.Add(Equip::ATMOSPHERIC_SHIELDING); ship->UpdateStats(); } } }