Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] (PR#14746) More governments generalization
Home

[Freeciv-Dev] (PR#14746) More governments generalization

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14746) More governments generalization
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 2 Dec 2005 03:33:17 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch:
 - adds three new effects: Unhappy_Factor, Upkeep_Factor and
   Unit_Upkeep_Free_Per_City
 - removes unit_*_factor and unit_free_* in governments.ruleset
 - adds new aux functions to effects code: get_player_output_bonus and
   get_city_output_bonus (existing get_city_output_bonus renamed to
   get_final_city_output_bonus)
 - free shield upkeep for units in anarchy and despotism is changed from
   equal to city size to 3 (equal to monarchy and communism); it was just
   to difficult to accomodate this special but non-important feature in a
   clean way - I _can_ put this back in as a magic constant, but I'd
   rather not

The next step is to generalize and simplify the waste (corruption)
concept.

  - Per

Index: server/score.c
===================================================================
--- server/score.c      (revision 11288)
+++ server/score.c      (working copy)
@@ -267,7 +267,7 @@
     pplayer->score.bnp += pcity->surplus[O_TRADE];
     pplayer->score.mfg += pcity->surplus[O_SHIELD];
 
-    bonus = get_city_output_bonus(pcity, O_SCIENCE) - 100;
+    bonus = get_final_city_output_bonus(pcity, O_SCIENCE) - 100;
     bonus = CLIP(0, bonus, 100);
     pplayer->score.literacy += (city_population(pcity) * bonus) / 100;
   } city_list_iterate_end;
Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 11288)
+++ server/ruleset.c    (working copy)
@@ -68,8 +68,6 @@
 static Impr_type_id lookup_impr_type(struct section_file *file, const char 
*prefix,
                                     const char *entry, bool required,
                                     const char *filename, const char 
*description);
-static int lookup_city_cost(struct section_file *file, const char *prefix,
-                           const char *entry, const char *filename);
 static char *lookup_helptext(struct section_file *file, char *prefix);
 
 static struct terrain *lookup_terrain(char *name, struct terrain *tthis);
@@ -588,37 +586,6 @@
 }
 
 /**************************************************************************
-  Lookup entry in the file and return the corresponding city cost:
-  value if int, or G_CITY_SIZE_FREE is entry is "City_Size".
-  Dies if gets some other string.  filename is for error message.
-
-  Returns 0 if no value is given in the ruleset.
-**************************************************************************/
-static int lookup_city_cost(struct section_file *file, const char *prefix,
-                           const char *entry, const char *filename)
-{
-  char *sval;
-  int ival = 0;
-
-  if (!section_file_lookup(file, "%s.%s", prefix, entry)) {
-    /* Default to 0. */
-    return 0;
-  }
-  
-  sval = secfile_lookup_str_int(file, &ival, "%s.%s", prefix, entry);
-  if (sval) {
-    if (mystrcasecmp(sval, "City_Size") == 0) {
-      ival = G_CITY_SIZE_FREE;
-    } else {
-      freelog(LOG_FATAL, "Bad %s \"%s\" for %s (%s)",
-             entry, sval, prefix, filename);
-      exit(EXIT_FAILURE);
-    }
-  }
-  return ival;
-}
-
-/**************************************************************************
   Lookup optional string, returning allocated memory or NULL.
 **************************************************************************/
 static char *lookup_string(struct section_file *file, const char *prefix,
@@ -1727,23 +1694,7 @@
     sz_strlcpy(g->graphic_alt,
               secfile_lookup_str(file, "%s.graphic_alt", sec[i]));
     
-    g->free_happy
-      = lookup_city_cost(file, sec[i], "unit_free_unhappy", filename);
-
-    g->unit_happy_cost_factor
-      = secfile_lookup_int(file, "%s.unit_unhappy_factor", sec[i]);
-
     output_type_iterate(o) {
-      char buf[128];
-
-      my_snprintf(buf, sizeof(buf), "unit_free_%s",
-                 get_output_identifier(o));
-      g->free_upkeep[o] = lookup_city_cost(file, sec[i], buf, filename);
-
-      g->unit_upkeep_factor[o]
-       = secfile_lookup_int_default(file, 0, "%s.unit_%s_factor", sec[i],
-                                    get_output_identifier(o));
-
       if (waste_name[o]) {
        g->waste[o].level = secfile_lookup_int(file, "%s.%s_level",
                                               sec[i], waste_name[o]);
@@ -2901,13 +2852,7 @@
     } requirement_vector_iterate_end;
     gov.reqs_count = j;
 
-    gov.unit_happy_cost_factor  = g->unit_happy_cost_factor;
-    gov.free_happy  = g->free_happy;
-
     output_type_iterate(o) {
-      gov.free_upkeep[o] = g->free_upkeep[o];
-      gov.unit_upkeep_factor[o] = g->unit_upkeep_factor[o];
-
       gov.output_before_penalty[o] = g->output_before_penalty[o];
       gov.celeb_output_before_penalty[o] = g->celeb_output_before_penalty[o];
       gov.output_inc_tile[o] = g->output_inc_tile[o];
Index: data/civ1/effects.ruleset
===================================================================
--- data/civ1/effects.ruleset   (revision 11288)
+++ data/civ1/effects.ruleset   (working copy)
@@ -62,7 +62,60 @@
 name    = "City_Vision_Radius_Sq"
 value   = 5
 
+[effect_base_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
 
+[effect_republic_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_democracy_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_republic_unit_unhappiness]
+name  = "Unhappy_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
+
+[effect_democracy_unit_unhappiness]
+name  = "Unhappy_Factor"
+value = 2
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+    }
+
+[effect_upkeep_free_units_anarchy]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Anarchy", "Player"
+    }
+
+[effect_upkeep_free_units_despotism]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Despotism", "Player"
+    }
+
 [effect_civil_war_0]
 name    = "Civil_War_Chance"
 value   = 90
Index: data/civ1/governments.ruleset
===================================================================
--- data/civ1/governments.ruleset       (revision 11288)
+++ data/civ1/governments.ruleset       (working copy)
@@ -39,11 +39,6 @@
 ;               should be a standard tag if preferred is not;
 ;              otherwise may be "-"
 
-; unit_*_factor = factor applied to individual unit upkeep for different 
-;                upkeep forms
-; unit_free_*   = base unit upkeep cost which the city gets "free"; only
-;                upkeep above this value applies; special value: "City_Size"
-
 ; corruption:
  
 ; _level            = percentage factor applied to corruption multiplied
@@ -87,16 +82,6 @@
 graphic     = "gov.anarchy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 0   ; ??
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 250
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -153,16 +138,6 @@
 graphic_alt = "-"
 ai_better   = "Monarchy"
 
-unit_unhappy_factor = 0 
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 370
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 2 
@@ -220,16 +195,6 @@
 graphic_alt = "-"
 ai_better   = "Communism"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 150
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -284,16 +249,6 @@
 graphic     = "gov.communism"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 62
 corruption_fixed_distance   = 10
 corruption_distance_factor  = 1 
@@ -356,16 +311,6 @@
 graphic     = "gov.republic"
 graphic_alt = "-"
 
-unit_unhappy_factor = 1
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 150
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -431,16 +376,6 @@
 graphic     = "gov.democracy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 2
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 0
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 0 
Index: data/civ2/effects.ruleset
===================================================================
--- data/civ2/effects.ruleset   (revision 11288)
+++ data/civ2/effects.ruleset   (working copy)
@@ -63,7 +63,110 @@
 name    = "City_Vision_Radius_Sq"
 value   = 5
 
+[effect_republic]
+name  = "Make_Content_Mil"
+value = 1
+reqs  =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
 
+[effect_base_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
+
+[effect_communism_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 2
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Communism", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_fundamentalism_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 2
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Fundamentalism", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_republic_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_democracy_unit_upkeep]
+name  = "Upkeep_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_republic_unit_unhappiness]
+name  = "Unhappy_Factor"
+value = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
+
+[effect_democracy_unit_unhappiness]
+name  = "Unhappy_Factor"
+value = 2
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+    }
+
+[effect_upkeep_free_units_anarchy]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Anarchy", "Player"
+    }
+
+[effect_upkeep_free_units_despotism]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Despotism", "Player"
+    }
+
+[effect_upkeep_free_units_monarchy]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Monarchy", "Player"
+    }
+
+[effect_upkeep_free_units_communism]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Communism", "Player"
+    }
+
+[effect_upkeep_free_units_fundamentalism]
+name  = "Unit_Upkeep_Free_Per_City"
+value = 10
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Fundamentalism", "Player"
+    }
+
 [effect_civil_war_0]
 name    = "Civil_War_Chance"
 value   = 90
Index: data/civ2/governments.ruleset
===================================================================
--- data/civ2/governments.ruleset       (revision 11288)
+++ data/civ2/governments.ruleset       (working copy)
@@ -37,11 +37,6 @@
 ;               should be a standard tag if preferred is not;
 ;              otherwise may be "-"
 
-; unit_*_factor = factor applied to individual unit upkeep for different 
-;                upkeep forms
-; unit_free_*   = base unit upkeep cost which the city gets "free"; only
-;                upkeep above this value applies; special value: "City_Size"
-
 ; corruption:
  
 ; _level            = percentage factor applied to corruption multiplied
@@ -84,16 +79,6 @@
 graphic     = "gov.anarchy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 0   ; ??
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 375
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -150,16 +135,6 @@
 graphic_alt = "-"
 ai_better   = "Monarchy"
 
-unit_unhappy_factor = 0 
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 300
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -219,16 +194,6 @@
 graphic_alt = "-"
 ai_better   = "Communism"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 3
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 250
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -286,16 +251,6 @@
 graphic     = "gov.communism"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1
-
-unit_free_unhappy = 0
-unit_free_shield  = 3
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 215
 corruption_fixed_distance   = 1
 corruption_distance_factor  = 1 
@@ -360,16 +315,6 @@
 graphic     = "gov.fundamentalism"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 10
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 1
 corruption_fixed_distance   = 1
 corruption_distance_factor  = 1 
@@ -437,16 +382,6 @@
 graphic     = "gov.republic"
 graphic_alt = "-"
 
-unit_unhappy_factor = 1
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 1
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 187
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -515,16 +450,6 @@
 graphic     = "gov.democracy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 2
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 0
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 0 
Index: data/default/effects.ruleset
===================================================================
--- data/default/effects.ruleset        (revision 11288)
+++ data/default/effects.ruleset        (working copy)
@@ -93,6 +93,84 @@
       "UnitClass", "Sea", "Local"
     }
 
+[effect_republic]
+name   = "Make_Content_Mil"
+value  = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
+
+[effect_base_unit_upkeep]
+name   = "Upkeep_Factor"
+value  = 1
+
+[effect_republic_unit_upkeep]
+name   = "Upkeep_Factor"
+value  = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_democracy_unit_upkeep]
+name   = "Upkeep_Factor"
+value  = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+      "OutputType", "Food", "Local"
+    }
+
+[effect_republic_unit_unhappiness]
+name   = "Unhappy_Factor"
+value  = 1
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
+
+[effect_democracy_unit_unhappiness]
+name   = "Unhappy_Factor"
+value  = 2
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Democracy", "Player"
+    }
+
+[effect_upkeep_free_units_anarchy]
+name   = "Unit_Upkeep_Free_Per_City"
+value  = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Anarchy", "Player"
+    }
+
+[effect_upkeep_free_units_despotism]
+name   = "Unit_Upkeep_Free_Per_City"
+value  = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Despotism", "Player"
+    }
+
+[effect_upkeep_free_units_monarchy]
+name   = "Unit_Upkeep_Free_Per_City"
+value  = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Monarchy", "Player"
+    }
+
+[effect_upkeep_free_units_communism]
+name   = "Unit_Upkeep_Free_Per_City"
+value  = 3
+reqs   =
+    { "type", "name", "range"
+      "Gov", "Communism", "Player"
+    }
+
 [effect_civil_war_0]
 name    = "Civil_War_Chance"
 value   = 90
Index: data/default/governments.ruleset
===================================================================
--- data/default/governments.ruleset    (revision 11288)
+++ data/default/governments.ruleset    (working copy)
@@ -39,11 +39,6 @@
 ; ai_better   = AI will not consider this government for use if the
 ;               government listed here is available
 
-; unit_*_factor = factor applied to individual unit upkeep for different 
-;                upkeep forms
-; unit_free_*   = base unit upkeep cost which the city gets "free"; only
-;                upkeep above this value applies; special value: "City_Size"
-
 ; corruption:
  
 ; _level            = percentage factor applied to corruption multiplied 
@@ -86,16 +81,6 @@
 graphic     = "gov.anarchy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 0   ; ??
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 250
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -138,16 +123,6 @@
 graphic_alt = "-"
 ai_better   = "Monarchy"
 
-unit_unhappy_factor = 0 
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = "City_Size"
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 370
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 2 
@@ -190,16 +165,6 @@
 graphic_alt = "-"
 ai_better   = "Communism"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 3
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 150
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -241,16 +206,6 @@
 graphic     = "gov.communism"
 graphic_alt = "-"
 
-unit_unhappy_factor = 0
-unit_shield_factor  = 1
-unit_food_factor    = 1
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 3
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 62
 corruption_fixed_distance   = 10
 corruption_distance_factor  = 1 
@@ -298,16 +253,6 @@
 graphic     = "gov.republic"
 graphic_alt = "-"
 
-unit_unhappy_factor = 1
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 1
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 150
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 1 
@@ -352,16 +297,6 @@
 graphic     = "gov.democracy"
 graphic_alt = "-"
 
-unit_unhappy_factor = 2
-unit_shield_factor  = 1
-unit_food_factor    = 2
-unit_gold_factor    = 1 
-
-unit_free_unhappy = 0
-unit_free_shield  = 0
-unit_free_food    = 0
-unit_free_gold    = 0
-
 corruption_level            = 0
 corruption_fixed_distance   = 0
 corruption_distance_factor  = 0 
Index: data/history/effects.ruleset
===================================================================
--- data/history/effects.ruleset        (revision 11288)
+++ data/history/effects.ruleset        (working copy)
@@ -84,6 +84,14 @@
       "UnitClass", "Sea", "Local"
     }
 
+[effect_republic]
+name  = "Make_Content_Mil"
+value = 1
+reqs  =
+    { "type", "name", "range"
+      "Gov", "Republic", "Player"
+    }
+
 [effect_airport]
 name   = "Veteran_Build"
 value  = 1
Index: data/history/governments.ruleset
===================================================================
--- data/history/governments.ruleset    (revision 11288)
+++ data/history/governments.ruleset    (working copy)
@@ -117,7 +117,6 @@
 unit_food_factor    = 1
 unit_gold_factor    = 0   ; ??
 
-unit_free_unhappy = 0
 unit_free_shield  = "City_Size"
 unit_free_food    = 0
 unit_free_gold    = 0
@@ -192,7 +191,6 @@
 unit_food_factor    = 1
 unit_gold_factor    = 1 
 
-unit_free_unhappy = 0
 unit_free_shield  = "City_Size"
 unit_free_food    = 0
 unit_free_gold    = 0
@@ -270,7 +268,6 @@
 unit_food_factor    = 1
 unit_gold_factor    = 1 
 
-unit_free_unhappy = 0
 unit_free_shield  = 3
 unit_free_food    = 0
 unit_free_gold    = 0
@@ -346,7 +343,6 @@
 unit_food_factor    = 1
 unit_gold_factor    = 1 
 
-unit_free_unhappy = 0
 unit_free_shield  = 3
 unit_free_food    = 0
 unit_free_gold    = 0
@@ -429,7 +425,6 @@
 unit_food_factor    = 2
 unit_gold_factor    = 1 
 
-unit_free_unhappy = 1
 unit_free_shield  = 0
 unit_free_food    = 0
 unit_free_gold    = 0
@@ -516,7 +511,6 @@
 unit_food_factor    = 2
 unit_gold_factor    = 1 
 
-unit_free_unhappy = 0
 unit_free_shield  = 0
 unit_free_food    = 0
 unit_free_gold    = 0
Index: common/unittype.c
===================================================================
--- common/unittype.c   (revision 11288)
+++ common/unittype.c   (working copy)
@@ -102,21 +102,26 @@
 int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
                      const struct government *g, Output_type_id otype)
 {
+  int val = ut->upkeep[otype];
+
   if (get_player_bonus(pplayer, EFT_FANATICS)
       && BV_ISSET(ut->flags, F_FANATIC)) {
     /* Special case: fanatics have no upkeep under fanaticism. */
     return 0;
   }
-  return ut->upkeep[otype] * g->unit_upkeep_factor[otype];
+  val *= get_player_output_bonus(pplayer, get_output_type(otype), 
+                                 EFT_UPKEEP_FACTOR);
+  return val;
 }
 
 /**************************************************************************
   Return the "happy cost" (the number of citizens who are discontented)
   for this unit.
 **************************************************************************/
-int utype_happy_cost(const struct unit_type *ut, const struct government *g)
+int utype_happy_cost(const struct unit_type *ut, 
+                     const struct player *pplayer)
 {
-  return ut->happy_cost * g->unit_happy_cost_factor;
+  return ut->happy_cost * get_player_bonus(pplayer, EFT_UNHAPPY_FACTOR);
 }
 
 /**************************************************************************
Index: common/unittype.h
===================================================================
--- common/unittype.h   (revision 11288)
+++ common/unittype.h   (working copy)
@@ -220,7 +220,7 @@
 
 int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
                       const struct government *g, Output_type_id otype);
-int utype_happy_cost(const struct unit_type *ut, const struct government *g);
+int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer);
 
 struct unit_type *can_upgrade_unittype(const struct player *pplayer,
                                       const struct unit_type *punittype);
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11288)
+++ common/packets.def  (working copy)
@@ -1115,12 +1115,6 @@
   UINT8 reqs_count;
   REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
 
-  UINT8 unit_happy_cost_factor;
-  UINT8 unit_upkeep_factor[O_MAX];
-      
-  UINT8 free_happy;
-  UINT8 free_upkeep[O_MAX];
-
   UINT8 output_before_penalty[O_MAX];
   UINT8 celeb_output_before_penalty[O_MAX];
   UINT8 output_inc_tile[O_MAX];
Index: common/city.c
===================================================================
--- common/city.c       (revision 11288)
+++ common/city.c       (working copy)
@@ -1073,33 +1073,6 @@
 }
 
 /**************************************************************************
-  Return the number of free units of upkeep for unit support the city
-  would get under the given government.
-**************************************************************************/
-int citygov_free_upkeep(const struct city *pcity,
-                       const struct government *gov, Output_type_id otype)
-{
-  if (gov->free_upkeep[otype] == G_CITY_SIZE_FREE) {
-    return pcity->size;
-  } else {
-    return gov->free_upkeep[otype];
-  }
-}
-
-/**************************************************************************
-  Return how many citizens may be made content by military garrisons under
-  this government type.
-**************************************************************************/
-int citygov_free_happy(const struct city *pcity, const struct government *gov)
-{
-  if (gov->free_happy == G_CITY_SIZE_FREE) {
-    return pcity->size;
-  } else {
-    return gov->free_happy;
-  }
-}
-
-/**************************************************************************
 Evaluate which style should be used to draw a city.
 **************************************************************************/
 int get_city_style(const struct city *pcity)
@@ -1463,7 +1436,7 @@
 /**************************************************************************
  Return the factor (in %) by which the city's output should be multiplied.
 **************************************************************************/
-int get_city_output_bonus(const struct city *pcity, Output_type_id otype)
+int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
 {
   struct output_type *output = &output_types[otype];
   int bonus1 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
@@ -1585,7 +1558,7 @@
 static inline void set_city_bonuses(struct city *pcity)
 {
   output_type_iterate(o) {
-    pcity->bonus[o] = get_city_output_bonus(pcity, o);
+    pcity->bonus[o] = get_final_city_output_bonus(pcity, o);
   } output_type_iterate_end;
 }
 
@@ -1985,15 +1958,12 @@
 {
   struct player *plr = city_owner(pcity);
   struct government *g = get_gov_pcity(pcity);
-
-  int free_happy = citygov_free_happy(pcity, g);
   int free_upkeep[O_COUNT];
+  int free_happy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
 
-  /* ??  This does the right thing for normal Republic and Democ -- dwp */
-  free_happy += get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
-
   output_type_iterate(o) {
-    free_upkeep[o] = citygov_free_upkeep(pcity, g, o);
+    free_upkeep[o] = get_city_output_bonus(pcity, get_output_type(o), 
+                                           EFT_UNIT_UPKEEP_FREE_PER_CITY);
   } output_type_iterate_end;
 
   /* Clear all usage values. */
@@ -2033,7 +2003,7 @@
   unit_list_iterate(pcity->units_supported, this_unit) {
     struct unit_type *ut = unit_type(this_unit);
     int upkeep_cost[O_COUNT], old_upkeep[O_COUNT];
-    int happy_cost = utype_happy_cost(ut, g);
+    int happy_cost = utype_happy_cost(ut, plr);
     bool changed = FALSE;
 
     /* Save old values so we can decide if the unit info should be resent */
@@ -2247,8 +2217,7 @@
    * roundoff errors. */
   val = total * MAX(dist, 1) * waste->level;
 
-  /* FIXME: should be a get_city_output_bonus? */
-  val -= (val * get_city_tile_output_bonus(pcity, NULL, &output_types[otype],
+  val -= (val * get_city_output_bonus(pcity, &output_types[otype],
                                           EFT_OUTPUT_WASTE_PCT)) / 100;
 
   val /= 100 * 100; /* Level is a % multiplied by 100 */
Index: common/city.h
===================================================================
--- common/city.h       (revision 11288)
+++ common/city.h       (working copy)
@@ -452,12 +452,6 @@
 
 int city_name_compare(const void *p1, const void *p2);
 
-/* city free cost values depending on government: */
-int citygov_free_upkeep(const struct city *pcity,
-                       const struct government *gov, Output_type_id otype);
-int citygov_free_happy(const struct city *pcity,
-                      const struct government *gov);
-
 /* city style functions */
 int get_city_style(const struct city *pcity);
 int get_player_city_style(const struct player *plr);
@@ -498,7 +492,7 @@
 int city_specialists(const struct city *pcity);                 /* 
elv+tax+scie */
 Specialist_type_id best_specialist(Output_type_id otype,
                                   const struct city *pcity);
-int get_city_output_bonus(const struct city *pcity, Output_type_id otype);
+int get_final_city_output_bonus(const struct city *pcity, Output_type_id 
otype);
 bool city_built_last_turn(const struct city *pcity);
 
 /* city creation / destruction */
Index: common/effects.c
===================================================================
--- common/effects.c    (revision 11288)
+++ common/effects.c    (working copy)
@@ -109,7 +109,10 @@
   "Happiness_To_Gold",
   "Fanatics",
   "No_Diplomacy",
-  "Trade_Revenue_Bonus"
+  "Trade_Revenue_Bonus",
+  "Unhappy_Factor",
+  "Upkeep_Factor",
+  "Unit_Upkeep_Free_Per_City"
 };
 
 static bool initialized = FALSE;
@@ -807,6 +810,34 @@
 }
 
 /**************************************************************************
+  Returns the player effect bonus of an output.
+**************************************************************************/
+int get_player_output_bonus(const struct player *pplayer,
+                            const struct output_type *poutput,
+                            enum effect_type effect_type)
+{
+  assert(pplayer != NULL);
+  assert(poutput != NULL);
+  assert(effect_type != EFT_LAST);
+  return get_target_bonus_effects(NULL, pplayer, NULL, NULL, NULL,
+                                  NULL, poutput, NULL, effect_type);
+}
+
+/**************************************************************************
+  Returns the player effect bonus of an output.
+**************************************************************************/
+int get_city_output_bonus(const struct city *pcity,
+                          const struct output_type *poutput,
+                          enum effect_type effect_type)
+{
+  assert(pcity != NULL);
+  assert(poutput != NULL);
+  assert(effect_type != EFT_LAST);
+  return get_target_bonus_effects(NULL, city_owner(pcity), pcity, NULL,
+                                  NULL, NULL, poutput, NULL, effect_type);
+}
+
+/**************************************************************************
   Returns the effect bonus at a building.
 **************************************************************************/
 int get_building_bonus(const struct city *pcity, Impr_type_id id,
Index: common/effects.h
===================================================================
--- common/effects.h    (revision 11288)
+++ common/effects.h    (working copy)
@@ -98,6 +98,9 @@
   EFT_FANATICS, /* stupid special case, we hatess it */
   EFT_NO_DIPLOMACY,
   EFT_TRADE_REVENUE_BONUS,
+  EFT_UNHAPPY_FACTOR, /* multiply unhappy upkeep by this effect */
+  EFT_UPKEEP_FACTOR,  /* multiply upkeep by this effect */
+  EFT_UNIT_UPKEEP_FREE_PER_CITY, /* this many units are free from upkeep */
   EFT_LAST     /* keep this last */
 };
 
@@ -172,6 +175,12 @@
                               const struct tile *ptile,
                               const struct output_type *poutput,
                               enum effect_type effect_type);
+int get_player_output_bonus(const struct player *pplayer,
+                            const struct output_type *poutput,
+                            enum effect_type effect_type);
+int get_city_output_bonus(const struct city *pcity,
+                          const struct output_type *poutput,
+                          enum effect_type effect_type);
 int get_building_bonus(const struct city *pcity, Impr_type_id building,
                       enum effect_type effect_type);
 int get_unittype_bonus(const struct player *pplayer,
Index: common/packets_gen.h
===================================================================
--- common/packets_gen.h        (revision 11288)
+++ common/packets_gen.h        (working copy)
@@ -834,10 +834,6 @@
   int id;
   int reqs_count;
   struct requirement reqs[MAX_NUM_REQS];
-  int unit_happy_cost_factor;
-  int unit_upkeep_factor[O_MAX];
-  int free_happy;
-  int free_upkeep[O_MAX];
   int output_before_penalty[O_MAX];
   int celeb_output_before_penalty[O_MAX];
   int output_inc_tile[O_MAX];
Index: common/government.h
===================================================================
--- common/government.h (revision 11288)
+++ common/government.h (working copy)
@@ -54,14 +54,6 @@
   struct ruler_title *ruler_titles;
   int   num_ruler_titles;
 
-  /* unit cost modifiers */
-  int unit_happy_cost_factor;
-  int unit_upkeep_factor[O_MAX];
-  
-  /* base cost that a city does not have to "pay" for */
-  int free_happy;
-  int free_upkeep[O_MAX];
-  
   /* government production penalties (when celebrating and when not) */
   int output_before_penalty[O_MAX];
   int celeb_output_before_penalty[O_MAX];
Index: ai/aitools.c
===================================================================
--- ai/aitools.c        (revision 11288)
+++ ai/aitools.c        (working copy)
@@ -1211,17 +1211,13 @@
   int unhap = 0;
 
   /* bail out now if happy_cost is 0 */
-  if (g->unit_happy_cost_factor == 0) {
+  if (get_player_bonus(city_owner(pcity), EFT_UNHAPPY_FACTOR) == 0) {
     return FALSE;
   }
-  
-  free_happy  = citygov_free_happy(pcity, g);
+  free_happy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
 
-  /* ??  This does the right thing for normal Republic and Democ -- dwp */
-  free_happy += get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
-
   unit_list_iterate(pcity->units_supported, punit) {
-    int happy_cost = utype_happy_cost(unit_type(punit), g);
+    int happy_cost = utype_happy_cost(unit_type(punit), city_owner(pcity));
 
     if (happy_cost <= 0) {
       continue;
Index: ai/aicity.c
===================================================================
--- ai/aicity.c (revision 11288)
+++ ai/aicity.c (working copy)
@@ -166,7 +166,7 @@
   }
   prod[O_GOLD] += get_city_tithes_bonus(acity);
   output_type_iterate(o) {
-    bonus[o] = get_city_output_bonus(acity, o);
+    bonus[o] = get_final_city_output_bonus(acity, o);
     waste[o] = city_waste(acity, o, prod[o] * bonus[o] / 100);
   } output_type_iterate_end;
   add_tax_income(pplayer,
@@ -263,7 +263,6 @@
   struct ai_data *ai = ai_data_get(pplayer);
   struct tile *ptile = pcity->tile;
   bool capital = is_capital(pcity);
-  struct government *gov = get_gov_pplayer(pplayer);
   struct req_source source = {
     .type = REQ_BUILDING,
     .value = {.building = id}
@@ -408,9 +407,8 @@
        case EFT_MAKE_CONTENT_MIL:
           if (get_city_bonus(pcity, EFT_NO_UNHAPPY) <= 0) {
            v += pcity->ppl_unhappy[4] * amount
-             * MAX(unit_list_size(pcity->units_supported)
-                 - gov->free_happy, 0) * 2;
-           v += c * MAX(amount + 2 - gov->free_happy, 1);
+             * MAX(unit_list_size(pcity->units_supported), 0) * 2;
+           v += c * MAX(amount + 2, 1);
          }
          break;
        case EFT_TECH_PARASITE:
@@ -625,6 +623,9 @@
          } players_iterate_end;
          break;
         /* Currently not supported for building AI - wait for modpack users */
+        case EFT_UNHAPPY_FACTOR:
+        case EFT_UPKEEP_FACTOR:
+        case EFT_UNIT_UPKEEP_FREE_PER_CITY:
         case EFT_CIVIL_WAR_CHANCE:
         case EFT_EMPIRE_SIZE_MOD:
         case EFT_EMPIRE_SIZE_STEP:
Index: client/gui-gtk-2.0/happiness.c
===================================================================
--- client/gui-gtk-2.0/happiness.c      (revision 11288)
+++ client/gui-gtk-2.0/happiness.c      (working copy)
@@ -291,9 +291,8 @@
   char buf[512], *bptr = buf;
   int nleft = sizeof(buf);
   struct city *pcity = pdialog->pcity;
-  struct government *g = get_gov_pcity(pcity);
   int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
-  int uhcfac = g->unit_happy_cost_factor;
+  int uhcfac = get_city_bonus(pcity, EFT_UNHAPPY_FACTOR);
 
   my_snprintf(bptr, nleft, _("Units: "));
   bptr = end_of_strn(bptr, &nleft);
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 11288)
+++ client/packhand.c   (working copy)
@@ -2258,13 +2258,7 @@
   }
   assert(gov->reqs.size == p->reqs_count);
 
-  gov->unit_happy_cost_factor  = p->unit_happy_cost_factor;
-  gov->free_happy          = p->free_happy;
-
   output_type_iterate(o) {
-    gov->free_upkeep[o] = p->free_upkeep[o];
-    gov->unit_upkeep_factor[o] = p->unit_upkeep_factor[o];
-
     gov->output_before_penalty[o] = p->output_before_penalty[o];
     gov->celeb_output_before_penalty[o] = p->celeb_output_before_penalty[o];
     gov->output_inc_tile[o] = p->output_inc_tile[o];
Index: client/helpdata.c
===================================================================
--- client/helpdata.c   (revision 11288)
+++ client/helpdata.c   (working copy)
@@ -1236,12 +1236,16 @@
 
 /****************************************************************
   Append text for government.
+
+  FIXME: We need to find a way to generate helptext from effects
+  here. For now lots of stuff is simply commented out.
 *****************************************************************/
 void helptext_government(char *buf, struct government *gov,
                         const char *user_text)
 {
+  const size_t bufsz = 64000; /* FIXME: should be passed in */
+#if 0
   bool active_types[O_MAX];
-  const size_t bufsz = 64000; /* FIXME: should be passed in */
 
   /* Try to guess which output types that are active in this 
    * game by checking if _any_ government uses it. */
@@ -1253,7 +1257,8 @@
       }
     } output_type_iterate_end;
   } government_iterate_end;
-  
+#endif
+
   buf[0] = '\0';
 
   if (gov->helptext[0] != '\0') {
@@ -1313,7 +1318,6 @@
               gov->free_happy);
     }
   }
-#endif
   output_type_iterate(ot) {
     if (gov->free_upkeep[ot] == G_CITY_SIZE_FREE) {
       sprintf(buf + strlen(buf),
@@ -1351,6 +1355,7 @@
                "any of your units.\n"), get_output_name(ot));
     }
   } output_type_iterate_end;
+#endif
   output_type_iterate(ot) {
     if (gov->output_before_penalty[ot] > 0
         && gov->output_before_penalty[ot] 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14746) More governments generalization, Per I. Mathisen <=