PyObject* py_mapper_unit_list(struct unit_list* s){ if(s == NULL) return Py_BuildValue(""); int length = unit_list_size(s); int i; PyObject* list = PyList_New(length); for(i=0; i<length; i++) { struct unit* u = unit_list_get(s, i); PyObject* item = py_mapper_unit(u); PyList_SetItem(list, i, item); } return list; }
/**************************************************************** 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); }
/************************************************************************** Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ void popup_diplomat_dialog(struct unit *pUnit, struct tile *ptile) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; struct city *pCity; struct unit *pTunit; bool spy; SDL_Rect area; if (pDiplomat_Dlg) { return; } is_unit_move_blocked = TRUE; pCity = tile_city(ptile); spy = unit_has_type_flag(pUnit, F_SPY); pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = pUnit->id; pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG)); /* window */ if (pCity) { if(spy) { pStr = create_str16_from_char(_("Choose Your Spy's Strategy") , adj_font(12)); } else { pStr = create_str16_from_char(_("Choose Your Diplomat's Strategy"), adj_font(12)); } } else { pStr = create_str16_from_char(_("Subvert Enemy Unit"), adj_font(12)); } pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = diplomat_dlg_window_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_CARAVAN_DLG_WINDOW, pWindow); pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.w = MAX(area.w, adj_size(8)); area.h = MAX(area.h, adj_size(2)); /* ---------- */ if((pCity)) { /* Spy/Diplomat acting against a city */ pDiplomat_Dlg->diplomat_target_id = pCity->id; /* -------------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_EMBASSY, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Establish Embassy"), diplomat_embassy_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_INVESTIGATE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Investigate City"), diplomat_investigate_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (spy && diplomat_can_do_action(pUnit, SPY_POISON, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Poison City"), spy_poison_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_SABOTAGE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Sabotage City"), spy ? spy_sabotage_request : diplomat_sabotage_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_STEAL, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Steal Technology"), spy ? spy_steal_popup : diplomat_steal_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_INCITE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Incite a Revolt"), diplomat_incite_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_MOVE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Keep moving"), diplomat_keep_moving_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } } else { if((pTunit=unit_list_get(ptile->units, 0))){ /* Spy/Diplomat acting against a unit */ pDiplomat_Dlg->diplomat_target_id = pTunit->id; /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_BRIBE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Bribe Enemy Unit"), diplomat_bribe_callback); pBuf->data.unit = pTunit; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, SPY_SABOTAGE_UNIT, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Sabotage Enemy Unit"), spy_sabotage_unit_callback); pBuf->data.unit = pTunit; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } } } /* ---------- */ create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Cancel"), diplomat_close_callback); set_wstate(pBuf , FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_LABEL , pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* ---------- */ pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf; /* setup window size and start position */ resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h); area = pWindow->area; auto_center_on_focus_unit(); put_window_near_map_tile(pWindow, pWindow->size.w, pWindow->size.h, pUnit->tile); /* setup widget size and start position */ pBuf = pWindow->prev; setup_vertical_widgets_position(1, area.x, area.y + 1, area.w, 0, pDiplomat_Dlg->pdialog->pBeginWidgetList, pBuf); /* --------------------- */ /* redraw */ redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, 0); widget_flush(pWindow); }
/**************************************************************** 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); }
/**************************************************************** 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); }