diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 45fcd8fa4..e5847a841 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -260,6 +260,9 @@ sub render_struct_fields { render_item($field); }; push @lines_rb, "}"; + + my $reftg = $field->getAttribute('ref-target'); + render_field_reftarget($type, $field, $name, $reftg) if ($reftg); } } @@ -267,6 +270,30 @@ sub render_struct_fields { } } +sub render_field_reftarget { + my ($parent, $field, $name, $reftg) = @_; + + my $aux = $field->getAttribute('aux-value'); + return if ($aux); # TODO + + my $tg = $global_types{$reftg}; + return if (!$tg); + my $tgvec = $tg->getAttribute('instance-vector'); + return if (!$tgvec); + $tgvec =~ s/\$global/df/; + return if $tgvec !~ /^[\w\.]+$/; + + my $tgname = "${name}_tg"; + $tgname =~ s/_id_tg//; + + for my $otherfield ($parent->findnodes('child::ld:field')) { + my $othername = $otherfield->getAttribute('name'); + $tgname .= '_' if ($othername and $tgname eq $othername); + } + + push @lines_rb, "def $tgname ; ${tgvec}[$name] ; end"; +} + sub render_class_vmethods { my ($vms) = @_; my $voff = 0; diff --git a/scripts/slayrace.rb b/scripts/slayrace.rb index eba57f0ef..bf8ccb939 100644 --- a/scripts/slayrace.rb +++ b/scripts/slayrace.rb @@ -1,19 +1,26 @@ -# slay all creatures of a given race (default = goblins) +# slay all creatures of a given race -race = $script_args[0] || 'GOBLIN' +race = $script_args[0] -all_races = df.world.raws.creatures.all.map { |cr| cr.creature_id } -raw_race = df.match_rawname(race, all_races) -raise 'invalid race' if not raw_race +all_races = df.world.units.active.map { |u| + u.race_tg.creature_id if not u.flags1.dead and not df.map_designation_at(u).hidden +}.compact.uniq.sort -race_nr = df.world.raws.creatures.all.index { |cr| cr.creature_id == raw_race } -count = 0 +if !race + puts all_races +else + raw_race = df.match_rawname(race, all_races) + raise 'invalid race' if not raw_race -df.world.units.active.each { |u| - if u.race == race_nr and u.body.blood_count != 0 - u.body.blood_count = 0 - count += 1 - end -} + race_nr = df.world.raws.creatures.all.index { |cr| cr.creature_id == raw_race } + count = 0 -puts "slain #{count} #{raw_race}" + df.world.units.active.each { |u| + if u.race == race_nr and u.body.blood_count != 0 and not u.flags1.dead + u.body.blood_count = 0 + count += 1 + end + } + + puts "slain #{count} #{raw_race}" +end