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 02:08:20 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This patch cleans up the function unit_upgrade_price. 
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 10:54:55.000000000 
+0100
@@ -315,13 +315,10 @@
 ...
 **************************************************************************/
-int unit_upgrade_price(struct player *pplayer, Unit_Type_id from,
-                      Unit_Type_id to)
+int unit_upgrade_price
+(const struct player * const pplayer,
+ 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 10:28:32.000000000 
+0100
@@ -221,6 +221,7 @@
 
 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 struct player * const pplayer,
+ const Unit_Type_id from, const Unit_Type_id to);
 
 Unit_Type_id find_unit_type_by_name(const char *s);

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