/**************************************************************************** Give technologies to players with EFT_TECH_PARASITE (traditionally from the Great Library). ****************************************************************************/ void do_tech_parasite_effect(struct player *pplayer) { int mod; struct effect_list *plist = effect_list_new(); /* Note that two EFT_TECH_PARASITE effects will combine into a single, * much worse effect. */ if ((mod = get_player_bonus_effects(plist, pplayer, EFT_TECH_PARASITE)) > 0) { char buf[512]; buf[0] = '\0'; effect_list_iterate(plist, peffect) { if (buf[0] != '\0') { sz_strlcat(buf, ", "); } get_effect_req_text(peffect, buf, sizeof(buf)); } effect_list_iterate_end; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(pplayer, i) && player_invention_state(pplayer, i) != TECH_KNOWN) { int num_players = 0; players_iterate(aplayer) { if (player_invention_state(aplayer, i) == TECH_KNOWN) { num_players++; } } players_iterate_end; if (num_players >= mod) { notify_player(pplayer, NULL, E_TECH_GAIN, FTC_SERVER_INFO, NULL, _("%s acquired from %s!"), advance_name_for_player(pplayer, i), buf); notify_embassies(pplayer, NULL, NULL, E_TECH_GAIN, FTC_SERVER_INFO, NULL, _("The %s have acquired %s from %s."), nation_plural_for_player(pplayer), advance_name_for_player(pplayer, i), buf); do_free_cost(pplayer, i); found_new_tech(pplayer, i, FALSE, TRUE); script_signal_emit("tech_researched", 3, API_TYPE_TECH_TYPE, advance_by_number(i), API_TYPE_PLAYER, pplayer, API_TYPE_STRING, "stolen"); break; } } } advance_index_iterate_end;
/**************************************************************** Create spy's tech stealing dialog *****************************************************************/ static void create_advances_list(struct player *pplayer, struct player *pvictim) { GtkWidget *sw, *label, *vbox, *view; GtkListStore *store; GtkCellRenderer *rend; GtkTreeViewColumn *col; spy_tech_shell = gtk_dialog_new_with_buttons(_("Steal Technology"), NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Steal"), GTK_RESPONSE_ACCEPT, NULL); setup_dialog(spy_tech_shell, toplevel); gtk_window_set_position(GTK_WINDOW(spy_tech_shell), GTK_WIN_POS_MOUSE); gtk_dialog_set_default_response(GTK_DIALOG(spy_tech_shell), GTK_RESPONSE_ACCEPT); label = gtk_frame_new(_("Select Advance to Steal")); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell))), label); vbox = gtk_vbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(label), vbox); store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); rend = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE, "mnemonic-widget", view, "label", _("_Advances:"), "xalign", 0.0, "yalign", 0.5, NULL); gtk_container_add(GTK_CONTAINER(vbox), label); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(sw), view); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_widget_set_size_request(sw, -1, 200); gtk_container_add(GTK_CONTAINER(vbox), sw); /* Now populate the list */ if (pvictim) { /* you don't want to know what lag can do -- Syela */ GtkTreeIter it; GValue value = { 0, }; advance_index_iterate(A_FIRST, i) { if(player_invention_state(pvictim, i)==TECH_KNOWN && (player_invention_state(pplayer, i)==TECH_UNKNOWN || player_invention_state(pplayer, i)==TECH_PREREQS_KNOWN)) { gtk_list_store_append(store, &it); g_value_init(&value, G_TYPE_STRING); g_value_set_static_string(&value, advance_name_for_player(client.conn.playing, i)); gtk_list_store_set_value(store, &it, 0, &value); g_value_unset(&value); gtk_list_store_set(store, &it, 1, i, -1); } } advance_index_iterate_end; gtk_list_store_append(store, &it); g_value_init(&value, G_TYPE_STRING); { struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); g_value_set_string(&value, astr_str(&str)); astr_free(&str); } gtk_list_store_set_value(store, &it, 0, &value); g_value_unset(&value); gtk_list_store_set(store, &it, 1, A_UNSET, -1); } gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_tech_shell), GTK_RESPONSE_ACCEPT, FALSE); gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell))); g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed", G_CALLBACK(spy_advances_callback), NULL); g_signal_connect(spy_tech_shell, "response", G_CALLBACK(spy_advances_response), NULL); steal_advance = 0; gtk_tree_view_focus(GTK_TREE_VIEW(view)); }
/************************************************************************** Slot for selecting player/nation **************************************************************************/ void plr_widget::nation_selected(const QItemSelection &sl, const QItemSelection &ds) { QModelIndex index; QVariant qvar; QModelIndexList indexes = sl.indexes(); struct city *pcity; const struct player_diplstate *state; struct player_research *research; char tbuf[256]; QString res; QString sp = " "; QString nl = "<br>"; struct player *pplayer; int a , b; bool added; bool entry_exist = false; struct player *me; Tech_type_id tech_id; other_player = NULL; intel_str.clear(); tech_str.clear(); ally_str.clear(); if (indexes.isEmpty()) { plr->update_report(); return; } index = indexes.at(0); qvar = index.data(Qt::UserRole); pplayer = reinterpret_cast<player *>(qvar.value<void *>()); other_player = pplayer; if (pplayer->is_alive == false) { plr->update_report(); return; } pcity = player_capital(pplayer); research = player_research_get(pplayer); switch (research->researching) { case A_UNKNOWN: res = _("(Unknown)"); break; case A_UNSET: res = _("(none)"); break; default: res = QString(advance_name_researching(pplayer)) + sp + "(" + QString::number(research->bulbs_researched) + "/" + QString::number(total_bulbs_required(pplayer)) + ")"; break; } /** Formatting rich text */ intel_str = QString("<table><tr><td><b>") + _("Nation") + QString("</b></td><td>") + QString(nation_adjective_for_player(pplayer)) + QString("</td><tr><td><b>") + N_("Ruler:") + QString("</b></td><td>") + QString(ruler_title_for_player(pplayer, tbuf, sizeof(tbuf))) + QString("</td></tr><tr><td><b>") + N_("Government:") + QString("</b></td><td>") + QString(government_name_for_player(pplayer)) + QString("</td></tr><tr><td><b>") + N_("Capital:") + QString("</b></td><td>") + QString(((!pcity) ? _("(unknown)") : city_name(pcity))) + QString("</td></tr><tr><td><b>") + N_("Gold:") + QString("</b></td><td>") + QString::number(pplayer->economic.gold) + QString("</td></tr><tr><td><b>") + N_("Tax:") + QString("</b></td><td>") + QString::number(pplayer->economic.tax) + QString("%</td></tr><tr><td><b>") + N_("Science:") + QString("</b></td><td>") + QString::number(pplayer->economic.science) + QString("%</td></tr><tr><td><b>") + N_("Luxury:") + QString("</b></td><td>") + QString::number(pplayer->economic.luxury) + QString("%</td></tr><tr><td><b>") + N_("Researching:") + QString("</b></td><td>") + res + QString("</td></table>"); for (int i = 0; i < static_cast<int>(DS_LAST); i++) { added = false; if (entry_exist) { ally_str += "<br>"; } entry_exist = false; players_iterate_alive(other) { if (other == pplayer) { continue; } state = player_diplstate_get(pplayer, other); if (static_cast<int>(state->type) == i) { if (added == false) { ally_str = ally_str + QString("<b>") + QString(diplstate_type_translated_name( static_cast<diplstate_type>(i))) + ": " + QString("</b>") + nl; added = true; } ally_str = ally_str + nation_plural_for_player(other) + ", "; entry_exist = true; } } players_iterate_alive_end; if (entry_exist) { ally_str.replace(ally_str.lastIndexOf(","), 1, "."); } } me = client_player(); if ((player_has_embassy(me, pplayer) || client_is_global_observer()) && me != pplayer) { a = 0; b = 0; techs_known = QString("<b>") + _("Techs unknown by") + sp + QString(nation_adjective_for_player(pplayer)) + sp + QString(_("nation")) + QString("</b> :"); techs_unknown = QString("<b>") + _("Techs unkown by you") + sp + QString("</b> :"); advance_iterate(A_FIRST, padvance) { tech_id = advance_number(padvance); if (player_invention_state(me, tech_id) == TECH_KNOWN && (player_invention_state(pplayer, tech_id) == TECH_UNKNOWN)) { a++; techs_known = techs_known + QString("<i>") + advance_name_for_player(pplayer, tech_id) + "," + QString("</i>") + sp; } if (player_invention_state(me, tech_id) == TECH_UNKNOWN && (player_invention_state(pplayer, tech_id) == TECH_KNOWN)) { b++; techs_unknown = techs_unknown + QString("<i>") + advance_name_for_player(pplayer, tech_id) + "," + QString("</i>") + sp; } } advance_iterate_end;