diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/unit.c freeciv/common/unit.c --- FreecivCVS/common/unit.c Fri Apr 7 18:14:51 2000 +++ freeciv/common/unit.c Sun Apr 9 14:31:27 2000 @@ -274,42 +274,45 @@ } /************************************************************************** -... +Check for any free space on pplayer's transporters at (x,y). +(Return number of units which may be added to transporters to fill them.) **************************************************************************/ int is_transporter_with_free_space(struct player *pplayer, int x, int y) { - int none_transporters=0, total_capacity=0; + int availability = 0; unit_list_iterate(map_get_tile(x, y)->units, punit) { - if(is_ground_units_transport(punit)) - total_capacity+=get_transporter_capacity(punit); - else if (is_ground_unit(punit)) - none_transporters++; + if (punit->owner == pplayer->player_no) { + if (is_ground_units_transport(punit)) + availability += get_transporter_capacity(punit); + else if (is_ground_unit(punit)) + availability--; + } } unit_list_iterate_end; - - return(total_capacity>none_transporters ? total_capacity-none_transporters : 0); + + return (availability > 0 ? availability : 0); } /************************************************************************** -The above one isn't quite what I want - Kris -Specifically: only pplayer's transports count; only returns true/false; -and returns true if (capacity == passengers). --dwp +Check for enough pplayer's transporters to carry pplayer's ground units at (x,y). +(Return true if capacity of transporters >= number of ground units.) **************************************************************************/ -int is_enough_transporter_space (struct player *pplayer, int x, int y) +int is_enough_transporter_space(struct player *pplayer, int x, int y) { - int none_transporters=0, total_capacity=0; - + int availability = 0; + unit_list_iterate(map_get_tile(x, y)->units, punit) { - if(is_ground_units_transport(punit) - && punit->owner == pplayer->player_no) - total_capacity+=get_transporter_capacity(punit); - else if (is_ground_unit(punit)) - none_transporters++; + if (punit->owner == pplayer->player_no) { + if (is_ground_units_transport(punit)) + availability += get_transporter_capacity(punit); + else if (is_ground_unit(punit)) + availability--; + } } unit_list_iterate_end; - - return(total_capacity>=none_transporters ? 1 : 0); + + return (availability >= 0 ? 1 : 0); } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/unittools.c freeciv/server/unittools.c --- FreecivCVS/server/unittools.c Fri Apr 7 17:38:13 2000 +++ freeciv/server/unittools.c Sun Apr 9 14:26:54 2000 @@ -777,24 +777,27 @@ if(!punit && cunit) punit = cunit; - if(punit && map_get_terrain(punit->x, punit->y)==T_OCEAN && - !is_enough_transporter_space(get_player(punit->owner), x, y)){ - unit_list_iterate(map_get_tile(x, y)->units, vunit){ - struct city *vcity = find_closest_owned_city(get_player(vunit->owner), x, y); - if(is_ground_unit(vunit)){ - teleport_unit_to_city(vunit, vcity, 0); - freelog(LOG_VERBOSE, "Teleported %s's %s to %s" - " as there is no transport space on square (%d, %d)", - get_player(vunit->owner)->name, unit_name(vunit->type), - vcity->name, x, y); - if (verbose) { - notify_player(get_player(vunit->owner), - _("Game: Teleported your %s to %s as there is" - " no transport space on square (%d, %d)."), - unit_name(vunit->type), vcity->name, x, y); + if(punit && map_get_terrain(punit->x, punit->y)==T_OCEAN) { + while(!is_enough_transporter_space(get_player(punit->owner), x, y)) { + unit_list_iterate(map_get_tile(x, y)->units, vunit) { + if(is_ground_unit(vunit)) { + struct city *vcity = + find_closest_owned_city(get_player(vunit->owner), x, y); + teleport_unit_to_city(vunit, vcity, 0); + freelog(LOG_VERBOSE, "Teleported %s's %s to %s" + " as there is no transport space on square (%d, %d)", + get_player(vunit->owner)->name, unit_name(vunit->type), + vcity->name, x, y); + if (verbose) { + notify_player(get_player(vunit->owner), + _("Game: Teleported your %s to %s as there is" + " no transport space on square (%d, %d)."), + unit_name(vunit->type), vcity->name, x, y); + } + break; /* break out of unit_list_iterate loop */ } } + unit_list_iterate_end; } - unit_list_iterate_end; } }