Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] (PR#2609) PATCH: clean up unit_upgrade_price
Home

[Freeciv-Dev] (PR#2609) PATCH: clean up unit_upgrade_price

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Erik.Sigra@xxxxxxxxxxxxxx
Cc: freeciv@xxxxxxx, freeciv-data@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2609) PATCH: clean up unit_upgrade_price
From: "Guest via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 19 Dec 2002 06:51:19 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[glip - Thu Dec 19 14:10:16 2002]: 
> Removing an unused parameter should be considered.  Arguments for 
> keeping it might include compliance to a pattern established by 
> similar functions or future extensibility. 
 
Now I have considered it and came to the conclusion that it should be 
removed. New patch attached. 
diff -rXi -U2 freeciv/ai/advdomestic.c freeciv-cleanup_unittype/ai/advdomestic.c
--- freeciv/ai/advdomestic.c    2002-12-17 21:15:19.000000000 +0100
+++ freeciv-cleanup_unittype/ai/advdomestic.c   2002-12-19 15:36:29.000000000 
+0100
@@ -713,5 +713,5 @@
         if (unit_id >= 0) {
           /* this is probably wrong -- Syela */
-          j = 8 * unit_upgrade_price(pplayer, punit->type, unit_id);
+          j = 8 * unit_upgrade_price(punit->type, unit_id);
           values[id] = MAX(values[id], j);
         }
diff -rXi -U2 freeciv/ai/aicity.c freeciv-cleanup_unittype/ai/aicity.c
--- freeciv/ai/aicity.c 2002-12-18 19:17:17.000000000 +0100
+++ freeciv-cleanup_unittype/ai/aicity.c        2002-12-19 15:37:44.000000000 
+0100
@@ -282,5 +282,5 @@
     }
     if (id >= 0) {
-      int cost = unit_upgrade_price(pplayer, punit->type, id);
+      const int cost = unit_upgrade_price(punit->type, id);
       int real_limit = limit;
       /* Triremes are DANGEROUS!! We'll do anything to upgrade 'em. */
diff -rXi -U2 freeciv/client/gui-gtk/citydlg.c 
freeciv-cleanup_unittype/client/gui-gtk/citydlg.c
--- freeciv/client/gui-gtk/citydlg.c    2002-12-16 03:19:35.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-gtk/citydlg.c   2002-12-19 
15:38:13.000000000 +0100
@@ -2699,5 +2699,5 @@
                           _("Darn"), NULL, 0, NULL);
     } else {
-      value = unit_upgrade_price(game.player_ptr, ut1, ut2);
+      value = unit_upgrade_price(ut1, ut2);
 
       if (game.player_ptr->economic.gold >= value) {
diff -rXi -U2 freeciv/client/gui-gtk/repodlgs.c 
freeciv-cleanup_unittype/client/gui-gtk/repodlgs.c
--- freeciv/client/gui-gtk/repodlgs.c   2002-12-11 12:30:48.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-gtk/repodlgs.c  2002-12-19 
15:38:24.000000000 +0100
@@ -928,5 +928,5 @@
            "Treasury contains %d gold."),
          unit_types[ut1].name, unit_types[ut2].name,
-         unit_upgrade_price(game.player_ptr, ut1, ut2),
+         unit_upgrade_price(ut1, ut2),
          game.player_ptr->economic.gold);
 
diff -rXi -U2 freeciv/client/gui-gtk-2.0/citydlg.c 
freeciv-cleanup_unittype/client/gui-gtk-2.0/citydlg.c
--- freeciv/client/gui-gtk-2.0/citydlg.c        2002-12-16 03:19:36.000000000 
+0100
+++ freeciv-cleanup_unittype/client/gui-gtk-2.0/citydlg.c       2002-12-19 
15:41:31.000000000 +0100
@@ -2658,5 +2658,5 @@
                           unit_upgrade_callback_no, 0, NULL);
     } else {
-      value = unit_upgrade_price(game.player_ptr, ut1, ut2);
+      value = unit_upgrade_price(ut1, ut2);
 
       if (game.player_ptr->economic.gold >= value) {
diff -rXi -U2 freeciv/client/gui-gtk-2.0/repodlgs.c 
freeciv-cleanup_unittype/client/gui-gtk-2.0/repodlgs.c
--- freeciv/client/gui-gtk-2.0/repodlgs.c       2002-12-16 03:19:36.000000000 
+0100
+++ freeciv-cleanup_unittype/client/gui-gtk-2.0/repodlgs.c      2002-12-19 
15:41:43.000000000 +0100
@@ -1011,5 +1011,5 @@
          "Treasury contains %d gold."),
        unit_types[ut1].name, unit_types[ut2].name,
-       unit_upgrade_price(game.player_ptr, ut1, ut2),
+       unit_upgrade_price(ut1, ut2),
        game.player_ptr->economic.gold);
   gtk_window_set_title(GTK_WINDOW(shell), _("Upgrade Obsolete Units"));
diff -rXi -U2 freeciv/client/gui-mui/dialogs.c 
freeciv-cleanup_unittype/client/gui-mui/dialogs.c
--- freeciv/client/gui-mui/dialogs.c    2002-12-11 12:30:48.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-mui/dialogs.c   2002-12-19 
15:38:49.000000000 +0100
@@ -1869,5 +1869,5 @@
   } else
   {
-    value = unit_upgrade_price(game.player_ptr, ut1, ut2);
+    value = unit_upgrade_price(ut1, ut2);
 
     if (game.player_ptr->economic.gold>=value)
diff -rXi -U2 freeciv/client/gui-mui/repodlgs.c 
freeciv-cleanup_unittype/client/gui-mui/repodlgs.c
--- freeciv/client/gui-mui/repodlgs.c   2002-11-18 19:33:03.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-mui/repodlgs.c  2002-12-19 
15:39:03.000000000 +0100
@@ -768,5 +768,5 @@
              "Treasury contains %d gold."),
              unit_types[ut1].name, unit_types[ut2].name,
-             unit_upgrade_price(game.player_ptr, ut1, ut2),
+             unit_upgrade_price(ut1, ut2),
              game.player_ptr->economic.gold);
 
diff -rXi -U2 freeciv/client/gui-win32/citydlg.c 
freeciv-cleanup_unittype/client/gui-win32/citydlg.c
--- freeciv/client/gui-win32/citydlg.c  2002-12-16 03:19:37.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-win32/citydlg.c 2002-12-19 
15:39:40.000000000 +0100
@@ -1591,5 +1591,5 @@
                            NULL);
     } else {
-      value=unit_upgrade_price(game.player_ptr, ut1, ut2);
+      value=unit_upgrade_price(ut1, ut2);
  
       if(game.player_ptr->economic.gold>=value) {
diff -rXi -U2 freeciv/client/gui-win32/repodlgs.c 
freeciv-cleanup_unittype/client/gui-win32/repodlgs.c
--- freeciv/client/gui-win32/repodlgs.c 2002-11-18 19:33:03.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-win32/repodlgs.c        2002-12-19 
15:39:56.000000000 +0100
@@ -577,5 +577,5 @@
                            "Treasury contains %d gold."),
                          unit_types[ut1].name, unit_types[ut2].name,
-                         unit_upgrade_price(game.player_ptr, ut1, ut2),
+                         unit_upgrade_price(ut1, ut2),
                          game.player_ptr->economic.gold);    
              
diff -rXi -U2 freeciv/client/gui-xaw/citydlg.c 
freeciv-cleanup_unittype/client/gui-xaw/citydlg.c
--- freeciv/client/gui-xaw/citydlg.c    2002-12-16 03:19:37.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-xaw/citydlg.c   2002-12-19 
15:40:51.000000000 +0100
@@ -2072,5 +2072,5 @@
                            NULL);
     } else {
-      value=unit_upgrade_price(game.player_ptr, ut1, ut2);
+      value = unit_upgrade_price(ut1, ut2);
 
       if(game.player_ptr->economic.gold>=value) {
diff -rXi -U2 freeciv/client/gui-xaw/repodlgs.c 
freeciv-cleanup_unittype/client/gui-xaw/repodlgs.c
--- freeciv/client/gui-xaw/repodlgs.c   2002-12-11 12:30:51.000000000 +0100
+++ freeciv-cleanup_unittype/client/gui-xaw/repodlgs.c  2002-12-19 
15:41:11.000000000 +0100
@@ -1022,5 +1022,5 @@
              "Treasury contains %d gold."),
            unit_types[ut1].name, unit_types[ut2].name,
-           unit_upgrade_price(game.player_ptr, ut1, ut2),
+           unit_upgrade_price(ut1, ut2),
            game.player_ptr->economic.gold);
 
diff -rXi -U2 freeciv/common/unittype.c 
freeciv-cleanup_unittype/common/unittype.c
--- freeciv/common/unittype.c   2002-12-18 19:17:17.000000000 +0100
+++ freeciv-cleanup_unittype/common/unittype.c  2002-12-19 15:34:02.000000000 
+0100
@@ -315,13 +315,9 @@
 ...
 **************************************************************************/
-int unit_upgrade_price(struct player *pplayer, Unit_Type_id from,
-                      Unit_Type_id to)
+int unit_upgrade_price(const Unit_Type_id from, const Unit_Type_id to)
 {
-  int total, build;
-  build = unit_value(from)/2;
-  total = unit_value(to);
-  if (build>=total)
-    return 0;
-  return (total-build)*2+(total-build)*(total-build)/20; 
+  const int diff = unit_value(to) - unit_value(from) / 2;
+
+  return (diff <= 0) ? 0 : diff * 2 + diff * diff / 20;
 }
 
diff -rXi -U2 freeciv/common/unittype.h 
freeciv-cleanup_unittype/common/unittype.h
--- freeciv/common/unittype.h   2002-12-18 19:17:17.000000000 +0100
+++ freeciv-cleanup_unittype/common/unittype.h  2002-12-19 15:35:00.000000000 
+0100
@@ -221,6 +221,5 @@
 
 int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id);
-int unit_upgrade_price(struct player *pplayer, Unit_Type_id from,
-                      Unit_Type_id to);
+int unit_upgrade_price(const Unit_Type_id from, const Unit_Type_id to);
 
 Unit_Type_id find_unit_type_by_name(const char *s);
diff -rXi -U2 freeciv/server/unithand.c 
freeciv-cleanup_unittype/server/unithand.c
--- freeciv/server/unithand.c   2002-12-19 09:59:53.000000000 +0100
+++ freeciv-cleanup_unittype/server/unithand.c  2002-12-19 15:44:23.000000000 
+0100
@@ -168,5 +168,5 @@
     return;
   }
-  cost = unit_upgrade_price(pplayer, packet->type, to_unit);
+  cost = unit_upgrade_price(packet->type, to_unit);
   conn_list_do_buffer(&pplayer->connections);
   unit_list_iterate(pplayer->units, punit) {
@@ -220,5 +220,5 @@
     return;
   }
-  cost = unit_upgrade_price(pplayer, punit->type, to_unit);
+  cost = unit_upgrade_price(punit->type, to_unit);
   if(cost > pplayer->economic.gold) {
     notify_player(pplayer, _("Game: Insufficient funds, upgrade costs %d."),

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