void Player::SetAlertState(Ship::AlertState as) { Ship::AlertState prev = GetAlertState(); switch (as) { case ALERT_NONE: if (prev != ALERT_NONE) Pi::cpan->MsgLog()->Message("", Lang::ALERT_CANCELLED); break; case ALERT_SHIP_NEARBY: if (prev == ALERT_NONE) Pi::cpan->MsgLog()->ImportantMessage("", Lang::SHIP_DETECTED_NEARBY); else Pi::cpan->MsgLog()->ImportantMessage("", Lang::DOWNGRADING_ALERT_STATUS); Sound::PlaySfx("OK"); break; case ALERT_SHIP_FIRING: Pi::cpan->MsgLog()->ImportantMessage("", Lang::LASER_FIRE_DETECTED); Sound::PlaySfx("warning", 0.2f, 0.2f, 0); break; } Pi::cpan->SetAlertState(as); Ship::SetAlertState(as); }
//XXX do in lua, or use the alert concept for all ships void Player::SetAlertState(Ship::AlertState as) { Ship::AlertState prev = GetAlertState(); switch (as) { case ALERT_NONE: if (prev != ALERT_NONE) Pi::game->log->Add(Lang::ALERT_CANCELLED); break; case ALERT_SHIP_NEARBY: if (prev == ALERT_NONE) Pi::game->log->Add(Lang::SHIP_DETECTED_NEARBY); else Pi::game->log->Add(Lang::DOWNGRADING_ALERT_STATUS); Sound::PlaySfx("OK"); break; case ALERT_SHIP_FIRING: Pi::game->log->Add(Lang::LASER_FIRE_DETECTED); Sound::PlaySfx("warning", 0.2f, 0.2f, 0); break; } Pi::game->GetCpan()->SetAlertState(as); Ship::SetAlertState(as); }
void Player::SetAlertState(Ship::AlertState as) { Ship::AlertState prev = GetAlertState(); switch (as) { case ALERT_NONE: if (prev != ALERT_NONE) Pi::cpan->MsgLog()->Message("", "Alert cancelled."); break; case ALERT_SHIP_NEARBY: if (prev == ALERT_NONE) Pi::cpan->MsgLog()->ImportantMessage("", "Ship detected nearby."); else Pi::cpan->MsgLog()->ImportantMessage("", "No fire detected for 60 seconds, downgrading alert status."); Sound::PlaySfx("OK"); break; case ALERT_SHIP_FIRING: Pi::cpan->MsgLog()->ImportantMessage("", "Laser fire detected."); Sound::PlaySfx("warning", 0.2f, 0.2f, 0); break; } Pi::cpan->SetAlertState(as); Ship::SetAlertState(as); }
void Ship::UpdateAlertState() { // no alerts if no radar int radar_cap = 0; Properties().Get("radar_cap", radar_cap); if (radar_cap <= 0) { // clear existing alert state if there was one if (GetAlertState() != ALERT_NONE) { SetAlertState(ALERT_NONE); LuaEvent::Queue("onShipAlertChanged", this, EnumStrings::GetString("ShipAlertStatus", ALERT_NONE)); } return; } bool ship_is_near = false, ship_is_firing = false; if (m_lastAlertUpdate + 1.0 <= Pi::game->GetTime()) { // time to update the list again, once per second should suffice m_lastAlertUpdate = Pi::game->GetTime(); // refresh the list m_nearbyBodies.clear(); static const double ALERT_DISTANCE = 100000.0; // 100km Pi::game->GetSpace()->GetBodiesMaybeNear(this, ALERT_DISTANCE, m_nearbyBodies); // handle the results for (auto i : m_nearbyBodies) { if ((i) == this) continue; if (!(i)->IsType(Object::SHIP) || (i)->IsType(Object::MISSILE)) continue; const Ship *ship = static_cast<const Ship*>(i); if (ship->GetShipType()->tag == ShipType::TAG_STATIC_SHIP) continue; if (ship->GetFlightState() == LANDED || ship->GetFlightState() == DOCKED) continue; if (GetPositionRelTo(ship).LengthSqr() < ALERT_DISTANCE*ALERT_DISTANCE) { ship_is_near = true; Uint32 gunstate = 0; for (int j = 0; j < ShipType::GUNMOUNT_MAX; j++) gunstate |= ship->m_gun[j].state; if (gunstate) { ship_is_firing = true; break; } } } // store m_shipNear = ship_is_near; m_shipFiring = ship_is_firing; } else { ship_is_near = m_shipNear; ship_is_firing = m_shipFiring; } bool changed = false; switch (m_alertState) { case ALERT_NONE: if (ship_is_near) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_NEARBY: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_FIRING: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); } else if (m_lastFiringAlert + 60.0 <= Pi::game->GetTime()) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } break; } if (changed) LuaEvent::Queue("onShipAlertChanged", this, EnumStrings::GetString("ShipAlertStatus", GetAlertState())); }
void Ship::UpdateAlertState() { // no alerts if no scanner if (m_equipment.Get(Equip::SLOT_SCANNER) == Equip::NONE) { // clear existing alert state if there was one if (GetAlertState() != ALERT_NONE) { SetAlertState(ALERT_NONE); Pi::luaOnShipAlertChanged->Queue(this, LuaConstants::GetConstantString(Pi::luaManager->GetLuaState(), "ShipAlertStatus", ALERT_NONE)); } return; } bool ship_is_near = false, ship_is_firing = false; for (Space::bodiesIter_t i = Space::bodies.begin(); i != Space::bodies.end(); i++) { if ((*i) == this) continue; if (!(*i)->IsType(Object::SHIP) || (*i)->IsType(Object::MISSILE)) continue; Ship *ship = static_cast<Ship*>(*i); if (ship->GetFlightState() == LANDED || ship->GetFlightState() == DOCKED) continue; if (GetPositionRelTo(ship).LengthSqr() < 100000.0*100000.0) { ship_is_near = true; Uint32 gunstate = 0; for (int j = 0; j < ShipType::GUNMOUNT_MAX; j++) gunstate |= ship->m_gunState[j]; if (gunstate) { ship_is_firing = true; break; } } } bool changed = false; switch (m_alertState) { case ALERT_NONE: if (ship_is_near) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } if (ship_is_firing) { m_lastFiringAlert = Pi::GetGameTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_NEARBY: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::GetGameTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_FIRING: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::GetGameTime(); } else if (m_lastFiringAlert + 60.0 <= Pi::GetGameTime()) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } break; } if (changed) Pi::luaOnShipAlertChanged->Queue(this, LuaConstants::GetConstantString(Pi::luaManager->GetLuaState(), "ShipAlertStatus", GetAlertState())); }
void Ship::UpdateAlertState() { // no alerts if no scanner if (m_equipment.Get(Equip::SLOT_SCANNER) == Equip::NONE) { // clear existing alert state if there was one if (GetAlertState() != ALERT_NONE) { SetAlertState(ALERT_NONE); LuaEvent::Queue("onShipAlertChanged", this, EnumStrings::GetString("ShipAlertStatus", ALERT_NONE)); } return; } static const double ALERT_DISTANCE = 100000.0; // 100km Space::BodyNearList nearby; Pi::game->GetSpace()->GetBodiesMaybeNear(this, ALERT_DISTANCE, nearby); bool ship_is_near = false, ship_is_firing = false; for (Space::BodyNearIterator i = nearby.begin(); i != nearby.end(); ++i) { if ((*i) == this) continue; if (!(*i)->IsType(Object::SHIP) || (*i)->IsType(Object::MISSILE)) continue; const Ship *ship = static_cast<const Ship*>(*i); if (ship->GetShipType().tag == ShipType::TAG_STATIC_SHIP) continue; if (ship->GetFlightState() == LANDED || ship->GetFlightState() == DOCKED) continue; if (GetPositionRelTo(ship).LengthSqr() < ALERT_DISTANCE*ALERT_DISTANCE) { ship_is_near = true; Uint32 gunstate = 0; for (int j = 0; j < ShipType::GUNMOUNT_MAX; j++) gunstate |= ship->m_gunState[j]; if (gunstate) { ship_is_firing = true; break; } } } bool changed = false; switch (m_alertState) { case ALERT_NONE: if (ship_is_near) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_NEARBY: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); SetAlertState(ALERT_SHIP_FIRING); changed = true; } break; case ALERT_SHIP_FIRING: if (!ship_is_near) { SetAlertState(ALERT_NONE); changed = true; } else if (ship_is_firing) { m_lastFiringAlert = Pi::game->GetTime(); } else if (m_lastFiringAlert + 60.0 <= Pi::game->GetTime()) { SetAlertState(ALERT_SHIP_NEARBY); changed = true; } break; } if (changed) LuaEvent::Queue("onShipAlertChanged", this, EnumStrings::GetString("ShipAlertStatus", GetAlertState())); }