[Freeciv-Dev] (PR#2690) [PATCH] Show unit location in its description
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2690) [PATCH] Show unit location in its description |
From: |
"Stepan Roh via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Tue, 31 Dec 2002 05:37:55 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
Implemented (without coordinates):
> - supported units should have indication of current location
> (coordinates and city name or "near <city name>", just like in civ2)
Features:
- in unit description (used e.g. in supported unit info in city dialog)
new line is added below home city: there could be "in <city>", "near
<city>", "far from <city>" (if distance is more than 6 tiles) or nothing.
Player's own cities have higher precedence than enemy cities if equally
distant.
Known bugs:
- could be slow
Patch attached (cvs diff -u agains latest CVS HEAD).
Tested with gtk client.
Have a nice day.
Stepan Roh
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.167
diff -u -r1.167 unit.c
--- common/unit.c 2002/12/18 17:36:19 1.167
+++ common/unit.c 2002/12/31 13:25:25
@@ -841,21 +841,42 @@
return tgt_ret;
}
+#define FAR_CITY_SQUARE_DIST (2*(6*6))
+
/**************************************************************************
...
**************************************************************************/
const char *unit_description(struct unit *punit)
{
- struct city *pcity;
+ struct city *pcity, *pcity_near;
+ int pcity_near_dist;
static char buffer[512];
pcity = player_find_city_by_id(game.player_ptr, punit->homecity);
- my_snprintf(buffer, sizeof(buffer), "%s%s\n%s\n%s",
+ if ((pcity_near = map_get_city(punit->x, punit->y))) {
+ pcity_near_dist = 0;
+ } else {
+ pcity_near = NULL;
+ pcity_near_dist = -1;
+ players_iterate(pplayer) {
+ city_list_iterate(pplayer->cities, pcity_current) {
+ int dist = sq_map_distance(pcity_current->x, pcity_current->y,
punit->x, punit->y);
+ if ((pcity_near_dist == -1) || (dist < pcity_near_dist) || ((dist ==
pcity_near_dist) && (punit->owner == pcity_current->owner))) {
+ pcity_near = pcity_current;
+ pcity_near_dist = dist;
+ }
+ } city_list_iterate_end;
+ } players_iterate_end;
+ }
+
+ my_snprintf(buffer, sizeof(buffer), "%s%s\n%s\n%s\n%s%s",
unit_type(punit)->name,
punit->veteran ? _(" (veteran)") : "",
unit_activity_text(punit),
- pcity ? pcity->name : "");
+ pcity ? pcity->name : "",
+ (pcity_near_dist >= FAR_CITY_SQUARE_DIST) ? _("far from ") :
(pcity_near_dist > 0) ? _("near ") : (pcity_near_dist == 0) ? _("in ") : "",
+ pcity_near ? pcity_near->name : "");
return buffer;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2690) [PATCH] Show unit location in its description,
Stepan Roh via RT <=
|
|