Beispiel #1
0
void Building::Copy(std::shared_ptr<const UniverseObject> copied_object, int empire_id) {
    if (copied_object.get() == this)
        return;
    std::shared_ptr<const Building> copied_building = std::dynamic_pointer_cast<const Building>(copied_object);
    if (!copied_building) {
        ErrorLogger() << "Building::Copy passed an object that wasn't a Building";
        return;
    }

    int copied_object_id = copied_object->ID();
    Visibility vis = GetUniverse().GetObjectVisibilityByEmpire(copied_object_id, empire_id);
    std::set<std::string> visible_specials = GetUniverse().GetObjectVisibleSpecialsByEmpire(copied_object_id, empire_id);

    UniverseObject::Copy(copied_object, vis, visible_specials);

    if (vis >= VIS_BASIC_VISIBILITY) {
        this->m_planet_id =                 copied_building->m_planet_id;

        if (vis >= VIS_PARTIAL_VISIBILITY) {
            this->m_name =                      copied_building->m_name;

            this->m_building_type =             copied_building->m_building_type;
            this->m_produced_by_empire_id = copied_building->m_produced_by_empire_id;

            if (vis >= VIS_FULL_VISIBILITY) {
                this->m_ordered_scrapped =      copied_building->m_ordered_scrapped;
            }
        }
    }
}
Beispiel #2
0
void CloneObjectsTest::testCloneMethod() {
    VMSymbol* methodSymbol = GetUniverse()->NewSymbol("myMethod");
    VMMethod* orig = GetUniverse()->NewMethod(methodSymbol, 0, 0);
    VMMethod* clone = orig->Clone();

    CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("class differs!!", orig->clazz, clone->clazz);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("objectSize differs!!", orig->objectSize, clone->objectSize);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfFields differs!!", orig->numberOfFields, clone->numberOfFields);

    CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfLocals differs!!",
            INT_VAL(load_ptr(orig->numberOfLocals)),
            INT_VAL(load_ptr(clone->numberOfLocals)));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("bcLength differs!!",
            INT_VAL(load_ptr(orig->bcLength)),
            INT_VAL(load_ptr(clone->bcLength)));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("maximumNumberOfStackElements differs!!",
            INT_VAL(load_ptr(orig->maximumNumberOfStackElements)),
            INT_VAL(load_ptr(clone->maximumNumberOfStackElements)));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfArguments differs!!",
            INT_VAL(load_ptr(orig->numberOfArguments)),
            INT_VAL(load_ptr(clone->numberOfArguments)));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfConstants differs!!",
            INT_VAL(load_ptr(orig->numberOfConstants)),
            INT_VAL(load_ptr(clone->numberOfConstants)));

    CPPUNIT_ASSERT_EQUAL_MESSAGE("GetHolder() differs!!", orig->GetHolder(), clone->GetHolder());
    CPPUNIT_ASSERT_EQUAL_MESSAGE("GetSignature() differs!!", orig->GetSignature(), clone->GetSignature());
}
void Empire::serialize(Archive& ar, const unsigned int version)
{
    ar  & BOOST_SERIALIZATION_NVP(m_id)
        & BOOST_SERIALIZATION_NVP(m_name)
        & BOOST_SERIALIZATION_NVP(m_player_name)
        & BOOST_SERIALIZATION_NVP(m_color)
        & BOOST_SERIALIZATION_NVP(m_capital_id)
        & BOOST_SERIALIZATION_NVP(m_techs)
        & BOOST_SERIALIZATION_NVP(m_meters)
        & BOOST_SERIALIZATION_NVP(m_research_queue)
        & BOOST_SERIALIZATION_NVP(m_research_progress)
        & BOOST_SERIALIZATION_NVP(m_production_queue)
        & BOOST_SERIALIZATION_NVP(m_available_building_types)
        & BOOST_SERIALIZATION_NVP(m_available_part_types)
        & BOOST_SERIALIZATION_NVP(m_available_hull_types)
        & BOOST_SERIALIZATION_NVP(m_supply_system_ranges)
        & BOOST_SERIALIZATION_NVP(m_supply_unobstructed_systems)
        & BOOST_SERIALIZATION_NVP(m_supply_starlane_traversals)
        & BOOST_SERIALIZATION_NVP(m_supply_starlane_obstructed_traversals)
        & BOOST_SERIALIZATION_NVP(m_available_system_exit_lanes)
        & BOOST_SERIALIZATION_NVP(m_fleet_supplyable_system_ids)
        & BOOST_SERIALIZATION_NVP(m_resource_supply_groups);

    if (GetUniverse().AllObjectsVisible() ||
        GetUniverse().EncodingEmpire() == ALL_EMPIRES ||
        m_id == GetUniverse().EncodingEmpire())
    {
        ar  & BOOST_SERIALIZATION_NVP(m_ship_designs)
            & BOOST_SERIALIZATION_NVP(m_sitrep_entries)
            & BOOST_SERIALIZATION_NVP(m_resource_pools)
            & BOOST_SERIALIZATION_NVP(m_population_pool)

            & BOOST_SERIALIZATION_NVP(m_explored_systems)
            & BOOST_SERIALIZATION_NVP(m_ship_names_used)

            & BOOST_SERIALIZATION_NVP(m_species_ships_owned)
            & BOOST_SERIALIZATION_NVP(m_ship_designs_owned)
            & BOOST_SERIALIZATION_NVP(m_species_colonies_owned)
            & BOOST_SERIALIZATION_NVP(m_outposts_owned)
            & BOOST_SERIALIZATION_NVP(m_building_types_owned)

            & BOOST_SERIALIZATION_NVP(m_empire_ships_destroyed)
            & BOOST_SERIALIZATION_NVP(m_ship_designs_destroyed)
            & BOOST_SERIALIZATION_NVP(m_species_ships_destroyed)
            & BOOST_SERIALIZATION_NVP(m_species_planets_invaded)

            & BOOST_SERIALIZATION_NVP(m_species_ships_produced)
            & BOOST_SERIALIZATION_NVP(m_ship_designs_produced)
            & BOOST_SERIALIZATION_NVP(m_species_ships_lost)
            & BOOST_SERIALIZATION_NVP(m_ship_designs_lost)
            & BOOST_SERIALIZATION_NVP(m_species_ships_scrapped)
            & BOOST_SERIALIZATION_NVP(m_ship_designs_scrapped)

            & BOOST_SERIALIZATION_NVP(m_species_planets_depoped)
            & BOOST_SERIALIZATION_NVP(m_species_planets_bombed)

            & BOOST_SERIALIZATION_NVP(m_building_types_produced)
            & BOOST_SERIALIZATION_NVP(m_building_types_scrapped);
    }
}
Beispiel #4
0
void Parser::genPushVariable(MethodGenerationContext* mgenc,
        const StdString& var) {
    // The purpose of this function is to find out whether the variable to be
    // pushed on the stack is a local variable, argument, or object field. This
    // is done by examining all available lexical contexts, starting with the
    // innermost (i.e., the one represented by mgenc).
    size_t index = 0;
    int context = 0;
    bool is_argument = false;

    if (mgenc->FindVar(var, &index, &context, &is_argument)) {
        if (is_argument)
            bcGen->EmitPUSHARGUMENT(mgenc, index, context);
        else
            bcGen->EmitPUSHLOCAL(mgenc, index, context);
    } else if (mgenc->HasField(var)) {
        VMSymbol* fieldName = GetUniverse()->SymbolFor(var);
        mgenc->AddLiteralIfAbsent(fieldName);
        bcGen->EmitPUSHFIELD(mgenc, fieldName);
    } else {

        VMSymbol* global = GetUniverse()->SymbolFor(var);
        mgenc->AddLiteralIfAbsent(global);

        bcGen->EmitPUSHGLOBAL(mgenc, global);
    }
}
void SpeciesManager::serialize(Archive& ar, const unsigned int version)
{
    // Don't need to send all the data about species, as this is derived from
    // content data files in species.txt that should be available to any
    // client or server.  Instead, just need to send the gamestate portion of
    // species: their homeworlds in the current game, and their opinions of
    // empires and eachother

    std::map<std::string, std::set<int> >                   species_homeworlds;
    std::map<std::string, std::map<int, double> >           empire_opinions;
    std::map<std::string, std::map<std::string, double> >   other_species_opinions;

    if (Archive::is_saving::value) {
        species_homeworlds =    GetSpeciesHomeworldsMap(GetUniverse().EncodingEmpire());
        empire_opinions =       GetSpeciesEmpireOpinionsMap(GetUniverse().EncodingEmpire());
        other_species_opinions= GetSpeciesSpeciesOpinionsMap(GetUniverse().EncodingEmpire());
    }

    ar  & BOOST_SERIALIZATION_NVP(species_homeworlds)
        & BOOST_SERIALIZATION_NVP(empire_opinions)
        & BOOST_SERIALIZATION_NVP(other_species_opinions);

    if (Archive::is_loading::value) {
        SetSpeciesHomeworlds(species_homeworlds);
        SetSpeciesEmpireOpinions(empire_opinions);
        SetSpeciesSpeciesOpinions(other_species_opinions);
    }
}
Beispiel #6
0
void Fleet::Copy(const UniverseObject* copied_object, int empire_id) {
    if (copied_object == this)
        return;
    const Fleet* copied_fleet = universe_object_cast<Fleet*>(copied_object);
    if (!copied_fleet) {
        Logger().errorStream() << "Fleet::Copy passed an object that wasn't a Fleet";
        return;
    }

    int copied_object_id = copied_object->ID();
    Visibility vis = GetUniverse().GetObjectVisibilityByEmpire(copied_object_id, empire_id);
    std::set<std::string> visible_specials = GetUniverse().GetObjectVisibleSpecialsByEmpire(copied_object_id, empire_id);

    UniverseObject::Copy(copied_object, vis, visible_specials);

    if (vis >= VIS_BASIC_VISIBILITY) {
        this->m_ships =         copied_fleet->VisibleContainedObjects(empire_id);
        this->m_next_system =   copied_fleet->m_next_system;
        this->m_prev_system =   copied_fleet->m_prev_system;

        if (vis >= VIS_PARTIAL_VISIBILITY) {
            this->m_speed =                 copied_fleet->m_speed;

            if (vis >= VIS_FULL_VISIBILITY) {
                this->m_moving_to =             copied_fleet->m_moving_to;
                this->m_travel_route =          copied_fleet->m_travel_route;
                this->m_travel_distance =       copied_fleet->m_travel_distance;
                this->m_arrived_this_turn =     copied_fleet->m_arrived_this_turn;
                this->m_arrival_starlane =      copied_fleet->m_arrival_starlane;

            } else {
                int             moving_to =         copied_fleet->m_next_system;
                std::list<int>  travel_route;
                double          travel_distance =   copied_fleet->m_travel_distance;

                const std::list<int>& copied_fleet_route = copied_fleet->m_travel_route;

                ShortenRouteToEndAtSystem(travel_route, moving_to);
                if (!travel_route.empty() && travel_route.front() != 0 && travel_route.size() != copied_fleet_route.size()) {
                    if (moving_to == copied_fleet->m_moving_to)
                        moving_to = travel_route.back();
                    try {
                        travel_distance -= GetUniverse().ShortestPath(travel_route.back(),
                                                                      copied_fleet_route.back()).second;
                    } catch (...) {
                        Logger().debugStream() << "Fleet::Copy couldn't find route to system(s):"
                                               << " travel route back: " << travel_route.back()
                                               << " or copied fleet route back: " << copied_fleet_route.back();
                    }
                }

                this->m_moving_to = moving_to;
                this->m_travel_route = travel_route;
                this->m_travel_distance = travel_distance;
            }
        }
    }
}
Beispiel #7
0
/*
 * Write data to this port.
 */
bool EspNetOutputPort::WriteDMX(const DmxBuffer &buffer,
                                uint8_t priority) {
  if (!GetUniverse())
    return false;

  if (!m_node->SendDMX(m_helper.EspNetUniverseId(GetUniverse()), buffer))
    return false;
  return true;
  (void) priority;
}
Beispiel #8
0
ObjectMap& EmpireKnownObjects(int empire_id) {
#ifdef FREEORION_BUILD_SERVER
    return GetUniverse().EmpireKnownObjects(empire_id);
#else
    int client_empire_id = ClientApp::GetApp()->EmpireID();
    if (empire_id == ALL_EMPIRES || empire_id == client_empire_id)
        return Objects();
    return GetUniverse().EmpireKnownObjects(empire_id); // should be empty as of this writing, as other empires' known objects aren't sent to clients
#endif
}
Beispiel #9
0
void MessageWndEdit::FindGameWords() {
     // add player and empire names
    for (std::map<int, Empire*>::value_type& entry : Empires()) {
        m_game_words.insert(entry.second->Name());
        m_game_words.insert(entry.second->PlayerName());
    }
    // add system names
    for (std::shared_ptr<System> system : GetUniverse().Objects().FindObjects<System>()) {
        if (system->Name() != "")
            m_game_words.insert(system->Name());
    }
     // add ship names
    for (std::shared_ptr<Ship> ship : GetUniverse().Objects().FindObjects<Ship>()) {
        if (ship->Name() != "")
            m_game_words.insert(ship->Name());
    }
     // add ship design names

    for (const auto& design : GetPredefinedShipDesignManager().GetOrderedShipDesigns()) {
        if (!design->Name().empty())
            m_game_words.insert(UserString(design->Name()));
    }
     // add specials names
    for (const std::string& special_name : SpecialNames()) {
        if (special_name != "")
            m_game_words.insert(UserString(special_name));
    }
     // add species names
    for (const std::map<std::string, Species*>::value_type& entry : GetSpeciesManager()) {
        if (entry.second->Name() != "")
            m_game_words.insert(UserString(entry.second->Name()));
    }
     // add techs names
    for (const std::string& tech_name : GetTechManager().TechNames()) {
        if (tech_name != "")
            m_game_words.insert(UserString(tech_name));
    }
    // add building type names
    for (const auto& entry : GetBuildingTypeManager()) {
        if (entry.second->Name() != "")
            m_game_words.insert(UserString(entry.second->Name()));
    }
    // add ship hulls
    for (const auto& design : GetPredefinedShipDesignManager().GetOrderedShipDesigns()) {
        if (!design->Hull().empty())
            m_game_words.insert(UserString(design->Hull()));
    }
    // add ship parts
    for (const auto& design : GetPredefinedShipDesignManager().GetOrderedShipDesigns()) {
        for (const std::string& part_name : design->Parts()) {
            if (part_name != "")
                m_game_words.insert(UserString(part_name));
        }
    }
 }
Beispiel #10
0
UniverseObject* GetUniverseObject(int object_id) {
#ifdef FREEORION_BUILD_SERVER
    return GetUniverse().Objects().Object(object_id);
#else
    // attempt to get live / up to date / mutable object
    UniverseObject* obj = GetUniverse().Objects().Object(object_id);
    // if not up to date info, use latest known out of date info about object
    if (!obj)
        obj = EmpireKnownObjects(ClientApp::GetApp()->EmpireID()).Object(object_id);
    return obj;
#endif
}
Beispiel #11
0
void UniverseObject::MoveTo(double x, double y) {
    if (x < 0.0 || GetUniverse().UniverseWidth() < x || y < 0.0 || GetUniverse().UniverseWidth() < y)
        DebugLogger() << "UniverseObject::MoveTo : Placing object \"" + m_name + "\" off the map area.";

    if (m_x == x && m_y == y)
        return;

    m_x = x;
    m_y = y;

    StateChangedSignal();
}
Beispiel #12
0
void CloneObjectsTest::testCloneBlock() {
    VMSymbol* methodSymbol = GetUniverse()->NewSymbol("someMethod");
    VMMethod* method = GetUniverse()->NewMethod(methodSymbol, 0, 0);
    VMBlock* orig = GetUniverse()->NewBlock(method,
            GetUniverse()->GetInterpreter()->GetFrame(),
            method->GetNumberOfArguments());
    VMBlock* clone = orig->Clone();

    CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("class differs!!", orig->clazz, clone->clazz);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("objectSize differs!!", orig->objectSize, clone->objectSize);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfFields differs!!", orig->numberOfFields, clone->numberOfFields);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("blockMethod differs!!", orig->blockMethod, clone->blockMethod);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("context differs!!", orig->context, clone->context);
}
Beispiel #13
0
void UniverseObject::MoveTo(double x, double y) {
    //Logger().debugStream() << "UniverseObject::MoveTo(double x, double y)";
    if (x < 0.0 || GetUniverse().UniverseWidth() < x || y < 0.0 || GetUniverse().UniverseWidth() < y)
        Logger().debugStream() << "UniverseObject::MoveTo : Placing object \"" + m_name + "\" off the map area.";

    m_x = x;
    m_y = y;

    // remove object from its old system (unless object is a system, as that would attempt to remove it from itself)
    if (this->ID() != this->SystemID())
        if (System* system = GetSystem(this->SystemID()))
            system->Remove(this->ID());

    StateChangedSignal();
}
Beispiel #14
0
void Planet::Copy(std::shared_ptr<const UniverseObject> copied_object, int empire_id) {
    if (copied_object.get() == this)
        return;
    auto copied_planet = std::dynamic_pointer_cast<const Planet>(copied_object);
    if (!copied_planet) {
        ErrorLogger() << "Planet::Copy passed an object that wasn't a Planet";
        return;
    }

    int copied_object_id = copied_object->ID();
    Visibility vis = GetUniverse().GetObjectVisibilityByEmpire(copied_object_id, empire_id);
    std::set<std::string> visible_specials = GetUniverse().GetObjectVisibleSpecialsByEmpire(copied_object_id, empire_id);

    UniverseObject::Copy(copied_object, vis, visible_specials);
    PopCenter::Copy(copied_planet, vis);
    ResourceCenter::Copy(copied_planet, vis);

    if (vis >= VIS_BASIC_VISIBILITY) {
        this->m_name =                      copied_planet->m_name;

        this->m_buildings =                 copied_planet->VisibleContainedObjectIDs(empire_id);
        this->m_type =                      copied_planet->m_type;
        this->m_original_type =             copied_planet->m_original_type;
        this->m_size =                      copied_planet->m_size;
        this->m_orbital_period =            copied_planet->m_orbital_period;
        this->m_initial_orbital_position =  copied_planet->m_initial_orbital_position;
        this->m_rotational_period =         copied_planet->m_rotational_period;
        this->m_axial_tilt =                copied_planet->m_axial_tilt;
        this->m_just_conquered =            copied_planet->m_just_conquered;

        if (vis >= VIS_PARTIAL_VISIBILITY) {
            if (vis >= VIS_FULL_VISIBILITY) {
                this->m_is_about_to_be_colonized =  copied_planet->m_is_about_to_be_colonized;
                this->m_is_about_to_be_invaded   =  copied_planet->m_is_about_to_be_invaded;
                this->m_is_about_to_be_bombarded =  copied_planet->m_is_about_to_be_bombarded;
                this->m_ordered_given_to_empire_id =copied_planet->m_ordered_given_to_empire_id;
                this->m_last_turn_attacked_by_ship= copied_planet->m_last_turn_attacked_by_ship;
            } else {
                // copy system name if at partial visibility, as it won't be copied
                // by UniverseObject::Copy unless at full visibility, but players
                // should know planet names even if they don't own the planet
                GetUniverse().InhibitUniverseObjectSignals(true);
                this->Rename(copied_planet->Name());
                GetUniverse().InhibitUniverseObjectSignals(false);
            }
        }
    }
}
Beispiel #15
0
FleetMoveOrder::FleetMoveOrder(int empire, int fleet_id, int start_system_id, int dest_system_id, bool append) :
    Order(empire),
    m_fleet(fleet_id),
    m_start_system(start_system_id),
    m_dest_system(dest_system_id),
    m_append(append)
{
    // perform sanity checks
    TemporaryPtr<const Fleet> fleet = GetFleet(FleetID());
    if (!fleet) {
        ErrorLogger() << "Empire with id " << EmpireID() << " ordered fleet with id " << FleetID() << " to move, but no such fleet exists";
        return;
    }

    TemporaryPtr<const System> destination_system = GetSystem(DestinationSystemID());
    if (!destination_system) {
        ErrorLogger() << "Empire with id " << EmpireID() << " ordered fleet to move to system with id " << DestinationSystemID() << " but no such system exists / is known to exist";
        return;
    }

    // verify that empire specified in order owns specified fleet
    if (!fleet->OwnedBy(EmpireID()) ) {
        ErrorLogger() << "Empire with id " << EmpireID() << " order to move but does not own fleet with id " << FleetID();
        return;
    }

    std::pair<std::list<int>, double> short_path = GetUniverse().ShortestPath(m_start_system, m_dest_system, empire);

    m_route.clear();
    std::copy(short_path.first.begin(), short_path.first.end(), std::back_inserter(m_route));

    // ensure a zero-length (invalid) route is not requested / sent to a fleet
    if (m_route.empty())
        m_route.push_back(m_start_system);
}
Beispiel #16
0
void Interpreter::doSuperSend(long bytecodeIndex) {
    VMSymbol* signature = static_cast<VMSymbol*>(method->GetConstant(bytecodeIndex));

    VMFrame* ctxt = GetFrame()->GetOuterContext();
    VMMethod* realMethod = ctxt->GetMethod();
    VMClass* holder = realMethod->GetHolder();
    VMClass* super = holder->GetSuperClass();
    VMInvokable* invokable = static_cast<VMInvokable*>(super->LookupInvokable(signature));

    if (invokable != nullptr)
        (*invokable)(GetFrame());
    else {
        long numOfArgs = Signature::GetNumberOfArguments(signature);
        vm_oop_t receiver = GetFrame()->GetStackElement(numOfArgs - 1);
        VMArray* argumentsArray = GetUniverse()->NewArray(numOfArgs);

        for (long i = numOfArgs - 1; i >= 0; --i) {
            vm_oop_t o = GetFrame()->Pop();
            argumentsArray->SetIndexableField(i, o);
        }
        vm_oop_t arguments[] = {signature, argumentsArray};

        AS_OBJ(receiver)->Send(doesNotUnderstand, arguments, 2);
    }
}
Beispiel #17
0
boost::statechart::result WaitingForTurnData::react(const TurnUpdate& msg) {
    TraceLogger(FSM) << "(HumanClientFSM) PlayingGame.TurnUpdate";

    int current_turn = INVALID_GAME_TURN;

    try {
        ExtractTurnUpdateMessageData(msg.m_message,           Client().EmpireID(),    current_turn,
                                     Empires(),               GetUniverse(),          GetSpeciesManager(),
                                     GetCombatLogManager(),   GetSupplyManager(),     Client().Players());
    } catch (...) {
        Client().GetClientUI().GetMessageWnd()->HandleLogMessage(UserString("ERROR_PROCESSING_SERVER_MESSAGE") + "\n");
        return discard_event();
    }

    DebugLogger(FSM) << "Extracted TurnUpdate message for turn: " << current_turn;

    Client().SetCurrentTurn(current_turn);

    // if I am the host, do autosave
    if (Client().Networking().PlayerIsHost(Client().PlayerID()))
        Client().Autosave();

    Client().HandleTurnUpdate();

    return transit<PlayingTurn>();
}
Beispiel #18
0
void FleetButton::RenderUnpressed() {
    GG::Pt ul = UpperLeft(), lr = LowerRight();
    const double midX = static_cast<double>(Value(ul.x + lr.x))/2.0;
    const double midY = static_cast<double>(Value(ul.y + lr.y))/2.0;

    if (m_selected && m_selection_texture) {
        double sel_ind_scale = GetOptionsDB().Get<double>("UI.fleet-selection-indicator-size");
        double sel_ind_half_size = Value(Width()) * sel_ind_scale / 2.0;

        GG::Pt sel_ul = GG::Pt(GG::X(static_cast<int>(midX - sel_ind_half_size)), GG::Y(static_cast<int>(midY - sel_ind_half_size)));
        GG::Pt sel_lr = GG::Pt(GG::X(static_cast<int>(midX + sel_ind_half_size)), GG::Y(static_cast<int>(midY + sel_ind_half_size)));

        glColor(GG::CLR_WHITE);
        m_selection_texture->OrthoBlit(sel_ul, sel_lr);
    }

    glColor(Color());
    if (m_vertex_components.empty()) {
        if (m_size_icon)
            m_size_icon->OrthoBlit(ul);
        for (std::vector<boost::shared_ptr<GG::Texture> >::iterator it = m_head_icons.begin(); it != m_head_icons.end(); ++it)
            (*it)->OrthoBlit(ul);
    } else {
        std::vector<double> vertsXY;
        vertsXY.push_back(midX + m_vertex_components[0]);
        vertsXY.push_back(midY + m_vertex_components[1]);
        vertsXY.push_back(midX + m_vertex_components[2]);
        vertsXY.push_back(midY + m_vertex_components[3]);
        vertsXY.push_back(midX + m_vertex_components[4]);
        vertsXY.push_back(midY + m_vertex_components[5]);
        vertsXY.push_back(midX + m_vertex_components[6]);
        vertsXY.push_back(midY + m_vertex_components[7]);

        for (std::vector<boost::shared_ptr<GG::Texture> >::iterator it = m_head_icons.begin(); it != m_head_icons.end(); ++it)
            RenderTexturedQuad(vertsXY, *it);
        RenderTexturedQuad(vertsXY, m_size_icon);
    }


    // Scanlines for not currently-visible objects?
    int empire_id = HumanClientApp::GetApp()->EmpireID();
    if (!scanline_shader || empire_id == ALL_EMPIRES || !GetOptionsDB().Get<bool>("UI.system-fog-of-war"))
        return;

    bool at_least_one_fleet_visible = false;
    for (std::vector<int>::const_iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) {
        if (GetUniverse().GetObjectVisibilityByEmpire(*it, empire_id) >= VIS_BASIC_VISIBILITY) {
            at_least_one_fleet_visible = true;
            break;
        }
    }
    if (at_least_one_fleet_visible)
        return;

    float fog_scanline_spacing = static_cast<float>(GetOptionsDB().Get<double>("UI.system-fog-of-war-spacing"));
    scanline_shader->Use();
    scanline_shader->Bind("scanline_spacing", fog_scanline_spacing);
    CircleArc(ul, lr, 0.0, TWO_PI, true);
    scanline_shader->stopUse();
}
Beispiel #19
0
int GetNewDesignID() {
#ifdef FREEORION_BUILD_SERVER
    return GetUniverse().GenerateDesignID();
#else
    return ClientApp::GetApp()->GetNewDesignID();
#endif
}
void
JXMesaCamera::Render()
{
	if (!PrepareMesa())
		{
		return;
		}

	// erase everything

	SetBackColor(itsWidget->GetBackColor());
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// prepare the display

	PrepareTransforms();

	// render the scene

	GetUniverse()->RenderAll(*this);

	// display the scene

	glFlush();

	if (itsDoubleBufferFlag)
		{
		XMesaCopySubBuffer(itsXMBuffer, itsGLViewport.x,itsGLViewport.y,
						   itsGLViewport.width,itsGLViewport.height);
		}
}
Beispiel #21
0
void Parser::keywordMessage(MethodGenerationContext* mgenc, bool super) {
    StdString kw = keyword();
    
    // special compilation for ifTrue and ifFalse
    if (!super && kw == "ifTrue:") {
        ifTrueMessage(mgenc);
        return;
    } else if (!super && kw == "ifFalse:") {
        ifFalseMessage(mgenc);
        return;
    }
    formula(mgenc);
    while (sym == Keyword) {
        kw.append(keyword());
        formula(mgenc);
    }

    VMSymbol* msg = GetUniverse()->SymbolFor(kw);

    mgenc->AddLiteralIfAbsent(msg);

    if (super)
        bcGen->EmitSUPERSEND(mgenc, msg);
    else
        bcGen->EmitSEND(mgenc, msg);

}
Beispiel #22
0
void Parser::nestedBlock(MethodGenerationContext* mgenc) {
    mgenc->AddArgumentIfAbsent("$block self");

    expect(NewBlock);
    if (sym == Colon)
        blockPattern(mgenc);

    // generate Block signature
    StdString block_sig = "$blockMethod@" + to_string(lexer->GetCurrentLineNumber());
    size_t arg_size = mgenc->GetNumberOfArguments();
    for (size_t i = 1; i < arg_size; i++)
        block_sig += ":";

    mgenc->SetSignature(GetUniverse()->SymbolFor(block_sig));

    blockContents(mgenc, false);

    // if no return has been generated, we can be sure that the last expression
    // in the block was not terminated by ., and can generate a return
    if (!mgenc->IsFinished()) {
        bcGen->EmitRETURNLOCAL(mgenc);
        mgenc->SetFinished(true);
    }

    expect(EndBlock);
}
Beispiel #23
0
void Moderator::CreateSystem::Execute() const {
    TemporaryPtr<System> system = GetUniverse().CreateSystem(m_star_type, GenerateSystemName(), m_x, m_y);
    if (!system) {
        Logger().errorStream() << "CreateSystem::Execute couldn't create system!";
        return;
    }
}
Beispiel #24
0
void Ship::Copy(TemporaryPtr<const UniverseObject> copied_object, int empire_id) {
    if (copied_object == this)
        return;
    TemporaryPtr<const Ship> copied_ship = boost::dynamic_pointer_cast<const Ship>(copied_object);
    if (!copied_ship) {
        Logger().errorStream() << "Ship::Copy passed an object that wasn't a Ship";
        return;
    }

    int copied_object_id = copied_object->ID();
    Visibility vis = GetUniverse().GetObjectVisibilityByEmpire(copied_object_id, empire_id);
    std::set<std::string> visible_specials = GetUniverse().GetObjectVisibleSpecialsByEmpire(copied_object_id, empire_id);

    UniverseObject::Copy(copied_object, vis, visible_specials);;

    if (vis >= VIS_BASIC_VISIBILITY) {
        if (this->m_fleet_id != copied_ship->m_fleet_id) {
            // as with other containers, removal from the old container is triggered by the contained Object; removal from System is handled by UniverseObject::Copy
            if (TemporaryPtr<Fleet> oldFleet = GetFleet(this->m_fleet_id)) 
                oldFleet->RemoveShip(this->ID());
            this->m_fleet_id =              copied_ship->m_fleet_id; // as with other containers (Systems), actual insertion into fleet ships set is handled by the fleet
        }

        if (vis >= VIS_PARTIAL_VISIBILITY) {
            if (this->Unowned())
                this->m_name =              copied_ship->m_name;

            this->m_design_id =             copied_ship->m_design_id;
            this->m_fighters =              copied_ship->m_fighters;
            this->m_missiles =              copied_ship->m_missiles;
            for (PartMeterMap::const_iterator it = copied_ship->m_part_meters.begin();
                 it != copied_ship->m_part_meters.end(); ++it)
            { this->m_part_meters[it->first]; }
            this->m_species_name =          copied_ship->m_species_name;

            if (vis >= VIS_FULL_VISIBILITY) {
                this->m_ordered_scrapped =          copied_ship->m_ordered_scrapped;
                this->m_ordered_colonize_planet_id= copied_ship->m_ordered_colonize_planet_id;
                this->m_ordered_invade_planet_id  = copied_ship->m_ordered_invade_planet_id;
                this->m_ordered_bombard_planet_id = copied_ship->m_ordered_bombard_planet_id;
                this->m_last_turn_active_in_combat= copied_ship->m_last_turn_active_in_combat;
                this->m_part_meters =               copied_ship->m_part_meters;
                this->m_produced_by_empire_id =     copied_ship->m_produced_by_empire_id;
            }
        }
    }
}
Beispiel #25
0
void _System::Exit_(Interpreter*, VMFrame* frame) {
    vm_oop_t err = frame->Pop();

    long err_no = INT_VAL(err);
    if (err_no != ERR_SUCCESS)
        frame->PrintStackTrace();
    GetUniverse()->Quit(err_no);
}
Beispiel #26
0
void _System::Global_(Interpreter*, VMFrame* frame) {
    VMSymbol* arg = static_cast<VMSymbol*>(frame->Pop());
    /*VMObject* self = */
    frame->Pop();
    vm_oop_t result = GetUniverse()->GetGlobal(arg);

    frame->Push(result ? result : load_ptr(nilObject));
}
Beispiel #27
0
void Parser::literalString(MethodGenerationContext* mgenc) {
    StdString s = _string();

    VMString* str = GetUniverse()->NewString(s);
    mgenc->AddLiteralIfAbsent(str);

    bcGen->EmitPUSHCONSTANT(mgenc, str);
}
Beispiel #28
0
vm_oop_t Parser::literalDouble(bool negateValue) {
    double d = std::strtod(text.c_str(), nullptr);
    if (negateValue) {
        d = 0 - d;
    }
    expect(Double);
    return GetUniverse()->NewDouble(d);
}
Beispiel #29
0
void CloneObjectsTest::testCloneInteger() {
    VMInteger* orig = GetUniverse()->NewInteger(42);
    VMInteger* clone = orig->Clone();

    CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("class differs!!", orig->GetClass(), clone->GetClass());
    CPPUNIT_ASSERT_EQUAL_MESSAGE("integer value differs!!", orig->embeddedInteger, clone->embeddedInteger);
}
Beispiel #30
0
void CloneObjectsTest::testCloneDouble() {
    VMDouble* orig = GetUniverse()->NewDouble(123.4);
    VMDouble* clone = orig->Clone();

    CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("class differs!!", orig->GetClass(), clone->GetClass());
    CPPUNIT_ASSERT_EQUAL_MESSAGE("double value differs!!", orig->embeddedDouble, clone->embeddedDouble);
}