diff -ru freeciv/server/unitfunc.c dev/server/unitfunc.c --- freeciv/server/unitfunc.c Fri Jun 23 22:02:27 2000 +++ dev/server/unitfunc.c Wed Jun 28 18:52:30 2000 @@ -2940,6 +2940,7 @@ if (!dest || &game.players[o]==dest) { if (map_get_known_and_seen(info.x, info.y, o) || map_get_known_and_seen(x, y, o)) { + info.veteran = (o==punit->owner)? punit->veteran: 0; send_packet_unit_info(get_player(o)->conn, &info); } } diff -ru freeciv/client/gui-gtk/mapctrl.c dev/client/gui-gtk/mapctrl.c --- freeciv/client/gui-gtk/mapctrl.c Fri Jun 16 18:23:50 2000 +++ dev/client/gui-gtk/mapctrl.c Wed Jun 28 20:51:29 2000 @@ -157,47 +157,24 @@ } if((punit=find_visible_unit(ptile)) && !pcity) { - char cn[64]; struct unit_type *ptype=get_unit_type(punit->type); - cn[0]='\0'; - if(punit->owner==game.player_idx) { - struct city *pcity; - pcity=player_find_city_by_id(game.player_ptr, punit->homecity); - if(pcity) - my_snprintf(cn, sizeof(cn), "/%s", pcity->name); - } - my_snprintf(s, sizeof(s), _("Unit: %s(%s%s)"), ptype->name, - get_nation_name(game.players[punit->owner].nation), cn); + my_snprintf(s, sizeof(s), _("Unit: %s(%s)"), + ptype->name, unit_owned_text(punit)); gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b, "GtkLabel::label", s, NULL); count++; if(punit->owner==game.player_idx) { - char uc[64] = ""; - if(unit_list_size(&ptile->units)>=2) { - my_snprintf(uc, sizeof(uc), _(" (%d more)"), - unit_list_size(&ptile->units) - 1); - } - my_snprintf(s, sizeof(s), "A:%d D:%d FP:%d HP:%d/%d%s%s", - ptype->attack_strength, - ptype->defense_strength, ptype->firepower, punit->hp, - ptype->hp, punit->veteran?" V":"", uc); - - if(punit->activity==ACTIVITY_GOTO || punit->connecting) { + if(punit->activity==ACTIVITY_GOTO || punit->connecting) { cross_head->x = punit->goto_dest_x; cross_head->y = punit->goto_dest_y; cross_head++; } - } else { - my_snprintf(s, sizeof(s), "A:%d D:%d FP:%d HP:%d0%%", - ptype->attack_strength, - ptype->defense_strength, ptype->firepower, - (punit->hp*100/ptype->hp + 9)/10 ); } gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b, - "GtkLabel::label", s, - NULL); + "GtkLabel::label", unit_statistics_text(punit), + NULL); count++; } diff -ru freeciv/common/unit.c dev/common/unit.c --- freeciv/common/unit.c Fri Jun 23 22:01:16 2000 +++ dev/common/unit.c Wed Jun 28 21:40:25 2000 @@ -1057,50 +1057,83 @@ } /************************************************************************** + Returns a string which tells about movement. + Format: ``Moves: (fuelLeft)movesLeft(movesPerTurn)'' + NB: the string is static and _must not_ be freed by calling function. + (easier coding, but dangerous in multi-threaded environment; + who made this up? [Kero]) +**************************************************************************/ +char *unit_moves_text(struct unit *punit) +{ + static char text[64]; + char addition[64]; + struct unit_type *ptype=get_unit_type(punit->type); + + my_snprintf(text, sizeof(text), "Moves: "); + if (is_air_unit(punit)) { + int rate=get_unit_type(punit->type)->move_rate/3; + int f=((punit->fuel)-1); + my_snprintf(addition, sizeof(addition), "(%d)", + (rate*f)+(punit->moves_left/3)); + mystrlcat(text, addition, sizeof(text)); + } + if (punit->moves_left/3 || punit->moves_left==0) { + my_snprintf(addition, sizeof(addition), "%d", punit->moves_left/3); + mystrlcat(text, addition, sizeof(text)); + } + if(punit->moves_left%3) { + if (punit->moves_left/3) mystrlcat(text, " ", sizeof(text)); + my_snprintf(addition, sizeof(addition), "%d/3", punit->moves_left%3); + mystrlcat(text, addition, sizeof(text)); + } + my_snprintf(addition, sizeof(addition), "(%d)", ptype->move_rate/3); + mystrlcat(text, addition, sizeof(text)); + return text; +} + +/************************************************************************** + Returns a string "owner/city" text +**************************************************************************/ +char *unit_owned_text(struct unit *punit) +{ + static char text[64]; + struct city *pcity=player_find_city_by_id(game.player_ptr, punit->homecity); + int nation=game.players[punit->owner].nation; + + my_snprintf(text, sizeof(text), "%s", get_nation_name(nation)); + if (pcity) { + char slashcity[64]; + my_snprintf(slashcity, sizeof(slashcity), "/%s", pcity->name); + mystrlcat(text, slashcity, sizeof(text)); + } + return text; +} + +/************************************************************************** + Returns a string with all battle statistics +**************************************************************************/ +char *unit_statistics_text(struct unit *punit) +{ + static char text[64]; + struct unit_type *ptype=get_unit_type(punit->type); + + my_snprintf(text, sizeof(text), "A:%d D:%d FP:%d HP:%d(%d)%s", + ptype->attack_strength, ptype->defense_strength, + ptype->firepower, punit->hp, + ptype->hp, punit->veteran?" V":""); + return text; +} + +/************************************************************************** ... **************************************************************************/ char *unit_activity_text(struct unit *punit) { static char text[64]; - char *moves_str; switch(punit->activity) { case ACTIVITY_IDLE: - moves_str = _("Moves"); - if(is_air_unit(punit)) { - int rate,f; - rate=get_unit_type(punit->type)->move_rate/3; - f=((punit->fuel)-1); - if(punit->moves_left%3) { - if(punit->moves_left/3>0) { - my_snprintf(text, sizeof(text), "%s: (%d)%d %d/3", moves_str, - ((rate*f)+(punit->moves_left/3)), - punit->moves_left/3, punit->moves_left%3); - } else { - my_snprintf(text, sizeof(text), "%s: (%d)%d/3", moves_str, - ((rate*f)+(punit->moves_left/3)), - punit->moves_left%3); - } - } else { - my_snprintf(text, sizeof(text), "%s: (%d)%d", moves_str, - rate*f+punit->moves_left/3, - punit->moves_left/3); - } - } else { - if(punit->moves_left%3) { - if(punit->moves_left/3>0) { - my_snprintf(text, sizeof(text), "%s: %d %d/3", moves_str, - punit->moves_left/3, punit->moves_left%3); - } else { - my_snprintf(text, sizeof(text), - "%s: %d/3", moves_str, punit->moves_left%3); - } - } else { - my_snprintf(text, sizeof(text), - "%s: %d", moves_str, punit->moves_left/3); - } - } - return text; + return unit_moves_text(punit); case ACTIVITY_POLLUTION: case ACTIVITY_ROAD: case ACTIVITY_RAILROAD: diff -ru freeciv/common/unit.h dev/common/unit.h --- freeciv/common/unit.h Wed May 24 21:13:02 2000 +++ dev/common/unit.h Wed Jun 28 19:32:00 2000 @@ -307,6 +307,9 @@ int kills_citizen_after_attack(struct unit *punit); struct unit_type *get_unit_type(Unit_Type_id id); +char *unit_moves_text(struct unit *punit); +char *unit_owned_text(struct unit *punit); +char *unit_statistics_text(struct unit *punit); char *unit_activity_text(struct unit *punit); char *unit_description(struct unit *punit); int ground_unit_transporter_capacity(int x, int y, int playerid);