ruby: add method for basic xml ref-target support, tweak scripts/slayrace

develop
jj 2012-06-25 19:05:50 +02:00
parent 17d06b969b
commit 412e8608d8
2 changed files with 48 additions and 14 deletions

@ -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;

@ -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