Complete.Org: Mailing Lists: Archives: freeciv-dev: September 1999:
Re: [Freeciv-Dev] Adding scripting language
Home

Re: [Freeciv-Dev] Adding scripting language

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv Dev <freeciv-dev@xxxxxxxxxxxx>
Subject: Re: [Freeciv-Dev] Adding scripting language
From: Artur Biesiadowski <abies@xxxxxxxxx>
Date: Wed, 01 Sep 1999 11:43:04 +0200

Jules Bean wrote:

> > Adding guile to C programs seems straigforward. Hooks into C data can be
> > added incrementally - when somebody will need somthing he will just add
> > needed accessor/side effect function.
> 
> True.  I think slang is supposed to be very simple to integrate with C.
> 
> Of course, just adding needed functions when somebody needs them isn't
> the best way to produce an elegant or consistent design ;)

I think it is not so bad if soem rules will be enforced. Taking guile in
focus, accessor functions could be standarized to

type-attribute-get and type-atrribute-set

so, for example, unit movesleft field will be accessed by

(unit-movesleft-get unit)
and
(unit-movesleft-set unit newval)

Functions affecting global data could be prefixed with world

(world-units-remove unit)

For map, (world-map-tile-get x y) or just (map-tile-get x y)  - (as map
is one of most often used structures)


So for example, script for building hydro plant could look like this

(define (can-build-hydroplant-p player city impr-id)  ; this will be
generated, not included in ruleset
(
  (set! x (city-x-get city) )
  (set! y (city-y-get city) )
  (and (can-build-default player city impr-id) ; check for already in
city, needed tech owner by player
    (or (map-have-terrain-near x y T-RIVER) (map-have-terrain-near x y
T-MOUNTAIN))
  )
)
)

can-build-default could be implemented in C or in guile - it will be
called very often (but sometimes would need to be either skipped or
shadowed by other condition put earlier). Maybe for sake of efficiency,
flag could be added to building, which would say
TEST_DEFAULT_BEFORE_SCRIPT - this would save some of guile-C
transitions.

One mroe thing - I was thinking about speed, but it should not be so
bad. If we add required building field to default checking, only 6-7
building are left in default ruleset for which special scripts would
have to be written. So for normal rules only 6-7 scripts would be run
for each city check, not 120 (improvements + wonders).

BTW, it could be also possible to globally shadow can-build-default with
own function for some strange ruleset.  If definition for it is
provided, TEST_DEFAULT_BEFORE_SCRIPT would not call C code, but guile
script.


Artur


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