1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
15 #include <fc_config.h>
32 /* client/gui-gtk-3.0 */
34 #include "gui_stuff.h"
36 #include "unitselunitdlg.h"
38 #include "transportdlg.h"
40 struct transport_radio_cb_data
{
45 /****************************************************************
46 Handle user response to transport dialog.
47 *****************************************************************/
48 static void transport_response_callback(GtkWidget
*dlg
, gint arg
)
50 if (arg
== GTK_RESPONSE_YES
) {
52 game_unit_by_number(GPOINTER_TO_INT(
53 g_object_get_data(G_OBJECT(dlg
),
57 int tp_id
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg
),
59 struct tile
*ptile
= g_object_get_data(G_OBJECT(dlg
), "tile");
63 request_unit_load(pcargo
, NULL
, ptile
);
65 struct unit
*ptransport
= game_unit_by_number(tp_id
);
67 if (ptransport
!= NULL
) {
69 request_unit_load(pcargo
, ptransport
, ptile
);
75 gtk_widget_destroy(dlg
);
78 /****************************************************************************
79 Handle transport request automatically when there's nothing to
80 choose from. Otherwise open up transport dialog for the unit
81 ****************************************************************************/
82 bool request_transport(struct unit
*cargo
, struct tile
*ptile
)
85 struct unit_list
*potential_transports
= unit_list_new();
86 struct unit
*best_transport
= transporter_for_unit(cargo
);
88 unit_list_iterate(ptile
->units
, ptransport
) {
89 if (can_unit_transport(ptransport
, cargo
)
90 && get_transporter_occupancy(ptransport
) < get_transporter_capacity(ptransport
)) {
91 unit_list_append(potential_transports
, ptransport
);
93 } unit_list_iterate_end
;
95 tcount
= unit_list_size(potential_transports
);
98 fc_assert(best_transport
== NULL
);
99 unit_list_destroy(potential_transports
);
101 return FALSE
; /* Unit was not handled here. */
102 } else if (tcount
== 1) {
103 /* There's exactly one potential transport - use it automatically */
104 fc_assert(unit_list_get(potential_transports
, 0) == best_transport
);
105 request_unit_load(cargo
, unit_list_get(potential_transports
, 0), ptile
);
107 unit_list_destroy(potential_transports
);
112 return select_tgt_unit(cargo
, ptile
, potential_transports
, best_transport
,
113 _("Transport selection"),
114 _("Looking for transport:"),
115 _("Transports available:"),
117 G_CALLBACK(transport_response_callback
));