Permobj now has a flags field; NOTIFY_EQUIP flag now in use; pobj_comp updated accord...
authorMartin Read <martin@blackswordsonics.com>
Sat, 8 Feb 2014 17:08:09 +0000 (17:08 +0000)
committerMartin Read <martin@blackswordsonics.com>
Sat, 8 Feb 2014 17:08:09 +0000 (17:08 +0000)
default.permobjs
objects.hh
pobj_comp

index f1c4aba..0883c56 100644 (file)
@@ -52,6 +52,7 @@ COLOUR white
 POWER 20
 POWER2 0
 DEPTH 30
+NOTIFY_EQUIP
 
 WEAPON staff of fire
 PLURAL staves of fire
@@ -360,7 +361,7 @@ COLOUR l_purple
 POWER 15
 POWER2 -15
 DEPTH 30
-
+NOTIFY_EQUIP
 
 RING regeneration ring
 PLURAL regeneration rings
index 63da4b0..2df3b99 100644 (file)
@@ -50,6 +50,11 @@ enum poclass_num {
 
 #include "pobj_id.hh"
 
+#define POBJ_FLAG_WORDS 1
+
+// POF field 0
+#define POF_NOTIFY_EQUIP 0x00000001u
+
 /*! \brief The 'permanent object' database */
 struct Permobj {
     char const name[48]; //!< English-language name of item
@@ -63,6 +68,7 @@ struct Permobj {
     int power;  //!< first POCLASS-specific data field
     int power2; //!< second POCLASS-specific data field
     int depth;  //!< shallowest depth at which item can be randomly gen'd
+    uint32_t flags[POBJ_FLAG_WORDS];
 };
 #define NO_POBJ (-1)
 
index 7ebdeae..f6f7fc9 100755 (executable)
--- a/pobj_comp
+++ b/pobj_comp
@@ -3,6 +3,7 @@
 use strict;
 use warnings;
 use English;
+use Time::HiRes qw( time );
 
 sub usage()
 {
@@ -18,22 +19,55 @@ our @rings;
 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},
@@ -45,7 +79,8 @@ sub commit_object($)
         'rarity' =>  $href->{rarity},
         'power' =>  $href->{power},
         'power2' =>  $href->{power2},
-        'depth' =>  $href->{depth}
+        'depth' =>  $href->{depth},
+        'flags' => $href->{flags}
     };
     if ($href->{tag} eq 'WEAPON')
     {
@@ -100,10 +135,12 @@ sub reinit_working_object($$)
     $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)
 {
@@ -278,7 +315,17 @@ 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);
@@ -286,7 +333,7 @@ print "\n";
 
 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;
@@ -307,7 +354,7 @@ for ($i = 0; $i <= $#weapons; ++$i, ++$total_objs)
         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))
 {
@@ -446,5 +493,7 @@ printf HEADERFILE "};\n".join('', @firsts)."\n#define NUM_OF_PERMOBJS %d\n\n// p
 
 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