Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.22/transportdlg.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
transportdlg.c
Go to the documentation of this file.
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)
6 any later version.
7
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***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22
23/* common */
24#include "game.h"
25#include "movement.h"
26#include "unit.h"
27
28/* client */
29#include "control.h"
30#include "tilespec.h"
31
32/* client/gui-gtk-3.22 */
33#include "gui_main.h"
34#include "gui_stuff.h"
35#include "sprite.h"
36#include "unitselunitdlg.h"
37
38#include "transportdlg.h"
39
40struct transport_radio_cb_data {
41 GtkWidget *dlg;
42 int tp_id;
43};
44
45/************************************************************************/
48 static void transport_response_callback(GtkWidget *dlg, gint arg)
49{
50 if (arg == GTK_RESPONSE_YES) {
51 struct unit *pcargo =
52 game_unit_by_number(GPOINTER_TO_INT(
53 g_object_get_data(G_OBJECT(dlg),
54 "actor")));
55
56 if (pcargo != NULL) {
57 int tp_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg),
58 "target"));
59 struct tile *ptile = g_object_get_data(G_OBJECT(dlg), "tile");
60
61 if (tp_id == 0) {
62 /* Load to any */
63 request_unit_load(pcargo, NULL, ptile);
64 } else {
65 struct unit *ptransport = game_unit_by_number(tp_id);
66
67 if (ptransport != NULL) {
68 /* Still exist */
69 request_unit_load(pcargo, ptransport, ptile);
70 }
71 }
72 }
73 }
74
75 gtk_widget_destroy(dlg);
76}
77
78/************************************************************************/
82 bool request_transport(struct unit *cargo, struct tile *ptile)
83{
84 int tcount;
85 struct unit_list *potential_transports = unit_list_new();
86 struct unit *best_transport = transporter_for_unit_at(cargo, ptile);
87
88 unit_list_iterate(ptile->units, ptransport) {
89 if (could_unit_load(cargo, ptransport)) {
90 unit_list_append(potential_transports, ptransport);
91 }
92 } unit_list_iterate_end;
93
94 tcount = unit_list_size(potential_transports);
95
96 if (tcount == 0) {
97 fc_assert(best_transport == NULL);
98 unit_list_destroy(potential_transports);
99
100 return FALSE; /* Unit was not handled here. */
101 } else if (tcount == 1) {
102 /* There's exactly one potential transport - use it automatically */
103 fc_assert(unit_list_get(potential_transports, 0) == best_transport);
104 request_unit_load(cargo, unit_list_get(potential_transports, 0), ptile);
105
106 unit_list_destroy(potential_transports);
107
108 return TRUE;
109 }
110
111 return select_tgt_unit(cargo, ptile, potential_transports, best_transport,
112 _("Transport selection"),
113 _("Looking for transport:"),
114 _("Transports available:"),
115 _("Load"),
116 G_CALLBACK(transport_response_callback));
117}
request_unit_load
void request_unit_load(struct unit *pcargo, struct unit *ptrans, struct tile *ptile)
Definition control.c:2054
control.h
fcintl.h
_
#define _(String)
Definition fcintl.h:67
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game.h
transport_response_callback
static void transport_response_callback(GtkWidget *dlg, gint arg)
Definition transportdlg.c:48
request_transport
bool request_transport(struct unit *cargo, struct tile *ptile)
Definition transportdlg.c:82
select_tgt_unit
bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct unit_list *potential_tgt_units, struct unit *suggested_tgt_unit, const gchar *dlg_title, const gchar *actor_label, const gchar *tgt_label, const gchar *do_label, GCallback do_callback)
Definition unitselunitdlg.c:70
gui_stuff.h
transportdlg.h
unitselunitdlg.h
gui_main.h
sprite.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
movement.h
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
transport_radio_cb_data
Definition transportdlg.c:40
transport_radio_cb_data::dlg
GtkWidget * dlg
Definition transportdlg.c:41
transport_radio_cb_data::tp_id
int tp_id
Definition transportdlg.c:42
unit
Definition unit.h:138
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tilespec.h
transporter_for_unit_at
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1902
could_unit_load
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:715
unit.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33