Author: sveinung
Date: Fri Nov  6 13:33:46 2015
New Revision: 30436

URL: http://svn.gna.org/viewcvs/freeciv?rev=30436&view=rev
Log:
client: maximize profit when disbanding a unit

At the moment a more profitable way will block a less profitable way.

Temporary down side: it becomes impossible to order a unit to Disband if
Recycle Unit is illegal but the player don't have enough information to
know that it is. Will only happen in custom rulesets where Recycle Unit is
forbidden based on something the player don't know.

See patch #6536

Modified:
    trunk/client/control.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=30436&r1=30435&r2=30436&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Fri Nov  6 13:33:46 2015
@@ -1653,6 +1653,34 @@
 **************************************************************************/
 void request_unit_disband(struct unit *punit)
 {
+  struct city *pcity;
+
+  if ((pcity = tile_city(unit_tile(punit)))) {
+    /* Try doing something more profitable. */
+
+    if (action_prob_possible(
+          action_prob_vs_city(punit, ACTION_HELP_WONDER, pcity))) {
+      /* Add 100% of the shields used to produce the unit to the current
+       * production of the city where it is located. */
+      request_do_action(ACTION_HELP_WONDER,
+                        punit->id, pcity->id, 0, "");
+      return;
+    }
+
+    if (action_prob_possible(
+          action_prob_vs_city(punit, ACTION_RECYCLE_UNIT, pcity))) {
+      /* Add 50% of the shields used to produce the unit to the current
+       * production of the city where it is located. */
+      request_do_action(ACTION_RECYCLE_UNIT,
+                        punit->id, pcity->id, 0, "");
+      return;
+    }
+
+    /* TODO: Should other actions that consumes the unit be considered?
+     * Join City may be an appealing alternative. Perhaps it should be a
+     * user configurable client option? */
+  }
+
   dsend_packet_unit_disband(&client.conn, punit->id);
 }
 


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

Reply via email to