/************************************************************************** For a string which _has_ intl marking (caller should check beforehand) returns gettext result of string inside marking. Below buf is an internal buffer which is never free'd. **************************************************************************/ static const char *convert_intl_marking(const char *str) { static struct astring buf = ASTRING_INIT; int len = strlen(str); fc_assert_ret_val(len >= 5, str); astr_set(&buf, "%s", str + 3); *((char *) &astr_str(&buf)[len - 5]) = '\0'; return Q_(astr_str(&buf)); }
/* * astr_not_empty_char * * Make sure the astr string is not empty (or NULL), use the specified single character. * * Parameter: The astr instance to be edited * Parameter: The character to use as the sole character if necessary * Returns: Pointer to the astr instance */ astr *astr_not_empty_char(astr *as, const char sole) { char sole_str[2] = {' ', '\0'}; if (as != NULL) { if (as->string == NULL || as->length <= 0) { sole_str[0] = sole; as = astr_set(as, sole_str); } astr_update(as); } return as; }
void test_not_empty_char(void) { astr *as; char *empty = ""; char space = ' '; char bang = '!'; char *space_str = " "; char *bang_str = "!"; as = astr_create(lower); aut_assert("1 test creation", strcmp(as->string, lower) == 0); as = astr_not_empty_char(as, bang); aut_assert("2 test not empty", strcmp(as->string, lower) == 0); as = astr_set(as, empty); as = astr_not_empty_char(as, space); aut_assert("3 test empty", strcmp(as->string, space_str) == 0); as = astr_set(as, empty); as = astr_not_empty_char(as, bang); aut_assert("4 test empty", strcmp(as->string, bang_str) == 0); }
void test_not_empty(void) { astr *as; char *empty = ""; char *space_str = " "; as = astr_create(lower); aut_assert("1 test creation", strcmp(as->string, lower) == 0); as = astr_not_empty(as); aut_assert("2 test not empty", strcmp(as->string, lower) == 0); as = astr_set(as, empty); as = astr_not_empty(as); aut_assert("3 test empty", strcmp(as->string, space_str) == 0); }
/* * afile_process_lines * * Process all lines from a file. * * Read lines from a file and call the specified function to process each line. * * We have to use an intermediate buffer to read the bytes of the file into. * It is not possible to know the length of the strings being read, so the * intermediate buffer is allocated to be the size of the file buffer. This * is much larger than necessary. There is room here for adjustment. Perhaps * 1/4th the size, or some other fraction, can be used. * * Parameter: The afile instance, opened * Parameter: A pointer to a function that will process one line of text * Returns: The number of lines processed */ int afile_process_lines(afile *af, int (*process)(astr *as)) { int result = 0; int line_count = 0; char *buffer = NULL; astr *work = NULL; if (af != NULL && af->file != NULL && process != NULL) { buffer = (char *)calloc(af->buffer_size, 1); while (fgets(buffer, af->buffer_size, af->file)) { work = astr_set(work, buffer); line_count++; process(work); } } return line_count; }
/**************************************************************** Popups the diplomat dialog *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; struct astring text = ASTRING_INIT; diplomat_id=punit->id; if((pcity=tile_city(dest_tile))){ /* Spy/Diplomat acting against a city */ diplomat_target_id=pcity->id; astr_set(&text, _("Your %s has arrived at %s.\nWhat is your command?"), unit_name_translation(punit), city_name(pcity)); if (!unit_has_type_flag(punit, UTYF_SPY)) { diplomat_dialog = popup_message_dialog(toplevel, "diplomatdialog", astr_str(&text), diplomat_embassy_callback, 0, 1, diplomat_investigate_callback, 0, 1, spy_poison_callback, 0, 1, diplomat_sabotage_callback, 0, 1, diplomat_steal_callback, 0, 1, diplomat_incite_callback, 0, 1, diplomat_keep_moving_callback_city, 0, 1, diplomat_cancel_callback, 0, 0, NULL); } else { diplomat_dialog = popup_message_dialog(toplevel, "spydialog", astr_str(&text), diplomat_embassy_callback, 0, 1, diplomat_investigate_callback, 0, 1, spy_poison_callback, 0, 1, spy_request_sabotage_list, 0, 1, spy_steal_popup, 0, 1, diplomat_incite_callback, 0, 1, diplomat_keep_moving_callback_city, 0, 1, diplomat_cancel_callback, 0, 0, NULL); } if(!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button0"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button1"), FALSE); } if(!diplomat_can_do_action(punit, SPY_POISON, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button2"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button3"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button4"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button5"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button6"), FALSE); } } else { if ((ptunit = unit_list_get(dest_tile->units, 0))) { /* Spy/Diplomat acting against a unit */ Widget shl; astr_set(&text, _("Your %s is waiting for your command."), unit_name_translation(punit)); diplomat_target_id=ptunit->id; shl=popup_message_dialog(toplevel, "spybribedialog", astr_str(&text), diplomat_bribe_callback, 0, 0, spy_sabotage_unit_callback, 0, 0, diplomat_keep_moving_callback_unit, 0, 1, diplomat_cancel_callback, 0, 0, NULL); if(!diplomat_can_do_action(punit, DIPLOMAT_BRIBE, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button0"), FALSE); if(!diplomat_can_do_action(punit, SPY_SABOTAGE_UNIT, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button1"), FALSE); if(!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button2"), FALSE); } } astr_free(&text); }
/**************************************************************** ... *****************************************************************/ static int create_improvements_list(struct player *pplayer, struct city *pcity, bool make_modal) { Widget spy_sabotage_form; Widget close_command; Dimension width1, width2; int j; static const char *improvements_can_sabotage[B_LAST+1]; spy_sabotage_shell = I_T(XtVaCreatePopupShell("spysabotageimprovementspopup", (make_modal ? transientShellWidgetClass : topLevelShellWidgetClass), toplevel, NULL)); spy_sabotage_form = XtVaCreateManagedWidget("spysabotageimprovementsform", formWidgetClass, spy_sabotage_shell, NULL); spy_improvements_list_label = I_L(XtVaCreateManagedWidget("spysabotageimprovementslistlabel", labelWidgetClass, spy_sabotage_form, NULL)); spy_improvements_list = XtVaCreateManagedWidget("spysabotageimprovementslist", listWidgetClass, spy_sabotage_form, NULL); close_command = I_L(XtVaCreateManagedWidget("spysabotageimprovementsclosecommand", commandWidgetClass, spy_sabotage_form, NULL)); spy_sabotage_command = I_L(XtVaCreateManagedWidget("spysabotageimprovementscommand", commandWidgetClass, spy_sabotage_form, XtNsensitive, False, NULL)); XtAddCallback(spy_improvements_list, XtNcallback, spy_select_improvement_callback, NULL); XtAddCallback(close_command, XtNcallback, spy_close_sabotage_callback, NULL); XtAddCallback(spy_sabotage_command, XtNcallback, spy_sabotage_callback, NULL); XtRealizeWidget(spy_sabotage_shell); /* Now populate the list */ j = 0; improvements_can_sabotage[j] = _("City Production"); improvement_type[j++] = -1; city_built_iterate(pcity, pimprove) { if (pimprove->sabotage > 0) { improvements_can_sabotage[j] = city_improvement_name_translation(pcity, pimprove); improvement_type[j++] = improvement_number(pimprove); } } city_built_iterate_end; if(j > 1) { static 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))); improvements_can_sabotage[j] = astr_str(&str); improvement_type[j++] = B_LAST; } else { improvement_type[0] = B_LAST; /* fake "discretion", since must be production */ } improvements_can_sabotage[j] = NULL; XtSetSensitive(spy_sabotage_command, FALSE); XawListChange(spy_improvements_list, (String *) improvements_can_sabotage, 0, 0, 1); XtVaGetValues(spy_improvements_list, XtNwidth, &width1, NULL); XtVaGetValues(spy_improvements_list_label, XtNwidth, &width2, NULL); XtVaSetValues(spy_improvements_list, XtNwidth, MAX(width1,width2), NULL); XtVaSetValues(spy_improvements_list_label, XtNwidth, MAX(width1,width2), NULL); return j; }
/**************************************************************** ... *****************************************************************/ static int create_advances_list(struct player *pplayer, struct player *pvictim, bool make_modal) { Widget spy_tech_form; Widget close_command; Dimension width1, width2; int j; static const char *advances_can_steal[A_LAST+1]; spy_tech_shell = I_T(XtVaCreatePopupShell("spystealtechpopup", (make_modal ? transientShellWidgetClass : topLevelShellWidgetClass), toplevel, NULL)); spy_tech_form = XtVaCreateManagedWidget("spystealtechform", formWidgetClass, spy_tech_shell, NULL); spy_advances_list_label = I_L(XtVaCreateManagedWidget("spystealtechlistlabel", labelWidgetClass, spy_tech_form, NULL)); spy_advances_list = XtVaCreateManagedWidget("spystealtechlist", listWidgetClass, spy_tech_form, NULL); close_command = I_L(XtVaCreateManagedWidget("spystealtechclosecommand", commandWidgetClass, spy_tech_form, NULL)); spy_steal_command = I_L(XtVaCreateManagedWidget("spystealtechcommand", commandWidgetClass, spy_tech_form, XtNsensitive, False, NULL)); XtAddCallback(spy_advances_list, XtNcallback, spy_select_tech_callback, NULL); XtAddCallback(close_command, XtNcallback, spy_close_tech_callback, NULL); XtAddCallback(spy_steal_command, XtNcallback, spy_steal_callback, NULL); XtRealizeWidget(spy_tech_shell); /* Now populate the list */ j = 0; advances_can_steal[j] = _("NONE"); advance_type[j] = -1; if (pvictim) { /* you don't want to know what lag can do -- Syela */ 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)) { advances_can_steal[j] = advance_name_translation(advance_by_number(i)); advance_type[j++] = i; } } { static 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))); advances_can_steal[j] = astr_str(&str); advance_type[j++] = A_UNSET; } } advance_index_iterate_end; if(j == 0) j++; advances_can_steal[j] = NULL; XtSetSensitive(spy_steal_command, FALSE); XawListChange(spy_advances_list, (char **)advances_can_steal, 0, 0, 1); XtVaGetValues(spy_advances_list, XtNwidth, &width1, NULL); XtVaGetValues(spy_advances_list_label, XtNwidth, &width2, NULL); XtVaSetValues(spy_advances_list, XtNwidth, MAX(width1,width2), NULL); XtVaSetValues(spy_advances_list_label, XtNwidth, MAX(width1,width2), NULL); return j; }
/**************************************************************** Popup new diplomat dialog. *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; diplomat_id = punit->id; if ((pcity = tile_city(dest_tile))) { /* Spy/Diplomat acting against a city */ diplomat_target_id = pcity->id; astr_set(&title, /* TRANS: %s is a unit name, e.g., Spy */ _("Choose Your %s's Strategy"), unit_name_translation(punit)); astr_set(&text, _("Your %s has arrived at %s.\nWhat is your command?"), unit_name_translation(punit), city_name(pcity)); if (!unit_has_type_flag(punit, UTYF_SPY)) { shl = popup_choice_dialog(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text), _("Establish _Embassy"), diplomat_embassy_callback, NULL, _("_Investigate City"), diplomat_investigate_callback, NULL, _("_Sabotage City"), diplomat_sabotage_callback, NULL, _("Steal _Technology"), diplomat_steal_callback, NULL, _("Incite a _Revolt"), diplomat_incite_callback, NULL, _("_Keep moving"), diplomat_keep_moving_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) choice_dialog_button_set_sensitive(shl, 0, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) choice_dialog_button_set_sensitive(shl, 1, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) choice_dialog_button_set_sensitive(shl, 2, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) choice_dialog_button_set_sensitive(shl, 3, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) choice_dialog_button_set_sensitive(shl, 4, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) choice_dialog_button_set_sensitive(shl, 5, FALSE); } else { shl = popup_choice_dialog(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text), _("Establish _Embassy"), diplomat_embassy_callback, NULL, _("_Investigate City"), diplomat_investigate_callback, NULL, _("_Poison City"), spy_poison_callback, NULL, _("Industrial _Sabotage"), spy_request_sabotage_list, NULL, _("Steal _Technology"), spy_steal_popup, NULL, _("Incite a _Revolt"), diplomat_incite_callback, NULL, _("_Keep moving"), diplomat_keep_moving_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) choice_dialog_button_set_sensitive(shl, 0, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) choice_dialog_button_set_sensitive(shl, 1, FALSE); if (!diplomat_can_do_action(punit, SPY_POISON, dest_tile)) choice_dialog_button_set_sensitive(shl, 2, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) choice_dialog_button_set_sensitive(shl, 3, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) choice_dialog_button_set_sensitive(shl, 4, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) choice_dialog_button_set_sensitive(shl, 5, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) choice_dialog_button_set_sensitive(shl, 6, FALSE); } diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); } else { if ((ptunit = unit_list_get(dest_tile->units, 0))){ /* Spy/Diplomat acting against a unit */ diplomat_target_id = ptunit->id; astr_set(&text, /* TRANS: %s is a unit name, e.g., Diplomat, Spy */ _("Your %s is waiting for your command."), unit_name_translation(punit)); shl = popup_choice_dialog(GTK_WINDOW(toplevel), _("Subvert Enemy Unit"), astr_str(&text), _("_Bribe Enemy Unit"), diplomat_bribe_callback, NULL, _("_Sabotage Enemy Unit"), spy_sabotage_unit_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_BRIBE, dest_tile)) { choice_dialog_button_set_sensitive(shl, 0, FALSE); } if (!diplomat_can_do_action(punit, SPY_SABOTAGE_UNIT, dest_tile)) { choice_dialog_button_set_sensitive(shl, 1, FALSE); } diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); } } astr_free(&title); astr_free(&text); }
/**************************************************************** Creates spy's building sabotaging dialog *****************************************************************/ static void create_improvements_list(struct player *pplayer, struct city *pcity) { GtkWidget *sw, *label, *vbox, *view; GtkListStore *store; GtkCellRenderer *rend; GtkTreeViewColumn *col; GtkTreeIter it; spy_sabotage_shell = gtk_dialog_new_with_buttons(_("Sabotage Improvements"), NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Sabotage"), GTK_RESPONSE_ACCEPT, NULL); setup_dialog(spy_sabotage_shell, toplevel); gtk_window_set_position(GTK_WINDOW(spy_sabotage_shell), GTK_WIN_POS_MOUSE); gtk_dialog_set_default_response(GTK_DIALOG(spy_sabotage_shell), GTK_RESPONSE_ACCEPT); label = gtk_frame_new(_("Select Improvement to Sabotage")); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_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", _("_Improvements:"), "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 */ gtk_list_store_append(store, &it); gtk_list_store_set(store, &it, 0, _("City Production"), 1, -1, -1); city_built_iterate(pcity, pimprove) { if (pimprove->sabotage > 0) { gtk_list_store_append(store, &it); gtk_list_store_set(store, &it, 0, city_improvement_name_translation(pcity, pimprove), 1, improvement_number(pimprove), -1); } } city_built_iterate_end; gtk_list_store_append(store, &it); { 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))); gtk_list_store_set(store, &it, 0, astr_str(&str), 1, B_LAST, -1); astr_free(&str); } gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_sabotage_shell), GTK_RESPONSE_ACCEPT, FALSE); gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_shell))); g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed", G_CALLBACK(spy_improvements_callback), NULL); g_signal_connect(spy_sabotage_shell, "response", G_CALLBACK(spy_improvements_response), NULL); sabotage_improvement = -2; gtk_tree_view_focus(GTK_TREE_VIEW(view)); }
/**************************************************************** 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)); }
/**************************************************************** Popup new diplomat dialog. *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; diplomat_target_id[ATK_CITY] = -1; diplomat_target_id[ATK_UNIT] = -1; diplomat_id = punit->id; astr_set(&title, /* TRANS: %s is a unit name, e.g., Spy */ _("Choose Your %s's Strategy"), unit_name_translation(punit)); astr_set(&text, /* TRANS: %s is a unit name, e.g., Diplomat, Spy */ _("Your %s is waiting for your command."), unit_name_translation(punit)); shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text)); if ((pcity = tile_city(dest_tile))) { /* Spy/Diplomat acting against a city */ diplomat_target_id[ATK_CITY] = pcity->id; action_entry(shl, action_enabled_unit_on_city_local( ACTION_ESTABLISH_EMBASSY, punit, pcity), _("Establish _Embassy"), (GCallback)diplomat_embassy_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_INVESTIGATE_CITY, punit, pcity), _("_Investigate City"), (GCallback)diplomat_investigate_callback); action_entry(shl, action_enabled_unit_on_city_local(ACTION_SPY_POISON, punit, pcity), _("_Poison City"), (GCallback)spy_poison_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_SABOTAGE_CITY, punit, pcity), _("_Sabotage City"), (GCallback)diplomat_sabotage_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_TARGETED_SABOTAGE_CITY, punit, pcity), _("Industrial _Sabotage"), (GCallback)spy_request_sabotage_list); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_STEAL_TECH, punit, pcity), _("Steal _Technology"), (GCallback)diplomat_steal_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_TARGETED_STEAL_TECH, punit, pcity), _("Industrial espionage"), (GCallback)spy_steal_popup); action_entry(shl, action_enabled_unit_on_city_local(ACTION_SPY_INCITE_CITY, punit, pcity), _("Incite a _Revolt"), (GCallback)diplomat_incite_callback); } if ((ptunit = unit_list_get(dest_tile->units, 0))) { /* Spy/Diplomat acting against a unit */ diplomat_target_id[ATK_UNIT] = ptunit->id; action_entry(shl, action_enabled_unit_on_unit_local( ACTION_SPY_BRIBE_UNIT, punit, ptunit), _("_Bribe Enemy Unit"), (GCallback)diplomat_bribe_callback); action_entry(shl, action_enabled_unit_on_unit_local( ACTION_SPY_SABOTAGE_UNIT, punit, ptunit), _("_Sabotage Enemy Unit"), (GCallback)spy_sabotage_unit_callback); } if (diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) { if (pcity) { choice_dialog_add(shl, _("_Keep moving"), (GCallback)diplomat_keep_moving_city_callback, NULL, FALSE); } else { choice_dialog_add(shl, _("_Keep moving"), (GCallback)diplomat_keep_moving_unit_callback, NULL, FALSE); } } choice_dialog_add(shl, GTK_STOCK_CANCEL, (GCallback)diplomat_cancel_callback, NULL, FALSE); choice_dialog_end(shl); diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); astr_free(&title); astr_free(&text); }