Author: sveinung Date: Fri Dec 5 13:44:29 2014 New Revision: 27185 URL: http://svn.gna.org/viewcvs/freeciv?rev=27185&view=rev Log: AI: Support the Enter Marketplace action.
- Consider to do Enter Marketplace when a unit can't do Establish Trade Route - Calculate the correct one time bonus for Enter Marketplace - if the real wish is trade routes "Enter Marketplace" unit want isn't increased See patch #5485 Modified: trunk/ai/default/advdomestic.c trunk/ai/default/aiunit.c trunk/common/aicore/caravan.c Modified: trunk/ai/default/advdomestic.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/advdomestic.c?rev=27185&r1=27184&r2=27185&view=diff ============================================================================== --- trunk/ai/default/advdomestic.c (original) +++ trunk/ai/default/advdomestic.c Fri Dec 5 13:44:29 2014 @@ -279,8 +279,10 @@ unit_type = get_role_unit(UTYF_TRADE_ROUTE, 0); } - if (!utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) { - /* This unit type isn't suitable for establishing trade routes. */ + if (!(utype_can_do_action(unit_type, ACTION_TRADE_ROUTE) + || utype_can_do_action(unit_type, ACTION_MARKETPLACE))) { + /* This unit type isn't suitable for establishing trade routes or + * entering market places. */ return; } @@ -296,13 +298,19 @@ /* We consider only initial benefit from establishing trade route. * We may actually get only initial benefit if both cities already - * have four trade routes, or if there already is route between them. */ + * have four trade routes, if there already is route between them + * or if the Establish Trade Route action is illegal. */ /* We assume that we are creating trade route to city with 75% of * pcitys trade 10 squares away. */ income = (10 + 10) * (1.75 * pcity->surplus[O_TRADE]) / 24 * 3; bonus = get_city_bonus(pcity, EFT_TRADE_REVENUE_BONUS); income = (float)income * pow(2.0, (double)bonus / 1000.0); + + if (!utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) { + /* Enter Marketplace has less initial income. */ + income = (income + 2) / 3; + } if (dest_city_nat_same_cont) { pct = trade_route_type_trade_pct(TRT_NATIONAL); @@ -346,15 +354,18 @@ * This method helps us out of deadlocks of completely stalled * scientific progress. */ - if (pplayer->economic.science < 50 && trade_routes < max_routes) { + if (pplayer->economic.science < 50 && trade_routes < max_routes + && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) { want *= (6 - pplayer->economic.science/10) * (6 - pplayer->economic.science/10); } - if (trade_routes == 0 && max_routes > 0) { + if (trade_routes == 0 && max_routes > 0 + && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) { /* If we have no trade routes at all, we are certainly creating a new one. */ want += trader_trait; - } else if (trade_routes < max_routes) { + } else if (trade_routes < max_routes + && utype_can_do_action(unit_type, ACTION_TRADE_ROUTE)) { /* Possibly creating a new trade route */ want += trader_trait / 4; } Modified: trunk/ai/default/aiunit.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiunit.c?rev=27185&r1=27184&r2=27185&view=diff ============================================================================== --- trunk/ai/default/aiunit.c (original) +++ trunk/ai/default/aiunit.c Fri Dec 5 13:44:29 2014 @@ -2142,10 +2142,11 @@ CHECK_UNIT(punit); - /* FIXME: Support the Enter Marketplace action. */ - if (!unit_can_do_action(punit, ACTION_TRADE_ROUTE) && - !unit_has_type_flag(punit, UTYF_HELP_WONDER)) { - /* we only want units that can establish trade or help build wonders */ + if (!unit_can_do_action(punit, ACTION_TRADE_ROUTE) + && !unit_can_do_action(punit, ACTION_MARKETPLACE) + && !unit_has_type_flag(punit, UTYF_HELP_WONDER)) { + /* we only want units that can establish trade, enter marketplace or + * help build wonders */ return; } @@ -2184,8 +2185,10 @@ && !is_wonder(city_dest->production.value.building)) || (unit_data->task == AIUNIT_TRADE && real_map_distance(city_dest->tile, unit_tile(punit)) <= 1 - && !is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE, - punit, city_dest))) { + && !(is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE, + punit, city_dest) + || is_action_enabled_unit_on_city(ACTION_MARKETPLACE, + punit, city_dest)))) { /* destination invalid! */ dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); log_base(LOG_CARAVAN2, "%s %s[%d](%d,%d) destination invalid!", @@ -2533,6 +2536,7 @@ dai_manage_settler(ait, pplayer, punit); return; } else if (unit_can_do_action(punit, ACTION_TRADE_ROUTE) + || unit_can_do_action(punit, ACTION_MARKETPLACE) || unit_has_type_flag(punit, UTYF_HELP_WONDER)) { TIMING_LOG(AIT_CARAVAN, TIMER_START); dai_manage_caravan(ait, pplayer, punit); Modified: trunk/common/aicore/caravan.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/aicore/caravan.c?rev=27185&r1=27184&r2=27185&view=diff ============================================================================== --- trunk/common/aicore/caravan.c (original) +++ trunk/common/aicore/caravan.c Fri Dec 5 13:44:29 2014 @@ -54,9 +54,12 @@ const struct unit *caravan) { caravan_parameter_init_default(parameter); - if (!unit_has_type_flag(caravan, UTYF_TRADE_ROUTE)) { + if (!unit_can_do_action(caravan, ACTION_TRADE_ROUTE)) { + parameter->consider_trade = FALSE; + } + if (!unit_can_do_action(caravan, ACTION_MARKETPLACE) + && !unit_can_do_action(caravan, ACTION_TRADE_ROUTE)) { parameter->consider_windfall = FALSE; - parameter->consider_trade = FALSE; } if (!unit_has_type_flag(caravan, UTYF_HELP_WONDER)) { parameter->consider_wonders = FALSE; @@ -229,7 +232,8 @@ When the caravan arrives, compute the benefit from the immediate windfall, taking into account the parameter's objective. ***************************************************************************/ -static double windfall_benefit(const struct city *src, +static double windfall_benefit(const struct unit *caravan, + const struct city *src, const struct city *dest, const struct caravan_parameter *param) { if (!param->consider_windfall || !can_cities_trade(src, dest)) { @@ -237,7 +241,8 @@ } else { int bonus = get_caravan_enter_city_trade_bonus(src, dest); - bool can_establish = can_establish_trade_route(src, dest); + bool can_establish = (unit_can_do_action(caravan, ACTION_TRADE_ROUTE) + && can_establish_trade_route(src, dest)); /* we get the full bonus only if this is a new trade route. * Really, g_c_e_c_t_b should compute this. I copy from unithand.c */ @@ -434,7 +439,7 @@ } trade = trade_benefit(pplayer_src, src, dest, parameter); - windfall = windfall_benefit(src, dest, parameter); + windfall = windfall_benefit(caravan, src, dest, parameter); wonder = wonder_benefit(caravan, arrival_time, dest, parameter); /* we want to aid for wonder building */ wonder *= 2; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits