diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/unitfunc.c workdir/server/unitfunc.c --- freeciv/server/unitfunc.c Thu May 18 22:21:44 2000 +++ workdir/server/unitfunc.c Sat May 20 00:41:40 2000 @@ -2679,11 +2679,6 @@ Groundunit ground unit transports moving to and from ships never take units with them. This is ok, but not always practical. - - There is currently a problem with groundunit transporter airplanes - leaving their cargo behind when moved as part of a carrier, but - since that problem is in the previous transport code and other - places in the code too I will leave it here for now. **************************************************************************/ void assign_units_to_transporter(struct unit *ptrans, int take_from_land) { @@ -2770,11 +2765,13 @@ if (ptrans->id == pcargo->transported_by) { if (pcargo->owner == playerid && pcargo->id != ptrans->id - && is_air_unit(pcargo) + && (!is_sailing_unit(pcargo)) && (unit_flag(pcargo->type, F_MISSILE) || !missiles_only) && !(is_ground_unit(ptrans) && ptile->terrain == T_OCEAN) && (capacity > 0)) { - capacity--; + if (is_air_unit(pcargo)) + capacity--; + /* Ground units are handled below */ } else pcargo->transported_by = -1; } @@ -2836,6 +2833,59 @@ && pcargo->owner == playerid) { capacity--; pcargo->transported_by = ptrans->id; + } + } unit_list_iterate_end; + } + } + + /** If any of the transported air units have land units on board take them with us **/ + { + int totcap = 0; + int available = ground_unit_transporter_capacity(x, y, playerid); + struct unit_list trans2s; + unit_list_init(&trans2s); + + unit_list_iterate(ptile->units, pcargo) { + if (pcargo->transported_by == ptrans->id + && is_ground_units_transport(pcargo) + && is_air_unit(pcargo)) { + totcap += get_transporter_capacity(pcargo); + unit_list_insert(&trans2s, pcargo); + } + } unit_list_iterate_end; + + unit_list_iterate(ptile->units, pcargo2) { + int has_trans = 0; + unit_list_iterate(trans2s, ptrans2) { + if (pcargo2->transported_by == ptrans2->id) + has_trans = 1; + } unit_list_iterate_end; + if (pcargo2->transported_by == ptrans->id) + has_trans = 1; + + if (has_trans + && is_ground_unit(pcargo2)) { + if (totcap > 0 + && (ptile->terrain == T_OCEAN || pcargo2->activity == ACTIVITY_SENTRY) + && pcargo2->owner == playerid + && pcargo2 != ptrans) { + pcargo2->transported_by = ptrans->id; + totcap--; + } else + pcargo2->transported_by = -1; + } + } unit_list_iterate_end; + + /* Uh oh. Not enough space on the square we leave if we don't + take extra units with us */ + if (totcap > available && ptile->terrain == T_OCEAN) { + unit_list_iterate(ptile->units, pcargo2) { + if (is_ground_unit(pcargo2) + && totcap > 0 + && pcargo2->owner == playerid + && pcargo2->transported_by != ptrans->id) { + pcargo2->transported_by = ptrans->id; + totcap--; } } unit_list_iterate_end; }