コード例 #1
0
/****************************************************************
  Ask the server how much the bribe is
*****************************************************************/
static void diplomat_bribe_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_unit_by_number(diplomat_target_id)) {
    request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
                            diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #2
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/**************************************************************************
  Asks the server how much the bribe is
**************************************************************************/
static void diplomat_bribe_callback(Widget w, XtPointer client_data, 
				    XtPointer call_data)
{
  destroy_message_dialog(w);

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_unit_by_number(diplomat_target_id)) {
    request_diplomat_answer(DIPLOMAT_BRIBE, diplomat_id,
                            diplomat_target_id, 0);
  }
}
コード例 #3
0
static int diplomat_bribe_yes_callback(struct widget *pWidget)
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    if (NULL != game_unit_by_number(pBribe_Dlg->diplomat_id)
        && NULL != game_unit_by_number(pBribe_Dlg->diplomat_target_id)) {
      request_diplomat_action(DIPLOMAT_BRIBE, pBribe_Dlg->diplomat_id,
                              pBribe_Dlg->diplomat_target_id, 0);
    }
    popdown_bribe_dialog();
  }  
  return -1;
}
コード例 #4
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/*************************************************************************
  Callback from diplomat/spy dialog for "keep moving".
  (This should only occur when entering the tile of an allied unit.)
**************************************************************************/
static void diplomat_keep_moving_unit_callback(GtkWidget *w, gpointer data)
{
    struct unit *punit;
    struct unit *tunit;

    if ((punit = game_unit_by_number(diplomat_id))
            && (tunit = game_unit_by_number(diplomat_target_id[ATK_UNIT]))
            && !same_pos(unit_tile(punit), unit_tile(tunit))) {
        request_diplomat_action(DIPLOMAT_MOVE, diplomat_id,
                                diplomat_target_id[ATK_UNIT], ATK_UNIT);
    }
    gtk_widget_destroy(diplomat_dialog);
}
コード例 #5
0
ファイル: aiguard.c プロジェクト: jheusala/freeciv
/**************************************************************************
  Check whether the assignment of a guard is still sane, and fix and problems.
  It was once sane, but might have been destroyed or become an enemy since.
**************************************************************************/
void aiguard_update_charge(struct unit *guard)
{
  struct unit_ai *guard_data = def_ai_unit_data(guard);
  const struct unit *charge_unit = game_unit_by_number(guard_data->charge);
  const struct city *charge_city = game_city_by_number(guard_data->charge);
  const struct player *guard_owner = unit_owner(guard);
  const struct player *charge_owner = NULL;

  fc_assert_ret(BODYGUARD_NONE <= guard_data->charge);
  /* IDs always distinct */
  fc_assert_ret(charge_unit == NULL || charge_city == NULL);

  if (charge_unit) {
    charge_owner = unit_owner(charge_unit);
  } else if (charge_city) {
    charge_owner = city_owner(charge_city);
  }

  if (!charge_unit && !charge_city && 0 < guard_data->charge) {
    guard_data->charge = BODYGUARD_NONE;
    BODYGUARD_LOG(LOGLEVEL_BODYGUARD, guard, "charge was destroyed");
  }
  if (charge_owner && charge_owner != guard_owner) {
    BODYGUARD_LOG(LOGLEVEL_BODYGUARD, guard, "charge transferred, dismiss");
    aiguard_clear_charge(guard);
  }

  CHECK_GUARD(guard);
}
コード例 #6
0
ファイル: dialogs.c プロジェクト: zielmicha/freeciv-mirror
/**************************************************************************
  User requested closing of pillage dialog.
**************************************************************************/
static void pillage_callback(Widget w, XtPointer client_data, 
			     XtPointer call_data)
{
  if (!is_showing_pillage_dialog) {
    destroy_message_dialog (w);
    return;
  }

  if (client_data) {
    struct unit *punit = game_unit_by_number(unit_to_use_to_pillage);
    if (punit) {
      struct act_tgt target;
      int what = XTPOINTER_TO_INT(client_data);

      if (what >= S_LAST + game.control.num_base_types) {
        target.type = ATT_ROAD;
        target.obj.road = what - S_LAST - game.control.num_base_types;
      } else if (what >= S_LAST) {
        target.type = ATT_BASE;
        target.obj.base = what - S_LAST;
      } else {
        target.type = ATT_SPECIAL;
        target.obj.spe = what;
      }

      request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE,
                                         &target);
    }
  }

  destroy_message_dialog (w);
  is_showing_pillage_dialog = FALSE;
}
コード例 #7
0
ファイル: aiguard.c プロジェクト: jheusala/freeciv
/**************************************************************************
  Do sanity checks on a guard, reporting error messages to the log
  if necessary.

  Inconsistent references do not always indicate an error, because units
  can change owners (for example, because of civil war) outside the control
  the the AI code.
**************************************************************************/
void aiguard_check_guard(const struct unit *guard)
{
  struct unit_ai *guard_data = def_ai_unit_data(guard);
  const struct unit *charge_unit = game_unit_by_number(guard_data->charge);
  const struct city *charge_city = game_city_by_number(guard_data->charge);
  const struct player *guard_owner = unit_owner(guard);
  const struct player *charge_owner = NULL;
  struct unit_ai *charge_data = NULL;

  fc_assert_ret(BODYGUARD_NONE <= guard_data->charge);
  /* IDs always distinct */
  fc_assert_ret(charge_unit == NULL || charge_city == NULL);

  if (charge_unit) {
    charge_owner = unit_owner(charge_unit);
    charge_data = def_ai_unit_data(charge_unit);
  } else if (charge_city) {
    charge_owner = city_owner(charge_city);
  }

  if (charge_unit && charge_data->bodyguard != guard->id) {
    BODYGUARD_LOG(LOG_DEBUG, guard, "inconsistent guard references");
  } else if (!charge_unit && !charge_city && 0 < guard_data->charge) {
    BODYGUARD_LOG(LOG_DEBUG, guard, "dangling guard reference");
  }
  if (charge_owner && pplayers_at_war(charge_owner, guard_owner)) {
    /* Probably due to civil war */
    BODYGUARD_LOG(LOG_DEBUG, guard, "enemy charge");
  } else if (charge_owner && charge_owner != guard_owner) {
    /* Probably sold a city with its supported units. */
    BODYGUARD_LOG(LOG_DEBUG, guard, "foreign charge");
  }
}
コード例 #8
0
/****************************************************************
  User selected poisoning from choice dialog
*****************************************************************/
static void spy_poison_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(SPY_POISON, diplomat_id, diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #9
0
/****************************************************************
 Requests up-to-date list of improvements, the return of
 which will trigger the popup_sabotage_dialog() function.
*****************************************************************/
static void spy_request_sabotage_list(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #10
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/****************************************************************
...  Ask the server how much the revolt is going to cost us
*****************************************************************/
static void diplomat_incite_callback(GtkWidget *w, gpointer data)
{
    if (NULL != game_unit_by_number(diplomat_id)
            && NULL != game_city_by_number(diplomat_target_id[ATK_CITY])) {
        request_diplomat_answer(DIPLOMAT_INCITE, diplomat_id,
                                diplomat_target_id[ATK_CITY], 0);
    }
    gtk_widget_destroy(diplomat_dialog);
}
コード例 #11
0
/****************************************************************
  User selected stealing from choice dialog
*****************************************************************/
static void diplomat_steal_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_STEAL, diplomat_id,
                            diplomat_target_id, A_UNSET);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #12
0
/****************************************************************
  User selected embassy establishing from choice dialog
*****************************************************************/
static void diplomat_embassy_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_EMBASSY, diplomat_id,
                            diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #13
0
/****************************************************************
  User selected investigating from choice dialog
*****************************************************************/
static void diplomat_investigate_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_city_by_number(diplomat_target_id)
      && NULL != game_unit_by_number(diplomat_id)) {
    request_diplomat_action(DIPLOMAT_INVESTIGATE, diplomat_id,
                            diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #14
0
/****************************************************************
  User selected sabotaging from choice dialog
*****************************************************************/
static void diplomat_sabotage_callback(GtkWidget *w, gpointer data)
{
  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, B_LAST + 1);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #15
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/**************************************************************************
  Callback from diplomat/spy dialog for "keep moving".
  (This should only occur when entering the tile of an allied unit..)
**************************************************************************/
static void diplomat_keep_moving_callback_unit(Widget w,
                                               XtPointer client_data,
                                               XtPointer call_data)
{
  struct unit *punit;
  struct unit *tunit;

  destroy_message_dialog(w);
  diplomat_dialog = NULL;

  if ((punit = game_unit_by_number(diplomat_id))
      && (tunit = game_unit_by_number(diplomat_target_id))
      && !same_pos(unit_tile(punit), unit_tile(tunit))) {
    request_diplomat_action(DIPLOMAT_MOVE, diplomat_id,
                            diplomat_target_id, ATK_UNIT);
  }
  process_diplomat_arrival(NULL, 0);
}
コード例 #16
0
/****************************************************************
  User responded to steal advances dialog
*****************************************************************/
static void spy_advances_response(GtkWidget *w, gint response, gpointer data)
{
  if (response == GTK_RESPONSE_ACCEPT && steal_advance > 0) {
    if (NULL != game_unit_by_number(diplomat_id)
        && NULL != game_city_by_number(diplomat_target_id)) {
      request_diplomat_action(DIPLOMAT_STEAL, diplomat_id,
                              diplomat_target_id, steal_advance);
    }
  }
  gtk_widget_destroy(spy_tech_shell);
  spy_tech_shell = NULL;
}
コード例 #17
0
/****************************************************************
 Requests up-to-date list of improvements, the return of
 which will trigger the popup_sabotage_dialog() function.
*****************************************************************/
static int spy_sabotage_request(struct widget *pWidget)
{
  if (NULL != game_unit_by_number(pDiplomat_Dlg->diplomat_id)
      && NULL != game_city_by_number(pDiplomat_Dlg->diplomat_target_id)) {
    request_diplomat_answer(DIPLOMAT_SABOTAGE, pDiplomat_Dlg->diplomat_id,
                            pDiplomat_Dlg->diplomat_target_id, 0);
  }

  popdown_diplomat_dialog();
  
  return -1;
}
コード例 #18
0
/****************************************************************
  User has responded to spy's sabotage building dialog
*****************************************************************/
static void spy_improvements_response(GtkWidget *w, gint response, gpointer data)
{
  if (response == GTK_RESPONSE_ACCEPT && sabotage_improvement > -2) {
    if (NULL != game_unit_by_number(diplomat_id)
        && NULL != game_city_by_number(diplomat_target_id)) {
      request_diplomat_action(DIPLOMAT_SABOTAGE, diplomat_id,
                              diplomat_target_id, sabotage_improvement + 1);
    }
  }
  gtk_widget_destroy(spy_sabotage_shell);
  spy_sabotage_shell = NULL;
}
コード例 #19
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/**************************************************************************
  Requests up-to-date list of improvements, the return of
  which will trigger the popup_sabotage_dialog() function.
**************************************************************************/
static void spy_request_sabotage_list(Widget w, XtPointer client_data,
				      XtPointer call_data)
{
  destroy_message_dialog(w);
  diplomat_dialog = NULL;

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_answer(DIPLOMAT_SABOTAGE, diplomat_id,
			    diplomat_target_id, 0);
  }
}
コード例 #20
0
/****************************************************************
...
*****************************************************************/
static int spy_poison_callback( struct widget *pWidget )
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    if (NULL != game_unit_by_number(pDiplomat_Dlg->diplomat_id)
        && NULL != game_city_by_number(pDiplomat_Dlg->diplomat_target_id)) {
      request_diplomat_action(SPY_POISON, pDiplomat_Dlg->diplomat_id,
                              pDiplomat_Dlg->diplomat_target_id, 0);
    }
  
    popdown_diplomat_dialog();
  }
  return -1;
}
コード例 #21
0
/****************************************************************
...
*****************************************************************/
static int diplomat_steal_callback(struct widget *pWidget)
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    if (NULL != game_unit_by_number(pDiplomat_Dlg->diplomat_id)
        && NULL != game_city_by_number(pDiplomat_Dlg->diplomat_target_id)) {
      request_diplomat_action(DIPLOMAT_STEAL, pDiplomat_Dlg->diplomat_id,
                              pDiplomat_Dlg->diplomat_target_id, A_UNSET);
    }
    
    popdown_diplomat_dialog();  
  }
  return -1;
}
コード例 #22
0
/****************************************************************
...  Ask the server how much the revolt is going to cost us
*****************************************************************/
static int diplomat_incite_callback(struct widget *pWidget)
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    if (NULL != game_unit_by_number(pDiplomat_Dlg->diplomat_id)
        && NULL != game_city_by_number(pDiplomat_Dlg->diplomat_target_id)) {
      request_diplomat_answer(DIPLOMAT_INCITE, pDiplomat_Dlg->diplomat_id,
                              pDiplomat_Dlg->diplomat_target_id, 0);
    }
    
    popdown_diplomat_dialog();
  }  
  return -1;
}
コード例 #23
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/****************************************************************
...
*****************************************************************/
static void spy_poison_callback(Widget w, XtPointer client_data, 
				XtPointer call_data)
{
  destroy_message_dialog(w);
  diplomat_dialog = NULL;

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(SPY_POISON, diplomat_id, diplomat_target_id, 0);
  }

  process_diplomat_arrival(NULL, 0);
}
コード例 #24
0
/****************************************************************
  Callback from diplomat/spy dialog for "keep moving".
  (This should only occur when entering allied city.)
*****************************************************************/
static void diplomat_keep_moving_callback(GtkWidget *w, gpointer data)
{
  struct unit *punit;
  struct city *pcity;

  if ((punit = game_unit_by_number(diplomat_id))
      && (pcity = game_city_by_number(diplomat_target_id))
      && !same_pos(unit_tile(punit), city_tile(pcity))) {
    request_diplomat_action(DIPLOMAT_MOVE, diplomat_id,
                            diplomat_target_id, 0);
  }
  gtk_widget_destroy(diplomat_dialog);
}
コード例 #25
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/****************************************************************
...
*****************************************************************/
static void diplomat_steal_callback(Widget w, XtPointer client_data, 
				    XtPointer call_data)
{
  destroy_message_dialog(w);
  diplomat_dialog = NULL;

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_STEAL, diplomat_id,
			    diplomat_target_id, A_UNSET);
  }

  process_diplomat_arrival(NULL, 0);
}
コード例 #26
0
/****************************************************************
  Fills the buf with proper text which should be displayed on 
  the helpbuild wonder button.
*****************************************************************/
static void get_help_build_wonder_button_label(char* buf, int bufsize,
                                               bool* help_build_possible)
{
  struct city* destcity = game_city_by_number(caravan_city_id);
  struct unit* caravan = game_unit_by_number(caravan_unit_id);
  
  if (destcity && caravan
      && unit_can_help_build_wonder(caravan, destcity)) {
    fc_snprintf(buf, bufsize, _("Help build _Wonder (%d remaining)"),
                impr_build_shield_cost(destcity->production.value.building)
                - destcity->shield_stock);
    *help_build_possible = TRUE;
  } else {
    fc_snprintf(buf, bufsize, _("Help build _Wonder"));
    *help_build_possible = FALSE;
  }
}
コード例 #27
0
/****************************************************************
  Callback from diplomat/spy dialog for "keep moving".
  (This should only occur when entering allied city.)
*****************************************************************/
static int diplomat_keep_moving_callback(struct widget *pWidget)
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    struct unit *punit;
    struct city *pcity;

    if ((punit = game_unit_by_number(pDiplomat_Dlg->diplomat_id))
        && (pcity = game_city_by_number(pDiplomat_Dlg->diplomat_target_id))
        && !same_pos(unit_tile(punit), city_tile(pcity))) {
      request_diplomat_action(DIPLOMAT_MOVE, pDiplomat_Dlg->diplomat_id,
                              pDiplomat_Dlg->diplomat_target_id, 0);
    }
    
    popdown_diplomat_dialog();  
  }
  return -1;
}
コード例 #28
0
ファイル: aiguard.c プロジェクト: jheusala/freeciv
/**************************************************************************
  Remove the assignment of a charge to a guard.

  Assumes that a unit can have at most one guard.
**************************************************************************/
void aiguard_clear_charge(struct unit *guard)
{
  struct unit_ai *guard_data = def_ai_unit_data(guard);
  struct unit *charge_unit = game_unit_by_number(guard_data->charge);
  struct city *charge_city = game_city_by_number(guard_data->charge);

  /* IDs always distinct */
  fc_assert_ret(charge_unit == NULL || charge_city == NULL);

  if (charge_unit) {
    BODYGUARD_LOG(LOGLEVEL_BODYGUARD, guard, "unassigned (unit)");
    def_ai_unit_data(charge_unit)->bodyguard = BODYGUARD_NONE;
  } else if (charge_city) {
    BODYGUARD_LOG(LOGLEVEL_BODYGUARD, guard, "unassigned (city)");
  }
  /* else not assigned or charge was destroyed */
  guard_data->charge = BODYGUARD_NONE;

  CHECK_GUARD(guard);
}
コード例 #29
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/****************************************************************
...
*****************************************************************/
static void spy_sabotage_callback(Widget w, XtPointer client_data, 
				  XtPointer call_data)
{  
  XtDestroyWidget(spy_sabotage_shell);
  spy_sabotage_shell = 0l;
  
  if(!sabotage_improvement){
    log_error("Bug in spy sabotage code");
    process_diplomat_arrival(NULL, 0);
    return;
  }

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_SABOTAGE, diplomat_id,
                            diplomat_target_id, sabotage_improvement + 1);
  }

  process_diplomat_arrival(NULL, 0);
}
コード例 #30
0
ファイル: diplomat_dialog.c プロジェクト: valisc/freeciv
/****************************************************************
...
*****************************************************************/
static void spy_steal_callback(Widget w, XtPointer client_data, 
			       XtPointer call_data)
{  
  XtDestroyWidget(spy_tech_shell);
  spy_tech_shell = 0l;
  
  if(!steal_advance){
    log_error("Bug in spy steal tech code");
    process_diplomat_arrival(NULL, 0);
    return;
  }

  if (NULL != game_unit_by_number(diplomat_id)
      && NULL != game_city_by_number(diplomat_target_id)) {
    request_diplomat_action(DIPLOMAT_STEAL, diplomat_id,
                            diplomat_target_id, steal_advance);
  }

  process_diplomat_arrival(NULL, 0);
}