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

[Freeciv-Dev] Re: Tech cost patch v3

[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 v3
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Wed, 28 Nov 2001 16:13:48 +0100

> > It doesn't look bad, only the coding style needs to be fined a bit, IMHO.
> It would help to know what it currently is ;)
See Coding RFC (just now discussed here, you should notice it) and vote there
for your favourite coding stile, as a start ;-).  I mentioned things I don't
like in my previous mail, they look fixed, that's great :-).

> Included is modified patch with following chages:
> - Converted c++-style comments to c-style
> - Add capability tech_cost
> - Added cost field to advance-structure
> - Calculate costs only once
> - Converted if in tech_cost to switch
> - Got rid of floats
> - Changed for (i = 0; i < players; ++i) to player_iterate
fine!

> > Shouldn't you also modify ai/advmilitary.c ? >:)
> I hope not, I haven't got faintest idea what happens there. Someone
> more familiar with ai should probably check if modifications are
> needed.
Use grep. Your GREAT friend! It tells me:
freeciv/ai/advmilitary.c:        techcost = techdist * (techdist + 
pplayer->research.researchpoints) *
freeciv/ai/advmilitary.c:      l = k * (k + pplayer->research.researchpoints) * 
game.researchcost;
So run your favourite editor, hunt these lines and modify them :-).

> +/**************************************************************************
> + Function to determine cost for technology.
> + Equation is determined from game.rgame.tech_cost_style
> + 0 == Civ (I|II) style. Every tech increases cost by game.researchcost.
> + 1 == Cost is game.researchcost*(1+numparenttechs).
> + 2 == Cost is (numplayers-civswithtech)/numplayers*costinstyle1
> + 3 == Cost is (numplayers-civsincontactwithtech)/numplayers*costinstyle1
> +**************************************************************************/
> +int tech_cost(struct player *pplayer, int tech)
> +{
> +  if (tech > game.num_tech_types)    /* Future tech */
> +    return pplayer->research.researchpoints * game.researchcost;
> +
> +  switch(game.rgame.tech_cost_style) {
> +    case 1: 
> +      {
> +        return tech_cost_rec(pplayer, tech);
> +      }
> +    case 2:
> +      {
> +        int players = get_num_human_and_ai_players();
> +        int mul = 10*(players - game.global_advances[tech]) / players;
+ (this means newline would be nice)
> +        return mul * tech_cost_rec(pplayer, tech)/10;
> +      }
> +    case 3:
> +      {
> +        int playerswithtech = 0;
> +        int players = get_num_human_and_ai_players();
> +        int mul;
+
> +        players_iterate(other) { /* Find out how many players have tech*/
> +          if (!player_has_embassy(pplayer, other))
> +            continue;
> +
> +          if (other->research.inventions[tech] == TECH_KNOWN)
> +            ++playerswithtech;
> +
- (this means this newline is not very nice :)
> +        } players_iterate_end;
+
> +        mul = 10*(players - playerswithtech) / players;
> +        return mul * tech_cost_rec(pplayer, tech)/10;
> +      }
> +    case 0:
> +      return pplayer->research.researchpoints * game.researchcost;
Maybe it would be nice to sort cases in ascending order, but never mind, this
comment is here just due to lack of any other things i don't like here ;-).
> +    default:
> +      freelog(LOG_ERROR, "Invalid tech_cost_style %d", 
> game.rgame.tech_cost_style);
> +      return 0;
> +  }
> +}
> +
> +/**************************************************************************
> + Count cost for technology recursively. 
> + Do no call this function directly, use tech_cost instead.
> + Result is researchcost*(1+numparents)
> +**************************************************************************/
> +int tech_cost_rec(struct player *pplayer, int tech)
> +{
> +  int price = game.researchcost;
+
> +  if (tech == 0)
> +    return 0;
> +  if (advances[tech].cost!=0)        /* Precalculated value */
> +    return advances[tech].cost;
> +
> +  price += tech_cost_rec(pplayer, advances[tech].req[0]);
> +  price += tech_cost_rec(pplayer, advances[tech].req[1]);
> +  advances[tech].cost = price;
> +  return price;

When it will be finetuned, Raimar will probably want to get it thru bugtracking
system (mail it at bugs@xxxxxxxxxxxxxxxxxxx).

-- 

                                Petr "Pasky" Baudis

UN*X programmer, UN*X administrator, hobbies = IPv6, IRC
Real Users hate Real Programmers.
Public PGP key, geekcode and stuff: http://pasky.ji.cz/~pasky/


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