Complete.Org: Mailing Lists: Archives: freeciv-dev: March 1999:
[Freeciv-Dev] Patch: check rates when switching between governments...
Home

[Freeciv-Dev] Patch: check rates when switching between governments...

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Patch: check rates when switching between governments...
From: rizos@xxxxxxxx
Date: Wed, 3 Mar 1999 23:10:05 -0600 (CST)

The following patch fixes a long-standing problem w.r.t. the rates, namely:
if one switches from a goverment of higher rate to another of lower rate,
rates are not checked and one is allowed, for example, to have 100% science
with a Republic (if switched to this from Democracy). The side-effect of
this is that the taxmen/scientists/elvis icons may be blocked and the player
will have to change rates through the menu option.

The patch assigns whatever amount exceeds maxrate to the 2nd highest rate
and sends an appropriate message. 
AI's are still allowed to set rates as they wish.

--rizos

============================================================================

files affected:
        server/plrhand.c
        server/plrhand.h
        server/stdinhand.c


--- plrhand-orig.c      Sun Feb 28 16:10:57 1999
+++ plrhand.c   Wed Mar  3 19:59:59 1999
@@ -898,6 +898,9 @@
   gamelog(GAMELOG_GOVERNMENT,"%s form a %s",
           get_race_name_plural(pplayer->race),
           get_government_name(preq->government));
+
+  if (!pplayer->ai.control)
+     check_player_government_rates(pplayer);
   
   send_player_info(pplayer, pplayer);
 }
@@ -919,9 +922,66 @@
   gamelog(GAMELOG_REVOLT,"The %s revolt!",
                 races[pplayer->race].name);
 
+  if (!pplayer->ai.control)
+     check_player_government_rates(pplayer);
+
   send_player_info(pplayer, pplayer);
   if (player_owns_active_govchange_wonder(pplayer))
     pplayer->revolution=1;
+}
+
+/**************************************************************************
+The following checks that government rates are acceptable for the present
+form of government. Has to be called when switching governments or when
+toggling from AI to human. If a rate exceeds maxrate for this government,
+it adjusts rates automatically adding the extra to the 2nd highest rate.
+(It assumes that for any government maxrate>=50)
+**************************************************************************/
+
+void check_player_government_rates(struct player *pplayer)
+{
+  int maxrate, surplus=0;
+
+  maxrate = get_government_max_rate(pplayer->government);
+  if (pplayer->economic.tax > maxrate) {
+      surplus = pplayer->economic.tax - maxrate;
+      pplayer->economic.tax = maxrate;
+      if (pplayer->economic.science > pplayer->economic.luxury)
+         pplayer->economic.science += surplus;
+      else
+         pplayer->economic.luxury += surplus;
+      notify_player(pplayer,
+             "Game: Tax rate exceeded the max rate for %s. Adjusted.", 
+                    get_government_name(pplayer->government));
+  }
+  if (pplayer->economic.science > maxrate) {
+      surplus = pplayer->economic.science - maxrate;
+      pplayer->economic.science = maxrate;
+      if (pplayer->economic.tax > pplayer->economic.luxury)
+         pplayer->economic.tax += surplus;
+      else
+         pplayer->economic.luxury += surplus;
+      notify_player(pplayer,
+             "Game: Science rate exceeded the max rate for %s. Adjusted.", 
+                    get_government_name(pplayer->government));
+  }
+  if (pplayer->economic.luxury > maxrate) {
+      surplus = pplayer->economic.luxury - maxrate;
+      pplayer->economic.luxury = maxrate;
+      if (pplayer->economic.tax > pplayer->economic.science)
+         pplayer->economic.tax += surplus;
+      else
+         pplayer->economic.science += surplus;
+      notify_player(pplayer,
+             "Game: Luxury rate exceeded the max rate for %s. Adjusted.", 
+                    get_government_name(pplayer->government));
+  }
+
+  if (surplus)
+      gamelog(GAMELOG_EVERYTHING, "RATE CHANGE: %s %i %i %i",
+              get_race_name_plural(pplayer->race), pplayer->economic.tax,
+              pplayer->economic.luxury, pplayer->economic.science);
+
 }
 
 /**************************************************************************

--- plrhand-orig.h      Sun Feb 28 16:10:57 1999
+++ plrhand.h   Wed Mar  3 18:26:58 1999
@@ -25,6 +25,7 @@
                              struct packet_player_request *preq);
 void handle_player_rates(struct player *pplayer, 
                         struct packet_player_request *preq);
+void check_player_government_rates(struct player *pplayer);
 
 void send_player_info(struct player *src, struct player *dest);
 
--- stdinhand-orig.c    Sun Feb 28 16:10:58 1999
+++ stdinhand.c Wed Mar  3 19:21:26 1999
@@ -651,6 +651,9 @@
   } else {
     notify_player(0, "Game: %s is now human.", pplayer->name);
     printf("%s is now under human control.\n",pplayer->name);
+
+    /* because the hard AI `cheats' with government rates but humans shouldn't 
*/
+    check_player_government_rates(pplayer);
   }
   send_player_info(pplayer,0);
 }

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