diff client/civclient.c client/civclient.c --- client/civclient.c Sun Aug 27 10:39:47 2000 +++ client/civclient.c Mon Sep 4 14:01:56 2000 @@ -201,7 +201,11 @@ handle_unit_info((struct packet_unit_info *)packet); break; - case PACKET_MOVE_UNIT: + case PACKET_ENEMY_UNIT: + handle_enemy_unit((struct packet_enemy_unit *)packet); + break; + + case PACKET_MOVE_UNIT: handle_move_unit((struct packet_move_unit *)packet); break; diff client/control.c client/control.c --- client/control.c Sun Aug 27 10:39:47 2000 +++ client/control.c Mon Sep 4 14:01:56 2000 @@ -829,11 +829,12 @@ /************************************************************************** ... **************************************************************************/ -void do_move_unit(struct unit *punit, struct packet_unit_info *pinfo) +void do_move_unit(struct unit *punit, struct unit *tempunit, int carried) { int x, y, was_teleported; - was_teleported=!is_tiles_adjacent(punit->x, punit->y, pinfo->x, pinfo->y); + was_teleported=!is_tiles_adjacent(punit->x, punit->y, + tempunit->x, tempunit->y); x=punit->x; y=punit->y; punit->x=-1; /* focus hack - if we're moving the unit in focus, it wont @@ -841,28 +842,34 @@ unit_list_unlink(&map_get_tile(x, y)->units, punit); - if(!pinfo->carried) + if(!carried) refresh_tile_mapcanvas(x, y, was_teleported); if(game.player_idx==punit->owner && punit->activity!=ACTIVITY_GOTO && auto_center_on_unit && - !tile_visible_and_not_on_border_mapcanvas(pinfo->x, pinfo->y)) - center_tile_mapcanvas(pinfo->x, pinfo->y); + !tile_visible_and_not_on_border_mapcanvas(tempunit->x, tempunit->y)) + center_tile_mapcanvas(tempunit->x, tempunit->y); - if(!pinfo->carried && !was_teleported) { - int dx=pinfo->x - x; + if(!carried && !was_teleported) { + int dx=tempunit->x - x; if(dx>1) dx=-1; else if(dx<-1) dx=1; if(smooth_move_units) - move_unit_map_canvas(punit, x, y, dx, pinfo->y - punit->y); + move_unit_map_canvas(punit, x, y, dx, tempunit->y - punit->y); refresh_tile_mapcanvas(x, y, 1); } - - punit->x=pinfo->x; - punit->y=pinfo->y; - punit->fuel=pinfo->fuel; - punit->hp=pinfo->hp; + + punit->x = tempunit->x; + punit->y = tempunit->y; + +/* These are already set (or will be set) at handle_unit_packet_common(). */ + +/* + punit->fuel = tempunit->fuel; + punit->hp = tempunit->hp; +*/ + unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit); for(y=punit->y-2; yy+3; ++y) { @@ -877,7 +884,7 @@ } } - if(!pinfo->carried && tile_is_known(punit->x,punit->y) == TILE_KNOWN) + if(!carried && tile_is_known(punit->x,punit->y) == TILE_KNOWN) refresh_tile_mapcanvas(punit->x, punit->y, 1); if(get_unit_in_focus()==punit) update_menus(); diff client/control.h client/control.h --- client/control.h Sun Aug 27 10:39:47 2000 +++ client/control.h Mon Sep 4 14:01:56 2000 @@ -15,7 +15,7 @@ #include "packets.h" -void do_move_unit(struct unit *punit, struct packet_unit_info *pinfo); +void do_move_unit(struct unit *punit, struct unit *tempunit, int carried); void do_unit_nuke(struct unit *punit); void do_unit_paradrop_to(struct unit *punit, int x, int y); void do_unit_connect(struct unit *punit, int x, int y); diff client/packhand.c client/packhand.c --- client/packhand.c Sat Sep 2 11:21:51 2000 +++ client/packhand.c Mon Sep 4 14:01:56 2000 @@ -68,6 +68,8 @@ static void handle_city_packet_common(struct city *pcity, int is_new, int popup); +static void handle_unit_packet_common(struct unit *tempunit, int carried, + int select_it); /************************************************************************** ... @@ -109,6 +111,49 @@ /************************************************************************** ... **************************************************************************/ +static void unpackage_enemy_unit(struct unit *punit, + struct packet_enemy_unit *packet) +{ + punit->id = packet->id; + punit->owner = packet->owner; + punit->x = packet->x; + punit->y = packet->y; + punit->type = packet->type; + punit->hp = packet->hp; + punit->activity = packet->activity; + + /* This sets dumb values for everything else. This is not really required, + but just want to be at the safe side. */ + { + punit->homecity = 0; + punit->veteran = 0; + punit->moves_left = 0; + punit->activity_count = 0; + punit->unhappiness = 0; + punit->upkeep = 0; + punit->upkeep_food = 0; + punit->upkeep_gold = 0; + punit->ai.control = 0; + punit->fuel = 0; + punit->goto_dest_x = -1; + punit->goto_dest_y = -1; + punit->activity_target = 0; + punit->paradropped = 0; + punit->connecting = 0; + punit->focus_status = FOCUS_AVAIL; + punit->bribe_cost = 0; /* done by handle_incite_cost() */ + punit->foul = 0; + punit->ord_map = 0; + punit->ord_city = 0; + punit->moved = 0; + punit->transported_by = 0; + punit->ai.control = 0; + } /* Dumb values */ +} + +/************************************************************************** +... +**************************************************************************/ void handle_join_game_reply(struct packet_join_game_reply *packet) { char msg[MAX_LEN_MSG]; @@ -616,8 +661,10 @@ { struct city *pcity; struct unit *punit; - int repaint_unit; - int repaint_city; /* regards unit's homecity */ + + /* When removing capability packet_enemy_unit, remove this + whole diplomat investigate block. It should appear only in + handle_enemy_unit(). */ /* Special case for a diplomat/spy investigating a city: The investigator needs to know the supported and present @@ -657,14 +704,30 @@ return; } + punit = fc_malloc(sizeof(struct unit)); + unpackage_unit(punit, packet); + handle_unit_packet_common(punit, packet->carried, packet->select_it); +} + +/************************************************************************** + ... +**************************************************************************/ +static void handle_unit_packet_common(struct unit *tempunit, int carried, + int select_it) +{ + struct city *pcity; + struct unit *punit; + int repaint_unit; + int repaint_city; /* regards unit's homecity */ + repaint_unit = 0; repaint_city = 0; - punit = player_find_unit_by_id(&game.players[packet->owner], packet->id); + punit = player_find_unit_by_id(&game.players[tempunit->owner], tempunit->id); if(punit) { int dest_x,dest_y; - if((punit->activity!=packet->activity) /* change activity */ - || (punit->activity_target!=packet->activity_target)) { /* or act's target */ + if((punit->activity!=tempunit->activity) /* change activity */ + || (punit->activity_target!=tempunit->activity_target)) { /* or act's target */ repaint_unit=1; if(wakeup_focus && (punit->owner==game.player_idx) && (punit->activity==ACTIVITY_SENTRY)) { @@ -672,8 +735,8 @@ /* RP: focus on (each) activated unit (e.g. when unloading a ship) */ } - punit->activity=packet->activity; - punit->activity_target=packet->activity_target; + punit->activity=tempunit->activity; + punit->activity_target=tempunit->activity_target; if(punit->owner==game.player_idx) refresh_unit_city_dialogs(punit); @@ -688,51 +751,51 @@ update_menus(); } - if(punit->homecity!=packet->homecity) { /* change homecity */ + if(punit->homecity!=tempunit->homecity) { /* change homecity */ struct city *pcity; if((pcity=find_city_by_id(punit->homecity))) { unit_list_unlink(&pcity->units_supported, punit); refresh_city_dialog(pcity); } - punit->homecity=packet->homecity; + punit->homecity=tempunit->homecity; if((pcity=find_city_by_id(punit->homecity))) { unit_list_insert(&pcity->units_supported, punit); repaint_city=1; } } - if(punit->hp!=packet->hp) { /* hp changed */ - punit->hp=packet->hp; + if(punit->hp!=tempunit->hp) { /* hp changed */ + punit->hp=tempunit->hp; repaint_unit=1; } - if (punit->type!=packet->type) { + if (punit->type!=tempunit->type) { struct city *pcity = map_get_city(punit->x, punit->y); - punit->type=packet->type; + punit->type=tempunit->type; repaint_unit=1; repaint_city=1; if (pcity && (pcity->id != punit->homecity)) { refresh_city_dialog(pcity); } } - if (punit->ai.control!=packet->ai) { - punit->ai.control=packet->ai; + if (punit->ai.control!=tempunit->ai.control) { + punit->ai.control=tempunit->ai.control; repaint_unit = 1; } - if(punit->x!=packet->x || punit->y!=packet->y) { /* change position */ + if(punit->x!=tempunit->x || punit->y!=tempunit->y) { /* change position */ struct city *pcity; pcity=map_get_city(punit->x, punit->y); - if(tile_is_known(packet->x, packet->y) == TILE_KNOWN) { - do_move_unit(punit, packet); + if(tile_is_known(tempunit->x, tempunit->y) == TILE_KNOWN) { + do_move_unit(punit, tempunit, carried); update_unit_focus(); } else { - do_move_unit(punit, packet); /* nice to see where a unit is going */ + do_move_unit(punit, tempunit, carried); /* nice to see where a unit is going */ client_remove_unit(punit->id); - refresh_tile_mapcanvas(packet->x, packet->y, 1); + refresh_tile_mapcanvas(tempunit->x, tempunit->y, 1); return; } if(pcity) { @@ -762,20 +825,20 @@ repaint_unit=0; } - if (punit->unhappiness!=packet->unhappiness) { - punit->unhappiness=packet->unhappiness; + if (punit->unhappiness!=tempunit->unhappiness) { + punit->unhappiness=tempunit->unhappiness; repaint_city=1; } - if (punit->upkeep!=packet->upkeep) { - punit->upkeep=packet->upkeep; + if (punit->upkeep!=tempunit->upkeep) { + punit->upkeep=tempunit->upkeep; repaint_city=1; } - if (punit->upkeep_food!=packet->upkeep_food) { - punit->upkeep_food=packet->upkeep_food; + if (punit->upkeep_food!=tempunit->upkeep_food) { + punit->upkeep_food=tempunit->upkeep_food; repaint_city=1; } - if (punit->upkeep_gold!=packet->upkeep_gold) { - punit->upkeep_gold=packet->upkeep_gold; + if (punit->upkeep_gold!=tempunit->upkeep_gold) { + punit->upkeep_gold=tempunit->upkeep_gold; repaint_city=1; } if (repaint_city) { @@ -784,32 +847,30 @@ } } - punit->veteran=packet->veteran; - punit->moves_left=packet->movesleft; - punit->bribe_cost=0; - punit->fuel=packet->fuel; - punit->goto_dest_x=packet->goto_dest_x; - punit->goto_dest_y=packet->goto_dest_y; - punit->paradropped=packet->paradropped; - punit->connecting=packet->connecting; + punit->veteran=tempunit->veteran; + punit->moves_left=tempunit->moves_left; + punit->fuel=tempunit->fuel; + punit->goto_dest_x=tempunit->goto_dest_x; + punit->goto_dest_y=tempunit->goto_dest_y; + punit->paradropped=tempunit->paradropped; + punit->connecting=tempunit->connecting; - dest_x = packet->x; - dest_y = packet->y; + dest_x = tempunit->x; + dest_y = tempunit->y; /*fog of war*/ if (!(tile_is_known(punit->x,punit->y) == TILE_KNOWN)) { - client_remove_unit(packet->id); + client_remove_unit(punit->id); refresh_tile_mapcanvas(dest_x, dest_y, 1); } } else { /* create new unit */ - punit=fc_malloc(sizeof(struct unit)); - unpackage_unit(punit, packet); + punit = tempunit; idex_register_unit(punit); punit->activity_count=0; /* never used in client/ or common/ --dwp */ - unit_list_insert(&game.players[packet->owner].units, punit); + unit_list_insert(&game.players[punit->owner].units, punit); unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit); if((pcity=find_city_by_id(punit->homecity))) @@ -820,7 +881,7 @@ unit_name(punit->type), punit->x, punit->y, punit->id, punit->homecity, (pcity ? pcity->name : _("(unknown)"))); - if (packet->carried) + if (carried) repaint_unit=0; else repaint_unit=1; @@ -836,11 +897,62 @@ if(repaint_unit) refresh_tile_mapcanvas(punit->x, punit->y, 1); - if(packet->select_it && (punit->owner==game.player_idx)) { + if(select_it && (punit->owner==game.player_idx)) { set_unit_focus_and_select(punit); } else { update_unit_focus(); } +} + +/************************************************************************** +... +**************************************************************************/ +void handle_enemy_unit(struct packet_enemy_unit *packet) +{ + struct city *pcity; + struct unit *punit; + + /* Special case for a diplomat/spy investigating a city: + The investigator needs to know the supported and present + units of a city, whether or not they are fogged. So, we + send a list of them all before sending the city info. */ + if ((packet->packet_use == UNIT_INFO_CITY_SUPPORTED) || + (packet->packet_use == UNIT_INFO_CITY_PRESENT)) { + static int last_serial_num = 0; + /* fetch city -- abort if not found */ + pcity = find_city_by_id(packet->info_city_id); + if (!pcity) { + return; + } + /* new serial number -- clear everything */ + if (last_serial_num != packet->serial_num) { + last_serial_num = packet->serial_num; + unit_list_iterate(pcity->info_units_supported, psunit) { + free(psunit); + } unit_list_iterate_end; + unit_list_unlink_all(&(pcity->info_units_supported)); + unit_list_iterate(pcity->info_units_present, ppunit) { + free(ppunit); + } unit_list_iterate_end; + unit_list_unlink_all(&(pcity->info_units_present)); + } + /* okay, append a unit struct to the proper list */ + if (packet->packet_use == UNIT_INFO_CITY_SUPPORTED) { + punit = fc_malloc(sizeof(struct unit)); + unpackage_enemy_unit(punit, packet); + unit_list_insert(&(pcity->info_units_supported), punit); + } else if (packet->packet_use == UNIT_INFO_CITY_PRESENT) { + punit = fc_malloc(sizeof(struct unit)); + unpackage_enemy_unit(punit, packet); + unit_list_insert(&(pcity->info_units_present), punit); + } + /* done with special case */ + return; + } + + punit = fc_malloc(sizeof(struct unit)); + unpackage_enemy_unit(punit, packet); + handle_unit_packet_common(punit, packet->carried, 0); } /************************************************************************** diff client/packhand.h client/packhand.h --- client/packhand.h Sun Aug 27 10:39:52 2000 +++ client/packhand.h Mon Sep 4 14:01:56 2000 @@ -24,6 +24,7 @@ void handle_map_info(struct packet_map_info *pinfo); void handle_select_nation(struct packet_generic_values *packet); void handle_unit_info(struct packet_unit_info *packet); +void handle_enemy_unit(struct packet_enemy_unit *packet); void handle_chat_msg(struct packet_generic_message *packet); void handle_remove_city(struct packet_generic_integer *packet); diff common/capstr.c common/capstr.c --- common/capstr.c Sat Sep 2 11:22:01 2000 +++ common/capstr.c Mon Sep 4 14:03:14 2000 @@ -73,7 +73,7 @@ #define CAPABILITY "+1.11 diplomat_investigate_fix production_change_fix" \ " game_ruleset nuclear_fallout land_channel_requirement event_wonder_obsolete" \ " event00_fix conn_info gen_impr_oversights diplo_move_city packet_short_city" \ -" indef_impr_types worklist_true_ids" +" indef_impr_types worklist_true_ids packet_enemy_unit" /* "+1.11" is protocol for 1.11.0 stable release. @@ -123,6 +123,9 @@ their true values (units are no longer B_LAST + unit_id). A flag field is added to discriminate between unit and improvement and to specify the end of the list. + + "packet_enemy_unit" is packet sent intead of full packet_unit_info to + enemies. */ void init_our_capability(void) diff common/packets.c common/packets.c --- common/packets.c Sat Sep 2 11:22:01 2000 +++ common/packets.c Mon Sep 4 14:01:57 2000 @@ -209,6 +209,9 @@ case PACKET_UNIT_INFO: return receive_packet_unit_info(pc); + case PACKET_ENEMY_UNIT: + return receive_packet_enemy_unit(pc); + case PACKET_CITY_INFO: return receive_packet_city_info(pc); @@ -2157,7 +2160,8 @@ cptr=put_uint8(cptr, req->goto_dest_x); cptr=put_uint8(cptr, req->goto_dest_y); cptr=put_uint16(cptr, req->activity_target); -if (pc && has_capability("diplomat_investigate_fix", pc->capability)) { +if (pc && has_capability("diplomat_investigate_fix", pc->capability) && + !has_capability("packet_enemy_unit", pc->capability)) { cptr=put_uint8(cptr, req->packet_use); cptr=put_uint16(cptr, req->info_city_id); cptr=put_uint16(cptr, req->serial_num); @@ -2171,6 +2175,112 @@ /************************************************************************* ... **************************************************************************/ +int send_packet_enemy_unit(struct connection *pc, + struct packet_enemy_unit *req) +{ + unsigned char buffer[MAX_LEN_PACKET], *cptr; + unsigned char pack; + + /* When removing capability packet_enemy_unit, see also + common/packets.h packet_unit_info + common/packets.c send_packet_unit_info() + common/packets.c receive_packet_unit_info() + client/packhand.c handle_unit_info() + */ + + if (pc && !has_capability("packet_enemy_unit", pc->capability)) { + + /* Send packet_unit_info instead. */ + struct packet_unit_info old; + + old.id = req->id; + old.owner = req->owner; + old.x = req->x; + old.y = req->y; + old.type = req->type; + old.hp = req->hp; + old.activity = req->activity; + old.packet_use = req->packet_use; + old.info_city_id = req->info_city_id; + old.serial_num = req->serial_num; + + old.veteran = 0; + old.homecity = 0; + old.movesleft = 0; + old.activity_count = 0; + old.unhappiness = 0; + old.upkeep = 0; + old.upkeep_food = 0; + old.upkeep_gold = 0; + old.ai = 0; + old.fuel = 0; + old.goto_dest_x = -1; + old.goto_dest_y = -1; + old.activity_target = 0; + old.paradropped = 0; + old.connecting = 0; + old.carried = 0; + old.select_it = 0; + + return send_packet_unit_info(pc, &old); + } /* !has_capability(packet_enemy_unit) */ + + cptr=put_uint8(buffer+2, PACKET_ENEMY_UNIT); + cptr=put_uint16(cptr, req->id); + cptr=put_uint8(cptr, req->owner); + cptr=put_uint8(cptr, req->x); + cptr=put_uint8(cptr, req->y); + cptr=put_uint8(cptr, req->type); + cptr=put_uint8(cptr, req->hp); + cptr=put_uint8(cptr, req->activity); + + pack=(req->carried ? 0x08 : 0); + cptr=put_uint8(cptr, pack); + + cptr=put_uint8(cptr, req->packet_use); + cptr=put_uint16(cptr, req->info_city_id); + cptr=put_uint16(cptr, req->serial_num); + + put_uint16(buffer, cptr-buffer); + return send_connection_data(pc, buffer, cptr-buffer); +} + +/************************************************************************* +... +**************************************************************************/ +struct packet_enemy_unit * +receive_packet_enemy_unit(struct connection *pc) +{ + int pack; + struct pack_iter iter; + struct packet_enemy_unit *packet= + fc_malloc(sizeof(struct packet_enemy_unit)); + + pack_iter_init(&iter, pc); + + iget_uint16(&iter, &packet->id); + iget_uint8(&iter, &packet->owner); + iget_uint8(&iter, &packet->x); + iget_uint8(&iter, &packet->y); + iget_uint8(&iter, &packet->type); + iget_uint8(&iter, &packet->hp); + iget_uint8(&iter, &packet->activity); + + iget_uint8(&iter, &pack); + packet->carried = (pack&0x08) ? 1 : 0; + + iget_uint8(&iter, &packet->packet_use); + iget_uint16(&iter, &packet->info_city_id); + iget_uint8(&iter, &packet->serial_num); + + pack_iter_end(&iter, pc); + remove_packet_from_buffer(pc->buffer); + return packet; +} + +/************************************************************************* +... +**************************************************************************/ int send_packet_city_info(struct connection *pc, struct packet_city_info *req) { unsigned char buffer[MAX_LEN_PACKET], *cptr; @@ -2511,7 +2621,8 @@ iget_uint8(&iter, &packet->goto_dest_x); iget_uint8(&iter, &packet->goto_dest_y); iget_uint16(&iter, &packet->activity_target); -if (pc && has_capability("diplomat_investigate_fix", pc->capability)) { +if (pc && has_capability("diplomat_investigate_fix", pc->capability) && + !has_capability("packet_enemy_unit", pc->capability)) { iget_uint8(&iter, &packet->packet_use); iget_uint16(&iter, &packet->info_city_id); iget_uint16(&iter, &packet->serial_num); diff common/packets.h common/packets.h --- common/packets.h Sat Sep 2 11:22:01 2000 +++ common/packets.h Mon Sep 4 14:01:57 2000 @@ -112,6 +112,7 @@ PACKET_RULESET_GAME, PACKET_CONN_INFO, PACKET_SHORT_CITY, + PACKET_ENEMY_UNIT, PACKET_LAST /* leave this last */ }; @@ -304,6 +305,29 @@ /* in packet only, not in unit struct */ int carried; int select_it; + +/* These should be only at packet_enemy_unit. Remove when removing + capability for packet_enemy_city. */ + int packet_use; /* see enum unit_info_use */ + int info_city_id; /* for UNIT_INFO_CITY_SUPPORTED + and UNIT_INFO_CITY_PRESENT uses */ + int serial_num; /* a 16-bit unsigned number, never zero + (not used by UNIT_INFO_IDENTITY) */ +}; + + +struct packet_enemy_unit { + int id; + int owner; + int x, y; + int type; + int hp; + int activity; + + int carried; /* FIXME: Should probably not sent carried units at + all. Just sent knowledge that there's units aboard + with carrier (for clients to display '+') */ + int packet_use; /* see enum unit_info_use */ int info_city_id; /* for UNIT_INFO_CITY_SUPPORTED and UNIT_INFO_CITY_PRESENT uses */ @@ -901,6 +925,10 @@ int send_packet_unit_info(struct connection *pc, struct packet_unit_info *req); struct packet_unit_info *receive_packet_unit_info(struct connection *pc); + +int send_packet_enemy_unit(struct connection *pc, + struct packet_enemy_unit *req); +struct packet_enemy_unit *receive_packet_enemy_unit(struct connection *pc); int send_packet_req_join_game(struct connection *pc, struct packet_req_join_game *request); diff common/packets_lsend.c common/packets_lsend.c --- common/packets_lsend.c Sun Aug 27 10:39:52 2000 +++ common/packets_lsend.c Mon Sep 4 14:01:57 2000 @@ -121,6 +121,14 @@ conn_list_iterate_end; } +void lsend_packet_enemy_unit(struct conn_list *dest, + struct packet_enemy_unit *req) +{ + conn_list_iterate(*dest, pconn) + send_packet_enemy_unit(pconn, req); + conn_list_iterate_end; +} + void lsend_packet_req_join_game(struct conn_list *dest, struct packet_req_join_game *request) { diff common/packets_lsend.h common/packets_lsend.h --- common/packets_lsend.h Sun Aug 27 10:39:52 2000 +++ common/packets_lsend.h Mon Sep 4 14:01:57 2000 @@ -42,6 +42,8 @@ struct packet_move_unit *request); void lsend_packet_unit_info(struct conn_list *dest, struct packet_unit_info *req); +void lsend_packet_enemy_unit(struct conn_list *dest, + struct packet_enemy_unit *req); void lsend_packet_req_join_game(struct conn_list *dest, struct packet_req_join_game *request); void lsend_packet_join_game_reply(struct conn_list *dest, diff server/unitfunc.c server/unitfunc.c --- server/unitfunc.c Sat Sep 2 11:22:06 2000 +++ server/unitfunc.c Mon Sep 4 14:09:21 2000 @@ -165,7 +165,7 @@ { struct player *cplayer; int first_packet; - struct packet_unit_info unit_packet; + struct packet_enemy_unit unit_packet; struct packet_city_info city_packet; /* Fetch target city's player. Sanity checks. */ @@ -186,15 +186,15 @@ As this is a special case we bypass send_unit_info. */ first_packet = TRUE; unit_list_iterate(pcity->units_supported, punit) { - package_unit(punit, &unit_packet, FALSE, FALSE, - UNIT_INFO_CITY_SUPPORTED, pcity->id, first_packet); - lsend_packet_unit_info(&pplayer->connections, &unit_packet); + package_enemy_unit(punit, &unit_packet, FALSE, + UNIT_INFO_CITY_SUPPORTED, pcity->id, first_packet); + lsend_packet_enemy_unit(&pplayer->connections, &unit_packet); first_packet = FALSE; } unit_list_iterate_end; unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, punit) { - package_unit(punit, &unit_packet, FALSE, FALSE, - UNIT_INFO_CITY_PRESENT, pcity->id, first_packet); - lsend_packet_unit_info(&pplayer->connections, &unit_packet); + package_enemy_unit(punit, &unit_packet, FALSE, + UNIT_INFO_CITY_PRESENT, pcity->id, first_packet); + lsend_packet_enemy_unit(&pplayer->connections, &unit_packet); first_packet = FALSE; } unit_list_iterate_end; /* Send city info to investigator's player. @@ -2936,11 +2936,12 @@ int x, int y, int carried, int select_it) { struct packet_unit_info info; + struct packet_enemy_unit einfo; if (dest==NULL) dest = &game.game_connections; - package_unit(punit, &info, carried, select_it, - UNIT_INFO_IDENTITY, 0, FALSE); + package_unit(punit, &info, carried, select_it); + package_enemy_unit(punit, &einfo, carried, UNIT_INFO_IDENTITY, 0, 0); conn_list_iterate(*dest, pconn) { struct player *pplayer = pconn->player; @@ -2948,7 +2949,11 @@ if (pplayer==NULL || map_get_known_and_seen(info.x, info.y, pplayer->player_no) || map_get_known_and_seen(x, y, pplayer->player_no)) { - send_packet_unit_info(pconn, &info); + if ((pplayer && pplayer->player_no == punit->owner) || + (!pplayer && pconn->observer)) + send_packet_unit_info(pconn, &info); + else + send_packet_enemy_unit(pconn, &einfo); } } conn_list_iterate_end; diff server/unithand.c server/unithand.c --- server/unithand.c Sat Sep 2 11:22:06 2000 +++ server/unithand.c Mon Sep 4 14:01:57 2000 @@ -1475,18 +1475,8 @@ ... **************************************************************************/ void package_unit(struct unit *punit, struct packet_unit_info *packet, - int carried, int select_it, enum unit_info_use packet_use, - int info_city_id, int new_serial_num) + int carried, int select_it) { - static unsigned int serial_num = 0; - - /* a 16-bit unsigned number, never zero */ - if (new_serial_num) { - serial_num = (serial_num + 1) & 0xFFFF; - if (serial_num == 0) - serial_num++; - } - packet->id = punit->id; packet->owner = punit->owner; packet->x = punit->x; @@ -1511,7 +1501,40 @@ packet->connecting = punit->connecting; packet->carried = carried; packet->select_it = select_it; - packet->packet_use = packet_use; +} + + +/************************************************************************** +... +**************************************************************************/ +void package_enemy_unit(struct unit *punit, struct packet_enemy_unit *packet, + int carried, enum unit_info_use packet_use, + int info_city_id, int new_serial_num) +{ + static unsigned int serial_num = 0; + + /* a 16-bit unsigned number, never zero */ + if (new_serial_num) { + serial_num = (serial_num + 1) & 0xFFFF; + if (serial_num == 0) + serial_num++; + } + packet->serial_num = serial_num; + packet->packet_use = packet_use; packet->info_city_id = info_city_id; - packet->serial_num = serial_num; + + packet->id = punit->id; + packet->owner = punit->owner; + packet->x = punit->x; + packet->y = punit->y; + packet->type = punit->type; + packet->hp = punit->hp; + + if (punit->activity != ACTIVITY_GOTO && + punit->activity != ACTIVITY_EXPLORE) + packet->activity = punit->activity; + else + packet->activity = ACTIVITY_IDLE; + + packet->carried = carried; } diff server/unithand.h server/unithand.h --- server/unithand.h Sun Aug 27 10:39:52 2000 +++ server/unithand.h Mon Sep 4 14:01:57 2000 @@ -61,7 +61,10 @@ void handle_incite_inq(struct connection *pconn, struct packet_generic_integer *packet); void package_unit(struct unit *punit, struct packet_unit_info *packet, - int carried, int select_it, enum unit_info_use packet_use, - int info_city_id, int new_serial_num); + int carried, int select_it); + +void package_enemy_unit(struct unit *punit, struct packet_enemy_unit *packet, + int carried, enum unit_info_use packet_use, + int info_city_id, int new_serial_num); #endif /* FC__UNITHAND_H */