Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] Re: Ruleset Development Was: Development Strategies
Home

[Freeciv-Dev] Re: Ruleset Development Was: Development Strategies

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Ben Webb <ben@xxxxxxxxxxxxxxxxxxxxxx>, Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Cc: <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Ruleset Development Was: Development Strategies
From: Andrew Sutton <ansutton@xxxxxxx>
Date: Tue, 4 Dec 2001 11:00:51 -0500

On Tuesday 04 December 2001 10:49 am, Ben Webb wrote:
> On Tue, 4 Dec 2001, Vasco Alexandre Da Silva Costa wrote:
> > I also think that things like number of unit types, etc, shouldn't be
> > capped with a small hardwired number.
>
>       Unit types are capped at a maximum of U_LAST (which is 200 at the
> moment, IIRC). There's no restriction on changing the number of unit types
> in the rulesets, however, as long as you don't exceed this maximum (in
> FreecivAC we support - well, kind of - SMAC-style "compound units" which
> are generated during the game, so we know this to be possible).

just curious. what's a compount unit?

> > I see no reason why the server can't at bootup read the rulesets and
> > dynamically set a MAX_UNITS variable or something.
>
> ...because then you'd have to replace
>
> extern struct unit_type unit_types[U_LAST];
>
> in unittype.h with a pointer, and mess with malloc and whatnot. This isn't
> exactly rocket science, but it's more fiddly and error-prone. Oh, and
> various stuff (worklists spring to mind) use U_LAST for other stuff too. A
> MAX_UNITS (well, game.num_unit_types) variable is indeed set by the server
> at bootup, though.


an additional consideration would be value binding for constant identifiers. 
if you're going to dynamically register units to determine the max type, then 
you'd probably want to dynamically set the identifier value of those unit 
types. it turns out that this is pretty easy and doesn't hurt effeciency at 
all. but if you do it dynamically, you woudn't want an array so much as a 
dynamic list. here's how you'd do it. this is just an example so i'm probably 
not using real code names - but you should get the picture.

// in unittype.h
// just for looks
typedef unsigned Unit_Type_Id;

// unit list
// this MUST end with a null ptr to cap
// list.
extern Unit_Type *the_unit_type_list;

// holds the highest value of type ids
extern Unit_Type_Id max_unit_types;

// names for unit ids
extern Unit_Type_Id UNIT_SETTLER;
extern Unit_Type_Id UNIT_WORKDER;
extern Unit_Type_Id UNIT_WARRIOR;

// regsitration api
// this method will assign an identifier value to the unit type id
// and append the unit type record to the end of the unit type list.

void register_unit_type( Unit_Type_Id *id, Unit_Type *type )
{
        // set the id allocator to 0
        // since its static, we won't need to declare this else
        // where.
        static Unit_Type_Id allocator = 0;

        // allocate the new id
        *id = allocator++;

        // append the unit
        list_append( the_unit_type_list, type );
}

that's it... now you have a framework for completely dynamic unit type 
registration and storage. well, almost it. you'd have to go thru and change 
everything that directly access the array of unit types. however, if 
everything used the get_unit_type() method, then it wouldn't be hard at all. 
just change that function.

Unit_Type *get_unit_type( Unit_Type_Id id )
{
        return list_find( the_unit_type_list, id );
}

am i missing anything?

andy


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