camp-synt1.0 is here..
Moderator: Forum Moderators
- mercurius999
- Posts: 44
- Joined: February 23rd, 2010, 1:29 pm
camp-synt1.0 is here..
hello there and thanks to developpers for this wonderful game!
When I decided to write a scenario/campaign I was stucked by the difficulty to learn exactly how to code it: template code and reference was not enough precise and, because I'm very lazy, I decided to write a generator of templates.
Now here attached you have the result of this sparetime work. It is a Perl script and I have packed it to an win32 executable file to be run from command line. It is designed to work both 1.6.5 and 1.7 version (but more oriented to the future..) and can generate working campaigns (tested on both previous mentioned version).
It aims to be portable also but I have tested only on one platform (please send feedback on your platform if it works).
I really want to know where the WML need to be corrected and I'll very like if WML gurus can add comment to the various cfg files to explicate in deeper the code.
May this work help someone to learn WML and to write amusing campaigns!
mercurius999
PS version is now 1.0.1 with minor changes applied
PPS version 1.0.2 Mar 2016 succesfully create a campaign loadable with Wesnoth 1.12.5
When I decided to write a scenario/campaign I was stucked by the difficulty to learn exactly how to code it: template code and reference was not enough precise and, because I'm very lazy, I decided to write a generator of templates.
Now here attached you have the result of this sparetime work. It is a Perl script and I have packed it to an win32 executable file to be run from command line. It is designed to work both 1.6.5 and 1.7 version (but more oriented to the future..) and can generate working campaigns (tested on both previous mentioned version).
It aims to be portable also but I have tested only on one platform (please send feedback on your platform if it works).
I really want to know where the WML need to be corrected and I'll very like if WML gurus can add comment to the various cfg files to explicate in deeper the code.
May this work help someone to learn WML and to write amusing campaigns!
mercurius999
PS version is now 1.0.1 with minor changes applied
PPS version 1.0.2 Mar 2016 succesfully create a campaign loadable with Wesnoth 1.12.5
- Attachments
-
- camp-synt1.0.2.rar
- # 1.0.2 fixed open for read
# fixed example name to relfect new paths and names
#add error message for possible mispelled unit name
# 1.0.1b version given as string
# 1.0.1 #fixed minor hero type and recalling - (5.14 KiB) Downloaded 270 times
-
- camp-synt1.0.1.rar
- old version
- (1.23 MiB) Downloaded 534 times
Last edited by mercurius999 on March 10th, 2016, 12:20 pm, edited 2 times in total.
- King_Elendil
- Posts: 250
- Joined: February 26th, 2010, 4:54 am
Re: camp-synt1.0 is here..
If I am correct, that means that this will not run on a mac . I am a mac user, and I am wondering if there was any way that you could make this program mac friendly ? If you can't I understand, but if you can I would greatly appreciate it.mercurius999 wrote:Now here attached you have the result of this sparetime work. It is a Perl script and I have packed it to an win32 executable file to be run from command line. ...
~Thanks
I'm finally admitting that this will be a very long (if not permanent) Wesbreak. Thank y'all for the great times, and may Wesnoth rise to become one of the most popular games on the planet.
- artisticdude
- Moderator Emeritus
- Posts: 2424
- Joined: December 15th, 2009, 12:37 pm
- Location: Somewhere in the middle of everything
Re: camp-synt1.0 is here..
*Another mac user signs the petition.*
"I'm never wrong. One time I thought I was wrong, but I was mistaken."
- mercurius999
- Posts: 44
- Joined: February 23rd, 2010, 1:29 pm
Re: camp-synt1.0 is here..
King_Elendil I think Mac have Perl installed in the core or is disponible to install.. I know nothing about Mac.. but can you try from your shell something like perl -v and see what appen.
m*
m*
Re: camp-synt1.0 is here..
you can run perl scripts on a mac from the shell, see here: http://developer.apple.com/internet/ope ... pting.html
- King_Elendil
- Posts: 250
- Joined: February 26th, 2010, 4:54 am
Re: camp-synt1.0 is here..
Maybe (I don't really know), but I do know that a mac cannot open .exe files. If you could package it in a different file-type, that would probably make it work.mercurius999 wrote:King_Elendil I think Mac have Perl installed in the core or is disponible to install.. I know nothing about Mac.. but can you try from your shell something like perl -v and see what appen.
m*
I'm finally admitting that this will be a very long (if not permanent) Wesbreak. Thank y'all for the great times, and may Wesnoth rise to become one of the most popular games on the planet.
Re: camp-synt1.0 is here..
all you need is the perl script itself - the exe is just for windows users where perl is not installed per default...
- King_Elendil
- Posts: 250
- Joined: February 26th, 2010, 4:54 am
Re: camp-synt1.0 is here..
OK I am a little lost. Can someone who uses a mac tell me how to open/use this?
I'm finally admitting that this will be a very long (if not permanent) Wesbreak. Thank y'all for the great times, and may Wesnoth rise to become one of the most popular games on the planet.
Re: camp-synt1.0 is here..
see above link, or maybe this one: http://www.mactech.com/articles/mactech ... index.html
Re: camp-synt1.0 is here..
Hopefully no one will mind that I'm posting to an older thread here. This thread is still linked to from the "Authoring Tools" page, though, and I wanted to post something I discovered trying to get camp-synt1.0.1 to work on Linux.
After running the PERL script in terminal, I had a problem with the filetype encoding of the "_main.cfg" file. Although I could read it in VIM, I could not get any other text editor to open the file. After a little detective work I found the cause was line 25:
so I changed it to this:
...and now it works fine. I think the encoding problem is the space right before the quotes in the original code.
I'm new here, so I just thought I'd share this as my first post on these forums.
After running the PERL script in terminal, I had a problem with the filetype encoding of the "_main.cfg" file. Although I could read it in VIM, I could not get any other text editor to open the file. After a little detective work I found the cause was line 25:
Code: Select all
text="camp-synt1.0.1.pl "
Code: Select all
text="Made using Camp-Synt by mercurius999"
I'm new here, so I just thought I'd share this as my first post on these forums.
Re: camp-synt1.0 is here..
Welcome to the forums mFragin, and old thread or not, thanks for taking the time to fix something that wasn't working so others can use it, that's never a bad first post!mFragin wrote:Hopefully no one will mind...
...and now it works fine. I think the encoding problem is the space right before the quotes in the original code.
I'm new here, so I just thought I'd share this as my first post on these forums.
Does it work on the current versions as well?
Mainline Maintainer: AOI, DM, NR, TB and THoT.
UMC Maintainer: Forward They Cried, A Few Logs, A Few More Logs, Start of the War, and Battle Against Time
UMC Maintainer: Forward They Cried, A Few Logs, A Few More Logs, Start of the War, and Battle Against Time
Re: camp-synt1.0 is here..
The version on the first post here ("camp-synt-1.0.1.rar") produces the error. In my last message I told which line of the produced _main.cfg file had the problem, but today I had time to track down the part of the PERL script itself:Turuk wrote:Does it work on the current versions as well?
Line 225 of camp-synt1.0.1.pl is
Code: Select all
text="'.$0.' '.$VERSION.'"
So I changed my copy of camp-synt1.0.1.pl to
Code: Select all
text="'.$0.'"
Note: I'm no PERL programmer, so although I got it fixed, I'd need to look more at line 9 of the program, as I think that's where the version was supposedly set, as maybe that's turning up null instead of having the version set:
Code: Select all
my $VERSION = 1.0.1; #fixed minor hero type and recalling
Re: camp-synt1.0 is here..
Certainly, always glad to have more users coming around and contributing! Nice to hear that you're spreading it to children so they can grow up and keep this game going.mFragin wrote:At any rate, the workaround is in the discussion thread. Just glad to have it working, as it's a great little script. Also, thanks for the welcom, Turuk! I hope to help out around here a little, as I use Wesnoth in some of the classes I teach, and it's the main focus of our school's computer club.
Mainline Maintainer: AOI, DM, NR, TB and THoT.
UMC Maintainer: Forward They Cried, A Few Logs, A Few More Logs, Start of the War, and Battle Against Time
UMC Maintainer: Forward They Cried, A Few Logs, A Few More Logs, Start of the War, and Battle Against Time
- mercurius999
- Posts: 44
- Joined: February 23rd, 2010, 1:29 pm
Re: camp-synt1.0 is here..
Ok sorry i was away for a while...
the problem as wisely spotted was on the version string resulting undef as string (but valid)
force the stringyfication of the version number online 9 must suffice.
the problem as wisely spotted was on the version string resulting undef as string (but valid)
force the stringyfication of the version number online 9 must suffice.
Code: Select all
#!perl
use strict;
use Getopt::Long;
use File::Spec;
use File::Path ;
use Fcntl;
################################################################################
### options from command line and varz declaration
my $VERSION = '1.0.1'; #fixed minor hero type and recalling
my %wesk;
my ($camp,$scennum,@heroes,@units,@scen_nam);
my ($dump,$force_rewrite,$syso_flag,$syso_err,$wespath);
my ($cur_dir,$root,@dirs,$addons);
&helpme()if( ! GetOptions(
'camp=s' => \$camp,
'num=i' => \$scennum,
'heros=s' =>\@heroes,
'units=s' =>\@units,
'scen=s' =>\@scen_nam,
'dump' => \$dump,
'force' => \$force_rewrite,
'wesnothpath=s' => \$wespath,
) or !$camp );
$syso_flag = defined $force_rewrite ? O_WRONLY|O_CREAT : O_WRONLY|O_CREAT|O_EXCL;
$syso_err = defined $force_rewrite ? "ERROR on forced rewrite of " : "NOT rewriting existing file: ";
$cur_dir = File::Spec->curdir();
$cur_dir = File::Spec->rel2abs
unless ( File::Spec->file_name_is_absolute($cur_dir) );
$root = File::Spec->catdir($cur_dir,$camp);
$addons = (defined $wespath && $wespath =~/1\.6/ ? 'campaigns' : 'add-ons');
$wesk{root}=$root;
@dirs=qw (scenarios maps units images portraits story utils translations sounds);
$wesk{dir}=[@dirs];
######### _main.cfg creation
$wesk{_main}={
file=>'_main.cfg',
dir=>undef,
templ=>\&_main_templ,
};
######### _server.pbl creation
$wesk{_server}={
file=>'_server.pbl',
dir=>undef,
templ=>\&_server_templ,
};
######### deaths.cfg creation
$wesk{deaths}={
file=>'deaths.cfg',
dir=>'utils',
templ=>\&deaths_templ,
};
######### route.cfg creation
$wesk{route}={
file=>'route.cfg',
dir=>'utils',
templ=>\&route_templ,
};
######### story.cfg creation
$wesk{story}={
file=>'story.cfg',
dir=>'utils',
templ=>\&story_templ,
};
######### utils.cfg creation
$wesk{utils}={
file=>'utils.cfg',
dir=>'utils',
templ=>\&utils_templ,
};
#varz
@wesk{qw(camp_name wespath author camp_acron)} = @{[$camp,$wespath,'TheAuthor',&acron(&descr($camp))]};
#### how many scenarios?
$wesk{scen_num}=defined $scen_nam[0]?scalar @scen_nam:$scennum||2;
######### scenarios tree and map creation
foreach my $lvl (1..$wesk{scen_num}) {
my $prefixed = sprintf '%02d',$lvl;
my $name = $scen_nam[$lvl-1] ||$wesk{camp_name}.'_part_'.$lvl;
$prefixed.='_'.$name;
my $follower=( $lvl<$wesk{scen_num}?
((sprintf '%02d',$lvl+1).'_'.($scen_nam[$lvl] ||
$wesk{camp_name}.'_part_'.($lvl+1))):
undef);
push @{$wesk{scenarios}},{
file=>$prefixed.'.cfg',
dir=>'scenarios',
templ=>\&scen_templ,
seeds =>[$prefixed,$follower],
};
push @{$wesk{maps}},{
file=>$prefixed.'.map',
dir=>'maps',
templ=>\&map_templ,
seeds =>[$prefixed],
};
}
######### units tree creation
foreach my $unit (@units){
my ($name,$race,$from)=split /\./,$unit;
push @{$wesk{units}},{
file=>$name.'.cfg',
dir=>'units',
seeds=>[$name,($race||'humans'),($from||'Peasant')],
templ=>\&unit_templ,
};
}
######### heroes tree creation
foreach my $hero (@heroes){
my ($name,$type)=split /\./,$hero;
push @{$wesk{heroes}},{
name=>$name,
type=>$type||'Peasant',
}
}
if (defined $dump){print Dumper (\%wesk)}
################################################################################
######## recipit complete start cooking
#### dirs
for my $dir($wesk{root},@{$wesk{dir}}){
if ($dir ne $wesk{root}){
$dir = File::Spec->catdir($wesk{root},$dir);
}
if (-d $dir) {
print "already exists $dir\n";
next;
}
else{ mkdir $dir || die "unable to create $dir"}
print "created $dir\n";
}
#### files
for my $f ($wesk{_main},$wesk{_server},$wesk{story},$wesk{deaths},$wesk{route},$wesk{utils},
@{$wesk{scenarios}},@{$wesk{maps}},@{$wesk{units}}
)
{
&gently_do($f->{file},$f->{dir},$f->{templ},@{$f->{seeds}})#akatasbrah
}
################################################################################
#### SUBS
################################################################################
sub gently_do{
my $file = shift;
my $dir = shift;
my $filler= shift;
my $data = &$filler(@_);
my $path=File::Spec->catfile($wesk{root},$dir,$file);
if (sysopen(FH, $path, $syso_flag)) {
print FH $data if $data;
close FH;
print "wrote file $path\n";
}
else{print $syso_err," $path\n";}
}
################################################################################
sub descr {my $a =shift;$a =~s/\.\w{3}$//g;$a =~ s/^\d\d_//g; $a =~ s/_/ /g;return $a}
################################################################################
sub acron {my $n=shift; $n=~s/(?<=\w)\w|\s//g;return uc $n}
################################################################################
sub unit_templ{
my ($name,$race,$from)=@_;
my $templ;
$race = 'humans' unless defined $race;
$from = 'Peasant' unless defined $from;
$from.='.cfg';
unless (-d $wesk{wespath}){
print "WARNING: path to wesnoth files (now set to'$wesk{wespath}') not specified while new unit specified ",
"to be copied from $race/$from.\n";
my $supposed = File::Spec->catdir('..','..','..',File::Spec->curdir());
$supposed = File::Spec->rel2abs($supposed);
print "WARNING: supposing a path for wesnoth files at: $supposed\n";
$wesk{wespath} = $supposed;
}
my $orig = File::Spec->catfile($wesk{wespath},'data','core','units',$race,$from);
unless (-e $orig){
print "WARNING: $orig not found! No unit will be created. Rerun with a correct -w option.\n";
return;
}
my $new = $name.'.cfg';
my $udescr = &descr($name);
open FROM, "<$orig" || die "Unable to open $orig. May be -w option incorrect? now set to:$wesk{wespath}";
while (<FROM>){
s/#textdomain.+$/#textdomain wesnoth-$wesk{camp_name}/;
s/id=.+$/id=$udescr/;
s/name= _ ".+"$/name= _ "$udescr"/;
$templ.=$_;
}
close FROM;
return $templ;
}
sub utils_templ{undef}
################################################################################
sub _main_templ{
my $templ;
$templ.='[textdomain]
name="wesnoth-'.$wesk{camp_name}.'"
path="data/'.$addons.'/'.$wesk{camp_name}.'/translations"
[/textdomain]
#textdomain wesnoth-'.$wesk{camp_name}.'
[campaign]
abbrev= _ "'.$wesk{camp_acron}.'"
id='.$wesk{camp_name}.'
name= _ "'.&descr($wesk{camp_name}).'"
define='.$wesk{camp_name}.'
icon=units/human-peasants/peasant.png
description= _ "TEMPLATE DESCRIPTION GENERATED BY '.$0.'"
image=portraits/humans/peasant.png
difficulties=EASY,NORMAL,HARD
difficulty_descriptions= _ "&units/human-peasants/peasant-idle-6.png=Easy;*&units/human-peasants/peasant.png=Medium;&units/human-peasants/woodsman.png=Hard"
first_scenario='.$wesk{scenarios}[0]{seeds}[0].'
[about]
title= _ "Author = '.$wesk{author}.' -> Powered by Perl"
text="'.$0.' '.$VERSION.'"
[/about]
[about]
title= _ "Current Maintainer"
text="Your Name"
[/about]
[/campaign]
#ifdef '.$wesk{camp_name}.'
[binary_path]
path='.$addons.'/'.$wesk{camp_name}.'
[/binary_path]
# Load campaign utilities first
{~'.$addons.'/'.$wesk{camp_name}.'/utils}
# Add custom units
[+units]
{~'.$addons.'/'.$wesk{camp_name}.'/units}
[/units]
# Add scenarios
{~'.$addons.'/'.$wesk{camp_name}.'/scenarios}
#endif
';
return $templ;
}
################################################################################
sub _server_templ {
my $templ='title="'.&descr($wesk{camp_name}).'"
type="campaign"
icon="images/units/human-peasants/peasant.png"
version="0.0.0"
author="Droidly generated by the power of Perl"
passphrase="it prevents others from modifying the version of your campaign on the campaign server"
description="A skeleton of your Great Campaign"
email="put@your.mail"
';
return $templ;
}
################################################################################
sub story_templ {
#my @scenarios = @_;
my $templ='#textdomain wesnoth-'.$wesk{camp_name}."\n";
foreach my $part (1..$wesk{scen_num}){
#my $name= &descr($wesk{scenarios}[$part-1]{file});
#$name=~s/\s+/_/g;
my $name =$wesk{scenarios}[$part-1]{seeds}[0];
$templ.='#define '.$wesk{camp_acron}.'_STORY_'.$name.'
[story]
[part]
music=gameplay01.ogg
story= _ "The story of the '.&descr($name).' scenario."
background=maps/wesnoth.png
[/part]
[/story]
#enddef
';
}
return $templ;
}
################################################################################
sub route_templ {
#my @scenarios = @_;
my $templ='#textdomain wesnoth-'.$wesk{camp_name}."\n";
foreach my $part(1..$wesk{scen_num}){
my $name= $wesk{scenarios}[$part-1]{seeds}[0];
#$name=~s/\s+/_/g;
$templ.='#define '.$wesk{camp_acron}.'_ROUTE_'.$name.'
[story]
[part]
background=maps/wesnoth.png
show_title=yes
{OLD_JOURNEY 100 150}
{OLD_REST 150 150}
{NEW_REST 200 150}
{NEW_JOURNEY 250 150}
{NEW_BATTLE 250 200}
{NEW_JOURNEY 250 250}
[/part]
[/story]
#enddef
';
}
return $templ;
}
################################################################################
sub deaths_templ {
my @heroes = @_;
my $templ ='#textdomain wesnoth-'.$wesk{camp_name}."\n".
'#define '.$wesk{camp_acron}.'_DEATHS'."\n\n";
foreach my $h (@{$wesk{heroes}}){
$templ.='[event]
name=die
[filter]
id='.&descr($h->{name}).'
[/filter]
[message]
speaker=unit
message= _ "'.&descr($h->{name}).'\'s final words"
[/message]
#[endlevel]
# result=defeat
#[/endlevel]
[/event]
'."\n\n";
}
$templ.='#enddef '.$wesk{camp_acron}.'_DEATHS'."\n\n";
return $templ;
}
################################################################################
sub scen_templ {
my ($name,$next)=@_;
my $friends;
for my $fr(1..$#{$wesk{heroes}}) {
if ($name =~/^01/){
$friends.='[unit]'."\n\tside=1\n".'
id='.&descr($wesk{heroes}[$fr]{name}).'
name= _ "'.&descr($wesk{heroes}[$fr]{name}).'"
type='.&descr($wesk{heroes}[$fr]{type}).'
# placement=leader #1.7.5?
x,y=3,3
find_vacant=yes
[/unit]
';
}
else{$friends.='[recall]'."\n\tid=".&descr($wesk{heroes}[$fr]{name})."\n".'[/recall]'."\n";}
}
my $templ ='#textdomain wesnoth-'.$wesk{camp_name}.'
[scenario]
name= _ "'.&descr($name).'"
id='.$name."\n next_scenario=".(defined $next ? $next:"null")."\n".
'
map_data="{~'.$addons.'/'.$wesk{camp_name}.'/maps/'.$name.'.map}"
{SCENARIO_MUSIC "gameplay01.ogg"}
{TURNS 25 20 15}
{MORNING}
{AFTERNOON}
{DUSK}
{FIRST_WATCH}
{SECOND_WATCH}
{DAWN}
victory_when_enemies_defeated=yes
disallow_recall=no
{'.$wesk{camp_acron}.'_STORY_'.$name.'}
{'.$wesk{camp_acron}.'_ROUTE_'.$name.'}
{'.$wesk{camp_acron}.'_DEATHS'.'}
[side]
type=Peasant
id='.&descr($wesk{heroes}[0]{name}).'
name= _ "'.&descr($wesk{heroes}[0]{name}).'"
side=1
controller=human
team_name="'.&descr($wesk{heroes}[0]{name}).' team"
description="'.&descr($wesk{heroes}[0]{name}).' description"
{GOLD 150 125 100}
canrecruit=yes
recruit=Peasant
fog=no
shroud=no
[/side]
[side]
side=2
team_name=enemies
description=Enemy Name
type=Horseman
canrecruit=yes
recruit=Peasant
{GOLD 150 200 250}
[ai]
recruitment_pattern=fighter
aggression=2
caution=0.05
village_value=0.05
leader_value=4.25
[/ai]
[/side]
[event]
name=prestart
'.$friends.'
[/event]
[event]
name=start
[message]
description=
message= _ " HERE STARTS THE SHOW OF THE SCENARIO '.&descr($name).'!"
[/message]
[objectives]
side=1
[objective]
description= _ "Victory Condition"
condition=win
[/objective]
[objective]
description= _ "Death of Hero"
condition=lose
[/objective]
[objective]
description= _ "Turns run out"
condition=lose
[/objective]
[/objectives]
[/event]
[/scenario]
';
}
################################################################################
sub map_templ {
my $templ;
my ($x,$y) = (12,12);
my @map=map{ [('Gg,') x ($x-1), 'Gg'] }0..$y;
$map[2][2]='1 Ke,';
$map[2][3]='Ce,';
$map[$x-2][$y-3]='2 Ke,';
$map[$x-2][$y-4]='Ce,';
map {unshift @map, [$_] }"","usage=map","border_size=1";
for my $row(@map){
$templ.= join ' ', @{$row};
$templ.= "\n";
}
return $templ;
}
################################################################################
sub helpme {
print <<EOH;
USAGE:
$0 -c -n -s [-s] -h [-h] -u [-u] -f -w
Warning: put underscores instead of spaces or include in double quotes (eg: a_string or "a string")
Warning: you can use long or short notations for options:
-c A_str is the same of -c "A str" and of --campaign=A_str and --campaign="A str"
OPTIONS:
-c Name_with_underscores or "Name in quotes". This option is mandatory.
-n Number of scenarios if not provided scenario's names via -s option
-s First_scenario [-s Second_scenario -s Third_scenario -s End]
one or more scenario names provided in sequential order
-h Hero_Name [-h Best_Friend -h My_Dog.Wolf]
one or more hero names to create and use in the story.
If the name contains a '.' (dot sign) everything following it is considerd as the type of that unit.
-u new_Unit [-u Another_one -u Last]
one or more new unit types to be included in the private units folder.
If the name contains two dot signs it will be splitted this way: new_unit_name, race, copied_from
like in: Farm_rebel.humans.Peasant
This need -w option properly set.
-f Force the rewrite of an existing file.
-w Wesnoth path (in double quotes if containing spaces) to access original units.
If this option is set and the path match 1.6 then the directory 'campaigns' is used instead of 'add-ons'.
EXAMPLES:
-c Camp_Name -n 3
-c Camp_Name -n 3 -f
-c Camp_Name -s Scenario_One -s Scenario_Two
-c Camp_Name -s Scenario_One -s Scenario_Two -h Hero_Name -u New_unit
-c Camp_Name -s One -s Two -h Hero_Name -h His_Friend -u New_unit -u New_Bowman
-c Camp_Name -s One -s Two -h Hero -h Friend.New_Bowman -u New_Bowman
-c Camp_Name -s One -s Two -h Hero.New_Bowman -u New_Bowman.humans.Peasant
This program was originally written by mercurius999 A T wesnoth forum
This program is free software and can be modified and redistributed as Perl itself.
This software come with no warranty at all.
EOH
exit 0;
}