コード例 #1
0
ファイル: Fleet.cpp プロジェクト: adesst/freeorion
void Fleet::AddShip(int ship_id) {
    if (this->Contains(ship_id)) {
        Logger().debugStream() << "Fleet::AddShip this fleet '" << this->Name() << "' already contained ship '" << ship_id << "'";
        return;
    }

    Ship* ship = GetShip(ship_id);
    if (!ship) {
        Logger().errorStream() << "Fleet::AddShips() : Attempted to add an id (" << ship_id << ") of a non-ship object to a fleet.";
        return;
    }

    //Logger().debugStream() << "Fleet '" << this->Name() << "' adding ship: " << ship_id;

    // remove ship from old fleet
    if (Fleet* old_fleet = GetFleet(ship->FleetID()))
        old_fleet->RemoveShip(ship_id);

    // ensure ship is in same system as this fleet
    int ship_system_id = ship->SystemID();
    int this_fleet_system_id = this->SystemID();
    if (ship_system_id != this_fleet_system_id)
        if (System* system = GetSystem(this_fleet_system_id))
            system->Insert(ship);   // sets ship's system, remove from old system (if any) and moves ship to system's location (if necessary)

    // add ship to this fleet, and set its internal fleet record

    ship->SetFleetID(ID());
    m_ships.insert(ship_id);

    RecalculateFleetSpeed();
    StateChangedSignal();
}
コード例 #2
0
ファイル: CombatSetupWnd.cpp プロジェクト: anarsky/freeorion
void CombatSetupWnd::RedoPlacementsButtonClicked() {
    const GG::Pt row_size = ListRowSize();
    for (std::map<int, Ogre::SceneNode*>::iterator it = m_placed_nodes.begin();
            it != m_placed_nodes.end();
            ++it) {
        Ship* ship = *Ogre::any_cast<Ship*>(&it->second->getUserAny());
        UniverseObject* o = m_combat_universe[ship->FleetID()];
        Fleet* fleet = boost::polymorphic_downcast<Fleet*>(o);
        ShipRow* row = new ShipRow(ship, fleet, row_size.x, row_size.y);
        m_listbox->Insert(row);
        m_remove_ship(it->first);
    }
    m_placed_nodes.clear();
}