Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12734) calculate city's lux need
Home

[Freeciv-Dev] (PR#12734) calculate city's lux need

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12734) calculate city's lux need
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 11 Apr 2005 09:10:01 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch adds a new function city_luxury_need() which calculates how
much luxury a city needs to achieve contentment and/or celebration. Jason
tells me this could speed up the B&B CM a lot. So here goes.

  - Per

Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.325
diff -u -r1.325 city.c
--- common/city.c       10 Apr 2005 23:55:24 -0000      1.325
+++ common/city.c       11 Apr 2005 15:50:13 -0000
@@ -2641,3 +2641,36 @@
   unit_list_free(pcity->units_supported);
   free(pcity);
 }
+
+/**************************************************************************
+  Calculate necessary luxury to achieve goals for this city.
+
+  We ignore here the fact that specialists may be taken from unhappy
+  citizens when we no longer have any content ones left.
+**************************************************************************/
+int city_luxury_need(struct city *pcity, bool order, bool celebrate)
+{
+  struct player *pplayer = city_owner(pcity);
+  int result = 0;
+  int happy, content, unhappy, angry;
+
+  if (order || celebrate) {
+    /* We need to figure out how much luxuries we need. */
+    citizen_base_mood(pplayer, 0, &happy, &content, &unhappy, &angry,
+                      pcity->size);
+    citizen_content_buildings(pcity, &content, &unhappy, &angry);
+    citizen_happy_units(pcity, &happy, &content, &unhappy, &angry);
+    citizen_happy_wonders(pcity, &happy, &content, &unhappy, &angry);
+  }
+  if (order || celebrate) {
+    /* Find out how much luxuries we need to make everyone content. */
+    result += (angry * 2 + unhappy) * HAPPY_COST;
+  }
+  if (celebrate) {
+    /* Find out how much extra luxuries we will need to make enough
+     * citizens happy that we can celebrate. */
+    result += ((pcity->size + 1) / 2) * HAPPY_COST;
+  }
+
+  return result;
+}
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.204
diff -u -r1.204 city.h
--- common/city.h       10 Apr 2005 21:53:30 -0000      1.204
+++ common/city.h       11 Apr 2005 15:50:13 -0000
@@ -518,6 +518,7 @@
 bool is_city_option_set(const struct city *pcity, enum city_options option);
 void city_styles_alloc(int num);
 void city_styles_free(void);
+int city_luxury_need(struct city *pcity, bool order, bool celebrate);
 
 void get_citizen_output(const struct city *pcity, int *output);
 void add_tax_income(const struct player *pplayer, int trade, int *output);
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.17
diff -u -r1.17 fc_types.h
--- common/fc_types.h   29 Mar 2005 12:28:26 -0000      1.17
+++ common/fc_types.h   11 Apr 2005 15:50:13 -0000
@@ -54,6 +54,9 @@
 struct tile;
 struct unit;
 
+struct cm_parameter;
+struct cm_result;
+
 #define SP_MAX 20
 #define MAX_NUM_REQS 2
 

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