[Freeciv-Dev] [Fwd: Re: (PR#18222) [Patch] AI builds caravans]
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
It seems that RT never sent this to the list.
After testing a lot of different versions, I think this works best
overall. I'll put this version in to more excessive testing. I plan to
commit this in a couple of days.
- ML
diff -Nurd -X.diff_ignore freeciv/ai/advdomestic.c freeciv/ai/advdomestic.c
--- freeciv/ai/advdomestic.c 2006-07-06 22:00:04.765625000 +0300
+++ freeciv/ai/advdomestic.c 2006-07-07 15:08:51.546875000 +0300
@@ -130,6 +130,104 @@
}
}
+/***************************************************************************
+ * Evaluate the need for units (like caravans) that create trade routes.
+ * If pplayer is not advanced enough to build caravans, the corresponding
+ * tech will be stimulated.
+ ***************************************************************************/
+static void ai_choose_trade_route(struct city *pcity,
+ struct ai_choice *choice,
+ struct ai_data *ai)
+{
+ struct player *pplayer = city_owner(pcity);
+ struct unit_type *unit_type;
+ int want;
+ int income, bonus;
+ int trade_routes;
+ Continent_id continent = tile_get_continent(pcity->tile);
+ bool dest_city_found = FALSE;
+
+ if (city_list_size(pplayer->cities) < 5) {
+ /* Consider trade routes only if enough destination cities.
+ * This is just a quick check. We make more detailed check below. */
+ return;
+ }
+
+ if (num_role_units(F_TRADE_ROUTE) == 0) {
+ /* No such units available in the ruleset */
+ return;
+ }
+
+ /* Look for proper destination city at the same continent. */
+ city_list_iterate(pplayer->cities, acity) {
+ if (can_cities_trade(pcity, acity) && tile_get_continent(acity->tile) ==
continent) {
+ dest_city_found = TRUE;
+ break;
+ }
+ } city_list_iterate_end;
+
+ if(!dest_city_found) {
+ /* No proper destination city at the same continent. */
+ return;
+ }
+
+ unit_type = best_role_unit(pcity, F_TRADE_ROUTE);
+
+ if (!unit_type) {
+ /* We cannot build such units yet
+ * but we will consider it to stimulate science */
+ unit_type = get_role_unit(F_TRADE_ROUTE, 0);
+ }
+
+ trade_routes = city_num_trade_routes(pcity);
+
+ /* 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. */
+
+ /* 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);
+
+ want = income * ai->gold_priority + income * ai->science_priority;
+
+ /* We get this income only once after all.
+ * This value is adjusted for most interesting gameplay.
+ * For optimal performance AI should build more caravans, but
+ * we want it to build less valued buildings too. */
+ want /= 130;
+
+ if (trade_routes == 0) {
+ /* If we have no trade routes at all, we are certainly creating a new one.
*/
+ want += 20;
+ } else if (trade_routes < NUM_TRADEROUTES) {
+ /* Possibly creating a new traderoute */
+ want += 5;
+ }
+
+ want -= unit_build_shield_cost(unit_type) * SHIELD_WEIGHTING / 150;
+
+ CITY_LOG(LOG_DEBUG, pcity,
+ "want for trade route unit is %d (expected initial income %d)",
+ want, income);
+
+ if (want > choice->want) {
+ /* This sets our tech want in cases where we cannot actually build
+ * the unit. */
+ unit_type = ai_wants_role_unit(pplayer, pcity, F_TRADE_ROUTE, want);
+ if (unit_type != NULL) {
+ choice->want = want;
+ choice->type = CT_NONMIL;
+ choice->choice = unit_type->index;
+ } else {
+ CITY_LOG(LOG_DEBUG, pcity,
+ "would but could not build trade route unit, bumped reqs");
+ }
+ }
+}
+
/**************************************************************************
This function should fill the supplied choice structure.
@@ -224,9 +322,14 @@
copy_if_better_choice(&cur, choice);
init_choice(&cur);
- /* Consider city improvments */
+ /* Consider city improvements */
ai_advisor_choose_building(pcity, &cur);
copy_if_better_choice(&cur, choice);
+
+ init_choice(&cur);
+ /* Consider building caravan-type units for trade route */
+ ai_choose_trade_route(pcity, &cur, ai);
+ copy_if_better_choice(&cur, choice);
}
if (choice->want >= 200) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] [Fwd: Re: (PR#18222) [Patch] AI builds caravans],
Marko Lindqvist <=
|
|