Exemplo n.º 1
0
/**************************************************************************
  Creates and popups the bribe dialog
**************************************************************************/
void popup_bribe_dialog(struct unit *punit, int cost)
{
  char tbuf[128], buf[128];

  fc_snprintf(tbuf, ARRAY_SIZE(tbuf), PL_("Treasury contains %d gold.",
                                          "Treasury contains %d gold.",
                                          client_player()->economic.gold),
              client_player()->economic.gold);

  if (unit_has_type_flag(punit, F_UNBRIBABLE)) {
    popup_message_dialog(toplevel, "diplomatbribedialog",
                         _("This unit cannot be bribed!"),
                         diplomat_bribe_no_callback, 0, 0, NULL);
  } else if (cost <= client_player()->economic.gold) {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribe unit for %d gold?\n%s",
                    "Bribe unit for %d gold?\n%s", cost), cost, tbuf);
    popup_message_dialog(toplevel, "diplomatbribedialog", buf,
			 diplomat_bribe_yes_callback, 0, 0,
			 diplomat_bribe_no_callback, 0, 0,
			 NULL);
  } else {
    fc_snprintf(buf, sizeof(buf),
                /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
                PL_("Bribing the unit costs %d gold.\n%s",
                    "Bribing the unit costs %d gold.\n%s", cost), cost, tbuf);
    popup_message_dialog(toplevel, "diplomatnogolddialog", buf,
			 diplomat_bribe_no_callback, 0, 0,
			 NULL);
  }
}
Exemplo n.º 2
0
/****************************************************************
...
*****************************************************************/
static void unitdisband_callback_yes(Widget w, XtPointer client_data, XtPointer call_data)
{
  struct unit_list *punits = client_data;

  /* Is it right place for breaking? -ev */
  if (!can_client_issue_orders()) {
    unit_list_destroy(punits);
    return;
  }

  unit_list_iterate(punits, punit) {
    if (!unit_has_type_flag(punit, UTYF_UNDISBANDABLE)) {
      request_unit_disband(punit);
    }
  } unit_list_iterate_end;

  unit_list_destroy(punits);
  destroy_message_dialog(w);
}
Exemplo n.º 3
0
/****************************************************************
  Popup unit bribe dialog
*****************************************************************/
void popup_bribe_dialog(struct unit *punit, int cost)
{
  GtkWidget *shell;
  char buf[1024];

  fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
                                        "Treasury contains %d gold.",
                                        client_player()->economic.gold),
              client_player()->economic.gold);

  if (unit_has_type_flag(punit, UTYF_UNBRIBABLE)) {
    shell = popup_choice_dialog(GTK_WINDOW(toplevel), _("Ooops..."),
                                 _("This unit cannot be bribed!"),
                                 GTK_STOCK_OK, NULL, NULL, NULL);
    gtk_window_present(GTK_WINDOW(shell));
    return;
  } else if (cost <= client_player()->economic.gold) {
    shell = gtk_message_dialog_new(NULL, 0,
      GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
      /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
      PL_("Bribe unit for %d gold?\n%s",
          "Bribe unit for %d gold?\n%s", cost), cost, buf);
    gtk_window_set_title(GTK_WINDOW(shell), _("Bribe Enemy Unit"));
    setup_dialog(shell, toplevel);
  } else {
    shell = gtk_message_dialog_new(NULL, 0,
      GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
      /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
      PL_("Bribing the unit costs %d gold.\n%s",
          "Bribing the unit costs %d gold.\n%s", cost), cost, buf);
    gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
    setup_dialog(shell, toplevel);
  }
  gtk_window_present(GTK_WINDOW(shell));
  
  g_signal_connect(shell, "response", G_CALLBACK(bribe_response), NULL);
}
Exemplo n.º 4
0
/**********************************************************************
  Returns an estimate for the profit gained through attack.
  Assumes that the victim is within one day's flight
**********************************************************************/
static int dai_evaluate_tile_for_air_attack(struct unit *punit, 
                                            struct tile *dst_tile)
{
  struct unit *pdefender;
  /* unit costs in shields */
  int balanced_cost, unit_cost, victim_cost = 0;
  /* unit stats */
  int unit_attack, victim_defence;
  /* final answer */
  int profit;
  /* time spent in the air */
  int sortie_time;
#define PROB_MULTIPLIER 100 /* should unify with those in combat.c */

  if (!can_unit_attack_tile(punit, dst_tile)
      || !(pdefender = get_defender(punit, dst_tile))) {
    return 0;
  }

  /* Ok, we can attack, but is it worth it? */

  /* Cost of our unit */
  unit_cost = unit_build_shield_cost(punit);
  /* This is to say "wait, ill unit will get better!" */
  unit_cost = unit_cost * unit_type(punit)->hp / punit->hp; 

  /* Determine cost of enemy units */
  victim_cost = stack_cost(punit, pdefender);
  if (0 == victim_cost) {
    return 0;
  }

  /* Missile would die 100% so we adjust the victim_cost -- GB */
  if (uclass_has_flag(unit_class(punit), UCF_MISSILE)) {
    victim_cost -= unit_build_shield_cost(punit);
  }

  unit_attack = (int) (PROB_MULTIPLIER 
                       * unit_win_chance(punit, pdefender));

  victim_defence = PROB_MULTIPLIER - unit_attack;

  balanced_cost = build_cost_balanced(unit_type(punit));

  sortie_time = (unit_has_type_flag(punit, UTYF_ONEATTACK) ? 1 : 0);

  profit = kill_desire(victim_cost, unit_attack, unit_cost, victim_defence, 1) 
    - SHIELD_WEIGHTING + 2 * TRADE_WEIGHTING;
  if (profit > 0) {
    profit = military_amortize(unit_owner(punit), 
                               game_city_by_number(punit->homecity),
                               profit, sortie_time, balanced_cost);
    log_debug("%s at (%d, %d) is a worthy target with profit %d", 
              unit_rule_name(pdefender), TILE_XY(dst_tile), profit);
  } else {
    log_debug("%s(%d, %d): %s at (%d, %d) is unworthy with profit %d",
              unit_rule_name(punit), TILE_XY(unit_tile(punit)),
              unit_rule_name(pdefender), TILE_XY(dst_tile), profit);
    profit = 0;
  }

  return profit;
}
Exemplo n.º 5
0
// TODO: Support irrigation modes
JNIEXPORT jbyteArray JNICALL Java_net_hackcasual_freeciv_NativeHarness_getAvailableCommandsForActiveUnit
  (JNIEnv * env, jobject obj) {
	struct unit * pUnit;
	char availCommands[COM_UNIT_LAST];
	int commandCount = 0;

	pUnit = head_of_units_in_focus();

	if (pUnit) {

	    struct tile *pTile = pUnit->tile;
	    struct city *pCity = tile_city(pTile);
	    struct terrain *pTerrain = tile_terrain(pTile);
	    struct base_type *pbase;
	    struct unit_list *punits = get_units_in_focus();


		if (can_unit_build_city(pUnit)) {
			availCommands[commandCount++] = COM_BUILD_CITY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_GOTO)) {
			availCommands[commandCount++] = COM_GO_TO;
			availCommands[commandCount++] = COM_GO_TO_CITY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_SENTRY)) {
			availCommands[commandCount++] = COM_SENTRY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_FORTIFYING)) {
			availCommands[commandCount++] = COM_FORTIFY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_EXPLORE)) {
			availCommands[commandCount++] = COM_EXPLORE;
		}

		availCommands[commandCount++] = COM_DISBAND;

		if (can_unit_do_activity(pUnit, ACTIVITY_ROAD) || can_unit_do_activity(pUnit, ACTIVITY_RAILROAD)) {
			availCommands[commandCount++] = COM_ROAD;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_IRRIGATE)) {
			availCommands[commandCount++] = COM_IRRIGATION;
		}

		if (can_unit_do_autosettlers(pUnit)) {
			availCommands[commandCount++] = COM_AUTO_WORKER;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_IRRIGATE)) {
			availCommands[commandCount++] = COM_CONNECT_IRRIGATION;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_ROAD)) {
			availCommands[commandCount++] = COM_CONNECT_ROAD;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_RAILROAD)) {
			availCommands[commandCount++] = COM_CONNECT_RAILROAD;
		}

		availCommands[commandCount++] = COM_WAIT;

		if (unit_can_help_build_wonder_here(pUnit)) {
			availCommands[commandCount++] = COM_BUILD_WONDER;
		}

		if (unit_can_est_trade_route_here(pUnit)) {
			availCommands[commandCount++] = COM_TRADE_ROUTE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_MINE)) {
			availCommands[commandCount++] = COM_MINE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_TRANSFORM)) {
			availCommands[commandCount++] = COM_TRANSFORM;
		}

		pbase = get_base_by_gui_type(BASE_GUI_FORTRESS, pUnit, pUnit->tile);

		if (!pCity && pbase) {
			availCommands[commandCount++] = COM_FORTRESS;
		}

		pbase = get_base_by_gui_type(BASE_GUI_AIRBASE, pUnit, pUnit->tile);

		if (!pCity && pbase) {
			availCommands[commandCount++] = COM_AIRBASE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_POLLUTION)) {
			availCommands[commandCount++] = COM_POLLUTION;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_FALLOUT)) {
			availCommands[commandCount++] = COM_FALLOUT;
		}

		if (can_unit_paradrop(pUnit)) {
			availCommands[commandCount++] = COM_PARADROP;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_PILLAGE)) {
			availCommands[commandCount++] = COM_FALLOUT;
		}

	    if (pCity && can_unit_change_homecity(pUnit)
			&& pCity->id != pUnit->homecity) {
	    	  availCommands[commandCount++] = COM_HOMECITY;
	    }

	    if (pUnit->occupy && get_transporter_occupancy(pUnit) > 0) {
	    	availCommands[commandCount++] = COM_UNLOAD_TRANSPORT;
	    }

	    if (units_can_load(punits)) {
	    	availCommands[commandCount++] = COM_LOAD;
	    }

	    if (units_can_unload(punits)) {
	    	availCommands[commandCount++] = COM_UNLOAD;
	    }

	    if (pCity && pCity->airlift) {
	    	availCommands[commandCount++] = COM_AIRLIFT;
	    }

	    if (pCity && can_upgrade_unittype(client.conn.playing, unit_type(pUnit))) {
	    	availCommands[commandCount++] = COM_UPGRADE;
	    }

	    if (diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, pUnit->tile)) {
			availCommands[commandCount++] = COM_DIPLOMAT;
		}

	    if (unit_has_type_flag(pUnit, F_NUCLEAR)) {
	    	availCommands[commandCount++] = COM_NUKE;
	    }

	}



	jbyteArray commands;

	commands = (*env)->NewByteArray(env, commandCount);

	(*env)->SetByteArrayRegion(env, commands, 0,
			commandCount, (jbyte *)availCommands);

	return commands;
}
Exemplo n.º 6
0
/****************************************************************
  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);
}
Exemplo n.º 7
0
/****************************************************************
 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);
}
Exemplo n.º 8
0
/****************************************************************
 Pops-up the Spy sabotage dialog, upon return of list of
 available improvements requested by the above function.
*****************************************************************/
void popup_sabotage_dialog(struct city *pCity)
{
  struct widget *pWindow = NULL, *pBuf = NULL , *pLast = NULL;
  struct CONTAINER *pCont;
  struct unit *pUnit = head_of_units_in_focus();
  SDL_String16 *pStr;
  SDL_Rect area, area2;
  int n, w = 0, h, imp_h = 0;
  
  if (pDiplomat_Dlg || !pUnit || !unit_has_type_flag(pUnit, F_SPY)) {
    return;
  }
  
  is_unit_move_blocked = TRUE;
    
  pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
  pDiplomat_Dlg->diplomat_id = pUnit->id;
  pDiplomat_Dlg->diplomat_target_id = pCity->id;
  pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG));
  
  pCont = fc_calloc(1, sizeof(struct CONTAINER));
  pCont->id0 = pCity->id;
  pCont->id1 = pUnit->id;/* spy id */
    
  pStr = create_str16_from_char(_("Select Improvement to Sabotage") , 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_TERRAIN_ADV_DLG_WINDOW, pWindow);
  pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow;
  
  area = pWindow->area;
  area.h = MAX(area.h, adj_size(2));
  
  /* ---------- */
  /* exit button */
  pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst,
                          WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
  pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"),
                                            adj_font(12));
  area.w += pBuf->size.w + adj_size(10);
  pBuf->action = diplomat_close_callback;
  set_wstate(pBuf, FC_WS_NORMAL);
  pBuf->key = SDLK_ESCAPE;
  
  add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf);
  /* ---------- */
  
  create_active_iconlabel(pBuf, pWindow->dst, pStr,
	    _("City Production"), sabotage_impr_callback);
  pBuf->data.cont = pCont;  
  set_wstate(pBuf, FC_WS_NORMAL);
  set_wflag(pBuf, WF_FREE_DATA);
  add_to_gui_list(MAX_ID - 1000, pBuf);
    
  area.w = MAX(area.w, pBuf->size.w);
  area.h += pBuf->size.h;

  /* separator */
  pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME);
    
  add_to_gui_list(ID_SEPARATOR, pBuf);
  area.h += pBuf->next->size.h;
  /* ------------------ */
  n = 0;
  city_built_iterate(pCity, pImprove) {
    if (pImprove->sabotage > 0) {
      
      create_active_iconlabel(pBuf, pWindow->dst, pStr,
	      (char *) city_improvement_name_translation(pCity, pImprove),
				      sabotage_impr_callback);
      pBuf->data.cont = pCont;
      set_wstate(pBuf , FC_WS_NORMAL);
  
      add_to_gui_list(MAX_ID - improvement_number(pImprove), pBuf);
    
      area.w = MAX(area.w , pBuf->size.w);
      imp_h += pBuf->size.h;
      
      if (!pDiplomat_Dlg->pdialog->pEndActiveWidgetList)
      {
	pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pBuf;
      }
    
      if (improvement_number(pImprove) > 9)
      {
        set_wflag(pBuf, WF_HIDDEN);
      }
      
      n++;    
      /* ----------- */
    }  
  } city_built_iterate_end;

  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pBuf;
  
  if (n > 0) {
    /* separator */
    pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME);
    
    add_to_gui_list(ID_SEPARATOR, pBuf);
    area.h += pBuf->next->size.h;
  /* ------------------ */
  }
  
  create_active_iconlabel(pBuf, pWindow->dst, pStr, _("At Spy's Discretion"),
			  sabotage_impr_callback);
  pBuf->data.cont = pCont;  
  set_wstate(pBuf, FC_WS_NORMAL);
  
  add_to_gui_list(MAX_ID - B_LAST, pBuf);
    
  area.w = MAX(area.w, pBuf->size.w);
  area.h += pBuf->size.h;
  /* ----------- */
  
  pLast = pBuf;
  pDiplomat_Dlg->pdialog->pBeginWidgetList = pLast;
  pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
  
  /* ---------- */
  if (n > 10)
  {
    imp_h = 10 * pBuf->size.h;
    
    n = create_vertical_scrollbar(pDiplomat_Dlg->pdialog,
		  1, 10, TRUE, TRUE);
    area.w += n;
  }
  /* ---------- */
  
  
  area.h += imp_h;

  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);        
  
  w = area.w;
  
  if (pDiplomat_Dlg->pdialog->pScroll)
  {
    w -= n;
    imp_h = pBuf->size.w;
  }
  else
  {
    imp_h = 0;
  }
  
  /* exit button */
  pBuf = pWindow->prev;
  pBuf->size.x = area.x + area.w - pBuf->size.w - 1;
  pBuf->size.y = pWindow->size.y + adj_size(2);
  
  /* Production sabotage */
  pBuf = pBuf->prev;
  
  pBuf->size.x = area.x;
  pBuf->size.y = area.y + 1;
  pBuf->size.w = w;
  h = pBuf->size.h;
  
  area2.x = adj_size(10);
  area2.h = adj_size(2);
  
  pBuf = pBuf->prev;
  while(pBuf)
  {
    
    if (pBuf == pDiplomat_Dlg->pdialog->pEndActiveWidgetList)
    {
      w -= imp_h;
    }
    
    pBuf->size.w = w;
    pBuf->size.x = pBuf->next->size.x;
    pBuf->size.y = pBuf->next->size.y + pBuf->next->size.h;
    
    if (pBuf->ID == ID_SEPARATOR)
    {
      FREESURFACE(pBuf->theme);
      pBuf->size.h = h;
      pBuf->theme = create_surf(w, h, SDL_SWSURFACE);
    
      area2.y = pBuf->size.h / 2 - 1;
      area2.w = pBuf->size.w - adj_size(20);
      
      SDL_FillRect(pBuf->theme , &area2, map_rgba(pBuf->theme->format, *get_game_colorRGB(COLOR_THEME_SABOTAGEDLG_SEPARATOR)));
    }
    
    if (pBuf == pLast) {
      break;
    }
    pBuf = pBuf->prev;  
  }
  
  if (pDiplomat_Dlg->pdialog->pScroll)
  {
    setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll,
	area.x + area.w,
    	pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y,
    	area.y - pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y +
	    area.h, TRUE);
  }
  
  /* -------------------- */
  /* redraw */
  redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, 0);

  widget_flush(pWindow);
  
}
Exemplo n.º 9
0
/**************************************************************************
  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);
  
}