Пример #1
0
int
main(int argc, char **argv)
{
	char buffer[0x1000] = { 0 };
	char user[0x100], pwd[0x100], cookie[0x100] = { 0 };

	(void)(argc);
	(void)(argv);

	if (
		!getenv("REQUEST_METHOD") ||
		strcmp(getenv("REQUEST_METHOD"), "POST") ||
		!fread(buffer, 1, sizeof(buffer) - 1, stdin)
	)
		login_page(NULL);

	chomp(buffer);

	if (parse_request(buffer, user, sizeof(user), pwd, sizeof(pwd)))
		login_page("Missing username or password");

	if (!match_user("db/members.csv", user, pwd))
		login_page("Incorrect username or password");

	if (set_cookie("db/loggedin.csv", user, cookie, sizeof(cookie)))
		login_page("Internal error, please try again");

	catalog_page(user, cookie);
	return 0;
}
void ttroop_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	max_checked_size_ = 1;

	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);

	catalog_page(window, STATUS_PAGE, false);

	hero_table_->set_callback_value_change(dialog_callback<ttroop_selection, &ttroop_selection::hero_changed>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "status", false)
		, boost::bind(
			&ttroop_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)STATUS_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "merit", false)
		, boost::bind(
			&ttroop_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)MERIT_PAGE
			, true));

	tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
	ok->set_active(false);
}
Пример #3
0
void tside_report::pre_show(CVideo& /*video*/, twindow& window)
{
	window.set_canvas_variable("border", variant("default-border"));

	window_ = &window;
	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);
	candidate_cities_ = current_team_.holden_cities();
	std::sort(candidate_cities_.begin(), candidate_cities_.end(), sort_city_status);

	tlabel* label = find_widget<tlabel>(&window, "status", false, true);
	std::stringstream status_str;
	// ing technology
	const ttechnology* ing_technology = current_team_.ing_technology();
	if (ing_technology) {
		const ttechnology& t = *ing_technology;
		status_str << tintegrate::generate_format(_("Researching technology"), "green") << ": ";
		status_str << t.name();
		status_str << "(";
		std::map<const ttechnology*, int>& halvies = current_team_.half_technologies();
		std::map<const ttechnology*, int>::const_iterator find = halvies.find(&t);
		if (find != halvies.end()) {
			status_str << find->second;
		} else {
			status_str << 0;
		}
		status_str << "/";
		int max_experience = current_team_.technology_max_experience(t);
		if (max_experience != t.max_experience()) {
			status_str << tintegrate::generate_format(max_experience, "blue");
		} else {
			status_str << max_experience;
		}
		status_str << ")";
	} else {
		status_str << tintegrate::generate_format(_("Have researched out all technology"), "green");
	}
	status_str << "\n";

	// treasure
	status_str << tintegrate::generate_format(_("Unallocated treasure"), "green") << ": ";
	status_str << current_team_.holded_treasures().size();
	status_str << "    ";

	// noble
	status_str << tintegrate::generate_format(_("Unallocated noble"), "green") << ": ";
	status_str << current_team_.unappoint_nobles().size();

	label->set_label(status_str.str());

	catalog_page(window, STATUS_PAGE, false);
	hero_table_->set_callback_value_change(dialog_callback3<tside_report, tlistbox, &tside_report::city_changed>);

	ttoggle_button* toggle = find_widget<ttoggle_button>(&window, "show", false, true);
	toggle->set_value(game_config::show_side_report);
}
Пример #4
0
void ttroop_list::pre_show(CVideo& /*video*/, twindow& window)
{
	window_ = &window;
	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	if (side_ >= 1) {
		label->set_label(_("side troop list"));
	} else {
		label->set_label(_("troop list"));
	}

	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);

	catalog_page(window, STATUS_PAGE, false);

	hero_table_->set_callback_value_change(dialog_callback<ttroop_list, &ttroop_list::city_changed>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ownership", false)
		, boost::bind(
			&ttroop_list::catalog_page
			, this
			, boost::ref(window)
			, (int)OWNERSHIP_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "status", false)
		, boost::bind(
			&ttroop_list::catalog_page
			, this
			, boost::ref(window)
			, (int)STATUS_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "merit", false)
		, boost::bind(
			&ttroop_list::catalog_page
			, this
			, boost::ref(window)
			, (int)MERIT_PAGE
			, true));

	if (candidate_troops_.empty()) {
		find_widget<tbutton>(&window, "ownership", false).set_active(false);
		find_widget<tbutton>(&window, "status", false).set_active(false);
		find_widget<tbutton>(&window, "merit", false).set_active(false);
		return;
	}
}
Пример #5
0
void trecruit::pre_show(CVideo& /*video*/, twindow& window)
{
    // int side_num = city_.side();
    std::stringstream str;

    tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

    int gold = current_team_.gold();

    tlabel* label = find_widget<tlabel>(&window, "title", false, true);
    str << _("Recruit") << "(" << gold << sngettext("unit^Gold", "Gold", gold) << ")";
    label->set_label(str.str());

    switch_type_internal(window);

    list->set_callback_value_change(dialog_callback<trecruit, &trecruit::type_selected>);

    hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);
    fresh_heros_ = city_.fresh_heros();
    std::sort(fresh_heros_.begin(), fresh_heros_.end(), compare_recruit);

    // fill data to hero_table
    catalog_page(window, ABILITY_PAGE, false);

    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "ability", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)ABILITY_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "adaptability", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)ADAPTABILITY_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "personal", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)PERSONAL_PAGE
            , true));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "relation", false)
        , boost::bind(
            &trecruit::catalog_page
            , this
            , boost::ref(window)
            , (int)RELATION_PAGE
            , true));

    // prev/next
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "prev", false)
        , boost::bind(
            &trecruit::switch_type
            , this
            , boost::ref(window)
            , false));
    connect_signal_mouse_left_click(
        find_widget<tbutton>(&window, "next", false)
        , boost::bind(
            &trecruit::switch_type
            , this
            , boost::ref(window)
            , true));

    tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
    const unit_type* t = unit_types_[type_index_];
    if (!checked_heros_.empty() && gold >= t->cost() * cost_exponent_ / 100) {
        if (!t->leader() || master()->official_ == hero_official_leader) {
            ok->set_active(true);
        } else {
            ok->set_active(false);
        }
    } else {
        ok->set_active(false);
    }
    tbutton* cancel = find_widget<tbutton>(&window, "cancel", false, true);
    cancel->set_visible(rpg_mode_? twidget::INVISIBLE: twidget::VISIBLE);

    if (rpg_mode_) {
        refresh_tooltip(window);
    }
}
Пример #6
0
void tside_list::pre_show(CVideo& /*video*/, twindow& window)
{
	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);

	catalog_page(window, STATUS_PAGE, false);

	hero_table_->set_callback_value_change(dialog_callback<tside_list, &tside_list::hero_changed>);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "status", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)STATUS_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "military", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)MILITARY_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "diplomatism", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)DIPLOMATISM_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "gold", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)GOLD_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "feature", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)FEATURE_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "artifical", false)
		, boost::bind(
			&tside_list::catalog_page
			, this
			, boost::ref(window)
			, (int)ARTIFICAL_PAGE
			, true));

	if (resources::controller->is_replaying()) {
		find_widget<tbutton>(&window, "plan", false).set_active(false);
	} else {
		connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "plan", false)
			, boost::bind(
				&tside_list::catalog_page
				, this
				, boost::ref(window)
				, (int)PLAN_PAGE
				, true));
	}
}
Пример #7
0
void thero_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	max_checked_size_ = 1;

	page_panel_ = find_widget<tstacked_widget>(&window, "page", false, true);
	lists_.push_back(find_widget<tlistbox>(&window, "ownership_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "ability_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "feature_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "adaptability_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "command_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "personal_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "relation_list", false, true));

	catalog_page(window, OWNERSHIP_PAGE, false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ownership", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)OWNERSHIP_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ability", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)ABILITY_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "feature", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)FEATURE_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "adaptability", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)ADAPTABILITY_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "command", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)COMMAND_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "personal", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)PERSONAL_PAGE
			, true));
	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "relation", false)
		, boost::bind(
			&thero_selection::catalog_page
			, this
			, boost::ref(window)
			, (int)RELATION_PAGE
			, true));

	tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
	ok->set_active(false);
}
Пример #8
0
void ttreasure_list::pre_show(CVideo& /*video*/, twindow& window)
{
    tlabel* label = find_widget<tlabel>(&window, "title", false, true);
    if (side_ >= 1) {
        label->set_label(_("Side Treasure List"));
    } else {
        label->set_label(_("Treasure List"));
    }

    hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);

    std::map<int, ownership>::iterator find_it;

    for (size_t i = 0; i < teams_.size(); i ++) {
        if (side_ != -1 && i != side_ - 1) {
            continue;
        }
        team& current_team = teams_[i];
        const std::vector<size_t>& holded_treasures = current_team.holded_treasures();
        for (std::vector<size_t>::const_iterator it = holded_treasures.begin(); it != holded_treasures.end(); ++ it) {
            size_t t = *it;
            find_it = ownerships_.find(t);
            if (find_it != ownerships_.end()) {
                find_it->second.sides_.push_back(&current_team);
            } else {
                ownership owner;
                owner.sides_.push_back(&current_team);
                ownerships_[t] = owner;
            }
        }

    }
    for (hero_map::iterator it = heros_.begin(); it != heros_.end(); ++ it) {
        hero& h = *it;
        if (side_ != -1 && h.side_ != side_ - 1) {
            continue;
        }
        if (h.treasure_ != HEROS_NO_TREASURE) {
            find_it = ownerships_.find(h.treasure_);
            if (find_it != ownerships_.end()) {
                find_it->second.heros_.push_back(&h);
            } else {
                ownership owner;
                owner.heros_.push_back(&h);
                ownerships_[h.treasure_] = owner;
            }
        }
    }
    /*
    	// hide treasure
    	const std::vector<int>& hide_treasures = resources::controller->treasures();
    	for (std::vector<int>::const_iterator it = hide_treasures.begin(); it != hide_treasures.end(); ++ it) {
    		size_t t = *it;
    		find_it = ownerships_.find(t);
    		if (find_it != ownerships_.end()) {
    			find_it->second.sides_.push_back(&teams_[0]);
    		} else {
    			ownership owner;
    			owner.sides_.push_back(&teams_[0]);
    			ownerships_[t] = owner;
    		}
    	}
    */
    catalog_page(window, OWNERSHIP_PAGE, false);

    hero_table_->set_callback_value_change(dialog_callback<ttreasure_list, &ttreasure_list::hero_changed>);
    /*
    	connect_signal_mouse_left_click(
    		find_widget<tbutton>(&window, "ownership", false)
    		, boost::bind(
    			&ttreasure_list::catalog_page
    			, this
    			, boost::ref(window)
    			, (int)OWNERSHIP_PAGE
    			, true));
    */
}
Пример #9
0
void tinterior::pre_show(CVideo& /*video*/, twindow& window)
{
	int side_num = current_team_.side();
	std::stringstream strstr;

	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	strstr.str();
	strstr << _("Interior") << "(" << city_.name() << ")";
	label->set_label(strstr.str());
	if (browse_) {
		label = find_widget<tlabel>(&window, "flag", false, true);
		strstr.str("");
		strstr << "(" << _("Browse") << ")";
		label->set_label(strstr.str());
	}

	const unit_type_data::unit_type_map& types = unit_types.types();
	for (unit_type_data::unit_type_map::const_iterator it = types.begin(); it != types.end(); ++ it) {
		if (it->second.master() == hero::number_market) {
			if (market_map_.find(&it->second) != market_map_.end()) {
				continue;
			}
			market_map_.insert(std::make_pair(&it->second, 0));
		}
		if (it->second.master() == hero::number_technology) {
			if (technology_map_.find(&it->second) != technology_map_.end()) {
				continue;
			}
			technology_map_.insert(std::make_pair(&it->second, 0));
		}
	}

	// candidate heros
	const std::vector<hero*>& freshes = city_.fresh_heros();
	std::copy(freshes.begin(), freshes.end(), std::back_inserter(fresh_heros_));
	const std::vector<hero*>& finishes = city_.finish_heros();
	std::copy(finishes.begin(), finishes.end(), std::back_inserter(fresh_heros_));
	for (std::vector<unit*>::iterator it = city_.reside_troops().begin(); it != city_.reside_troops().end(); ++ it) {
		unit& u = **it;
		hero* h = &u.master();
		fresh_heros_.push_back(h);
		if (u.second().valid()) {
			h = &u.second();
			fresh_heros_.push_back(h);
		}
		if (u.third().valid()) {
			h = &u.third();
			fresh_heros_.push_back(h);
		}
	}
	for (std::vector<unit*>::iterator it = city_.field_troops().begin(); it != city_.field_troops().end(); ++ it) {
		unit& u = **it;
		hero* h = &u.master();
		fresh_heros_.push_back(h);
		if (u.second().valid()) {
			h = &u.second();
			fresh_heros_.push_back(h);
		}
		if (u.third().valid()) {
			h = &u.third();
			fresh_heros_.push_back(h);
		}
	}

	// calculate artificals
	const std::vector<map_location>& economy_area = city_.economy_area();
	for (std::vector<map_location>::const_iterator it = economy_area.begin(); it != economy_area.end(); ++ it) {
		unit_map::const_iterator find = units_.find(*it);
		if (!find.valid()) {
			continue;
		}
		std::map<const unit_type*, int>::iterator find2 = market_map_.find(find->type());
		if (find2 != market_map_.end()) {
			find2->second ++;
			continue;
		}
		find2 = technology_map_.find(find->type());
		if (find2 != technology_map_.end()) {
			find2->second ++;
		}
	}

	std::sort(fresh_heros_.begin(), fresh_heros_.end(), compare_politics);

	// mayor
	tcontrol* control = find_widget<tcontrol>(&window, "mayor", false, true);
	hero* mayor = city_.mayor();
	if (mayor->valid()) {
		control->set_label(mayor->image());
	} else {
		control->set_label("");
	}

	tlistbox* list = find_widget<tlistbox>(&window, "type_list", false, true);

	for (std::vector<department>::const_iterator d_it = departments_.begin(); d_it != departments_.end(); ++ d_it) {
		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = d_it->image_;
		list_item_item.insert(std::make_pair("icon", list_item));

		list_item["label"] = d_it->name_;
		list_item_item.insert(std::make_pair("name", list_item));

		list_item["label"] = d_it->portrait_;
		list_item_item.insert(std::make_pair("portrait", list_item));

		strstr.str("");
		strstr << "X";
		if (d_it->type_ == department::commercial) {
			strstr << calculate_markets(d_it->exploiture_).first;
		} else if (d_it->type_ == department::technology) {
			strstr << calculate_technologies(d_it->exploiture_).first;
		}
		strstr << "=";
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("number", list_item));

		strstr.str("");
		if (d_it->type_ == department::commercial) {
			strstr << calculate_markets(d_it->exploiture_).second;
		} else if (d_it->type_ == department::technology) {
			strstr << calculate_technologies(d_it->exploiture_).second;
		}
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("total", list_item));

		strstr.str("");
		strstr << d_it->exploiture_ << "%";
		list_item["label"] = strstr.str();
		list_item_item.insert(std::make_pair("exploiture", list_item));

		list->add_row(list_item_item);
	}

	appoint_ = find_widget<tbutton>(&window, "appoint", false, true);
	appoint_->set_active(false);

	// default: 0th department
	if (mayor->valid()) {
		for (std::vector<hero*>::iterator it = fresh_heros_.begin(); it != fresh_heros_.end(); ++ it) {
			if (*it == mayor) {
				checked_hero_ = std::distance(fresh_heros_.begin(), it);
				break;
			}
		}
		VALIDATE(checked_hero_ != -1, "exist mayor(" + mayor->name() + "), but cannot find mayor in candidate hero.");
	}

	// type_selected(window);
	refresh_tooltip(window);

	list->set_callback_value_change(dialog_callback<tinterior, &tinterior::type_selected>);

	hero_table_ = find_widget<tlistbox>(&window, "hero_table", false, true);
	
	// fill data to hero_table
	catalog_page(window, ABILITY_PAGE, false);

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "ability", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)ABILITY_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "ability", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "adaptability", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)ADAPTABILITY_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "adaptability", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "relation", false)
		, boost::bind(
			&tinterior::catalog_page
			, this
			, boost::ref(window)
			, (int)RELATION_PAGE
			, true));
	if (fresh_heros_.empty()) {
		find_widget<tbutton>(&window, "relation", false).set_active(false);
	}

	connect_signal_mouse_left_click(
		*appoint_
		, boost::bind(
			&tinterior::appoint
			, this
			, boost::ref(window)));
}