use strict;
use warnings;
use English;
+use Time::HiRes qw( time );
sub usage()
{
our @food;
our @carrion;
+our %flag_indices =
+(
+ 'NOTIFY_EQUIP' => 0 # the first of probably many.
+);
+
+
sub macroify_objname($)
{
- my $name = "".shift(@_);
+ my $name = "".shift @_;
$name =~ tr/'//d;
return uc(($name =~ tr/a-zA-Z/_/csr));
}
+sub flag_string($)
+{
+ my $aref = shift @_;
+ my @flag_fields = ();
+ if (!defined($aref))
+ {
+ return "0";
+ }
+ else
+ {
+ my $name;
+ for $name (@$aref)
+ {
+ die("Attempt to generate a flag string containing an undefined flag $name!") if !exists($flag_indices{$name});
+ my $idx = $flag_indices{$name};
+ $#flag_fields = $idx if ($idx > $#flag_fields);
+ if (!defined($flag_fields[$idx]))
+ {
+ $flag_fields[$idx] = "0 ";
+ }
+ $flag_fields[$idx] .= "| POF_$name ";
+ }
+ }
+ return join(", ", @flag_fields);
+}
+
sub commit_object($)
{
- my $href = shift;
+ my $href = shift(@_);
die("Attempt to commit an unnamed object!") if !exists($href->{name});
die("Attempt to commit a ASCIIless object ".$href->{name}."!") if !exists($href->{ascii});
die("Attempt to commit a UTF8less object ".$href->{name}."!") if !exists($href->{uni});
if (!exists($href->{plural}))
{
# naive fallback, guaranteed to look shit sooner or later
+ $href->{plural} = $href->{name}."s";
}
my $new_hash = {
'name' => $href->{name},
'rarity' => $href->{rarity},
'power' => $href->{power},
'power2' => $href->{power2},
- 'depth' => $href->{depth}
+ 'depth' => $href->{depth},
+ 'flags' => $href->{flags}
};
if ($href->{tag} eq 'WEAPON')
{
$working_object{name} = shift;
$working_object{plural} = "$working_object{name}s";
$working_object{tag} = shift;
+ $working_object{flags} = [];
}
my $input_line;
+our $start_time = time();
print "Processing permobj database $input_fname";
for $input_line (@input_file)
{
}
else
{
- die("Malformed/unrecognized line $input_line in object $working_object{name}");
+ my $test_line = "$input_line";
+ $test_line =~ s/\s+//;
+ if (exists($flag_indices{$test_line}))
+ {
+ my $aref = $working_object{flags};
+ push @$aref, $test_line;
+ }
+ else
+ {
+ die("Malformed/unrecognized line $input_line in object $working_object{name}");
+ }
}
}
commit_object(\%working_object);
open(HEADERFILE, ">", "pobj_id.hh") or die "pobj_comp: could not open pobj_id.hh for write: $!";
open(SOURCEFILE, ">", "permobj.cc") or die "pobj_comp: could not open permobj.cc for write: $!";
-print HEADERFILE "// pobj_id.hh\n// This file is autogenerated from $input_fname\n// and is subject to the same copyright licensing terms as that file.\n// Do not edit this file directly; edit $input_fname then use pobj_comp to\n// regenerate this file and permobj.cc\n#pragma once\nenum Pobj_id {\n";
+print HEADERFILE "// pobj_id.hh\n// This file is autogenerated from $input_fname\n// and is subject to the same copyright licensing terms as that file.\n// Do not edit this file directly; edit $input_fname\n// then use pobj_comp to regenerate this file and permobj.cc\n#pragma once\nenum Pobj_id {\n";
print SOURCEFILE "// permobj.cc\n// This file is autogenerated from $input_fname\n// and is subject to the same copyright licensing terms as that file.\n// Do not edit this file directly; edit $input_fname then use pobj_comp to\n// regenreate this file and pobj_id.hh\n#include \"victrix-abyssi.hh\"\nPermobj permobjs[NUM_OF_PERMOBJS] = {\n";
my $phref;
my $i;
print HEADERFILE ",\n";
}
print HEADERFILE " ${tagname}";
- printf SOURCEFILE " { \"%s\", \"%s\", \"%s\", POCLASS_WEAPON, %d, %s, %s, Gcol_%s, %d, %d, %d },\n", $phref->{name}, $phref->{plural}, $phref->{desc}, $phref->{rarity}, $phref->{ascii}, $phref->{uni}, $phref->{colour}, $phref->{power}, $phref->{power2}, $phref->{depth};
+ printf SOURCEFILE " { \"%s\", \"%s\", \"%s\", POCLASS_WEAPON, %d, %s, %s, Gcol_%s, %d, %d, %d, { %s } },\n", $phref->{name}, $phref->{plural}, $phref->{desc}, $phref->{rarity}, $phref->{ascii}, $phref->{uni}, $phref->{colour}, $phref->{power}, $phref->{power2}, $phref->{depth}, flag_string($phref->{flags});
}
if (defined($tagname))
{
close(SOURCEFILE);
close(HEADERFILE);
+our $end_time = time();
+printf "Processed $total_objs objects in %1.4f seconds.\n", ($end_time - $start_time);
-# vim:autoindent
+# vim:autoindent:smartindent