Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11379) Crazy CM recommends fast famine
Home

[Freeciv-Dev] (PR#11379) Crazy CM recommends fast famine

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: miky40@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#11379) Crazy CM recommends fast famine
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 8 Dec 2004 19:16:18 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11379 >

> [jing - Tue Dec 07 08:38:14 2004]:
> 
> CVS 06Dec2004 S2_0 Linux gtk+2.0
> 
> Load attached game (login as jing) and try auto arrange worker in
> Chengdu.  The CM will turn 4 workers into scientists, resulting in
> extreme shortage of food.  Not very smart.

Problem is cm_init_emergency_parameter is used as the fallback when a
surplus of 0 can't be reached.  And cm_init_emergency_parameter is
really bad.

This patch inserts a new set of parameters in first.  The surpluses
should always be makeable so it should never fail (rather clever I
think).  cm_init_emergency_parameter is still used as a final fallback
but should never be reached.

-jason

Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.283
diff -u -r1.283 cityturn.c
--- server/cityturn.c   8 Dec 2004 17:36:09 -0000       1.283
+++ server/cityturn.c   9 Dec 2004 03:12:57 -0000
@@ -245,9 +245,23 @@
       cm_query_result(pcity, &cmp, &cmr);
 
       if (!cmr.found_a_valid) {
-       /* Emergency management.  Get _some_ result. */
-        cm_init_emergency_parameter(&cmp);
+       /* Emergency management.  Get _some_ result.  This doesn't use
+        * cm_init_emergency_parameter so we can keep the factors from
+        * above. */
+       output_type_iterate(o) {
+         cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
+                                      MIN(pcity->surplus[o], 0));
+       } output_type_iterate_end;
+       cmp.require_happy = FALSE;
+       cmp.allow_disorder = TRUE;
        cm_query_result(pcity, &cmp, &cmr);
+
+       if (!cmr.found_a_valid) {
+         /* Should never happen. */
+         CITY_LOG(LOG_ERROR, pcity, "emergency management");
+         cm_init_emergency_parameter(&cmp);
+         cm_query_result(pcity, &cmp, &cmr);
+       }
       }
     } else {
       cmp.minimal_surplus[O_FOOD] = 0;
@@ -262,9 +276,23 @@
       }
 
       if (!cmr.found_a_valid) {
-       CITY_LOG(LOG_DEBUG, pcity, "emergency management");
-        cm_init_emergency_parameter(&cmp);
+       /* Emergency management.  Get _some_ result.  This doesn't use
+        * cm_init_emergency_parameter so we can keep the factors from
+        * above. */
+       output_type_iterate(o) {
+         cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
+                                      MIN(pcity->surplus[o], 0));
+       } output_type_iterate_end;
+       cmp.require_happy = FALSE;
+       cmp.allow_disorder = TRUE;
        cm_query_result(pcity, &cmp, &cmr);
+
+       if (!cmr.found_a_valid) {
+         /* Should never happen. */
+         CITY_LOG(LOG_ERROR, pcity, "emergency management");
+         cm_init_emergency_parameter(&cmp);
+         cm_query_result(pcity, &cmp, &cmr);
+       }
       }
     }
   }

[Prev in Thread] Current Thread [Next in Thread]