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

[Freeciv-Dev] Perl scripting implemented

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv Development <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Perl scripting implemented
From: Peter Barker <pbarker@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Apr 2001 14:46:56 +1000 (EST)

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();
}
===================================

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.

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.

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})".

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

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

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?


About a year ago I implemented a callback system for freeciv. This
basically allowed you to add units and buildings in what I would say iss a
better manner than the existing config-file format. It works like this
(the example I am using is a building which functions like Magellan's
Expedition):

1. Insert into the code at appropriate places hooks e.g. for calculating a
unit's movement points
2 .Upon server startup, dlopen all .so's in a particular directory, run an
initialise method from that .so. (say goodbye to portability :-)
3. The initialise method registers callbacks corresponding to the
appropriate hook in the code.
4. When the hooks are hit,the callbacks are passed the
unit's (or city's, or...) pointer, frobbing it directly e.g. increasing
movement points if that unit's home city contains the appropriate
building.

I implemented it in a fairly ugly manner, but you could imagine being able
to just drop a .so in a directory, review allowable units/buildings before
starting the game (clients need the .so....)...

OK, I think I've rambled enough.

Yours,
-- 
Peter Barker                          |   N    _--_|\ /---- Barham, Vic 
Programmer,Sysadmin,Geek              | W + E /     /\                
pbarker@xxxxxxxxxxxxxxxxxxxxx         |   S   \_,--?_*<-- Canberra      
You need a bigger hammer.             |             v    [35S, 149E]   
"Besides, what most US companies would call R&D, we call 'getting shit done'.
 We're an emminently practical people in many ways."
- jeremyl@xxxxxxxxxxx on SlashDot.





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