Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: unit flags/capabilities

[Freeciv-Dev] Re: unit flags/capabilities

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx, vze2zq63@xxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: unit flags/capabilities
From: Andrew Sutton <ansutton@xxxxxxx>
Date: Thu, 29 Nov 2001 14:24:57 -0500

> How would this proposed inheritence system handle flying settlers?
> We're not talking about a system with a fixed list of units for the
> ruleset to pick from (or, at least IMO, we shouldn't be).  Ultimately a
> more flexible system that allows the ruleset to specify every property
> of the unit would be better.  This would also allow SMAC-style units
> with a minimum of fuss.

now, see... this is good. this is a requirement that drives design :)

so lets see what we want to do. we need to be able to define some structure 
that allows units to pick and choose capabilities. for example, a flying unit 
that can build cities.

i see a couple different ways to do this. the first is through the use of 
flags. each flag defines a capability or property. a unit specification 
subscribes to the flags that have been provided. of course, you'd basically 
need an unlimitted flag-space for extension (my previous discussion on unit 
flags solves this and provides this capability). the only issue this doesn't 
gracefully solve is a value association with the a flag. for example, a 
transport unit needs to specify how many units it can transport.

implementing this will probably eliminate the need for the an inheritance 
hierarchy because it it encapsulates specialization as static data as opposed 
to overloaded functions or data.

the alternative is to do it functionally and that's a little more 
complicated. this isn't a bad thing though because it allows modularization 
of each capability and some real flexibility when you're setting it all up. 
but, even in this case, i don't think you need the inheritence. you'll have 
to modularize all the units - or at least write enough code so that units can 
specify either generic or specialized capability flags.

struct movement_capab {
        int (*can_move_land)();
        int (*can_move_sea)();
        int (*can_move_air)();
        // ...

struct transport_capab {
        int trans_max;                  // total number of units
        int (*load_unit)( unit *);      // loads a unit into the transport
        unit *(*unload_unit)();         // unloads a unit

struct build_city_capab {
        int (*build_city)();

keep in mind that this is off the top of my head. each capability structure 
defines a set of properties and methods associated with the unit. the unit 
structure contains the following structure:

struct capability_vector {
        transport_capab *transport;
        build_city_capab *build_city;
        // ...

then, when you're defining units, each unit can customize its data and refine 
the way that this stuff is implemented.

// in flying_settler.c
static int flying_settler_can_move() { return 1; }

static struct movement_capab {

static struct build_city_capab {
        generic_build_city              // defined elsewhere

or something like that... it would take a little more thought to really 
refine the way this works.


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