Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: Tech cost patch v5
Home

[Freeciv-Dev] Re: Tech cost patch v5

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Juha Litola <slave@xxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Tech cost patch v5
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 Nov 2001 12:57:01 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, Nov 29, 2001 at 01:13:36PM +0200, Juha Litola wrote:
> Overhauled things a bit ;)
> 
> Changes to v4:
> - separated tech_cost_style to tech_cost_style and tech_leakage
> - implemented reading costs from techs.ruleset. If some costs
>   aren't entered, we'll calculate them using method 1.
> - costs are now transferred to client
> - costs are precalculated at server/ruleset.c
> - modified game.ruleset files included
> - added writing costs to rulesout.c

I still think that 

+/**************************************************************************
+ Count cost for technology recursively.
+ Do no call this function directly, use tech_cost instead.
+ Result is researchcost*(1+numparents)
+**************************************************************************/
+static int tech_cost_rec(Tech_Type_id tech)
+{
+  int price = game.researchcost;
+  if (tech == A_NONE)
+    return 0;
+  if (advances[tech].cost != 0)        /* Precalculated value */
+    return advances[tech].cost;
+
+  price += tech_cost_rec(advances[tech].req[0]);
+  price += tech_cost_rec(advances[tech].req[1]);
+  advances[tech].cost = price;
+  return price;
+}

is ugly. Add a preset_cost and a num_parents field to
tech. Precalculate the num_parents field. Change

+  case 1:
+  case 2:
+    cost = advances[tech].cost;
+    break;

to

+  case 1:
     cost = advances[tech].num_parents*game.researchcost;
     break;
+  case 2:
     if (advances[tech].preset_cost==-1) // wasn't found in the ruleset
        cost = advances[tech].num_parents*game.researchcost;
     else
        cost = advances[tech].preset_cost;
+    break;

This mixing of the two styles in one field is IMHO ugly.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "There are three ways to get something done. Do it yourself, hire someone
  to do it for you or forbid your kids to do it."


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