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

 This names steps of the happiness calculation. So when one wants to
check if another building could help happiness, one checks
ppl_unhappy[CITY_HAPPY_BUILDINGS] and not ppl_unhappy[2].


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aicity.c freeciv/ai/aicity.c
--- freeciv/ai/aicity.c	2007-01-26 11:00:49.000000000 +0200
+++ freeciv/ai/aicity.c	2007-01-28 23:31:18.000000000 +0200
@@ -345,14 +345,14 @@
     /* TODO */
     break;
   case EFT_NO_UNHAPPY:
-    v += (get_entertainers(pcity) + pcity->ppl_unhappy[4]) * 30;
+    v += (get_entertainers(pcity) + pcity->ppl_unhappy[CITY_HAPPY_FINAL]) * 30;
     break;
   case EFT_FORCE_CONTENT:
   case EFT_MAKE_CONTENT:
     if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
       int factor = 2;
 
-      v += MIN(amount, pcity->ppl_unhappy[4] + get_entertainers(pcity)) * 35;
+      v += MIN(amount, pcity->ppl_unhappy[CITY_HAPPY_FINAL] + get_entertainers(pcity)) * 35;
 
       /* Try to build wonders to offset empire size unhappiness */
       if (city_list_size(pplayer->cities) 
@@ -368,14 +368,14 @@
     break;
   case EFT_MAKE_CONTENT_MIL_PER:
     if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
-      v += MIN(pcity->ppl_unhappy[4] + get_entertainers(pcity),
+      v += MIN(pcity->ppl_unhappy[CITY_HAPPY_FINAL] + get_entertainers(pcity),
 	       amount) * 25;
       v += MIN(amount, 5) * c;
     }
     break;
   case EFT_MAKE_CONTENT_MIL:
     if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
-      v += pcity->ppl_unhappy[4] * amount
+      v += pcity->ppl_unhappy[CITY_HAPPY_FINAL] * amount
         * MAX(unit_list_size(pcity->units_supported), 0) * 2;
       v += c * MAX(amount + 2, 1);
     }
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c	2007-01-26 11:00:49.000000000 +0200
+++ freeciv/common/city.c	2007-01-28 22:52:33.000000000 +0200
@@ -996,9 +996,9 @@
 **************************************************************************/
 bool city_happy(const struct city *pcity)
 {
-  return (pcity->ppl_happy[4] >= (pcity->size + 1) / 2
-	  && pcity->ppl_unhappy[4] == 0
-          && pcity->ppl_angry[4] == 0
+  return (pcity->ppl_happy[CITY_HAPPY_FINAL] >= (pcity->size + 1) / 2
+	  && pcity->ppl_unhappy[CITY_HAPPY_FINAL] == 0
+          && pcity->ppl_angry[CITY_HAPPY_FINAL] == 0
           && pcity->size >= game.info.celebratesize);
 }
 
@@ -1008,8 +1008,9 @@
 **************************************************************************/
 bool city_unhappy(const struct city *pcity)
 {
-  return (pcity->ppl_happy[4] <
-	  pcity->ppl_unhappy[4] + 2 * pcity->ppl_angry[4]);
+  return (pcity->ppl_happy[CITY_HAPPY_FINAL] <
+	  pcity->ppl_unhappy[CITY_HAPPY_FINAL] +
+          2 * pcity->ppl_angry[CITY_HAPPY_FINAL]);
 }
 
 /**************************************************************************
@@ -1710,10 +1711,13 @@
 {
   int x = pcity->prod[O_LUXURY];
 
-  happy_copy(pcity, 0);
+  happy_copy(pcity, CITY_HAPPY_EMPIRE);
 
-  citizen_luxury_happy(pcity, &x, &pcity->ppl_angry[1], &pcity->ppl_unhappy[1], 
-                       &pcity->ppl_happy[1], &pcity->ppl_content[1]);
+  citizen_luxury_happy(pcity, &x,
+                       &pcity->ppl_angry[CITY_HAPPY_LUXURY],
+                       &pcity->ppl_unhappy[CITY_HAPPY_LUXURY], 
+                       &pcity->ppl_happy[CITY_HAPPY_LUXURY],
+                       &pcity->ppl_content[CITY_HAPPY_LUXURY]);
 }
 
 /**************************************************************************
@@ -2116,24 +2120,33 @@
   add_specialist_output(pcity, pcity->citizen_base);
 
   set_city_production(pcity);
-  citizen_base_mood(pplayer, city_specialists(pcity), &pcity->ppl_happy[0], 
-                    &pcity->ppl_content[0], &pcity->ppl_unhappy[0], 
-                    &pcity->ppl_angry[0], pcity->size);
+  citizen_base_mood(pplayer, city_specialists(pcity),
+                    &pcity->ppl_happy[CITY_HAPPY_EMPIRE], 
+                    &pcity->ppl_content[CITY_HAPPY_EMPIRE],
+                    &pcity->ppl_unhappy[CITY_HAPPY_EMPIRE], 
+                    &pcity->ppl_angry[CITY_HAPPY_EMPIRE],
+                    pcity->size);
   pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
   citizen_happy_luxury(pcity);	/* with our new found luxuries */
-  happy_copy(pcity, 1);
-  citizen_content_buildings(pcity, &pcity->ppl_content[2], 
-                            &pcity->ppl_unhappy[2], &pcity->ppl_angry[2]);
-  happy_copy(pcity, 2);
+  happy_copy(pcity, CITY_HAPPY_LUXURY);
+  citizen_content_buildings(pcity,
+                            &pcity->ppl_content[CITY_HAPPY_BUILDINGS], 
+                            &pcity->ppl_unhappy[CITY_HAPPY_BUILDINGS],
+                            &pcity->ppl_angry[CITY_HAPPY_BUILDINGS]);
+  happy_copy(pcity, CITY_HAPPY_BUILDINGS);
   /* Martial law & unrest from units */
-  citizen_happy_units(pcity, &pcity->ppl_happy[3],
-                      &pcity->ppl_content[3], &pcity->ppl_unhappy[3], 
-                      &pcity->ppl_angry[3]);
-  happy_copy(pcity, 3);
+  citizen_happy_units(pcity,
+                      &pcity->ppl_happy[CITY_HAPPY_MARTIAL],
+                      &pcity->ppl_content[CITY_HAPPY_MARTIAL],
+                      &pcity->ppl_unhappy[CITY_HAPPY_MARTIAL], 
+                      &pcity->ppl_angry[CITY_HAPPY_MARTIAL]);
+  happy_copy(pcity, CITY_HAPPY_MARTIAL);
   /* Building (including wonder) happiness effects */
-  citizen_happy_wonders(pcity, &pcity->ppl_happy[4],
-                      &pcity->ppl_content[4], &pcity->ppl_unhappy[4],
-                      &pcity->ppl_angry[4]);
+  citizen_happy_wonders(pcity,
+                        &pcity->ppl_happy[CITY_HAPPY_WONDERS],
+                        &pcity->ppl_content[CITY_HAPPY_WONDERS],
+                        &pcity->ppl_unhappy[CITY_HAPPY_WONDERS],
+                        &pcity->ppl_angry[CITY_HAPPY_WONDERS]);
   unhappy_city_check(pcity);
   set_surpluses(pcity);
 
diff -Nurd -X.diff_ignore freeciv/common/city.h freeciv/common/city.h
--- freeciv/common/city.h	2007-01-19 16:20:07.000000000 +0200
+++ freeciv/common/city.h	2007-01-28 22:54:52.000000000 +0200
@@ -150,6 +150,14 @@
 #define ASSERT_REAL_CHOICE_TYPE(type)                                    \
         assert(type >= 0 && type < CT_LAST /* && type != CT_NONE */ );
 
+/* Do not change order of these unless you really know what you are doing! */
+#define CITY_HAPPY_EMPIRE    0
+#define CITY_HAPPY_LUXURY    1
+#define CITY_HAPPY_BUILDINGS 2
+#define CITY_HAPPY_MARTIAL   3
+#define CITY_HAPPY_WONDERS   4
+#define CITY_HAPPY_FINAL     CITY_HAPPY_WONDERS
+
 
 struct ai_choice {
   int choice;            /* what the advisor wants */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to