[Freeciv-Dev] Re: Tech cost patch v6
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, Nov 29, 2001 at 03:14:12PM +0100, Raimar Falke wrote:
> On Thu, Nov 29, 2001 at 03:28:49PM +0200, Juha Litola wrote:
> > On Thu, Nov 29, 2001 at 02:11:34PM +0100, Raimar Falke wrote:
> >
> > > Problem: where is num_reqs set to 0 (initialized)?
> > Hmm, it seems to be 0 when I test it, but maybe it's just good luck.
> >
> > > Suggestion: at the correct places (one for the server and one for the
> > > client) do:
> > > for each tech:
> > > tech.num_reqs=0;
> > > for each tech:
> > > num_req_techs(tech)
> > > and later doesn't use num_req_techs() anymore.
> > Where is the right place in client. In server it could be in
> > ruleset.c, but I couldn't find suitable place in client.
>
> Good question. Possible answers:
> - client/packhand.c:handle_ruleset_tech: you have to count the
> received techs OR trust that the server sents them in ascending order
> and catch the last one
> - depending on the game state
>
> I'm not sure what is the correct way. Can anybody help here?
Doesn't it suffice to add it to packet_ruleset_tech ?
struct packet_ruleset_tech {
int id, req[2]; /* indices for advances[] */
int flags;
char name[MAX_LEN_NAME];
char *helptext; /* same as for packet_ruleset_unit, above */
};
By the way, the algorithm is wrong: it only works on a tech *tree*,
but we really have an acyclic graph.
+/**************************************************************************
+ Count number of requirements technology has including itself.
+ Cache result to advances[tech].num_reqs.
+**************************************************************************/
+int num_req_techs(Tech_Type_id tech)
+{
+ int value = 1;
+ if (tech == A_NONE)
+ return 0;
+ if (advances[tech].num_reqs != 0) /* Precalculated value */
+ return advances[tech].num_reqs;
+
+ value += num_req_techs(advances[tech].req[0]);
+ value += num_req_techs(advances[tech].req[1]);
+ advances[tech].num_reqs = value;
+ return value;
+}
You have to scan and mark the whole tree for req[0], then read the
marks for req[1].
> Raimar
--
Reinier
- [Freeciv-Dev] Tech cost patch v5, Juha Litola, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v5, Raimar Falke, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v5, Juha Litola, 2001/11/29
- [Freeciv-Dev] Tech cost patch v6, Juha Litola, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Raimar Falke, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Juha Litola, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Raimar Falke, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6,
Reinier Post <=
- [Freeciv-Dev] Re: Tech cost patch v6, Juha Litola, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Petr Baudis, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Juha Litola, 2001/11/29
- [Freeciv-Dev] Re: Tech cost patch v6, Raahul Kumar, 2001/11/30
- [Freeciv-Dev] Re: Tech cost patch v6, Juha Litola, 2001/11/30
|
|