Added the tool to create the unit tree in html,

as used for units.wesnoth.org (written by elricz)
This commit is contained in:
Mark de Wever 2007-04-14 20:16:29 +00:00
parent 4c50d77561
commit 1116c5e16f
13 changed files with 1178 additions and 0 deletions

View file

@ -111,6 +111,8 @@ Version 1.3.1+svn:
* New tool, macroscope, generates cross-reference reports on macro usage.
* The old find-unused-images and find-unused-sounds scripts are deleted
(replaced by macroscope).
* New tool to create the unit tree in html, as used for units.wesnoth.org
(written by elricz)
* miscellanous changes and bug fixes
* a friendly healer will now stop poisoned unit to lose HP
* a unit that dies while attacking will now correctly play its own death

View file

@ -0,0 +1,68 @@
#!/usr/bin/perl -w
if($#ARGV !=1){
die"TeamColorizer.pl input-file output-file\n";
}
$infilename=shift(@ARGV);
$outfilename=shift(@ARGV);
$team_red=255;
$team_green=0;
$team_blue=0;
$team_red_max=255;
$team_green_max=255;
$team_blue_max=255;
$team_red_min=0;
$team_green_min=0;
$team_blue_min=0;
$flag_rgb="244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,236,0,140,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241";
#$flag_rgb="236,0,140,244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241";
@flag=split(/,/,$flag_rgb);
if($#flag<3){die "error, flag_rgb not well defined";}
$base_red=$flag[0];
$base_green=$flag[1];
$base_blue=$flag[2];
$base_sum=$base_red+$base_green+$base_blue;
while($#flag>2){
$red=shift(@flag);
$green=shift(@flag);
$blue=shift(@flag);
$old_rgb=sprintf("%lx", $red*256*256+$green*256+$blue);
$sum=$red+$green+$blue;
if($sum<=$base_sum){
$ratio=$sum/$base_sum;
$new_red=$team_red*$ratio+$team_red_min*(1-$ratio);
$new_green=$team_green*$ratio+$team_green_min*(1-$ratio);
$new_blue=$team_blue*$ratio+$team_blue_min*(1-$ratio);
}else{
$ratio=$base_sum/$sum;
$new_red=$team_red*$ratio+$team_red_max*(1-$ratio);
$new_green=$team_green*$ratio+$team_green_max*(1-$ratio);
$new_blue=$team_blue*$ratio+$team_blue_max*(1-$ratio);
}
$new_red=sprintf("%d",$new_red);
$new_green=sprintf("%d",$new_green);
$new_blue=sprintf("%d",$new_blue);
$new_rgb=sprintf("%lx", $new_red*256*256+$new_green*256+$new_blue);
# print "red: $red\tgreen: $green\tblue: $blue\t$old_rgb\n";
# print "\tred: $new_red\tgreen: $new_green\tblue: $new_blue\t$new_rgb\n";
$fill_cmd="-fill \"#$new_rgb\" -opaque \"#$old_rgb\"";
# print "$fill_cmd\n";
push(@fill,$fill_cmd);
}
$convert="convert ";
foreach(@fill){
# print "$_";
$convert="$convert $_";
}
$convert = "$convert $infilename $outfilename";
print "$convert\n";
system($convert);

View file

@ -0,0 +1,24 @@
<http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<link rel="alternate stylesheet" href="../units1.css" title="xangelo">
<script type="text/javascript" src="../styleswitcher.js"></script>
<title>Wesnoth unit animations</title>
</head>
<body>
<h1>Wesnoth unit animations</h1>
<p>The numbers are the number of frames for that category. The ~ sign means that there is no animation for that unit in that category</p>
<p><a href="index.html">Back to start</a></p>
<table width=100% border=1>
<tr class="first">
<td width=20%>Unit</td>
<td width=10%>Attack</td>
<td width=10%>Death</td>
<td width=10%>Defend</td>
<td width=10%>Healing</td>
<td width=10%>Idle</td>
<td width=10%>Leading</td>
<td width=10%>Movement</td>
<td width=10%>Recruit</td>
</tr>

View file

@ -0,0 +1,31 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit tree</h1>
<p>Choose the version you want to browse:</p>
<p><a href="stable/index.html">Stable (1.2.3)</a></p>
<p><a href="dev/index.html">Development (1.3.1)</a></p>
<p><a href="trunk/index.html">Trunk (Updated 14 Apr)</a></p>
<br>
<p>For all the translation of the unit description and trees, visit:</p>
<p><a href="http://www.xs4all.nl/~roadie/wesnoth_units/1.0/">1.0 Branch</a></p>
<p><a href="http://www.xs4all.nl/~roadie/wesnoth_units/1.2/">1.2 Branch</a></p>
<p><a href="http://zapicm.googlepages.com/home">Tar files</a></p>
<br>
<p>User made eras:</p>
<p><a href="stable/EXE/index.html">Extended Era (0.21.0)</a></p>
<p><a href="stable/EOM/index.html">Era of Myths (Beta 6)</a></p>
<br>
<p>For an ipod version of the 1.2 version unit list, download:</p>
<p><a href="ipod_folder.zip">Ipod files</a> (161 Kb. zip file)</p>
<br>
<p>Older stable versions:</p>
<p><a href="1_02/index.html">Version 1.0.2</a></p>
<br>
<p>Official game page: <i><a href="http://www.wesnoth.org">Battle for Wesnoth</a></i></p>
</body>
</html>

View file

@ -0,0 +1,39 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit tree</h1>
<p>Based on version<!-- --> X.X.X</p>
<p><a href="tree_race.html">Race</a></p>
<ul>
<li><a href='tree_drake.html'>Drakes</a>
<li><a href='tree_dwarf.html'>Dwarves</a>
<li><a href='tree_elf.html'>Elves</a>
<li><a href='tree_goblin.html'>Goblins</a>
<li><a href='tree_human.html'>Humans</a>
<li><a href='tree_lizard.html'>Lizards</a>
<li><a href='tree_mechanical.html'>Mechanical</a>
<li><a href='tree_merman.html'>Mermen</a>
<li><a href='tree_monster.html'>Monsters</a>
<li><a href='tree_naga.html'>Nagas</a>
<li><a href='tree_ogre.html'>Ogres</a>
<li><a href='tree_orc.html'>Orcs</a>
<li><a href='tree_troll.html'>Trolls</a>
<li><a href='tree_undead.html'>Undead</a>
<li><a href='tree_wose.html'>Woses</a>
</ul>
</p>
<p><a href="tree_faction.html">Faction</a></p>
<ul>
<li><a href='tree_drakes-default.html'>Drakes</a>
<li><a href='tree_knalgans-default.html'>Knalgan Alliance</a>
<li><a href='tree_loyalists-default.html'>Loyalists</a>
<li><a href='tree_northerners-default.html'>Northerners</a>
<li><a href='tree_rebels-default.html'>Rebels</a>
<li><a href='tree_undead-default.html'>Undead</a>
</ul>
</body>
</html>

View file

@ -0,0 +1,74 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit list</h1>
<p>Based on version<!-- --> X.X.X</p>
<p><a href=fr/index.html>Français</a>&nbsp;
<a href=en_GB/index.html>English [GB]</a>&nbsp;
<a href=pt_BR/index.html>Português do Brasil</a>&nbsp;
<a href=nl/index.html>Nederlands</a>&nbsp;
<a href=sk/index.html>Slovenčina</a>&nbsp;
<a href=de/index.html>Deutsch</a>&nbsp;
<a href=sv/index.html>Svenska</a>&nbsp;
<a href=cs/index.html>Čeština</a>&nbsp;
<a href=it/index.html>Italiano</a>&nbsp;
<a href=pl/index.html>Polski</a>&nbsp;
<a href=ca/index.html>Català</a>&nbsp;
<a href=ja/index.html>日本語</a>&nbsp;
<a href=fi/index.html>Suomi</a>&nbsp;
<a href=es/index.html>Español</a>&nbsp;
<a href=ru/index.html>Русский</a>&nbsp;
<a href=tr/index.html>Türkçe</a>&nbsp;
<a href=hu/index.html>Magyar</a>&nbsp;
<a href=no/index.html>Norsk bokmål</a>&nbsp;
<a href=af/index.html>Afrikaans</a>&nbsp;
<a href=la/index.html>Latina</a>&nbsp;
<a href=sl/index.html>Slovenščina</a>&nbsp;
<a href=eo/index.html>Esperanto</a>&nbsp;
<a href=zh_CN/index.html>中文</a>&nbsp;
<a href=el/index.html>Ελληνικά</a>&nbsp;
<a href=he/index.html>עברית</a>&nbsp;
<a href=eu/index.html>Euskera</a>&nbsp;
<a href=et/index.html>Eesti</a>&nbsp;
<a href=da/index.html>Dansk</a>&nbsp;
<a href=sr/index.html>Srpski</a>&nbsp;
<a href=bg/index.html>Български</a>&nbsp;
<a href=ko/index.html>한국어</a>&nbsp;
<a href=gl_ES/index.html>Galego</a>&nbsp;
<a href=ro/index.html>Românã</a>&nbsp;
<a href=pt/index.html>Português</a>&nbsp;
<a href=tl/index.html>Filipino</a>&nbsp;
</p>
<p><a href="tree_race.html">Race</a></p>
<ul>
<li><a href='tree_drake.html'>Drakes</a>
<li><a href='tree_dwarf.html'>race^Dwarves</a>
<li><a href='tree_elf.html'>Elves</a>
<li><a href='tree_goblin.html'>race^Goblins</a>
<li><a href='tree_human.html'>Humans</a>
<li><a href='tree_lizard.html'>race^Lizards</a>
<li><a href='tree_mechanical.html'>race^Mechanical</a>
<li><a href='tree_merman.html'>race^Mermen</a>
<li><a href='tree_monster.html'>race^Monsters</a>
<li><a href='tree_naga.html'>race^Nagas</a>
<li><a href='tree_ogre.html'>race^Ogres</a>
<li><a href='tree_orc.html'>Orcs</a>
<li><a href='tree_troll.html'>race^Trolls</a>
<li><a href='tree_undead.html'>race^Undead</a>
<li><a href='tree_wose.html'>race^Woses</a>
</ul>
<p><a href="tree_faction.html">Faction</a></p>
<ul>
<li><a href='tree_drakes-default.html'>Drakes</a>
<li><a href='tree_knalgans-default.html'>Knalgan Alliance</a>
<li><a href='tree_loyalists-default.html'>Loyalists</a>
<li><a href='tree_northerners-default.html'>Northerners</a>
<li><a href='tree_rebels-default.html'>Rebels</a>
<li><a href='tree_undead-default.html'>Undead</a>
</ul>
</body>
</html>

View file

@ -0,0 +1,26 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit list</h1>
<p>Based on version<!-- --> X.X.X</p>
<p><a href="index.html">Back to start</a></p>
<p>
<a href='#drakes'>Drakes</a>&nbsp
<a href='#knalgans'>Knalgan Alliance</a>&nbsp
<a href='#loyalists'>Loyalists</a>&nbsp
<a href='#northerners'>Northerners</a>&nbsp
<a href='#rebels'>Rebels</a>&nbsp
<a href='#undead'>Undead</a>&nbsp
</p>
<table width=100% border=1>
<tr class="first">
<td width=20%>Level<!-- --> 0</td>
<td width=20%>Level<!-- --> 1</td>
<td width=20%>Level<!-- --> 2</td>
<td width=20%>Level<!-- --> 3</td>
<td width=20%>Level<!-- --> 4</td>
</tr>

View file

@ -0,0 +1,5 @@
</table>
<p><a href=index.html>Back to start</a></p>
<p style="font-size: smaller">Generated on date GMT</p>
</body>
</html>

View file

@ -0,0 +1,18 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit list</h1>
<p>Based on version<!-- --> X.X.X</p>
<p><a href="index.html">Back to start</a></p>
<table width=100% border=1>
<tr class="first">
<td width=20%>Level<!-- --> 0</td>
<td width=20%>Level<!-- --> 1</td>
<td width=20%>Level<!-- --> 2</td>
<td width=20%>Level<!-- --> 3</td>
<td width=20%>Level<!-- --> 4</td>
</tr>

View file

@ -0,0 +1,35 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>Wesnoth unit tree</title>
</head>
<body>
<h1>Wesnoth unit list</h1>
<p>Based on version<!-- --> X.X.X</p>
<p><a href="index.html">Back to start</a></p>
<p>
<a href='#drake'>Drakes</a>&nbsp
<a href='#dwarf'>race^Dwarves</a>&nbsp
<a href='#elf'>Elves</a>&nbsp
<a href='#goblin'>race^Goblins</a>&nbsp
<a href='#human'>Humans</a>&nbsp
<a href='#lizard'>race^Lizards</a>&nbsp
<a href='#mechanical'>race^Mechanical</a>&nbsp
<a href='#merman'>race^Mermen</a>&nbsp
<a href='#monster'>race^Monsters</a>&nbsp
<a href='#naga'>race^Nagas</a>&nbsp
<a href='#ogre'>race^Ogres</a>&nbsp
<a href='#orc'>Orcs</a>&nbsp
<a href='#troll'>race^Trolls</a>&nbsp
<a href='#undead'>race^Undead</a>&nbsp
<a href='#wose'>race^Woses</a>&nbsp
</p>
<table width=100% border=1>
<tr class="first">
<td width=20%>Level<!-- --> 0</td>
<td width=20%>Level<!-- --> 1</td>
<td width=20%>Level<!-- --> 2</td>
<td width=20%>Level<!-- --> 3</td>
<td width=20%>Level<!-- --> 4</td>
</tr>

View file

@ -0,0 +1,147 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<html lang="en">
<head>
<link rel="stylesheet" href="../units.css" title="Eleazar">
<title>{id}</title>
<!--id={num}-->
</head>
<body>
<h1>{id}</h1>
<p>Level<!-- --> {level}</p>
<img src={image}>&nbsp;{image_female}
<p><b>Advances to: </b>
{advancetohtml}</p>
<p><b>Advance from:</b>
--advancefrom--</p>
<p>
<b>HP: </b>{hitpoints}&nbsp;
<b>Cost: </b>{cost}&nbsp;
<b>Moves: </b>{movement}&nbsp;
<b>Alignment: </b>
<!-- -->{alignment}<!-- -->&nbsp;
<b>XP: </b>{experience}
</p>
<p><b>Abilities: </b>
<!-- -->{abilities}</p>
<p style="font-size: smaller">{unit_description}</p>
<h2>attacks</h2>
<table border=1>
<th>
<td><b>Name</b></td>
<td><b>Type</b></td>
<td><b>Strikes</b></td>
<td><b>Range</b></td>
<td><b>Special</b></td>
</th>
--attacks--
</table>
<h2>Resistances</h2>
<table border=1>
<tr>
<td><b>blade</b></td>
<td align=right>::blade::</td>
</tr>
<tr>
<td><b>cold</b></td>
<td align=right>::cold::</td>
</tr>
<tr>
<td><b>fire</b></td>
<td align=right>::fire::</td>
</tr>
<tr>
<td><b>holy</b></td>
<td align=right>::holy::</td>
</tr>
<tr>
<td><b>impact</b></td>
<td align=right>::impact::</td>
</tr>
<tr>
<td><b>pierce</b></td>
<td align=right>::pierce::</td>
</tr>
</table>
<br>
<h2>Terrain Modifiers</h2>
<table border=1>
<tr>
<td><b>Terrain</b></td>
<td><b>Movement</b></td>
<td><b>Defense</b></td>
</tr>
<tr>
<td>Castle</td>
<td align=right>~castle~</td>
<td align=right>::castle::</td>
</tr>
<tr>
<td>Village</td>
<td align=right>~village~</td>
<td align=right>::village::</td>
</tr>
<tr>
<td>Deep Water</td>
<td align=right>~deep_water~</td>
<td align=right>::deep_water::</td>
</tr>
<tr>
<td>Shallow Water</td>
<td align=right>~shallow_water~</td>
<td align=right>::shallow_water::</td>
</tr>
<tr>
<td>Grassland</td>
<td align=right>~grassland~</td>
<td align=right>::grassland::</td>
</tr>
<tr>
<td>Forest</td>
<td align=right>~forest~</td>
<td align=right>::forest::</td>
</tr>
<tr>
<td>Hills</td>
<td align=right>~hills~</td>
<td align=right>::hills::</td>
</tr>
<tr>
<td>Mountains</td>
<td align=right>~mountains~</td>
<td align=right>::mountains::</td>
</tr>
<tr>
<td>Swamp</td>
<td align=right>~swamp_water~</td>
<td align=right>::swamp_water::</td>
</tr>
<tr>
<td>Sand</td>
<td align=right>~sand~</td>
<td align=right>::sand::</td>
</tr>
<tr>
<td>Cave</td>
<td align=right>~cave~</td>
<td align=right>::cave::</td>
</tr>
<tr>
<td>Tundra</td>
<td align=right>~tundra~</td>
<td align=right>::tundra::</td>
</tr>
<tr>
<td>Mushroom Grove</td>
<td align=right>~fungus~</td>
<td align=right>::fungus::</td>
</tr>
<tr>
<td>Chasm</td>
<td align=right>~canyon~</td>
<td align=right>::canyon::</td>
</tr>
</table>
<br>
<p style="font-size: smaller"><a href=index.html>Back to start</a></p>
</body>
</html>

View file

@ -0,0 +1,43 @@
body {
background-color: #999;
font-family: Verdana, Helvetica, sans-serif;
}
td {
font-size: 12px;
text-align: center;
padding: 5px;
}
tr.first {
text-align: center;
font-weight: bold;
font-size: medium;
}
td.race {
padding-top: 12px;
text-align: center;
font-weight: bstand;
color: #DDD;
background-color: #4b4437;
font-size: 24px;
}
td.yes {
color: #DDD;
background-color: navy;
}
a {
color: #218;
font-size: 16px;
}
a:visited {
color: #537;
}
a:hover {
color: #05A;
}

666
data/tools/unit_tree/units.pl Executable file
View file

@ -0,0 +1,666 @@
#!/usr/bin/perl
# Script: units.pl
# Purpose: To generate flat files and HTML files from the Battle for Wesnoth unit configuration files
#
# Requisites: All the following files, that are included in the package:
# anim_header.html: Template for the header of the report of animations made
# index_base.html: Index page that will be presented, in case translations are not selected
# index_languages.html: Index page that will be presented, in case translations are selected
# TeamColorizer.pl: Script created by Darth Fool, to change the magenta color of the units pngs
# tree_fact_header.html: Template for the header of the tree by faction
# tree_footer.html: Template for the footer of the unit trees
# tree_header.html: Template for the header of the unit trees, except the ones by race of faction
# tree_race_header.html: Template for the header of the tree by race
# unit.html: Template for the unit page
# units.css: Style file for all the html pages
# For converting the images using the TeamColorizer.pl script, ImageMagik must be installed,
# and the convert utility accessible from the console
# The Perl module Locale::Maketext::Gettext is required for the translations, the latest version can be found at CPAN (http://cpan.org)
# If the translation is not going to be used, the line use Locale::Maketext::Gettext; can be commented to avoid installing the module
#
# Usage: Select the amount of data to be generated using the flags on the Options section.
# Enter the appropriate paths for the Wesnoth directory, and the folders that will contain the html files
# and the reports. Use relative paths, that doesn't contain spaces, it wouldn't work if a space is found.
# Run the script, no parameters needed.
#
# Version: 1.0 (14 Apr 2007)
# Author: Miguel Zapico (elricz.m@gmail.com)
# -- Options --
# This option will determine if the html files are generated, in the folder determined by $html_dir
my $html_gen = 1;
# This option will determine if the html files translations are generated, and it will create the folders
# based on the contents of the po folder of Wesnoth
my $translate = 1;
# This option will determine if the attack images are copied, and the images units are copied and colorized
my $images = 1;
# This option will determine if the html report on made animations is generated
my $animations = 1;
# This is the version number that will appear on the unit trees
my $version = '1.3.1+svn';
# If the script is run on Windows, set this option to 1
my $windows = 1;
use Tie::File;
use File::Copy;
# -- Paths --
my ($wesnoth_dir, $data_dir, $html_dir, $report_dir);
$wesnoth_dir = '../../..';
$html_dir = 'files';
$report_dir = 'reports';
# Directories creations
unless (-e $html_dir) {mkdir $html_dir or die "$html_dir directory cannot be created: $!\n";};
unless (-e $report_dir) {mkdir $report_dir or die "$report_dir directory cannot be created: $!\n";};
unless (-e "$html_dir/attacks") {mkdir "$html_dir/attacks" or die "$html_dir/attacks directory cannot be created: $!\n";};
unless (-e "$html_dir/units") {mkdir "$html_dir/units" or die "$html_dir/units directory cannot be created: $!\n";};
$data_dir = "$wesnoth_dir/data";
# Variables used to generate the html
my ($i, $html, %types, %unit_id, @adv);
$unit_id{AdvanceTo} = 'AdvanceTo';
# Variables used on the tree generation
my (%spaces, %adv_from, %units, %units_id, %adv, %factions, %attacks, %att_id);
my %races = qw/race Race drake Drakes dwarf race^Dwarves elf Elves goblin race^Goblins human Humans lizard race^Lizards
mechanical race^Mechanical merman race^Mermen monster race^Monsters naga race^Nagas ogre race^Ogres
orc Orcs troll race^Trolls undead race^Undead wose race^Woses/;
# HTML code for each attack
my $att_html = "<tr>\n\t<td><img src={icon}></td>\n\t";
$att_html .= "<td>{name}</td>\n\t<td>{type}</td>\n\t<td>{damage}-{number}</td>\n\t<td>{range}</td>\n\t<td>{special}<!-- -->&nbsp;</td>\n</tr>\n";
# -- HTML files and raw data reports generation --
print "Starting the generation of unit files\n";
# Information on the units.cfg file
&ProcessTypes();
#Files that will contain the units data
open (UNITS, "> $report_dir/units.txt") or die "Couldn't create units.txt: $!\n";
open (RES, "> $report_dir/resistances.txt") or die "Couldn't create resistances.txt: $!\n";
open (ADV, "> $report_dir/advances.txt") or die "Couldn't create advances.txt: $!\n";
open (ATTACK, "> $report_dir/attacks.txt") or die "Couldn't create attacks.txt: $!\n";
open (FACT, "> $report_dir/factions.txt") or die "Couldn't create factions.txt: $!\n";
# Headers
print UNITS "id\tname\trace\thitpoints\tmovement_type\tmovement\texperience\tlevel\talignment\timage\tcost\tusage\tabilities\n";
print RES "id\tVariable\tValue\tCategory\n";
print ADV "id\tAdvanceTo\n";
print ATTACK "id\tname\ttype\trange\tdamage\tnumber\ticon\tspecial\n";
# Load HTML template
open (HTML, "unit.html");
$html .= $_ while (<HTML>);
close HTML;
# Now all the unit files in the data/units directory
# chdir ($data_dir) or die "Can't chdir to $dir $!";
my @units = glob("$data_dir/units/*.cfg");
&ProcessUnit($_) foreach @units;
# Factions, populates the factions file
my @factions = glob("$data_dir/factions/*");
my %mp;
foreach (@factions) {
&ProcessFaction ($_) if (/cfg$/);
}
close UNITS;
close RES;
close ADV;
close ATTACK;
close FACT;
# Multiplayer
# Check advances to not miss any unit
tie @adv, 'Tie::File', "$report_dir/advances.txt" or die "Couldn't open advances.txt: $!\n";
for (@adv) {
my ($id, $adv) = split /\t/;
$mp{$adv}++ if $mp{$id}; # List the units that will be processed as MP
s/\t([A-Za-z ]+)/\t$unit_id{$1}/; # Changes names to ids in the advance file
}
untie @adv;
# Print multiplayer units
open (UNITS, "$report_dir/units.txt") or die "Couldn't open units.txt: $!\n";
open (MP, "> $report_dir/mp_units.txt") or die "Couldn't create mp_units.txt: $!\n";
print MP "id\tname\trace\thitpoints\tmovement_type\tmovement\texperience\tlevel\talignment\timage\tcost\tusage\tabilities\n";
while (<UNITS>) {
my $unit = $_;
my ($none, $id, @other) = split /\t/; # We have names, not ids, on the %mp hash
print MP $unit if $mp{$id};
}
close MP;
close UNITS;
# -- Tree generation --
if ($html_gen) {
print "Starting the generation of unit trees\n";
copy('units.css',"$html_dir/units.css");
# Load HTML templates
open (HTML, "tree_header.html") or die "Couldn't open header: $!\n";
my @header = <HTML>;
s/X.X.X/$version/ foreach @header;
close HTML;
open (HTML, "tree_footer.html") or die "Couldn't open footer: $!\n";
my @footer = <HTML>;
@footer[2] =~ s/date/gmtime(time)/e; # Generation time
close HTML;
# Get the advances for each unit
open (ADV, "$report_dir/advances.txt") or die "Couldn't open advances.txt: $!\n";
while (<ADV>) {
chomp;
my ($id, $adv) = split /\t/;
$spaces{$id}++; # Used on the rowspan
$adv_from{$adv} = $id;
push @{$adv{$id}}, $adv;
}
close ADV;
# Calculate the correct row span for each unit
foreach (sort keys %spaces) {
if ($spaces{$_} > 1 and $adv_from{$_}) {
$spaces{$adv_from{$_}} += $spaces{$_} - 1;
}
}
# Units information
open (UNITS, "$report_dir/units.txt") or die "Couldn't open units.txt: $!\n";
while (<UNITS>) {
chomp;
my ($id, @stats) = split /\t/;
$units{$id} = [ @stats ];
$units_id{$stats[0]} = $id;
}
close UNITS;
# Attacks information
open (ATT, "$report_dir/attacks.txt") or die "Couldn't open attacks.txt: $!\n";
while (<ATT>) {
chomp;
my ($id, @stats) = split /\t/;
$att_id{$id}++; # Numeral for the hash, there may be better ways to do it
$attacks{$id}[$att_id{$id}-1] = [ @stats ];
}
close ATT;
# Tree by race
open (INDEX, "> $html_dir/tree_race.html") or die "Couldn't create tree_race.html: $!\n";
open (HTML, "tree_race_header.html") or die "Couldn't open header: $!\n";
while (<HTML>) {s/X.X.X/$version/; print INDEX;}
close HTML;
foreach $race (sort keys %races) {
if ($race ne "race") {
open ($race, ">", "$html_dir/tree_$race.html") or die "Couldn't create $race.html: $!\n"; # Use the variable as the filehandle
print $race @header;
print INDEX "\n<tr>\n<td class='race' id=\"$race\" colspan=5>$races{$race}</td>\n</tr>\n";
print $race "\n<tr>\n<td class='race' id=\"$race\" colspan=5>$races{$race}</td>\n</tr>\n";
foreach (sort keys %units) {
if ($race eq $units{$_}[1]) { # Only process units for the current race
if ($units{$_}[12] eq '') {
&PrintUnitTree($_, *INDEX) unless $adv_from{$_};
&PrintUnitTree($_, $race) unless $adv_from{$_};
}
}
}
print $race @footer;
close $race;
}
}
print INDEX @footer;
close INDEX;
# Update Advance From on each file
&UpdateAdvanceFrom;
# Tree by faction
# Load factions
open (INDEX, "> $html_dir/tree_faction.html") or die "Couldn't create tree_faction.html: $!\n";
open (HTML, "tree_fact_header.html") or die "Couldn't open header: $!\n";
while (<HTML>) {s/X.X.X/$version/; print INDEX;}
close HTML;
# Delete the advances from the units in the factions, so the tree can be built
my @delete_adv = qw/Thug Footpad Spearman Bowman Poacher Lieutenant/;
delete($adv_from{$units_id{$_}}) foreach @delete_adv;
open (FACTIONS, "$report_dir/factions.txt") or die "Couldn't open factions.txt: $!\n";
while (<FACTIONS>) {
chomp;
my ($faction, @stats) = split /\t/;
if ($faction =~ /(\w+)-default/) { # The standard factions came with "default" in their name
$factions{$1} = [ @stats ];
open ($faction, ">", "$html_dir/tree_$faction.html") or die "Couldn't create $faction.html: $!\n";
print $faction @header;
my $faction_name = ucfirst($1);
# Adjust the name of the factions to get them translated
$faction_name = 'Knalgan Alliance' if $faction_name eq 'Knalgans';
print INDEX "\n<tr>\n<td class='race' id=\"$1\" colspan=5>$faction_name</td>\n</tr>\n";
foreach (@stats) {
&PrintUnitTree($units_id{$_}, *INDEX) unless $adv_from{$units_id{$_}};
&PrintUnitTree($units_id{$_}, $faction) unless $adv_from{$units_id{$_}};
}
print $faction @footer;
close $faction;
}
}
close FACTIONS;
# Load footer
print INDEX @footer;
close INDEX;
# Copy the index file before translating
if ($translate) {
open (HTML, 'index_languages.html') or die "Couldn't open index_languages.html: $!\n";
} else {
open (HTML, 'index_base.html') or die "Couldn't open index_base.html: $!\n";
}
open (INDEX, "> $html_dir/index.html") or die "Couldn't create index.html: $!\n";
while (<HTML>) {s/X.X.X/$version/; print INDEX;}
close HTML;
close INDEX;
}
# -- Translate file --
&TranslateUnits if $translate;
print "Removing English comments\n";
&RemoveComments if $html_gen;
# -- Copy images --
if ($images) {
# Attacks images
print "Copying attack icons\n";
open (ATT, "$report_dir/attacks.txt") or die "Couldn't open attacks.txt: $!\n";
while (<ATT>) {
chomp;
my (@stats) = split /\t/;
copy ("$wesnoth_dir/images/$stats[6]","$html_dir/$stats[6]");
print "$wesnoth_dir/images/$stats[6]\t$html_dir/$stats[6]\n";
}
close ATT;
# Unit images, to be colorized
print "Copying and colorizing units\n";
# Prepare folders
my @unit_images = glob("$wesnoth_dir/images/units/*");
foreach $unit_image (@unit_images) {
$unit_image =~ s(.*\/)(); # Take only the folder name
if ($unit_image !~ /\./) {
unless (-e "$html_dir/units/$unit_image") {mkdir "$html_dir/units/$unit_image" or die "$unit_image directory cannot be created: $!\n";};
}
}
# Unit images
open (UNITS, "$report_dir/units.txt") or die "Couldn't open units.txt: $!\n";
my $colorizer = "TeamColorizer.pl";
$colorizer = './' . $colorizer unless $windows;
while (<UNITS>) {
chomp;
my @stats = split /\t/;
(my $image = $stats[9]);
$image =~ s/"//g;
system ("$colorizer $wesnoth_dir/images/$image $html_dir/$image");
$image =~ s/.png/+female.png/;
system ("$colorizer $wesnoth_dir/images/$image $html_dir/$image");
}
close UNITS;
# zombie units
my @zombies = qw/drake mounted saurian swimmer troll wose/;
foreach $zombie (@zombies) {
system ("$colorizer $wesnoth_dir/images/units/undead/zombie-$zombie.png $html_dir/units/undead/zombie-$zombie.png");
system ("$colorizer $wesnoth_dir/images/units/undead/soulless-$zombie.png $html_dir/units/undead/soulless-$zombie.png");
}
}
# -- Generate animation information
if ($animations) {
print "Generating animation information\n";
my %tags;
my @anim = qw/animation death defend healing_anim idle_anim leading_anim movement_anim recruit_anim/;
my $re_anim = "(";
$re_anim .= "$_|" foreach @anim;
$re_anim =~ s/\|$/)/;
# Load HTML templates
open (HTML, "anim_header.html") or die "Couldn't open header: $!\n";
my @header = <HTML>;
close HTML;
open (HTML, "tree_footer.html") or die "Couldn't open footer: $!\n";
my @footer = <HTML>;
@footer[2] =~ s/date/gmtime(time)/e; # Generation time
close HTML;
open (INDEX, "> $html_dir/animations.html") or die "Couldn't create animations.html: $!\n";
# Load units information
my @units = glob("$data_dir/units/*.cfg");
foreach $unit (@units) {
my ($id,$tag,$in,$images);
open (UNIT, "<$unit") or die "Can't open $unit: $!\n";
while (<UNIT>) {
chomp; s/^\s*//;
$id = $1 if /id=(.+)/;
($tag,$in,$images) = ($1,1,0) if /\[$re_anim\]/;
$images++ if ($in && /image=/);
if (m{\[\/$re_anim\]}) {
$tags{$id}{$tag} += $images;
($in,$images) = (0,0);
}
}
}
# Print information
print INDEX @header;
foreach $unit (sort keys %tags) {
print INDEX "<tr>\n\t<td>$unit</td>\n";
foreach $tag (@anim) {
print INDEX "\t<td" . ($tags{$unit}{$tag} ? " class=\"yes\">$tags{$unit}{$tag}" : ">~") . "</td>\n";
}
print INDEX "</tr>\n";
}
print INDEX @footer;
}
# -- Subroutines used in the code--
# Sub to parse the unit file, and print both the text files and the html
sub ProcessUnit {
$unit = shift;
$i++; # This will be the unit id
open (UNIT, "<$unit") or die "Can't open $unit: $!\n";
my (%unit,%attack,%res,%move,$att);
my $flag = 1; # This flag will identify the section inside the config file
while (<UNIT>) {
chomp; s/^\s*//;
last if /^\[variation/; # Don't process double data
if (/^\[female/) { # Used in the HTML generation, not included on the units.txt file
($unit{image_female} = $unit{image}) =~ s/.png/+female.png/;
$unit{image_female} = "<img src=" . $unit{image_female} . ">";
last;
}
# Primary information ($flag = 1)
if (/=/ and $flag == 1) {
my ($prop,$value) = split /=/;
$unit{$prop} = $value unless $unit{$prop}; # The first value encountered is the one that last
}
# Abilities, single regular expresion
$unit{abilities} .= lc("$1 ") if (/{ABILITY_(.*?)(_.*)?}/ and $flag == 1);
# Soulless units, the stats are in the first {UNIT_BODY...}
if (/^{UNIT_BODY_\w+\s(\w+)\s(\w+)\s(\w+)\s(\w+)/) {
$unit{image2} = "units/undead/$1.png>&nbsp;\n<img src=units/undead/$1-drake.png>&nbsp;\n<img src=units/undead/$1-mounted.png>";
$unit{image2} .= "&nbsp;\n<img src=units/undead/$1-saurian.png>&nbsp;\n<img src=units/undead/$1-swimmer.png>";
$unit{image2} .= "&nbsp;\n<img src=units/undead/$1-troll.png>&nbsp;\n<img src=units/undead/$1-wose.png";
$unit{image} = "units/undead/$1.png";
$unit{movement_type} = $2;
$unit{movement} = $3;
$unit{hitpoints} = $4;
}
# Deviations from the move type, if any ($flag = 2)
$flag = 1 if /^\[\/(resistance|defense|death|movement_costs)\]/;
if (/=/ and $flag == 2) {
my ($type, $value) = split /=/;
$cost = 0 if $cost >= 100;
if ($var eq "movement_costs") {
$move{$type} = $value;
print RES "$i\t$type\t" . $value . "\t$var\n";
} else {
$res{$type} = (100-$value) . "%";
print RES "$i\t$type\t" . (100-$value) . "\t$var\n";
}
}
($flag,$var) = (2,$1) if /^\[(resistance|defense|movement_costs)\]/;
# Attacks ($flag = 3)
if (/{WEAPON_SPECIAL_(.*)}/ and $flag == 3) { # Special attack starts with {WEAPON_SPECIAL
$attack{special} = lc($1);
# Special cases, slow and plague types are not in the .mo files
$attack{special} .= "s" if $attack{special} =~ /(?:slow|drain)/;
$attack{special} = "plague" if $attack{special} =~ /plague/;
}
if ($flag == 3 and /^\[\/attack\]/ ) {
$flag = 1;
$attack{icon} = "attacks/$attack{name}.png" unless $attack{icon}; # If the value is not present, make it equal to the name
print ATTACK "$i\t$attack{name}\t$attack{type}\t$attack{range}\t$attack{damage}\t$attack{number}\t$attack{icon}\t$attack{special}\n";
($att .= $att_html) =~ s/{(\w+?)}/$attack{$1}/eg; # Construct the html for the attack
%attack = '';
}
if (/=/ and $flag == 3) {
my ($prop,$value) = split /=/ if /=/;
$attack{$prop} = $value;
}
($flag, $attack{special}) = (3, '') if /^\[attack\]/;
# Skip Death sequence
$flag = 4 if /^\[death\]/;
}
# Print to match the headers, there may be empty elements
$unit{abilities} =~ s/\s$//; # Fix the extra space in the abilities
print UNITS "$i\t$unit{id}\t$unit{race}\t$unit{hitpoints}\t$unit{movement_type}\t$unit{movement}\t$unit{experience}";
print UNITS "\t$unit{level}\t$unit{alignment}\t$unit{image}\t$unit{cost}\t$unit{usage}\t$unit{abilities}\n";
$unit{image} = $unit{image2} if $unit{image2};
# Advances
$unit_id{$unit{id}} = $i;
if ($unit{advanceto} ne 'null') {
foreach (split (/,/,$unit{advanceto})) {
print ADV "$i\t$_\n";
(my $link = $_) =~ s/\s/_/g;
$unit{advancetohtml} .= "<a href=$link.html>$_</a>&nbsp\n";
}
}
close UNIT;
# Generate HTML
if ($html_gen) {
(my $filename = $unit{id}) =~ s/\s/_/g;
$unit{unit_description} =~ s/( _ )?"//g;
$unit{num} = $i;
$unit{abilities} =~ s/\s/<!-- -->\n<!-- -->/;
foreach (keys %{ $types{$unit{movement_type}}{defense} }) {
$res{$_} = $types{$unit{movement_type}}{defense}{$_} . "%" unless $res{$_};
}
foreach (keys %{ $types{$unit{movement_type}}{movement} }) {
$move{$_} = $types{$unit{movement_type}}{movement}{$_} unless $move{$_};
}
open (HTML_UNIT, "> $html_dir/$filename.html") or die "Couldn't create $unit{id}: $!\n";
($html_unit = $html) =~ s/{(\w+?)}/$unit{$1}/eg;
$html_unit =~ s/::(\w+?)::/$res{$1}/eg;
$html_unit =~ s/~(\w+?)~/$move{$1}/eg;
$html_unit =~ s/--attacks--/$att/;
print HTML_UNIT $html_unit;
close HTML_UNIT;
}
}
# Sub to process the move types data from the units.cfg file
sub ProcessTypes {
my ($flag, $id);
open (TYPES, "<$data_dir/units.cfg") or die "Can't open units.cfg: $!\n";
open (REPORT, ">$report_dir/types.txt") or die "Can't open $unit: $!\n";
print REPORT "Mov_type\tVariable\tValue\tCategory\n";
while (<TYPES>) {
chomp; s/^\s*//;
$flag = 0 if /^\[\/movetype\]/;
$flag = 1 if /^\[movetype\]/;
$id = $1 if (/^name=(.*)/ and $flag);
$flag = 1 if /^\[\/(movement_costs|defense|resistance)\]/;
if ($flag==2) {
my ($var,$value) = split /=/;
print REPORT "$id\t$var\t$value\tMovement\n";
$types{$id}{movement}{$var} = $value;
}
$flag = 2 if /^\[movement_costs\]/;
if ($flag==3) {
my ($var,$value) = split /=/;
print REPORT "$id\t$var\t" . (100-$value) . "\tDefense\n";
$types{$id}{defense}{$var} = (100-$value);
}
$flag = 3 if (/^\[defense\]/ and $flag);
if ($flag==4) {
my ($var,$value) = split /=/;
print REPORT "$id\t$var\t" . (100-$value) . "\tResistance\n";
$types{$id}{defense}{$var} = (100-$value);
}
$flag = 4 if /^\[resistance\]/;
}
close TYPES;
}
# Sub to extract the factions from the factions file
sub ProcessFaction {
my $faction = shift;
my $unit_list;
open (FACTION, "<$faction") or die "Can't open $faction: $!\n";
while (<FACTION>) {
chomp; s/^\s*//;
$faction =~ s/factions\/(.+)\.cfg/$1/;
$unit_list .= "$1," if /^(?:leader|recruit)=(.+)/; # Only get the leaders and recruit, and all in the same line
}
$unit_list =~ s/,/\t/g;
$mp{$_}++ foreach split (/\t/, $unit_list); # Feed the %mp hash with the units
$faction =~ s(.*\/)(); # Take only the faction name
print FACT "$faction\t$unit_list\n";
}
# This sub prints the full section of the tree correspoding to the unit
sub PrintUnitTree {
my $unit = shift;
my $fh = shift; # The file to write in is also a parameter of the sub
unless ($adv_from{$unit}) { # Only process base units, units that don't have an advance from
print $fh "\n<tr>\n";
for ($i=0; $i<$units{$unit}[6];$i++) { # Add as many cells as levels (6th element of the unit array)
if ($spaces{$unit} > 1) { # Here we print the html for the row span
print $fh "<td rowspan=$spaces{$unit}></td>";
} else {
print $fh "<td></td>";
}
}
}
# Print the unit
if ($spaces{$unit} > 1) {
print $fh "<td rowspan=$spaces{$unit}>";
&PrintUnit ($unit, $fh);
print $fh "\n</td>";
} else {
print $fh "<td>";
&PrintUnit ($unit, $fh);
print $fh "\n</td>";
}
# If the unit has advances, call this sub again
if ($adv{$unit}) {
foreach $i (0..$#{ $adv{$unit} }) {
&PrintUnitTree ($adv{$unit}[$i], $fh);
}
} else {
print $fh "\n</tr>\n";
}
}
# Sub to print the unit information in HTML format
sub PrintUnit {
my $unit = shift; my $fh = shift;
(my $filename = $units{$unit}[0]) =~ s/\s/_/g;
print $fh "<a href=$filename.html><img src=$units{$unit}[8] alt=\"$units{$unit}[0]\"></a>";
print $fh "<br>\n<a href=$filename.html>$units{$unit}[0]</a>";
print $fh "<br>\n<!-- -->$units{$unit}[7]";
print $fh "<br>\nHP:$units{$unit}[2]";
print $fh "&nbsp;&nbsp;MP:$units{$unit}[4]";
print $fh "&nbsp;&nbsp;XP:$units{$unit}[5]";
$units{$unit}[11] =~ s/(\w)\s/$1<!-- -->\n<!-- -->/; # The code still needs one word to translate per line, surronded by html tags
print $fh "<br>\n<i>$units{$unit}[11]</i>" if length($units{$unit}[11]) > 0;
foreach $i (0..$#{ $attacks{$unit} }) { # There may be more than one attack
print $fh "\n<br>$attacks{$unit}[$i][2]<!-- -->: $attacks{$unit}[$i][3] - $attacks{$unit}[$i][4]";
print $fh "\n&nbsp;(<!-- -->$attacks{$unit}[$i][6]<!-- -->)" if $attacks{$unit}[$i][6];
}
}
# Updates the unit files with the Advance From information
sub UpdateAdvanceFrom {
my @html_units = glob("$html_dir/*.html");
foreach (@html_units) {
tie @html, 'Tie::File', $_ or die "Couldn't open file: $!\n";
my $adv_html;
for (@html) {
# Build the advance from html based on the id
if (/--id=(\d+)--/) {
my $id = $1;
(my $filename = $units{$adv_from{$id}}[0]) =~ s/\s/_/g;
$adv_html = "<a href=$filename.html>$units{$adv_from{$id}}[0]</a>";
}
s/--advancefrom--/$adv_html/;
last if (/<b>HP: <\/b>/); # Stop processing the file here
}
untie @html;
}
}
# Remove comments in the english files
sub RemoveComments {
my @html_units = glob("$html_dir/*.html");
foreach (@html_units) {
print "$_\n";
tie @html, 'Tie::File', $_ or die "Couldn't open $_: $!\n";
for (@html) {
s/<!-- -->//g;
s|\.\./unit|unit|;
s|race\^||;
}
untie @html;
}
}
# Translate the html using the gettext module
sub TranslateUnits {
use Locale::Maketext::Gettext;
my @countries = glob("$wesnoth_dir/po/*");
foreach $country (@countries) {
$country =~ s(.*\/)(); # Take only the country
unless (-e "$html_dir/$country") {mkdir "$html_dir/$country" or die "$country directory cannot be created: $!\n";};
print "Processing $country\n";
my $MOfile = "$wesnoth_dir/po/$country/LC_MESSAGES/wesnoth.mo";
%dict = read_mo($MOfile);
# Add female entries
foreach $key (keys %dict) {
if ($key =~ /^female/) {
(my $newkey = $key) =~ s/^female.//;
$dict{$newkey} = $dict{$key};
}
}
# Process only the html files from the HTML folder
my @html_units = glob("$html_dir/*.html");
foreach $unit (@html_units) {
open (UNIT, "$unit") or die "Couldn't open $unit: $!\n";
$unit =~ s|/|/$country/|; # Create the same file in the country folder
open (TRANS, ">$unit") or die "Couldn't create $unit: $!\n";
while ($line = <UNIT>) {
$line = "<p><a href=../index.html>English</a></p>\n" if $line =~/^<p><a href=fr/; # Change links
if ($line =~/^<p><a href='EXE/) {$line = "" unless ($country =~ /(ca|fr|it)/);}
$line = "" if $line =~/^<p><a href='EOM/;
$line = "" if $line =~ m|<a href=\w+/index.html>|;
$line =~ s/<html lang="en">/<html lang="$country">/; # Change language tag
if ($line =~ m/>([^<]+)</g) { # Process the words between html tags
if ($dict{$1}) {
$line =~ s/>([^<]+)</>$dict{$1}</;
}
# Descriptions
if (length($1) > 50) {
my $patt = $1;
foreach $key (keys %dict) {
if ($key =~ /$patt/) { # English descriptions may not be complete (see info_html), a partial match should be unique enough
$line =~ s/>([^<]+)</>$dict{$key}</;
$line =~ s/\n/\n<br>/g; # Change line feeds to <br>
$line =~ s/<br>[A-Za-z :]+<\/p>/<\/p>/; # Remove the special notes line
last;
}
}
}
$line =~ s/<!-- -->//g; # Remove comments
$line =~ s|race\^||; # Remove race^ in case it is not translated
}
$line =~ s{src=("?)(?=\w)}{src=$1../}g; # Change the links
print TRANS $line;
}
close TRANS;
close UNIT;
}
}
}