[Freeciv-Dev] Flags on demand
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Currently there are some flags in rulesets and surely there will be
more. All of them have hardcoded meanings. With C code it is maybe ok,
but with script language we will be limiting ourselves.
My idea is to allow any flags to be defined. More they should be handled
transparently to ruleset writer, script writer and even C writer (except
few interface routines). So there will be no many flag fields, but just
has_unit_flag(int flag)
has_city_flag(int flag)
etc.
Flag as int would not be available directly anywhere. It would have to
be obtained through
int get_unit_flag(const char * flagname)
If we would like to sacrifice a bit of performance for readibility we
could directly use has_unit_flag(const char * flagname) every time.
At start of each ruleset file there would be entry called legal flags,
which would give all names for flags. Flags could be created at time
they are first met in actual description, but this way typos would not
be noticed. Having all possible flags in one place before they are used
could also simplify implementation.
I don't think that it will be useful directly in C code - from one side
it will reduce number of enums and save some typing for new flag
implementation, on other hand could cause some more problems with
keeping C code and rulesets in sync. But when scripts will be fully
working it will be real gain. For example we want to have one unit that
is able to build roads on non-mountain terrain and second that is able
to build it everywhere. Instead of hacking C code we just do
[legal flags]
...
"BuildRoad", "BuildMountainRoad"
...
[unit1]
...
flags = "BuildRoad",...
...
[unit2]
...
flags = "BuildRoad", "BuildMountainRoad"
...
script (java-like)
boolean can_build_road(unit u)
{
if ( u.hadFlag("BuildRoad") &&
( map.terrain(u.x,u.y) != TERRAIN_MOUNTAIN ||
u.hasFlag("BuildMountainRoad" )
)
return true;
return false;
}
Artur
- [Freeciv-Dev] Flags on demand,
Artur Biesiadowski <=
|
|