コード例 #1
0
    hole_filling_filter::hole_filling_filter() :
        _width(0), _height(0), _stride(0), _bpp(0),
        _extension_type(RS2_EXTENSION_DEPTH_FRAME),
        _current_frm_size_pixels(0),
        _hole_filling_mode(hole_fill_def)
    {
        _stream_filter.stream = RS2_STREAM_DEPTH;
        _stream_filter.format = RS2_FORMAT_Z16;

        auto hole_filling_mode = std::make_shared<ptr_option<uint8_t>>(
            hole_fill_min,
            hole_fill_max,
            hole_fill_step,
            hole_fill_def,
            &_hole_filling_mode, "Hole Filling mode");

        hole_filling_mode->set_description(hf_fill_from_left, "Fill from Left");
        hole_filling_mode->set_description(hf_farest_from_around, "Farest from around");
        hole_filling_mode->set_description(hf_nearest_from_around, "Nearest from around");

        hole_filling_mode->on_set([this, hole_filling_mode](float val)
        {
            std::lock_guard<std::mutex> lock(_mutex);

            if (!hole_filling_mode->is_valid(val))
                throw invalid_value_exception(to_string()
                    << "Unsupported mode for hole filling selected: value " << val << " is out of range.");

            _hole_filling_mode = static_cast<uint8_t>(val);
        });

        register_option(RS2_OPTION_HOLES_FILL, hole_filling_mode);

    }
コード例 #2
0
    pointcloud::pointcloud()
        :stream_filter_processing_block("Pointcloud")
    {
        _occlusion_filter = std::make_shared<occlusion_filter>();

        auto occlusion_invalidation = std::make_shared<ptr_option<uint8_t>>(
            occlusion_none,
            occlusion_max - 1, 1,
            occlusion_none,
            (uint8_t*)&_occlusion_filter->_occlusion_filter,
            "Occlusion removal");
        occlusion_invalidation->on_set([this, occlusion_invalidation](float val)
        {
            if (!occlusion_invalidation->is_valid(val))
                throw invalid_value_exception(to_string()
                    << "Unsupported occlusion filtering requiested " << val << " is out of range.");

            _occlusion_filter->set_mode(static_cast<uint8_t>(val));

        });

        occlusion_invalidation->set_description(0.f, "Off");
        occlusion_invalidation->set_description(1.f, "Heuristic");
        occlusion_invalidation->set_description(2.f, "Exhaustive");
        register_option(RS2_OPTION_FILTER_MAGNITUDE, occlusion_invalidation);
    }
コード例 #3
0
    disparity_transform::disparity_transform(bool transform_to_disparity):
        generic_processing_block(transform_to_disparity ? "Depth to Disparity" : "Disparity to Depth"),
        _transform_to_disparity(transform_to_disparity),
        _update_target(false),
        _stereoscopic_depth(false),
        _focal_lenght_mm(0.f),
        _stereo_baseline_meter(0.f),
        _depth_units(0.f),
        _d2d_convert_factor(0.f),
        _width(0), _height(0), _bpp(0)
    {
        auto transform_opt = std::make_shared<ptr_option<bool>>(
            false,true,true,true,
            &_transform_to_disparity,
            "Stereoscopic Transformation Mode");
        transform_opt->set_description(false, "Disparity to Depth");
        transform_opt->set_description(true, "Depth to Disparity");
        transform_opt->on_set([this, transform_opt](float val)
        {
            std::lock_guard<std::mutex> lock(_mutex);
            if (!transform_opt->is_valid(val))
                throw invalid_value_exception(to_string() << "Unsupported transformation mode" << (int)val << " is out of range.");

            on_set_mode(static_cast<bool>(!!int(val)));
        });

        unregister_option(RS2_OPTION_FRAMES_QUEUE_SIZE);

        on_set_mode(_transform_to_disparity);
    }
コード例 #4
0
ファイル: crypt.c プロジェクト: Shea690901/LeprechaunLIB
static void create()
{
    ::create();
    add_noun("crypt");
    set_description("a crypt");
    set_exit("up", "temple");
}
コード例 #5
0
ファイル: exception.hpp プロジェクト: xykivo/android
 /// Move other into this
 ///
 /// \return Reference to this
 Exception& operator=(
     Exception&& other) ///< [in] Exception moved
     noexcept {
   std::exception::operator=(other);
   set_description(other.description());
   return (*this);
 }
コード例 #6
0
    void on_clone_encounter()
    {
        auto selected_encounter = encounters_page_->get_selected_encounter();

        if (selected_encounter)
        {
            current_encounter_ = std::make_shared<paradice::encounter>();
            encounter_editor_->set_encounter_name(
                "Clone of " + selected_encounter->get_name());

            // Deep copy the beasts.
            std::vector<std::shared_ptr<paradice::beast>> beasts;

            for (auto const &original_beast : selected_encounter->get_beasts())
            {
                auto new_beast = std::make_shared<paradice::beast>();

                new_beast->set_name(original_beast->get_name());
                new_beast->set_description(original_beast->get_description());
                beasts.push_back(new_beast);
            }

            encounter_editor_->set_encounter_beasts(beasts);
            encounter_editor_->set_bestiary(bestiary_page_->get_beasts());

            encounter_tab_card_->select_face(encounter_editor_face);
            encounter_tab_card_->set_focus();
        }
    }
コード例 #7
0
static gboolean
hippo_block_netflix_movie_update_from_xml (HippoBlock           *block,
                                           HippoDataCache       *cache,
                                           LmMessageNode        *node)
{
    HippoBlockNetflixMovie *block_netflix = HIPPO_BLOCK_NETFLIX_MOVIE(block);
    LmMessageNode *netflix_node, *queue_node;
    LmMessageNode *child_node;
    HippoPerson *user;
    const char *description = NULL;
    const char *image_url = NULL;
    GSList *queue = NULL;

    if (!HIPPO_BLOCK_CLASS(hippo_block_netflix_movie_parent_class)->update_from_xml(block, cache, node))
        return FALSE;

    if (!hippo_xml_split(cache, node, NULL,
                         "netflixMovie", HIPPO_SPLIT_NODE, &netflix_node,
                         "description", HIPPO_SPLIT_STRING | HIPPO_SPLIT_ELEMENT | HIPPO_SPLIT_OPTIONAL, &description,
                         NULL))
        return FALSE;

    /* The imageUrl should be on the netflixMovie node, but we have to keep it on the
     * queue node in what the server sends for a while for compatibility purposes,
     * so we support it in either location.
     */
    if (!hippo_xml_split(cache, netflix_node, NULL,
                         "queue", HIPPO_SPLIT_NODE, &queue_node,
                         "userId", HIPPO_SPLIT_PERSON, &user,
                         "imageUrl", HIPPO_SPLIT_STRING | HIPPO_SPLIT_OPTIONAL, &image_url,
                         NULL))
        return FALSE;
    
    if (image_url == NULL) {
        if (!hippo_xml_split(cache, queue_node, NULL, 
                             "imageUrl", HIPPO_SPLIT_STRING, &image_url,
                             NULL))
            return FALSE;
    }
        
    for (child_node = queue_node->children; child_node; child_node = child_node->next) {
       HippoNetflixMovie *movie;        
       if (strcmp(child_node->name, "movie") != 0)
           continue;
       movie = hippo_netflix_movie_new_from_xml(cache, child_node);
       if (movie != NULL)
           queue = g_slist_prepend(queue, movie);
    }

    queue = g_slist_reverse(queue);

    set_description(block_netflix, description);
    set_image_url(block_netflix, image_url);
    set_queue(block_netflix, queue);

    hippo_block_abstract_person_set_user(HIPPO_BLOCK_ABSTRACT_PERSON(block_netflix), user);
    
    return TRUE;
}
コード例 #8
0
static Status
register_client_callback (SmsConn    conn,
                          SmPointer  manager_data,
                          char      *previous_id)
{
        GsmXSMPClient *client = manager_data;
        gboolean       handled;
        char          *id;

        g_debug ("GsmXSMPClient: Client '%s' received RegisterClient(%s)",
                 client->priv->description,
                 previous_id ? previous_id : "NULL");


        /* There are three cases:
         * 1. id is NULL - we'll use a new one
         * 2. id is known - we'll use known one
         * 3. id is unknown - this is an error
         */
        id = g_strdup (previous_id);

        handled = FALSE;
        g_signal_emit (client, signals[REGISTER_REQUEST], 0, &id, &handled);
        if (! handled) {
                g_debug ("GsmXSMPClient:  RegisterClient not handled!");
                g_free (id);
                free (previous_id);
                g_assert_not_reached ();
                return FALSE;
        }

        if (IS_STRING_EMPTY (id)) {
                g_debug ("GsmXSMPClient:   rejected: invalid previous_id");
                free (previous_id);
                return FALSE;
        }

        g_object_set (client, "startup-id", id, NULL);

        set_description (client);

        g_debug ("GsmXSMPClient: Sending RegisterClientReply to '%s'", client->priv->description);

        SmsRegisterClientReply (conn, id);

        if (IS_STRING_EMPTY (previous_id)) {
                /* Send the initial SaveYourself. */
                g_debug ("GsmXSMPClient: Sending initial SaveYourself");
                SmsSaveYourself (conn, SmSaveLocal, False, SmInteractStyleNone, False);
                client->priv->current_save_yourself = SmSaveLocal;
        }

        gsm_client_set_status (GSM_CLIENT (client), GSM_CLIENT_REGISTERED);

        g_free (id);
        free (previous_id);

        return TRUE;
}
コード例 #9
0
ファイル: cov_scope.C プロジェクト: ggcov/ggcov
cov_range_scope_t::cov_range_scope_t(
    const cov_file_t *file,
    unsigned long start,
    unsigned long end)
 :  file_(file),
    start_(start),
    end_(end)
{
    set_description();
}
コード例 #10
0
ファイル: cov_scope.C プロジェクト: ggcov/ggcov
cov_range_scope_t::cov_range_scope_t(
    const char *filename,
    unsigned long start,
    unsigned long end)
 :  file_(cov_file_t::find(filename)),
    start_(start),
    end_(end)
{
    set_description();
}
コード例 #11
0
ファイル: Item.cpp プロジェクト: KCherkasov/Vikings_village
size_t Item::import_from_table(prototypes::ItemTable data) {
  size_t response = 0;
  response = set_name(data._name);
  response = set_description(data._description);
  response = set_bonuses(data._bonuses);
  response = set_penalties(data._penalties);
  response = set_slots(data._slots);
  response = set_cost(data._cost);
  return response;
}
コード例 #12
0
ファイル: new-room.c プロジェクト: rmanis/lil
void create() {
    ::create();
    set_glance(GLANCE);
    set_description("This is a new room.  Someone should describe it.");
    simple_set_exits( ([
                           // "north" : "destination"
                       ]) );

    load_from_data();
}
コード例 #13
0
ファイル: darkWoods.cpp プロジェクト: abailey21/Silvergate
bool DarkWoods::menu(Player *player)
{
    char choice;

    set_locationTitle("Dark Woods");
    set_description("The woods hold a mysterious aura, that\nmakes you feel uncomfortable as you enter the dark\nlabyrinth of gnarled beast like trees and barbed grass\nblades. No one knows what resides in these woods,\nbut once inside you can never feel alone they say\n\n");

    do
    {
        print_description();

        cout << "S: Murky Swamp\n";
        cout << "C: Strange Cabin\n";
        cout << "O: Unusal Formation\n";
        cout << "L: Leave\n\n";
        cout << "Q: Quit Game\n\n";
        cout << "> ";

        cin >> choice;

        switch(choice)
        {
            case 's':
            case 'S':
                //murkyswamp();
                return false;
                break;

            case 'c':
            case 'C':
                //strangecabin();
                return false;
                break;

            case 'o':
            case 'O':
                //unusualformation();
                return false;
                break;

            case 'l':
            case 'L':
                player->set_currentLocation("Devils Cross");
                return false;
                break;

            case 'q':
            case 'Q':
                return true;
                break;
        }

    } while (true);
}
コード例 #14
0
ファイル: devilsCross.cpp プロジェクト: abailey21/Silvergate
bool DevilsCross::menu(Player *player)
{
    char choice;

    set_locationTitle("Devils Cross");
    set_description("you reach the beaten path of the devil's cross,\nwind beating you from all directions. You feel\nslightly overwhelmed at the vastness of it all\nas you look from North to South and back again,\ncontemplating where to go next.\n\n");

    do
    {
        print_description();

        cout << "N: North - Silvergate\n";
        cout << "S: South - The Arena\n";
        cout << "E: East - Dark Woods\n";
        cout << "W: West - The Wizard's Tower\n\n";
        cout << "Q: Quit Game\n\n";
        cout << "> ";

        cin >> choice;

        switch(choice)
        {
            case 'n':
            case 'N':
                player->set_currentLocation("Silvergate");
                return false;
                break;

            case 's':
            case 'S':
                player->set_currentLocation("Arena");
                return false;
                break;

            case 'e':
            case 'E':
                player->set_currentLocation("Dark Woods");
                return false;
                break;

            case 'w':
            case 'W':
                player->set_currentLocation("Wizards Tower");
                return false;
                break;

            case 'q':
            case 'Q':
                return true;
                break;
        }

    } while (true);
}
コード例 #15
0
ファイル: wizardsTower.cpp プロジェクト: abailey21/Silvergate
bool WizardsTower::menu(Player *player)
{
    char choice;

    set_locationTitle("Wizards Tower");
    set_description("You stand before the colossus tower,\nyour hairs standing on end at the very thought of the\nmagical essences that radiate from this brick and motor\nplace is more homely than even the most bustling\ngiant which penetrates the very skyline and into the realm of the gods.\n\n");

    do
    {
        print_description();

        cout << "E: Arcane Enchanter Room\n";
        cout << "I: Rejuvenation Temple\n";
        cout << "G: Alchemist Chamber\n";
        cout << "L: Leave\n\n";
        cout << "Q: Quit Game\n\n";
        cout << "> ";

        cin >> choice;

        switch(choice)
        {
            case 'e':
            case 'E':
                //arcaneEnchanterRoom();
                return false;
                break;

            case 'r':
            case 'R':
                //rejuvenationtemple();
                return false;
                break;

            case 'a':
            case 'A':
                //alchemistchamber();
                return false;
                break;

            case 'l':
            case 'L':
                player->set_currentLocation("Devils Cross");
                return false;
                break;

            case 'q':
            case 'Q':
                return true;
                break;
        }

    } while (true);
}
コード例 #16
0
static void
hippo_block_amazon_activity_update (HippoBlock *block)
{
    HippoBlockAmazonActivity *block_amazon_activity = HIPPO_BLOCK_AMAZON_ACTIVITY(block);
    const char *description = NULL;
    const char *image_url = NULL;
    guint image_width;
    guint image_height;
    const char *review_title = NULL;
    int review_rating = -1;
    const char *list_name = NULL;
    const char *list_link = NULL;
    const char *list_item_comment = NULL; 
    
    HIPPO_BLOCK_CLASS(hippo_block_amazon_activity_parent_class)->update(block);

    ddm_data_resource_get(block->resource,
                          "description", DDM_DATA_STRING, &description,
                          "imageUrl", DDM_DATA_URL, &image_url,
                          "imageWidth", DDM_DATA_INTEGER, &image_width,
                          "imageHeight", DDM_DATA_INTEGER, &image_height,
                          NULL);

    if (block->type == HIPPO_BLOCK_TYPE_AMAZON_REVIEW) {
        ddm_data_resource_get(block->resource,
                              "reviewRating", DDM_DATA_INTEGER, &review_rating,
                              "reviewTitle", DDM_DATA_STRING, &review_title,
                              NULL);
    } else { /* HIPPO_BLOCK_TYPE_WISH_LIST_ITEM */
        ddm_data_resource_get(block->resource,
                              "comment", DDM_DATA_STRING, &list_item_comment,
                              "listLink", DDM_DATA_URL, &list_link,
                              "listName", DDM_DATA_STRING, &list_name,
                              NULL);
    }


    set_description(block_amazon_activity, description);
    set_image_width(block_amazon_activity, image_width);
    set_image_height(block_amazon_activity, image_height);
    set_image_url(block_amazon_activity, image_url); 
    set_review_title(block_amazon_activity, review_title);
    set_review_rating(block_amazon_activity, review_rating);
    set_list_name(block_amazon_activity, list_name);
    set_list_link(block_amazon_activity, list_link);
    set_list_item_comment(block_amazon_activity, list_item_comment);
}
コード例 #17
0
ファイル: Questions.cpp プロジェクト: mikolajs/milionaire
/** metoda testująca zawartość klasy - na razy drukująca w konsoli kolejne pytania */
void Questions::test()
{
    qDebug() << "POCZĄTEK TESTU" ;
    createXMLforTest();
    set_filename("testowy.xml");
    //tempReader();
    loadFile();
    qDebug() << "Ilość pytań: ";
    qDebug() << questVector.size();
    qDebug() << "Ilość w poziomach: ";
    QVector<int> vec = countQuestionInLevels();
    for (QVector<int>::iterator it = vec.begin(); it != vec.end(); ++it) qDebug() << (*it);
    set_description("Quiz przetworzony w teście.");
    set_filename("przetworzony.xml");
    saveFile();
    qDebug() << "KONIEC TESTU" ;
}
コード例 #18
0
static void
setup_connection (GsmXSMPClient *client)
{
        GIOChannel    *channel;
        int            fd;

        g_debug ("GsmXSMPClient: Setting up new connection");

        fd = IceConnectionNumber (client->priv->ice_connection);
        fcntl (fd, F_SETFD, fcntl (fd, F_GETFD, 0) | FD_CLOEXEC);
        channel = g_io_channel_unix_new (fd);
        client->priv->watch_id = g_io_add_watch (channel,
                                                 G_IO_IN | G_IO_ERR,
                                                 (GIOFunc)client_iochannel_watch,
                                                 client);
        g_io_channel_unref (channel);

        set_description (client);

        g_debug ("GsmXSMPClient: New client '%s'", client->priv->description);
}
コード例 #19
0
/*
  =======================================================================================
  =======================================================================================
*/
BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) 
	{
	case WM_INITDIALOG:
		SetDlgItemInt(hDlg, IDC_MAX_PARTICLES, 1000, TRUE);
		SendMessage(GetDlgItem(hDlg, IDC_RAND_SEED), EM_SETLIMITTEXT, 8, 0);
		SetDlgItemInt(hDlg, IDC_RAND_SEED, 1, FALSE);
		set_description(hDlg);
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) 
		{
		case IDC_CHOOSE_LIST:
			choose_src_list(hDlg);
			break;

		case ID_RUN:
			if (run(hDlg)) {
				MessageBox(hDlg, "New list file created.", "Success", MB_OK);
			}

			break;

		case IDCANCEL:
			DestroyWindow(hDlg);
			break;
		}

		return TRUE;

	case WM_DESTROY:
		PostQuitMessage(0);
		return TRUE;		
	}

	return FALSE;
}
コード例 #20
0
ファイル: ifo_file.cpp プロジェクト: 2php/stardict-3
DictInfo& DictInfo::operator=(const DictInfo& dict_info)
{
	clear();
	ifo_file_name = dict_info.ifo_file_name;

	if(dict_info.is_wordcount())
		set_wordcount(dict_info.get_wordcount());
	if(dict_info.is_filecount())
		set_filecount(dict_info.get_filecount());
	if(dict_info.is_synwordcount())
		set_synwordcount(dict_info.get_synwordcount());
	if(dict_info.is_bookname())
		set_bookname(dict_info.get_bookname());
	if(dict_info.is_author())
		set_author(dict_info.get_author());
	if(dict_info.is_email())
		set_email(dict_info.get_email());
	if(dict_info.is_website())
		set_website(dict_info.get_website());
	if(dict_info.is_date())
		set_date(dict_info.get_date());
	if(dict_info.is_description())
		set_description(dict_info.get_description());
	if(dict_info.is_index_file_size())
		set_index_file_size(dict_info.get_index_file_size());
	if(dict_info.is_sametypesequence())
		set_sametypesequence(dict_info.get_sametypesequence());
	if(dict_info.is_dicttype())
		set_dicttype(dict_info.get_dicttype());
	if(dict_info.is_version())
		set_version(dict_info.get_version());
	if(dict_info.is_infotype())
		set_infotype(dict_info.get_infotype());

	f_idxoffsetbits = dict_info.f_idxoffsetbits;
	return *this;
}
コード例 #21
0
static void
set_properties_callback (SmsConn     conn,
                         SmPointer   manager_data,
                         int         num_props,
                         SmProp    **props)
{
        GsmXSMPClient *client = manager_data;
        int            i;

        g_debug ("GsmXSMPClient: Set properties from client '%s'", client->priv->description);

        for (i = 0; i < num_props; i++) {
                delete_property (client, props[i]->name);
                g_ptr_array_add (client->priv->props, props[i]);

                debug_print_property (props[i]);

                if (!strcmp (props[i]->name, SmProgram))
                        set_description (client);
        }

        free (props);

}
コード例 #22
0
static gboolean
hippo_block_amazon_activity_update_from_xml (HippoBlock           *block,
                                             HippoDataCache       *cache,
                                             LmMessageNode        *node)
{
    HippoBlockAmazonActivity *block_amazon_activity = HIPPO_BLOCK_AMAZON_ACTIVITY(block);
    LmMessageNode *amazon_activity_node;
    LmMessageNode *review_node = NULL;
    LmMessageNode *list_item_node = NULL;
    HippoPerson *user;
    const char *description = NULL;
    const char *image_url = NULL;
    guint image_width;
    guint image_height;
    const char *review_title = NULL;
    int review_rating = -1;
    const char *list_name = NULL;
    const char *list_link = NULL;
    const char *list_item_comment = NULL; 

    if (!HIPPO_BLOCK_CLASS(hippo_block_amazon_activity_parent_class)->update_from_xml(block, cache, node))
        return FALSE;

    if (!hippo_xml_split(cache, node, NULL,
                         "amazonActivity", HIPPO_SPLIT_NODE, &amazon_activity_node,
                         "description", HIPPO_SPLIT_STRING | HIPPO_SPLIT_ELEMENT | HIPPO_SPLIT_OPTIONAL, &description,
                         NULL))
        return FALSE;

    if (!hippo_xml_split(cache, amazon_activity_node, NULL,
                         "review", HIPPO_SPLIT_NODE | HIPPO_SPLIT_OPTIONAL, &review_node,
                         "listItem", HIPPO_SPLIT_NODE | HIPPO_SPLIT_OPTIONAL, &list_item_node,
                         "userId", HIPPO_SPLIT_PERSON, &user,
                         "imageUrl", HIPPO_SPLIT_STRING, &image_url,
                         "imageWidth", HIPPO_SPLIT_INT32, &image_width,
                         "imageHeight", HIPPO_SPLIT_INT32, &image_height, 
                         NULL))
        return FALSE;
    
    if (review_node != NULL) {
        if (!hippo_xml_split(cache, review_node, NULL, 
                             "title", HIPPO_SPLIT_STRING, &review_title,
                             "rating", HIPPO_SPLIT_INT32, &review_rating,   
                             NULL))
            return FALSE;
    }

    if (list_item_node != NULL) {
        if (!hippo_xml_split(cache, list_item_node, NULL, 
                             "listName", HIPPO_SPLIT_STRING, &list_name,
                             "listLink", HIPPO_SPLIT_STRING, &list_link, 
                             "comment", HIPPO_SPLIT_STRING | HIPPO_SPLIT_ELEMENT, &list_item_comment,
                             NULL))
            return FALSE;
     }

    set_description(block_amazon_activity, description);
    set_image_width(block_amazon_activity, image_width);
    set_image_height(block_amazon_activity, image_height);
    set_image_url(block_amazon_activity, image_url); 
    set_review_title(block_amazon_activity, review_title);
    set_review_rating(block_amazon_activity, review_rating);
    set_list_name(block_amazon_activity, list_name);
    set_list_link(block_amazon_activity, list_link);
    set_list_item_comment(block_amazon_activity, list_item_comment);

    hippo_block_abstract_person_set_user(HIPPO_BLOCK_ABSTRACT_PERSON(block_amazon_activity), user);
    
    return TRUE;
}
コード例 #23
0
ファイル: multiplayer_create.cpp プロジェクト: Li2012/wesnoth
void create::process_event()
{
	int mousex, mousey;
	SDL_GetMouseState(&mousex,&mousey);
	tooltips::process(mousex, mousey);

	if (cancel_game_.pressed()) {
		set_result(QUIT);
		return;
	}

	if (launch_game_.pressed() || levels_menu_.double_clicked()) {
		if (engine_.current_level().can_launch_game()) {
			if (engine_.current_level_type() == level::CAMPAIGN ||
				engine_.current_level_type() == level::SP_CAMPAIGN) {

				std::string difficulty = select_campaign_difficulty();
				if (difficulty == "CANCEL") {
					return;
				}

				engine_.prepare_for_campaign(difficulty);
			}

			engine_.prepare_for_new_level();

			set_result(CREATE);
			return;
		} else {
			gui2::show_transient_message(disp_.video(), "",
				_("The level is invalid."));
		}
	}

	if (level_type_combo_.changed()) {
		init_level_type_changed(0);
	}

	if (load_game_.pressed()) {
		engine_.prepare_for_saved_game();

		set_result(LOAD_GAME);

		return;
	}

	bool update_mod_button_label = mod_selection_ != mods_menu_.selection();
	if (select_mod_.pressed() || mods_menu_.double_clicked()) {
		int index = mods_menu_.selection();
		engine_.set_current_mod_index(index);
		engine_.toggle_current_mod();

		update_mod_button_label = true;
		synchronize_selections();
	}

	if (update_mod_button_label) {
		mod_selection_ = mods_menu_.selection();
		engine_.set_current_mod_index(mod_selection_);
		set_description(engine_.current_extra(create_engine::MOD).description);
		if (engine_.dependency_manager().is_modification_active(mod_selection_)) {
			select_mod_.set_label(_("Deactivate"));
		} else {
			select_mod_.set_label(_("Activate"));
		}
	}

	bool era_changed = era_selection_ != eras_menu_.selection();
	era_selection_ = eras_menu_.selection();

	if (era_changed) {
		engine_.set_current_era_index(era_selection_);

		set_description(engine_.current_extra(create_engine::ERA).description);
		synchronize_selections();
	}

	if (filter_name_.text() != engine_.level_name_filter()) {
		engine_.apply_level_filter(filter_name_.text());
		init_level_type_changed(0);
	}

	bool level_changed = level_selection_ != levels_menu_.selection();
	level_selection_ = levels_menu_.selection();

	if (level_changed && level_selection_ >= 0) {
		init_level_changed(level_selection_);

		synchronize_selections();
	}

	if (engine_.generator_assigned() && generator_settings_.pressed()) {
		engine_.generator_user_config(disp_);

		level_changed = true;
	}

	if(engine_.generator_assigned() &&
		(level_changed || regenerate_map_.pressed())) {
		const cursor::setter cursor_setter(cursor::WAIT);
		cursor::setter cur(cursor::WAIT);

		engine_.init_generated_level_data();

		if (!engine_.current_level().data()["error_message"].empty())
			gui2::show_message(disp().video(), "map generation error",
				engine_.current_level().data()["error_message"]);

		level_changed = true;
	}

	if(level_changed) {
		std::stringstream players;
		std::stringstream map_size;

		players << _("Players: ");

		engine_.current_level().set_metadata();

		draw_level_image();

		set_description(engine_.current_level().description());

		switch (engine_.current_level_type()) {
		case level::SCENARIO:
		case level::USER_MAP:
		case level::USER_SCENARIO:
		case level::RANDOM_MAP: {

			scenario* current_scenario =
				dynamic_cast<scenario*>(&engine_.current_level());

			players << current_scenario->num_players();
			map_size << _("Size: ") << current_scenario->map_size();

			break;
		}
		case level::CAMPAIGN:
		case level::SP_CAMPAIGN: {
			campaign* current_campaign =
				dynamic_cast<campaign*>(&engine_.current_level());

			players << current_campaign->min_players();
			if (current_campaign->max_players() !=
				current_campaign->min_players()) {

				players << " to " << current_campaign->max_players();
			}

			break;
		}
		} // end switch

		map_size_label_.set_text(map_size.str());
		num_players_label_.set_text(players.str());

		launch_game_.enable(engine_.current_level().can_launch_game());
		generator_settings_.enable(engine_.generator_assigned());
		regenerate_map_.enable(engine_.generator_assigned());
	}

	if (filter_num_players_slider_.value() != engine_.player_num_filter()) {
		const int val = filter_num_players_slider_.value();
		engine_.apply_level_filter(val);
		std::stringstream ss;
		if (val == 1) {
			ss << _("Number of players: any");
		} else {
			ss << _("Number of players: ") << val;
		}
		filter_num_players_label_.set_text(ss.str());
		init_level_type_changed(0);
	}
}
コード例 #24
0
ファイル: fallback_dpkg.c プロジェクト: denisw/libpsys
static int do_register(psys_pkg_t pkg, psys_err_t *err, jmp_buf *buf)
{
	int ret;
	char *dpkgname = NULL;
	const char *dpkgarch;
	struct pkginfo *dpkg;
	psys_flist_t flist = NULL;
	char *filelist_path = NULL;
	char *md5list_path = NULL;

	set_error_handler(err, *buf, out);

	dpkgname = dpkg_name(psys_pkg_vendor(pkg), psys_pkg_name(pkg));
	dpkg = findpackage(dpkgname);
	if (ensure_not_installed(dpkg, err)) {
		ret = -1;
		goto out;
	}

	if (ensure_dependencies_met(pkg, err)) {
		ret = -1;
		goto out;
	}

	blankpackage(dpkg);
	blankpackageperfile(&dpkg->installed);

	/* Name, Version */
	dpkg->name = dpkgname;
	parseversion(&dpkg->installed.version, psys_pkg_version(pkg));

	/* Architecture */
	dpkgarch = dpkg_arch(psys_pkg_arch(pkg), err);
	if (!dpkgarch) {
		ret = -1;
		goto out;
	}
	dpkg->installed.architecture = dpkgarch;

	/* Description */
	set_description(dpkg, pkg);

	/* 
	 * Maintainer
	 *
	 * FIXME: Our Maintainer value does not conform to the format
	 * mandated by the Debian Policy Manual (which is "Name <E-Mail>"),
	 * but this is better than not specifying a Maintainer at all
	 * (which is a mandatory field)
	 */
	dpkg->installed.maintainer = nfstrsave(psys_pkg_vendor(pkg));

	/* Priority */
	dpkg->priority = pri_optional;

	/* Dependencies */
	add_dependencies(dpkg, pkg);

	flist = psys_pkg_flist(pkg, err);
	if (!flist) {
		ret = -1;
		goto out;
	}

	/* Installed Size */
	set_installed_size(dpkg, flist);

	/* File List */
	filelist_path = create_file_list(dpkg, flist, err);
	if (!filelist_path) {
		ret = -1;
		goto out;
	}

	/* MD5SUMS List */
	md5list_path = create_md5sums_list(dpkg, flist, err);
	if (!md5list_path) {
		ret = -1;
		goto out;
	}

	dpkg->want = want_install;
	dpkg->status = stat_installed;
	modstatdb_note(dpkg);

	ret = 0;
out:
	if (md5list_path) {
		if (ret == -1)
			remove(md5list_path);
		free(md5list_path);
	}
	if (filelist_path) {
		if (ret == -1)
			remove(filelist_path);
		free(filelist_path);
	}
	if (flist)
		psys_flist_free(flist);
	return ret;
}
コード例 #25
0
ファイル: Bolq.hpp プロジェクト: jackie1223456/cs162
 Bolq() : Fighter("Bolq XXXL", 500, 8, 100, 7)
 {
   weapon = new Weapon("Bomb.com", 80, 0.4, true);
   set_description();
 }
コード例 #26
0
ファイル: mail-to-task.c プロジェクト: sbaconnais/evolution
static gboolean
do_mail_to_event (AsyncData *data)
{
	EClient *client;
	CamelFolder *folder = data->folder;
	GPtrArray *uids = data->uids;
	GError *error = NULL;

	client = e_client_cache_get_client_sync (data->client_cache,
		data->source, data->extension_name, 30, NULL, &error);

	/* Sanity check. */
	g_return_val_if_fail (
		((client != NULL) && (error == NULL)) ||
		((client == NULL) && (error != NULL)), TRUE);

	if (error != NULL) {
		report_error_idle (_("Cannot open calendar. %s"), error->message);
	} else if (e_client_is_readonly (E_CLIENT (client))) {
		switch (data->source_type) {
		case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
			report_error_idle (_("Selected calendar is read only, thus cannot create event there. Select other calendar, please."), NULL);
			break;
		case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
			report_error_idle (_("Selected task list is read only, thus cannot create task there. Select other task list, please."), NULL);
			break;
		case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
			report_error_idle (_("Selected memo list is read only, thus cannot create memo there. Select other memo list, please."), NULL);
			break;
		default:
			g_warn_if_reached ();
			break;
		}
	} else {
		gint i;
		ECalComponentDateTime dt, dt2;
		struct icaltimetype tt, tt2;
		struct _manage_comp *oldmc = NULL;

		#define cache_backend_prop(prop) { \
			gchar *val = NULL; \
			e_client_get_backend_property_sync (E_CLIENT (client), prop, &val, NULL, NULL); \
			g_free (val); \
		}

		/* precache backend properties, thus editor have them ready when needed */
		cache_backend_prop (CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS);
		cache_backend_prop (CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS);
		cache_backend_prop (CAL_BACKEND_PROPERTY_DEFAULT_OBJECT);
		e_client_get_capabilities (E_CLIENT (client));

		#undef cache_backend_prop

		/* set start day of the event as today, without time - easier than looking for a calendar's time zone */
		tt = icaltime_today ();
		dt.value = &tt;
		dt.tzid = NULL;

		tt2 = tt;
		icaltime_adjust (&tt2, 1, 0, 0, 0);
		dt2.value = &tt2;
		dt2.tzid = NULL;

		for (i = 0; i < (uids ? uids->len : 0); i++) {
			CamelMimeMessage *message;
			ECalComponent *comp;
			ECalComponentText text;
			icalproperty *icalprop;
			icalcomponent *icalcomp;
			struct _manage_comp *mc;

			/* retrieve the message from the CamelFolder */
			/* FIXME Not passing a GCancellable or GError. */
			message = camel_folder_get_message_sync (
				folder, g_ptr_array_index (uids, i),
				NULL, NULL);
			if (!message) {
				continue;
			}

			comp = e_cal_component_new ();

			switch (data->source_type) {
			case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
				e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
				break;
			case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
				e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO);
				break;
			case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
				e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL);
				break;
			default:
				g_warn_if_reached ();
				break;
			}

			e_cal_component_set_uid (comp, camel_mime_message_get_message_id (message));
			e_cal_component_set_dtstart (comp, &dt);

			if (data->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) {
				/* make it an all-day event */
				e_cal_component_set_dtend (comp, &dt2);
			}

			/* set the summary */
			text.value = camel_mime_message_get_subject (message);
			text.altrep = NULL;
			e_cal_component_set_summary (comp, &text);

			/* set all fields */
			if (data->selected_text) {
				GSList sl;

				text.value = data->selected_text;
				text.altrep = NULL;
				sl.next = NULL;
				sl.data = &text;

				e_cal_component_set_description_list (comp, &sl);
			} else
				set_description (comp, message);

			if (data->with_attendees) {
				gchar *organizer;

				/* set actual user as organizer, to be able to change event's properties */
				organizer = set_organizer (comp, data->folder);
				set_attendees (comp, message, organizer);
				g_free (organizer);
			}

			/* set attachment files */
			set_attachments (E_CAL_CLIENT (client), comp, message);

			/* priority */
			set_priority (comp, CAMEL_MIME_PART (message));

			/* no need to increment a sequence number, this is a new component */
			e_cal_component_abort_sequence (comp);

			icalcomp = e_cal_component_get_icalcomponent (comp);

			icalprop = icalproperty_new_x ("1");
			icalproperty_set_x_name (icalprop, "X-EVOLUTION-MOVE-CALENDAR");
			icalcomponent_add_property (icalcomp, icalprop);

			mc = g_new0 (struct _manage_comp, 1);
			mc->client = g_object_ref (client);
			mc->comp = g_object_ref (comp);
			g_mutex_init (&mc->mutex);
			g_cond_init (&mc->cond);
			mc->mails_count = uids->len;
			mc->mails_done = i + 1; /* Current task */
			mc->editor_title = NULL;
			mc->can_continue = TRUE;

			if (oldmc) {
				/* Wait for user to quit the editor created in previous iteration
				 * before displaying next one */
				gboolean can_continue;
				g_mutex_lock (&oldmc->mutex);
				g_cond_wait (&oldmc->cond, &oldmc->mutex);
				g_mutex_unlock (&oldmc->mutex);
				can_continue = oldmc->can_continue;
				free_manage_comp_struct (oldmc);
				oldmc = NULL;

				if (!can_continue)
					break;
			}

			e_cal_client_get_object_sync (
				E_CAL_CLIENT (client),
				icalcomponent_get_uid (icalcomp),
				NULL, &mc->stored_comp, NULL, NULL);

			/* Prioritize ahead of GTK+ redraws. */
			g_idle_add_full (
				G_PRIORITY_HIGH_IDLE,
				(GSourceFunc) do_manage_comp_idle, mc, NULL);

			oldmc = mc;

			g_object_unref (comp);
			g_object_unref (message);

		}

		/* Wait for the last editor and then clean up */
		if (oldmc) {
			g_mutex_lock (&oldmc->mutex);
			g_cond_wait (&oldmc->cond, &oldmc->mutex);
			g_mutex_unlock (&oldmc->mutex);
			free_manage_comp_struct (oldmc);
		}
	}

	/* free memory */
	if (client != NULL)
		g_object_unref (client);
	g_ptr_array_unref (uids);
	g_object_unref (folder);

	g_object_unref (data->client_cache);
	g_object_unref (data->source);
	g_free (data->selected_text);
	g_free (data);
	data = NULL;

	if (error != NULL)
		g_error_free (error);

	return TRUE;
}
コード例 #27
0
bool player::create(game *g, character_type type, std::string tempname)
{
 weapon = item(g->itypes[0], 0);

 int iMaxX = (g->VIEWX < 12) ? 80 : (g->VIEWX*2)+56;
 int iMaxY = (g->VIEWY < 12) ? 25 : (g->VIEWY*2)+1;

 WINDOW* w = newwin(25, 80, (iMaxY > 25) ? (iMaxY-25)/2 : 0, (iMaxX > 80) ? (iMaxX-80)/2 : 0);

 int tab = 0, points = 38;
 if (type != PLTYPE_CUSTOM) {
  switch (type) {
   case PLTYPE_RANDOM: {
    str_max = rng(6, 12);
    dex_max = rng(6, 12);
    int_max = rng(6, 12);
    per_max = rng(6, 12);
    points = points - str_max - dex_max - int_max - per_max;
    if (str_max > HIGH_STAT)
     points -= (str_max - HIGH_STAT);
    if (dex_max > HIGH_STAT)
     points -= (dex_max - HIGH_STAT);
    if (int_max > HIGH_STAT)
     points -= (int_max - HIGH_STAT);
    if (per_max > HIGH_STAT)
     points -= (per_max - HIGH_STAT);

    int num_gtraits = 0, num_btraits = 0, rn, tries;
    while (points < 0 || rng(-3, 20) > points) {
     if (num_btraits < MAX_TRAIT_POINTS && one_in(3)) {
      tries = 0;
      do {
       rn = random_bad_trait();
       tries++;
      } while ((has_trait(rn) ||
              num_btraits - traits[rn].points > MAX_TRAIT_POINTS) && tries < 5);
      if (tries < 5) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_btraits -= traits[rn].points;
      }
     } else {
      switch (rng(1, 4)) {
       case 1: if (str_max > 5) { str_max--; points++; } break;
       case 2: if (dex_max > 5) { dex_max--; points++; } break;
       case 3: if (int_max > 5) { int_max--; points++; } break;
       case 4: if (per_max > 5) { per_max--; points++; } break;
      }
     }
    }
    while (points > 0) {
     switch (rng((num_gtraits < MAX_TRAIT_POINTS ? 1 : 5), 9)) {
     case 1:
     case 2:
     case 3:
     case 4:
      rn = random_good_trait();
      if (!has_trait(rn) && points >= traits[rn].points &&
          num_gtraits + traits[rn].points <= MAX_TRAIT_POINTS) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_gtraits += traits[rn].points;
      }
      break;
     case 5:
      switch (rng(1, 4)) {
       case 1: if (str_max < HIGH_STAT) { str_max++; points--; } break;
       case 2: if (dex_max < HIGH_STAT) { dex_max++; points--; } break;
       case 3: if (int_max < HIGH_STAT) { int_max++; points--; } break;
       case 4: if (per_max < HIGH_STAT) { per_max++; points--; } break;
      }
      break;
     case 6:
     case 7:
     case 8:
     case 9:
      rn = random_skill();

      Skill *aSkill = Skill::skill(rn);
      int level = skillLevel(aSkill);

      if (level < points) {
        points -= level + 1;
        skillLevel(aSkill).level(level + 2);
      }
      break;
     }
    }
   } break;
   case PLTYPE_TEMPLATE: {
    std::ifstream fin;
    std::stringstream filename;
    filename << "data/" << tempname << ".template";
    fin.open(filename.str().c_str());
    if (!fin.is_open()) {
     debugmsg("Couldn't open %s!", filename.str().c_str());
     return false;
    }
    std::string(data);
    getline(fin, data);
    load_info(g, data);
    points = 0;
   } break;
  }
  tab = 3;
 } else
  points = OPTIONS[OPT_INITIAL_POINTS];

 do {
  werase(w);
  wrefresh(w);
  switch (tab) {
   case 0: tab += set_stats      (w, this, points); break;
   case 1: tab += set_traits     (w, this, points); break;
   case 2: tab += set_skills     (w, this, points); break;
   case 3: tab += set_description(w, this, points); break;
  }
 } while (tab >= 0 && tab < 4);
 delwin(w);

 if (tab < 0)
  return false;

 // Character is finalized.  Now just set up HP, &c
 for (int i = 0; i < num_hp_parts; i++) {
  hp_max[i] = calc_HP(str_max, has_trait(PF_TOUGH));
  hp_cur[i] = hp_max[i];
 }
 if (has_trait(PF_GLASSJAW)) {
  hp_max[hp_head] = int(hp_max[hp_head] * .85);
  hp_cur[hp_head] = hp_max[hp_head];
 }
 if (has_trait(PF_SMELLY))
  scent = 800;
 if (has_trait(PF_ANDROID)) {
  add_bionic(bionic_id(rng(bio_memory, max_bio_start - 1)));// Other
  if (bionics[my_bionics[0].id].power_cost > 0) {
   add_bionic(bionic_id(rng(1, bio_ethanol)));	// Power Source
   max_power_level = 10;
   power_level = 10;
  } else {
   bionic_id tmpbio;
   do
    tmpbio = bionic_id(rng(bio_ethanol + 1, bio_armor_legs));
   while (bionics[tmpbio].power_cost > 0);
   add_bionic(tmpbio);
   max_power_level = 0;
   power_level = 0;
  }

/* CHEATER'S STUFF

  add_bionic(bionic_id(rng(0, bio_ethanol)));	// Power Source
  for (int i = 0; i < 5; i++)
   add_bionic(bionic_id(rng(bio_memory, max_bio_start - 1)));// Other
  max_power_level = 80;
  power_level = 80;

End of cheatery */
 }

 if (has_trait(PF_MARTIAL_ARTS)) {
  itype_id ma_type;
  do {
   int choice = menu("Pick your style:",
                     "Karate", "Judo", "Aikido", "Tai Chi", "Taekwando", NULL);
   if (choice == 1)
    ma_type = itm_style_karate;
   if (choice == 2)
    ma_type = itm_style_judo;
   if (choice == 3)
    ma_type = itm_style_aikido;
   if (choice == 4)
    ma_type = itm_style_tai_chi;
   if (choice == 5)
    ma_type = itm_style_taekwando;
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn("Use this style?"));
  styles.push_back(ma_type);
 }
 ret_null = item(g->itypes[0], 0);
 if (!styles.empty())
  weapon = item(g->itypes[ styles[0] ], 0, ':');
 else
  weapon   = item(g->itypes[0], 0);
// Nice to start out less than naked.
 item tmp(g->itypes[itm_jeans_fit], 0, 'a');
 worn.push_back(tmp);
 tmp = item(g->itypes[itm_tshirt_fit], 0, 'b');
 worn.push_back(tmp);
 tmp = item(g->itypes[itm_sneakers_fit], 0, 'c');
 worn.push_back(tmp);
// The near-sighted get to start with glasses.
 if (has_trait(PF_MYOPIC)) {
  tmp = item(g->itypes[itm_glasses_eye], 0, 'd');
  worn.push_back(tmp);
 }
// Likewise, the asthmatic start with their medication.
 if (has_trait(PF_ASTHMA)) {
  tmp = item(g->itypes[itm_inhaler], 0, 'a' + worn.size());
  inv.push_back(tmp);
 }
 // Basic starter gear, added independently of profession.
 tmp = item(g->itypes[itm_pockknife], 0,'a' + worn.size());
  inv.push_back(tmp);
 tmp = item(g->itypes[itm_lighter], 0,'a' + worn.size());
  inv.push_back(tmp);
// make sure we have no mutations
 for (int i = 0; i < PF_MAX2; i++)
  my_mutations[i] = false;
 return true;
}
コード例 #28
0
bool player::create(game *g, character_type type, std::string tempname)
{
 weapon = item(g->itypes["null"], 0);
 
 g->u.prof = profession::generic();

 WINDOW* w = newwin(25, 80, (TERMY > 25) ? (TERMY-25)/2 : 0, (TERMX > 80) ? (TERMX-80)/2 : 0);

 int tab = 0, points = 38;
 if (type != PLTYPE_CUSTOM) {
  switch (type) {
   case PLTYPE_RANDOM: {
    str_max = rng(6, 12);
    dex_max = rng(6, 12);
    int_max = rng(6, 12);
    per_max = rng(6, 12);
    points = points - str_max - dex_max - int_max - per_max;
    if (str_max > HIGH_STAT)
     points -= (str_max - HIGH_STAT);
    if (dex_max > HIGH_STAT)
     points -= (dex_max - HIGH_STAT);
    if (int_max > HIGH_STAT)
     points -= (int_max - HIGH_STAT);
    if (per_max > HIGH_STAT)
     points -= (per_max - HIGH_STAT);

    int num_gtraits = 0, num_btraits = 0, rn, tries;
    while (points < 0 || rng(-3, 20) > points) {
     if (num_btraits < MAX_TRAIT_POINTS && one_in(3)) {
      tries = 0;
      do {
       rn = random_bad_trait();
       tries++;
      } while ((has_trait(rn) ||
              num_btraits - traits[rn].points > MAX_TRAIT_POINTS) && tries < 5);
      if (tries < 5) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_btraits -= traits[rn].points;
      }
     } else {
      switch (rng(1, 4)) {
       case 1: if (str_max > 5) { str_max--; points++; } break;
       case 2: if (dex_max > 5) { dex_max--; points++; } break;
       case 3: if (int_max > 5) { int_max--; points++; } break;
       case 4: if (per_max > 5) { per_max--; points++; } break;
      }
     }
    }
    while (points > 0) {
     switch (rng((num_gtraits < MAX_TRAIT_POINTS ? 1 : 5), 9)) {
     case 1:
     case 2:
     case 3:
     case 4:
      rn = random_good_trait();
      if (!has_trait(rn) && points >= traits[rn].points &&
          num_gtraits + traits[rn].points <= MAX_TRAIT_POINTS) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_gtraits += traits[rn].points;
      }
      break;
     case 5:
      switch (rng(1, 4)) {
       case 1: if (str_max < HIGH_STAT) { str_max++; points--; } break;
       case 2: if (dex_max < HIGH_STAT) { dex_max++; points--; } break;
       case 3: if (int_max < HIGH_STAT) { int_max++; points--; } break;
       case 4: if (per_max < HIGH_STAT) { per_max++; points--; } break;
      }
      break;
     case 6:
     case 7:
     case 8:
     case 9:
      rn = random_skill();

      Skill *aSkill = Skill::skill(rn);
      int level = skillLevel(aSkill);

      if (level < points) {
        points -= level + 1;
        skillLevel(aSkill).level(level + 2);
      }
      break;
     }
    }
   } break;
   case PLTYPE_TEMPLATE: {
    std::ifstream fin;
    std::stringstream filename;
    filename << "data/" << tempname << ".template";
    fin.open(filename.str().c_str());
    if (!fin.is_open()) {
     debugmsg("Couldn't open %s!", filename.str().c_str());
     return false;
    }
    std::string(data);
    getline(fin, data);
    load_info(g, data);
    points = 0;
   } break;
  }
  tab = 3;
 } else
  points = OPTIONS[OPT_INITIAL_POINTS];

 do {
  werase(w);
  wrefresh(w);
  switch (tab) {
   case 0: tab += set_stats      (w, g, this, points); break;
   case 1: tab += set_traits     (w, g, this, points); break;
   case 2: tab += set_profession (w, g, this, points); break;
   case 3: tab += set_skills     (w, g, this, points); break;
   case 4: tab += set_description(w, g, this, points); break;
  }
 } while (tab >= 0 && tab < 5);
 delwin(w);

 if (tab < 0)
  return false;

 // Character is finalized.  Now just set up HP, &c
 for (int i = 0; i < num_hp_parts; i++) {
  hp_max[i] = calc_HP(str_max, has_trait(PF_TOUGH));
  hp_cur[i] = hp_max[i];
 }
 if (has_trait(PF_GLASSJAW)) {
  hp_max[hp_head] = int(hp_max[hp_head] * .85);
  hp_cur[hp_head] = hp_max[hp_head];
 }
 if (has_trait(PF_SMELLY))
  scent = 800;
 if (has_trait(PF_ANDROID)) {
  std::map<std::string,bionic_data*>::iterator random_bionic = bionics.begin();
  std::advance(random_bionic,rng(0,bionics.size()-1));
  add_bionic(random_bionic->first);// Other
  if (bionics[my_bionics[0].id]->power_cost > 0) {
   add_bionic(bionic_id(power_source_bionics[rng(0,power_source_bionics.size())]));	// Power Source
   max_power_level = 10;
   power_level = 10;
  } else {
   bionic_id tmpbio;
   do
   tmpbio = bionic_id(unpowered_bionics[rng(0, unpowered_bionics.size())]);
   while (bionics[tmpbio]->power_cost > 0);
   add_bionic(tmpbio);
   max_power_level = 0;
   power_level = 0;
  }

/* CHEATER'S STUFF

  add_bionic(bionic_id(rng(0, "bio_ethanol")));	// Power Source
  for (int i = 0; i < 5; i++)
   add_bionic(bionic_id(rng("bio_memory", max_"bio_start" - 1)));// Other
  max_power_level = 80;
  power_level = 80;

End of cheatery */
 }

 if (has_trait(PF_MARTIAL_ARTS)) {
  itype_id ma_type;
  do {
   int choice = menu("Pick your style:",
                     "Karate", "Judo", "Aikido", "Tai Chi", "Taekwondo", NULL);
   if (choice == 1)
    ma_type = "style_karate";
   if (choice == 2)
    ma_type = "style_judo";
   if (choice == 3)
    ma_type = "style_aikido";
   if (choice == 4)
    ma_type = "style_tai_chi";
   if (choice == 5)
    ma_type = "style_taekwondo";
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn("Use this style?"));
  styles.push_back(ma_type);
 }
 ret_null = item(g->itypes["null"], 0);
 if (!styles.empty())
  weapon = item(g->itypes[ styles[0] ], 0, ':');
 else
  weapon   = item(g->itypes["null"], 0);
 
 item tmp; //gets used several times

 std::vector<std::string> prof_items = g->u.prof->items();
 for (std::vector<std::string>::const_iterator iter = prof_items.begin(); iter != prof_items.end(); ++iter) {
  item tmp = item(g->itypes.at(*iter), 0, 'a' + worn.size());
  if (tmp.is_armor()) {
   if (tmp.has_flag(IF_VARSIZE))
    tmp.item_flags |= mfb(IF_FIT);      
   worn.push_back(tmp);
  } else {
   inv.push_back(tmp);
  }

  // if we start with drugs, need to start strongly addicted, too
  if (tmp.is_food()) {
   it_comest *comest = dynamic_cast<it_comest*>(tmp.type);
   if (comest->add != ADD_NULL) {
    addiction add(comest->add, 10);
    g->u.addictions.push_back(add);
   }
  }
 }

// The near-sighted get to start with glasses.
 if (has_trait(PF_MYOPIC)) {
  tmp = item(g->itypes["glasses_eye"], 0, 'a' + worn.size());
  worn.push_back(tmp);
 }
// And the far-sighted get to start with reading glasses.
 if (has_trait(PF_HYPEROPIC)) {
  tmp = item(g->itypes["glasses_reading"], 0, 'a' + worn.size());
  worn.push_back(tmp);
 }
// Likewise, the asthmatic start with their medication.
 if (has_trait(PF_ASTHMA)) {
  tmp = item(g->itypes["inhaler"], 0, 'a' + worn.size());
  inv.push_back(tmp);
 }
// Basic starter gear, added independently of profession.
 tmp = item(g->itypes["pockknife"], 0,'a' + worn.size());
  inv.push_back(tmp);
 tmp = item(g->itypes["matches"], 0,'a' + worn.size());
  inv.push_back(tmp);
// make sure we have no mutations
 for (int i = 0; i < PF_MAX2; i++)
  my_mutations[i] = false;
 return true;
}
コード例 #29
0
bool player::create(game *g, character_type type, std::string tempname)
{
 weapon = item(g->itypes["null"], 0);

 g->u.prof = profession::generic();

 WINDOW* w = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
                    (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0,
                    (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0);

 int tab = 0, points = 38, max_trait_points = 12;
 if (type != PLTYPE_CUSTOM) {
  switch (type) {
   case PLTYPE_RANDOM: {
    str_max = rng(6, 12);
    dex_max = rng(6, 12);
    int_max = rng(6, 12);
    per_max = rng(6, 12);
    points = points - str_max - dex_max - int_max - per_max;
    if (str_max > HIGH_STAT)
     points -= (str_max - HIGH_STAT);
    if (dex_max > HIGH_STAT)
     points -= (dex_max - HIGH_STAT);
    if (int_max > HIGH_STAT)
     points -= (int_max - HIGH_STAT);
    if (per_max > HIGH_STAT)
     points -= (per_max - HIGH_STAT);

    int num_gtraits = 0, num_btraits = 0, rn, tries;
    while (points < 0 || rng(-3, 20) > points) {
     if (num_btraits < max_trait_points && one_in(3)) {
      tries = 0;
      do {
       rn = random_bad_trait();
       tries++;
      } while ((has_trait(rn) ||
              num_btraits - traits[rn].points > max_trait_points) && tries < 5);
      if (tries < 5) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_btraits -= traits[rn].points;
      }
     } else {
      switch (rng(1, 4)) {
       case 1: if (str_max > 5) { str_max--; points++; } break;
       case 2: if (dex_max > 5) { dex_max--; points++; } break;
       case 3: if (int_max > 5) { int_max--; points++; } break;
       case 4: if (per_max > 5) { per_max--; points++; } break;
      }
     }
    }
    while (points > 0) {
     switch (rng((num_gtraits < max_trait_points ? 1 : 5), 9)) {
     case 1:
     case 2:
     case 3:
     case 4:
      rn = random_good_trait();
      if (!has_trait(rn) && points >= traits[rn].points &&
          num_gtraits + traits[rn].points <= max_trait_points) {
       toggle_trait(rn);
       points -= traits[rn].points;
       num_gtraits += traits[rn].points;
      }
      break;
     case 5:
      switch (rng(1, 4)) {
       case 1: if (str_max < HIGH_STAT) { str_max++; points--; } break;
       case 2: if (dex_max < HIGH_STAT) { dex_max++; points--; } break;
       case 3: if (int_max < HIGH_STAT) { int_max++; points--; } break;
       case 4: if (per_max < HIGH_STAT) { per_max++; points--; } break;
      }
      break;
     case 6:
     case 7:
     case 8:
     case 9:
      rn = random_skill();

      Skill *aSkill = Skill::skill(rn);
      int level = skillLevel(aSkill);

      if (level < points) {
        points -= level + 1;
        skillLevel(aSkill).level(level + 2);
      }
      break;
     }
    }
   } break;
   case PLTYPE_TEMPLATE: {
    std::ifstream fin;
    std::stringstream filename;
    filename << "data/" << tempname << ".template";
    fin.open(filename.str().c_str());
    if (!fin.is_open()) {
     debugmsg("Couldn't open %s!", filename.str().c_str());
     return false;
    }
    std::string(data);
    getline(fin, data);
    load_info(g, data);
    points = 0;
   } break;
  }
  tab = NEWCHAR_TAB_MAX;
 } else
  points = OPTIONS[OPT_INITIAL_POINTS];
  max_trait_points = OPTIONS[OPT_MAX_TRAIT_POINTS];

 do {
  werase(w);
  wrefresh(w);
  switch (tab) {
   case 0: tab += set_stats      (w, g, this, points); break;
   case 1: tab += set_traits     (w, g, this, points, max_trait_points); break;
   case 2: tab += set_profession (w, g, this, points); break;
   case 3: tab += set_skills     (w, g, this, points); break;
   case 4: tab += set_description(w, g, this, points); break;
  }
 } while (tab >= 0 && tab <= NEWCHAR_TAB_MAX);
 delwin(w);

 if (tab < 0)
  return false;

 // Character is finalized.  Now just set up HP, &c
 for (int i = 0; i < num_hp_parts; i++) {
  hp_max[i] = calc_HP(str_max, has_trait(PF_TOUGH));
  hp_cur[i] = hp_max[i];
 }
 if (has_trait(PF_HARDCORE)) {
  for (int i = 0; i < num_hp_parts; i++) {
   hp_max[i] = int(hp_max[i] * .25);
   hp_cur[i] = hp_max[i];
  }
 } if (has_trait(PF_GLASSJAW)) {
  hp_max[hp_head] = int(hp_max[hp_head] * .80);
  hp_cur[hp_head] = hp_max[hp_head];
 }
 if (has_trait(PF_SMELLY))
  scent = 800;
 if (has_trait(PF_ANDROID)) {
  bionic_id first_bio;
  do {
   first_bio = g->random_good_bionic();
  } while (bionics[first_bio]->power_cost > 10);
  add_bionic(first_bio);
  add_bionic(bionic_id(power_source_bionics[rng(0,power_source_bionics.size()-1)]));	// Power Source
  max_power_level = 10;
  power_level = 10;
 }

 if (has_trait(PF_MARTIAL_ARTS)) {
  itype_id ma_type;
  do {
   int choice = menu(false, _("Pick your style:"),
                     _("Karate"), _("Judo"), _("Aikido"), _("Tai Chi"),
                     _("Taekwondo"), NULL);
   if (choice == 1)
    ma_type = "style_karate";
   if (choice == 2)
    ma_type = "style_judo";
   if (choice == 3)
    ma_type = "style_aikido";
   if (choice == 4)
    ma_type = "style_tai_chi";
   if (choice == 5)
    ma_type = "style_taekwondo";
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn(_("Use this style?")));
  styles.push_back(ma_type);
  style_selected=ma_type;
 }

    if (has_trait(PF_MARTIAL_ARTS2)) {
  itype_id ma_type;
  do {
   int choice = menu(false, _("Pick your style:"),
                     _("Capoeira"), _("Krav Maga"), _("Muay Thai"),
                     _("Ninjutsu"), _("Zui Quan"), NULL);
   if (choice == 1)
    ma_type = "style_capoeira";
   if (choice == 2)
    ma_type = "style_krav_maga";
   if (choice == 3)
    ma_type = "style_muay_thai";
   if (choice == 4)
    ma_type = "style_ninjutsu";
   if (choice == 5)
    ma_type = "style_zui_quan";
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn(_("Use this style?")));
  styles.push_back(ma_type);
  style_selected=ma_type;
 }
 if (has_trait(PF_MARTIAL_ARTS3)) {
  itype_id ma_type;
  do {
   int choice = menu(false, _("Pick your style:"),
                     _("Tiger"), _("Crane"), _("Leopard"), _("Snake"),
                     _("Dragon"), NULL);
   if (choice == 1)
    ma_type = "style_tiger";
   if (choice == 2)
    ma_type = "style_crane";
   if (choice == 3)
    ma_type = "style_leopard";
   if (choice == 4)
    ma_type = "style_snake";
   if (choice == 5)
    ma_type = "style_dragon";
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn(_("Use this style?")));
  styles.push_back(ma_type);
  style_selected=ma_type;
 }
 if (has_trait(PF_MARTIAL_ARTS4)) {
  itype_id ma_type;
  do {
   int choice = menu(false, _("Pick your style:"),
                     _("Centipede"), _("Viper"), _("Scorpion"), _("Lizard"),
                     _("Toad"), NULL);
   if (choice == 1)
    ma_type = "style_centipede";
   if (choice == 2)
    ma_type = "style_venom_snake";
   if (choice == 3)
    ma_type = "style_scorpion";
   if (choice == 4)
    ma_type = "style_lizard";
   if (choice == 5)
    ma_type = "style_toad";
   item tmpitem = item(g->itypes[ma_type], 0);
   full_screen_popup(tmpitem.info(true).c_str());
  } while (!query_yn(_("Use this style?")));
  styles.push_back(ma_type);
  style_selected=ma_type;
 }
 ret_null = item(g->itypes["null"], 0);
 weapon = get_combat_style();
 
 
 item tmp; //gets used several times

 std::vector<std::string> prof_items = g->u.prof->items();
 for (std::vector<std::string>::const_iterator iter = prof_items.begin(); iter != prof_items.end(); ++iter)
 {
    tmp = item(item_controller->find_template(*iter), 0);
    inv.push_back(tmp);
 }

 std::vector<addiction> prof_addictions = g->u.prof->addictions();
 for (std::vector<addiction>::const_iterator iter = prof_addictions.begin(); iter != prof_addictions.end(); ++iter)
 {
     g->u.addictions.push_back(*iter);
 }

 // Grab the skills from the profession, if there are any
 profession::StartingSkillList prof_skills = g->u.prof->skills();
 for (profession::StartingSkillList::const_iterator iter = prof_skills.begin(); 
      iter != prof_skills.end(); ++iter)
 {
     assert(Skill::skill(iter->first));
     if (Skill::skill(iter->first))
     {
        g->u.boost_skill_level(iter->first, iter->second);
     }
 }

 // Those who are both near-sighted and far-sighted start with bifocal glasses.
 if (has_trait(PF_HYPEROPIC) && has_trait(PF_MYOPIC))
 {
    tmp = item(g->itypes["glasses_bifocal"], 0);
    inv.push_back(tmp);
 }
 // The near-sighted start with eyeglasses.
 else if (has_trait(PF_MYOPIC))
 {
    tmp = item(g->itypes["glasses_eye"], 0);
    inv.push_back(tmp);
 }
 // The far-sighted start with reading glasses.
 else if (has_trait(PF_HYPEROPIC))
 {
    tmp = item(g->itypes["glasses_reading"], 0);
    inv.push_back(tmp);
 }

// Likewise, the asthmatic start with their medication.
 if (has_trait(PF_ASTHMA)) {
  tmp = item(g->itypes["inhaler"], 0);
  inv.push_back(tmp);
 }
// Basic starter gear, added independently of profession.
 tmp = item(g->itypes["pockknife"], 0);
  inv.push_back(tmp);
 tmp = item(g->itypes["matches"], 0);
  inv.push_back(tmp);
// make sure we have no mutations
 for (int i = 0; i < PF_MAX2; i++)
  if (!has_base_trait(i))
	my_mutations[i] = false;
	
	// Equip any armor from our inventory. If we are unable to wear some of it due to encumberance, it will silently fail.
    std::vector<item*> tmp_inv;
    inv.dump(tmp_inv);
    
    for(std::vector<item*>::iterator i = tmp_inv.begin(); i != tmp_inv.end(); ++i)
    {
        if( (*i)->is_armor())
        {
            if( (*i)->has_flag("VARSIZE"))
            {
                (*i)->item_tags.insert("FIT");
            }
            // It might be more elegant to use player::wear_item, but then we have to implement our own inventory removal.
            wear(g, (*i)->invlet, false);
        }
    }

 // Ensure that persistent morale effects (e.g. Optimist) are present at the start.
 apply_persistent_morale();
 return true;
}
コード例 #30
0
void create::process_event_impl(const process_event_data & data)
{
	if (data.quit) {
		set_result(QUIT);
		return;
	}

	if (data.create) {
		if (engine_.current_level().can_launch_game()) {

			engine_.prepare_for_era_and_mods();

			if (engine_.current_level_type() == ng::level::TYPE::CAMPAIGN ||
				engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {

				std::string difficulty = engine_.select_campaign_difficulty();
				if (difficulty == "CANCEL") {
					return;
				}

				engine_.prepare_for_campaign(difficulty);
			}
			else if (engine_.current_level_type() == ng::level::TYPE::SCENARIO)
			{
				engine_.prepare_for_scenario();
			}
			else
			{
				//This means define= doesn't work for random generated scenarios
				engine_.prepare_for_other();
			}

			engine_.prepare_for_new_level();

			set_result(CREATE);
			return;
		} else {
			gui2::show_transient_message(disp_.video(), "",
				_("The level is invalid."));
		}
	}

	if (level_type_combo_.changed()) {
		init_level_type_changed(0);
	}

	if (data.load) {
		try
		{
			savegame::loadgame load(disp_,
				game_config_manager::get()->game_config(), engine_.get_state());

			if (data.filename) {
				if (!load.load_game(*data.filename, false, false, false, "", true)) {
					return ;
				}
			} else {
				if (!load.load_multiplayer_game()) {
					return ;
				}
			}

			if (load.cancel_orders())
				engine_.get_state().cancel_orders();

			engine_.prepare_for_saved_game();
			set_result(LOAD_GAME);

			return;
		}
		catch(config::error&) {
		}
	}

	if (mod_selection_ != mods_menu_.selection()) {
		mod_selection_ = mods_menu_.selection();
		engine_.set_current_mod_index(mod_selection_);
		set_description(engine_.current_extra(ng::create_engine::MOD).description);
	}

	int changed_mod = mods_menu_.last_changed();
	if (changed_mod != -1) {
		engine_.set_current_mod_index(changed_mod);
		engine_.toggle_current_mod();
		synchronize_selections();
	}

	bool era_changed = era_selection_ != eras_menu_.selection();
	era_selection_ = eras_menu_.selection();

	if (era_changed) {
		engine_.set_current_era_index(era_selection_);

		set_description(engine_.current_extra(ng::create_engine::ERA).description);
		synchronize_selections();
	}

	if (filter_name_.text() != engine_.level_name_filter()) {
		engine_.apply_level_filter(filter_name_.text());
		init_level_type_changed(0);
	}

	bool level_changed = level_selection_ != levels_menu_.selection();
	level_selection_ = levels_menu_.selection();

	if (level_changed && level_selection_ >= 0) {
		init_level_changed(level_selection_);

		synchronize_selections();
	}

	if (engine_.generator_assigned() && generator_settings_.pressed()) {
		engine_.generator_user_config(disp_);

		level_changed = true;
	}

	if(engine_.generator_assigned() &&
		(level_changed || regenerate_map_.pressed())) {
		const cursor::setter cursor_setter(cursor::WAIT);
		cursor::setter cur(cursor::WAIT);

		engine_.init_generated_level_data();

		if (!engine_.current_level().data()["error_message"].empty())
			gui2::show_message(disp().video(), "map generation error",
				engine_.current_level().data()["error_message"]);

		level_changed = true;
	}

	if(level_changed) {
		std::stringstream players;
		std::stringstream map_size;

		players << _("Players: ");

		engine_.current_level().set_metadata();

		draw_level_image();

		set_description(engine_.current_level().description());

		switch (engine_.current_level_type().v) {
		case ng::level::TYPE::SCENARIO:
		case ng::level::TYPE::USER_MAP:
		case ng::level::TYPE::USER_SCENARIO:
		case ng::level::TYPE::RANDOM_MAP: {

			ng::scenario* current_scenario =
				dynamic_cast<ng::scenario*>(&engine_.current_level());

			assert(current_scenario);

			players << current_scenario->num_players();
			map_size << _("Size: ") << current_scenario->map_size();

			break;
		}
		case ng::level::TYPE::CAMPAIGN:
		case ng::level::TYPE::SP_CAMPAIGN: {
			 ng::campaign* current_campaign =
				dynamic_cast<ng::campaign*>(&engine_.current_level());

			assert(current_campaign);

			players << current_campaign->min_players();
			if (current_campaign->max_players() !=
				current_campaign->min_players()) {

				players << " to " << current_campaign->max_players();
			}

			break;
		}
		} // end switch

		map_size_label_.set_text(map_size.str());
		num_players_label_.set_text(players.str());

		launch_game_.enable(engine_.current_level().can_launch_game());
		generator_settings_.enable(engine_.generator_assigned());
		regenerate_map_.enable(engine_.generator_assigned());
	}

	if (filter_num_players_slider_.value() != engine_.player_num_filter()) {
		const int val = filter_num_players_slider_.value();
		engine_.apply_level_filter(val);
		std::stringstream ss;
		if (val == 1) {
			ss << _("Number of players: any");
		} else {
			ss << _("Number of players: ") << val;
		}
		filter_num_players_label_.set_text(ss.str());
		init_level_type_changed(0);
	}
}