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>
25 #include "clientutils.h"
27 /* This module contains functions that would belong to the client,
28 * except that in case of freeciv-web, server does handle these
29 * for the web client. */
32 /****************************************************************************
33 Creates the activity progress text for the given tile.
34 ****************************************************************************/
35 const char *concat_tile_activity_text(struct tile
*ptile
)
37 int activity_total
[ACTIVITY_LAST
];
38 int activity_units
[ACTIVITY_LAST
];
39 int extra_total
[MAX_EXTRA_TYPES
];
40 int extra_units
[MAX_EXTRA_TYPES
];
41 int rmextra_total
[MAX_EXTRA_TYPES
];
42 int rmextra_units
[MAX_EXTRA_TYPES
];
43 int num_activities
= 0;
45 static struct astring str
= ASTRING_INIT
;
49 memset(activity_total
, 0, sizeof(activity_total
));
50 memset(activity_units
, 0, sizeof(activity_units
));
51 memset(extra_total
, 0, sizeof(extra_total
));
52 memset(extra_units
, 0, sizeof(extra_units
));
53 memset(rmextra_total
, 0, sizeof(rmextra_total
));
54 memset(rmextra_units
, 0, sizeof(rmextra_units
));
56 unit_list_iterate(ptile
->units
, punit
) {
57 if (is_clean_activity(punit
->activity
)) {
58 int eidx
= extra_index(punit
->activity_target
);
60 rmextra_total
[eidx
] += punit
->activity_count
;
61 rmextra_total
[eidx
] += get_activity_rate_this_turn(punit
);
62 rmextra_units
[eidx
] += get_activity_rate(punit
);
63 } else if (is_build_activity(punit
->activity
, ptile
)) {
64 int eidx
= extra_index(punit
->activity_target
);
66 extra_total
[eidx
] += punit
->activity_count
;
67 extra_total
[eidx
] += get_activity_rate_this_turn(punit
);
68 extra_units
[eidx
] += get_activity_rate(punit
);
70 activity_total
[punit
->activity
] += punit
->activity_count
;
71 activity_total
[punit
->activity
] += get_activity_rate_this_turn(punit
);
72 activity_units
[punit
->activity
] += get_activity_rate(punit
);
74 } unit_list_iterate_end
;
76 activity_type_iterate(i
) {
77 if (is_build_activity(i
, ptile
)) {
78 enum extra_cause cause
= EC_NONE
;
81 case ACTIVITY_GEN_ROAD
:
87 case ACTIVITY_IRRIGATE
:
88 cause
= EC_IRRIGATION
;
94 fc_assert(cause
!= EC_NONE
);
98 if (cause
!= EC_NONE
) {
99 extra_type_by_cause_iterate(cause
, ep
) {
100 int ei
= extra_index(ep
);
102 if (extra_units
[ei
] > 0) {
103 remains
= tile_activity_time(i
, ptile
, ep
) - extra_total
[ei
];
105 turns
= 1 + (remains
+ extra_units
[ei
] - 1) / extra_units
[ei
];
107 /* extra will be finished this turn */
110 if (num_activities
> 0) {
113 astr_add(&str
, "%s(%d)", extra_name_translation(ep
), turns
);
116 } extra_type_by_cause_iterate_end
;
118 } else if (is_clean_activity(i
)) {
119 enum extra_rmcause rmcause
= ERM_NONE
;
122 case ACTIVITY_PILLAGE
:
123 rmcause
= ERM_PILLAGE
;
125 case ACTIVITY_POLLUTION
:
126 rmcause
= ERM_CLEANPOLLUTION
;
128 case ACTIVITY_FALLOUT
:
129 rmcause
= ERM_CLEANFALLOUT
;
132 fc_assert(rmcause
!= ERM_NONE
);
136 if (rmcause
!= ERM_NONE
) {
137 extra_type_by_rmcause_iterate(rmcause
, ep
) {
138 int ei
= extra_index(ep
);
140 if (rmextra_units
[ei
] > 0) {
141 remains
= tile_activity_time(i
, ptile
, ep
) - rmextra_total
[ei
];
143 turns
= 1 + (remains
+ rmextra_units
[ei
] - 1) / rmextra_units
[ei
];
145 /* extra will be removed this turn */
148 if (num_activities
> 0) {
151 astr_add(&str
, rmcause
== ERM_PILLAGE
? _("Pillage %s(%d)") : _("Clean %s(%d)"),
152 extra_name_translation(ep
), turns
);
155 } extra_type_by_rmcause_iterate_end
;
157 } else if (is_tile_activity(i
)) {
158 if (activity_units
[i
] > 0) {
159 remains
= tile_activity_time(i
, ptile
, NULL
) - activity_total
[i
];
161 turns
= 1 + (remains
+ activity_units
[i
] - 1) / activity_units
[i
];
163 /* activity will be finished this turn */
166 if (num_activities
> 0) {
169 astr_add(&str
, "%s(%d)", get_activity_text(i
), turns
);
173 } activity_type_iterate_end
;
175 return astr_str(&str
);