Complete.Org: Mailing Lists: Archives: freeciv-data: August 2000:
[freeciv-data] classes.ruleset version 3 plus class_processor
Home

[freeciv-data] classes.ruleset version 3 plus class_processor

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv Developement list <freeciv-dev@xxxxxxxxxxx>
Cc: Freeciv data list <freeciv-data@xxxxxxxxxxx>
Subject: [freeciv-data] classes.ruleset version 3 plus class_processor
From: Tomasz Wegrzanowski <maniek@xxxxxxxx>
Date: Mon, 7 Aug 2000 22:08:11 +0200
Reply-to: freeciv-data@xxxxxxxxxxx

Here is classes.ruleset with new classes : indian_ocean, pacific, atlantic,
baltic_sea and arctic (with less countries tha Robert proposed).

Also attached are:

classes_reverse, which takes classes.ruleset at stdin
and output at stdout :
class1          nation1 nation2 nation3
class2          nation4 nation5 nation6
...

class_processor, which opens ./classes.ruleset to read classification,
and takes request on @ARGV (as parameters), and outputs on stdout
ready-to-use nations.ruleset.
Generated ruleset includes barbarians, misc_cities, metadata and comments
cut&pasted from real nations.ruleset.

Example :
$ ./classes_processor 'europe & latinate + ( africa - black )'
;
; File generated in answer to request ``europe & latinate + ( africa - black )''
;

[datafile]
description="Nations data for Freeciv, europe & latinate + ( africa - black )"
options="1.9"

; Below: nations data in sections [nation_*] for
; all nations available. If you want to have more
; nations just add one at the end. There is a maximum
; of 63 nations however. I hope it is enough :-)
;
; Notes:
;
; name          = name of the nation
; plural        = plural form of the nation name (use "?plural:" qualifier)
; leader        = default leader names for the nation
; leader_sex    = sex of each default leader: "Male" or "Female"
; flag          = string to look for in client tilespec files for
;                 preferred flag icon
; flag_alt      = alternate flag icon string, or "-"
;
; Next are some hints for AI, as defined in struct player_race
; Ask the guy who designed this struct for more explanation :-)
; AFAIK some of them are not implemented yet.
;
; attack        = c 0 = optimize for food, 2 =  optimize for prod
;                 c0 = large amount of buildings, 2 = units
; expand        = c0 = transform first ,  2 = build cities first
; civilized     = c 0 = do not use nukes,  2 = use nukes, lots of pollution
; advisors      = some kind of advisors, not implemented anyway
; tech_goals    = technology goals, up to 10
; wonder        = primary wonder
; government    = wanted government
;
; cities        = city names, of course :-)
;
;
; section [misc] currently contains cities suggested when
; you run out of default cities for your nation
;

*include "nation/boer.ruleset"
*include "nation/carthaginian.ruleset"
*include "nation/catalan.ruleset"
*include "nation/french.ruleset"
*include "nation/italian.ruleset"
*include "nation/portuguese.ruleset"
*include "nation/spanish.ruleset"

;
; barbarians MUST go last
;
*include "nation/barbarian.ruleset"

*include "nation/misc_cities.ruleset"
$


-- Attached file included as plaintext by Listar --

#!/usr/bin/perl -w

my (%nations_in_class);

foreach $line(<>) {
  my ($nation,$classes_list) = ($line =~ /(\S+)\s+(.*)/);
  my @class_set = split /\s+/,$classes_list;
  foreach my $class(@class_set) {
      push @{$nations_in_class{$class}}, $nation;
  }
}

for my $class (sort keys %nations_in_class) {
  print $class, ' ' x (20-length $class), join (' ', 
@{$nations_in_class{$class}}), "\n";
}


-- Attached file included as plaintext by Listar --

#!/usr/bin/perl -w

$ruleset_header1 = 
'[datafile]
description="Nations data for Freeciv, ';

$ruleset_header2 = '"
options="1.9"

; Below: nations data in sections [nation_*] for
; all nations available. If you want to have more
; nations just add one at the end. There is a maximum
; of 63 nations however. I hope it is enough :-)
;
; Notes:
;
; name          = name of the nation
; plural        = plural form of the nation name (use "?plural:" qualifier)
; leader        = default leader names for the nation
; leader_sex    = sex of each default leader: "Male" or "Female"
; flag          = string to look for in client tilespec files for
;                 preferred flag icon
; flag_alt      = alternate flag icon string, or "-"
;
; Next are some hints for AI, as defined in struct player_race
; Ask the guy who designed this struct for more explanation :-)
; AFAIK some of them are not implemented yet.
;
; attack        = c 0 = optimize for food, 2 =  optimize for prod
;                 c0 = large amount of buildings, 2 = units
; expand        = c0 = transform first ,  2 = build cities first
; civilized     = c 0 = do not use nukes,  2 = use nukes, lots of pollution
; advisors      = some kind of advisors, not implemented anyway
; tech_goals    = technology goals, up to 10
; wonder        = primary wonder
; government    = wanted government
;
; cities        = city names, of course :-)
;
;
; section [misc] currently contains cities suggested when
; you run out of default cities for your nation
;

';

sub set_add(%%) {
  my %r;
  foreach $k(keys %{$_[0]}, keys %{$_[1]}) {
    $r{$k} = 1;
  }
  return \%r;
}

sub set_multiply(%%) {
  my %s2 = %{$_[1]};
  my %r;
  foreach my $k(keys %{$_[0]}) {
    $r{$k} = 1 if ($s2{$k});
  }
  return \%r;
}

sub set_subst(%%) {
  my %s2 = %{$_[1]};
  my %r;
  foreach my $k(keys %{$_[0]}) {
    $r{$k} = 1 unless ($s2{$k});
  }
  return \%r;
}

sub generate_ruleset (@) {
  print ";\n; File generated in answer to request ``$request''\n;\n\n";
  print $ruleset_header1, $request, $ruleset_header2;
  foreach (@_) {
    print "*include \"nation/$_.ruleset\"\n";
  }
  print "\n;\n; barbarians MUST go last\n;\n";
  foreach (sort keys %{$classification{'barbarians'}}) {
    print "*include \"nation/$_.ruleset\"\n";
  }
  print "\n";
  foreach (sort keys %{$classification{'misc_cities'}}) {
    print "*include \"nation/$_.ruleset\"\n";
  }
}

sub execute_operation ($$$) {
  my ($s1, $op, $s2) = @_;
  if ($op eq '+') {
   return set_add ($s1, $s2);
  }
  if ($op eq '&') {
   return set_multiply ($s1, $s2);
  }
  if ($op eq '-') {
   return set_subst ($s1, $s2);
  }
  return $s2 if ($s2);
  return $s1 if ($s1);
  die "Wrong operation [$s1 $op $s2]"
}

sub run_request (@) {
  my @tokens = @_;
  my (@sets_stack, @ops_stack);
  my $depth = 0;
  while (@tokens) {
      my $token = shift @tokens;
      if ($token eq '(') { $depth ++ }
      elsif ($token eq ')') {
            $depth --;
            my $set_last = pop @sets_stack;
            $sets_stack[-1] = execute_operation ($sets_stack[-1], pop 
@ops_stack, $set_last);
      }
      elsif ($token =~ /[+&-]/) {
            push @ops_stack, $token;
      }
      elsif (defined $sets_stack[$depth]) {
             $sets_stack[-1] = execute_operation ( $sets_stack[-1], pop 
@ops_stack, $classification{$token} );
      } else {
             push @sets_stack, $classification{$token};
      }
  }
  if (@ops_stack)
    { die "Syntax error somewhere in your request. Probably too many + - or &" }
  my @final_set = sort keys %{$sets_stack[0]};
  if ($sets_stack[1])
    { die "Syntax error somewhere in your request. Probably unbalanced parens" }
  return @final_set;
}

sub parse_request ($) {
  my $request = shift;
  my @tokens;
  while ($request =~ /\s*([()+&-]|[a-zA-Z0-9_]+)\s*(.*)/) {
    push @tokens, $1;
    $request = $2;
  }
  return run_request (@tokens);
}

### MAIN ()

unless ($request = "@ARGV") {
  print "Run it : $0 [request]\n";
  exit 1;
}

open CLASSES_RULESET, "classes.ruleset";

foreach $line (<CLASSES_RULESET>) {
  my ($nation, $classes_list) = ($line =~ /(\S+)\s+(.*)/);
  my @nation_in_classes = split /\s+/,$classes_list;
  push @nation_set, $nation;
  $nation_has_classes{$nation} = \@nation_in_classes;
}

close CLASSES_RULESET;

foreach $nation(@nation_set) {
  foreach $class(@{$nation_has_classes{$nation}}) {
    $classification{$class}{$nation} = 1;
  }
}

generate_ruleset (parse_request ($request));


-- Attached file included as plaintext by Listar --

american        real modern america white anglosaxon pacific atlantic
arab            real medieval modern middle_east semite white indian_ocean
argentine       real modern america white latinate antarctic atlantic
australian      real modern oceania white anglosaxon antarctic pacific 
indian_ocean
aztec           real ancient america indian pacific atlantic
babylonian      real ancient middle_east white semite
barbarian       barbarians
bavarian        real modern europe germanic white
boer            real modern africa white colonization antarctic atlantic 
indian_ocean
brazilian       real modern america latinate white atlantic
canadian        real modern america white anglosaxon pacific atlantic arctic
carthaginian    real ancient africa mediterranean punic white semite
catalan         real modern europe mediterranean latinate white atlantic
chilean         real modern america latinate white antarctic pacific
chinese         real ancient medieval modern asia yellow pacific
cornish         real medieval europe celtic white atlantic
czech           real medieval modern europe slavic white
danish          real medieval modern europe scandinavia germanic white 
north_sea atlantic
dunedain        fantasy tolkien
dutch           real medieval modern europe germanic white colonization 
north_sea atlantic
egyptian        real ancient africa middle_east mediterranean black
english         real medieval modern white colonization europe anglosaxon 
north_sea
estonian        real modern finno_ugric white europe baltic_sea
filipino        real modern oceania pacific
finnish         real modern scandinavia europe finno_ugric white baltic_sea 
arctic
french          real medieval modern europe latinate white colonization 
mediterranean north_sea atlantic
german          real ancient medieval modern germanic white europe north_sea 
baltic_sea
greek           real ancient modern europe mediterranean middle_east hellenic 
white
hungarian       real medieval modern europe finno_ugric white
inca            real ancient indian america pacific
indian          real ancient modern asia white indian_ocean
irish           real medieval modern celtic white europe atlantic
israeli         real ancient modern middle_east semite white
italian         real modern latinate white europe mediterranean
japanese        real ancient medieval modern asia yellow pacific
kenyan          real modern africa black indian_ocean
korean          real medieval modern asia yellow pacific
krevi           fantasy
latvian         real modern baltic white europe baltic_sea
lithuanian      real medieval modern baltic white europe baltic_sea
misc_cities     misc_cities
mongol          real medieval asia yellow
mordor          fantasy tolkien
olympic         fantasy
persian         real ancient middle_east hellenic white indian_ocean
polish          real europe medieval modern slavic white baltic_sea
portuguese      real medieval modern latinate white colonization europe atlantic
roman           real ancient europe mediterranean white punic
russian         real medieval modern slavic white europe black_sea pacific 
arctic
scottish        real europe medieval modern celtic white north_sea atlantic
silesian        real medieval modern europe slavic white
singaporean     real modern asia yellow pacific indian_ocean
sioux           real ancient indian america colonization
spanish         real medieval modern latinate white europe colonization 
mediterranean atlantic
swedish         real medieval modern europe scandinavia germanic white 
baltic_sea arctic
thai            real ancient modern asia yellow pacific indian_ocean
turk            real medieval modern europe mediterranean middle_east white 
black_sea
ukrainian       real europe medieval modern slavic white black_sea
vietnamese      real ancient modern asia yellow pacific
viking          real medieval europe scandinavia germanic white north_sea 
atlantic baltic_sea arctic
welsh           real medieval europe celtic white atlantic
zulu            real colonization black africa




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