Author: sveinung
Date: Tue Jan  6 13:05:59 2015
New Revision: 27552

URL: http://svn.gna.org/viewcvs/freeciv?rev=27552&view=rev
Log:
Centralize the bonus reduction of Enter Marketplace.

Make get_caravan_enter_city_trade_bonus() handle the bonus reduction of
Enter Marketplace (without establishing a trade route).

See patch #5661

Modified:
    branches/S2_6/ai/default/advdomestic.c
    branches/S2_6/client/gui-sdl/action_dialog.c
    branches/S2_6/client/gui-sdl/menu.c
    branches/S2_6/client/gui-sdl2/action_dialog.c
    branches/S2_6/client/gui-sdl2/menu.c
    branches/S2_6/common/aicore/caravan.c
    branches/S2_6/common/traderoutes.c
    branches/S2_6/common/traderoutes.h
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/ai/default/advdomestic.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/advdomestic.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/ai/default/advdomestic.c      (original)
+++ branches/S2_6/ai/default/advdomestic.c      Tue Jan  6 13:05:59 2015
@@ -316,6 +316,9 @@
    * have four trade routes, if there already is route between them
    * or if the Establish Trade Route action is illegal. */
 
+  /* The calculations of get_caravan_enter_city_trade_bonus() have to be
+   * duplicated here because the city traded with is imaginary. */
+
   /* 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;

Modified: branches/S2_6/client/gui-sdl/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl/action_dialog.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl/action_dialog.c        (original)
+++ branches/S2_6/client/gui-sdl/action_dialog.c        Tue Jan  6 13:05:59 2015
@@ -890,7 +890,8 @@
   /* ---------- */
   if (action_prob_possible(act_probs[ACTION_TRADE_ROUTE])) {
     int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
-                                                     target_city);
+                                                     target_city,
+                                                     TRUE);
 
     fc_snprintf(cBuf, sizeof(cBuf),
                 /* TRANS: Estimated one time bonus and recurring revenue
@@ -909,9 +910,9 @@
   /* ---------- */
   if (action_prob_possible(act_probs[ACTION_MARKETPLACE])) {
     int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
-                                                     target_city);
-
-    revenue = (revenue + 2) / 3;
+                                                     target_city,
+                                                     FALSE);
+
     fc_snprintf(cBuf, sizeof(cBuf),
                 /* TRANS: Estimated one time bonus for the
                  * Enter Marketplace action. */

Modified: branches/S2_6/client/gui-sdl/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl/menu.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl/menu.c (original)
+++ branches/S2_6/client/gui-sdl/menu.c Tue Jan  6 13:05:59 2015
@@ -1145,7 +1145,8 @@
                                        ACTION_TRADE_ROUTE)
           && (pHomecity = game_city_by_number(pUnit->homecity))
           && can_cities_trade(pHomecity, pCity)) {
-       int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pCity);
+        int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pCity,
+                                                         TRUE);
        
         if (can_establish_trade_route(pHomecity, pCity)) {
           fc_snprintf(cBuf, sizeof(cBuf),

Modified: branches/S2_6/client/gui-sdl2/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/action_dialog.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/action_dialog.c       (original)
+++ branches/S2_6/client/gui-sdl2/action_dialog.c       Tue Jan  6 13:05:59 2015
@@ -895,7 +895,8 @@
   /* ---------- */
   if (action_prob_possible(act_probs[ACTION_TRADE_ROUTE])) {
     int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
-                                                     target_city);
+                                                     target_city,
+                                                     TRUE);
 
     fc_snprintf(cBuf, sizeof(cBuf),
                 /* TRANS: Estimated one time bonus and recurring revenue
@@ -914,9 +915,9 @@
   /* ---------- */
   if (action_prob_possible(act_probs[ACTION_MARKETPLACE])) {
     int revenue = get_caravan_enter_city_trade_bonus(actor_homecity,
-                                                     target_city);
-
-    revenue = (revenue + 2) / 3;
+                                                     target_city,
+                                                     FALSE);
+
     fc_snprintf(cBuf, sizeof(cBuf),
                 /* TRANS: Estimated one time bonus for the
                  * Enter Marketplace action. */

Modified: branches/S2_6/client/gui-sdl2/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/menu.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/menu.c        (original)
+++ branches/S2_6/client/gui-sdl2/menu.c        Tue Jan  6 13:05:59 2015
@@ -1135,7 +1135,8 @@
                                        ACTION_TRADE_ROUTE)
           && (pHomecity = game_city_by_number(pUnit->homecity))
           && can_cities_trade(pHomecity, pCity)) {
-        int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pCity);
+        int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pCity,
+                                                         TRUE);
 
         if (can_establish_trade_route(pHomecity, pCity)) {
           fc_snprintf(cBuf, sizeof(cBuf),

Modified: branches/S2_6/common/aicore/caravan.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/aicore/caravan.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/common/aicore/caravan.c       (original)
+++ branches/S2_6/common/aicore/caravan.c       Tue Jan  6 13:05:59 2015
@@ -240,16 +240,10 @@
     return 0;
   }
   else {
-    int bonus = get_caravan_enter_city_trade_bonus(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 */
-    if (!can_establish) {
-      bonus += 2;
-      bonus /= 3;
-    }
+    int bonus = get_caravan_enter_city_trade_bonus(src, dest,
+                                                   can_establish);
 
     /* bonus goes to both sci and gold. */
     bonus *= 2;

Modified: branches/S2_6/common/traderoutes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/traderoutes.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/common/traderoutes.c  (original)
+++ branches/S2_6/common/traderoutes.c  Tue Jan  6 13:05:59 2015
@@ -365,11 +365,12 @@
   trade route and also when you simply sell your trade goods at the
   new city.
 
-  Note if you trade with a city you already have a trade route with,
-  you'll only get 1/3 of this value.
+  If you change this calculation remember to also update its duplication
+  in dai_choose_trade_route()
 **************************************************************************/
 int get_caravan_enter_city_trade_bonus(const struct city *pc1, 
-                                       const struct city *pc2)
+                                       const struct city *pc2,
+                                       const bool establish_trade)
 {
   int tb, bonus;
 
@@ -386,6 +387,13 @@
   
   tb = (float)tb * pow(2.0, (double)bonus / 1000.0);
 
+  if (!establish_trade) {
+    /* There will only be a full bonus if a new trade route is
+     * established. The one time bonus from Enter Marketplace is about one
+     * third of the one time bonus from Establish Trade Route. */
+    tb = (tb + 2) / 3;
+  }
+
   return tb;
 }
 

Modified: branches/S2_6/common/traderoutes.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/traderoutes.h?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/common/traderoutes.h  (original)
+++ branches/S2_6/common/traderoutes.h  Tue Jan  6 13:05:59 2015
@@ -83,8 +83,9 @@
 bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
 int trade_between_cities(const struct city *pc1, const struct city *pc2);
 int city_num_trade_routes(const struct city *pcity);
-int get_caravan_enter_city_trade_bonus(const struct city *pc1, 
-                                       const struct city *pc2);
+int get_caravan_enter_city_trade_bonus(const struct city *pc1,
+                                       const struct city *pc2,
+                                       const bool establish_trade);
 int city_trade_removable(const struct city *pcity,
                          struct city_list *would_remove);
 

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=27552&r1=27551&r2=27552&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Tue Jan  6 13:05:59 2015
@@ -2315,11 +2315,8 @@
   /* We now know for sure whether we can establish a trade route. */
 
   /* Calculate and announce initial revenue. */
-  revenue = get_caravan_enter_city_trade_bonus(pcity_homecity, pcity_dest);
-  if (!can_establish) {
-    /* enter marketplace */
-    revenue = (revenue + 2) / 3;
-  }
+  revenue = get_caravan_enter_city_trade_bonus(pcity_homecity, pcity_dest,
+                                               can_establish);
 
   bonus_type = 
trade_route_settings_by_type(cities_trade_route_type(pcity_homecity, 
pcity_dest))->bonus_type;
   bonus_str = NULL;


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to