Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2001:
[Freeciv-Dev] Re: Perl scripting implemented
Home

[Freeciv-Dev] Re: Perl scripting implemented

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Peter Barker <pbarker@xxxxxxxxxxxxxxxxxxxxx>
Cc: Freeciv Development <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Perl scripting implemented
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Apr 2001 12:05:53 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Wed, Apr 25, 2001 at 02:46:56PM +1000, Peter Barker wrote:
> Hi...
>       I've been playing around with scripting in Freeciv. I have perl
> scripting to this point:
> ==========================
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> use Freeciv qw (
>               get_cities
>               );
> require Freeciv::City;
> 
> print STDERR "reorient workers running\n";
> 
> print STDERR "About to call my_get_cities\n";
> my @my_cities = &get_cities();
> 
> print STDERR "I got " . scalar(@my_cities) . " cities\n";
> foreach my $my_city (@my_cities) {
>   print STDERR "$my_city\n";
>   print STDERR "Keys: " . join (',',keys %$my_city) . "\n";
>   print STDERR "Size is " .  $my_city->size() . "\n";
>   print STDERR "X is " .  $my_city->x() . "\n";
>   print STDERR "Y is " .  $my_city->y() . "\n";
>   print STDERR "food_surplus is " .  $my_city->food_surplus() . "\n";
>   print STDERR "shield_surplus is " .  $my_city->shield_surplus() . "\n";
>   print STDERR "tax_total is " .  $my_city->tax_total() . "\n";
>   print STDERR "Size is " .  $my_city->size() . "\n";
> 
>   $my_city->froody();
>   $my_city->auto_arrange_workers();
> }
> ===================================

Nice.

> In other words:
>  - I've wrapped all the integers in city.h
>  - I've implemented "auto_arrange_workers"
>  - froody() exists in a file "FreeCiv/City.pm". The others are implemented
> in XS.

What is XS?

> I've added another menu option (in gui-gtk) "Scripts". An entry "Refresh"
> will read all entries from a magic directory where you drop your scripts.
> You can then choose and run those scripts from the menu.

What kind of interface is between the civclient and the perl script? 
In what way and form the information and commands (to send certain
packets) are exchanged?

> I'm after thoughts and comments on an interface for the module.
> 
> Currently I'm using accessor methods, as above. I think a nicer interface
> would be a tied hash, so you can say "City is at ($city->{x},$city->{y})".

If I would implement this in python I would use a hash. The access
would then become city.data["x"] . If this is to much typing it is
possible to redirect members accesses at runtime. This would give
city.x but all data is still in city.data.

> I think the next thing I want to implement is a "$city->get_tiles()",
> which will return an array of Freeciv::CityTile. CityTile (ISA

ISA? Sorry I'm only done some small scripts in perl and no OO.

> FreeCiv::Tile) will give accessor methods on the various productions and
> in-use-by-worker information. Perhaps add_worker and remove_worker, as
> well. This _should_ be sufficient to allow people to write their own
> optimisers ("Optimise for Science", "Optimise for Production" etc).

There is one in C already. Search for CMA in the archive.

> If anyone would like to see some _very_ ugly diffs, I'm quite happy to
> supply them.

Since I won't get more stupid by looking at them: can you send them to me?

> OK, on to some other matters I've been wondering about:
> 
> There is a define "CITY_MAP_SIZE" in city.h. I note, however, that various
> constants are still floating around which would completely screw things
> over if you tried to increase CITY_MAP_SIZE. Has anyone tried playing with
> larger city sizes?

AFAIK no. IMHO it is a big amount of work.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "We just typed make..."
    -- Stephen Lambrigh, Director of Server Product Marketing at Informix,
                         about porting their Database to Linux



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