Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # Scans an input file for items in any of ranged weapons category
- # and creates a file for melee damage, similar to "UFOextender: Gun Melee".
- # YAML module 1.23 is recommended.
- # Thanks to tinita and ingy from #yaml@freenode.net
- use strict;
- use warnings;
- use 5.010;
- # install YAML or YAML::XS with
- # cpan YAML
- # cpan YAML::XS
- # or
- # apt-get install libyaml-perl
- # apt-get install libyaml-libyaml-perl
- use YAML qw/ LoadFile DumpFile /;
- #use YAML::XS qw/ LoadFile DumpFile /;
- use List::Util qw/ any none /;
- $YAML::UseHeader = 0;
- $YAML::Preserve = 1;
- my ($filename) = @ARGV;
- #my ($filename) = '/usr/share/openxcom/mods/XComFiles/Ruleset/items_XCOMFILES.rul';
- #my ($filename) = 'items_XCOMFILES.rul';
- my $data = LoadFile($filename);
- my $items_new = [];
- #for my $item (@{ $data->{items} }) {
- # In case the single root key isn't 'items'
- my @key_list = keys(%$data);
- my $single_key = $key_list[0];
- for my $item (@{ $data->{ $single_key } }) {
- my $categories = $item->{categories};
- # if categories doesn't exist or is empty
- if (not $categories or not @$categories) {
- next;
- }
- # if categories doesn't contain any ranged weapon
- if ( ( none { $_ eq "STR_PISTOLS" or
- $_ eq "STR_BOWS" or
- $_ eq "STR_SMGS" or
- $_ eq "STR_SHOTGUNS" or
- $_ eq "STR_RIFLES" or
- $_ eq "STR_SNIPER_RIFLES" or
- $_ eq "STR_CANNONS" or
- $_ eq "STR_MACHINE_GUNS" or
- $_ eq "STR_LAUNCHERS" } @$categories ) or
- ( any { $_ eq "STR_CLIPS" } @$categories ) ) {
- next;
- }
- # delete all unnecessary fields; 'categories' is still needed
- foreach my $key (keys %$item) {
- if ( ($key ne 'categories') and ($key ne 'type') ) {
- delete $item->{$key};
- }
- }
- # add melee power/TUs/accuracy fields
- if (any { $_ eq "STR_PISTOLS" } @$categories) {
- $item->{meleePower} = 20;
- $item->{tuMelee} = 15;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_BOWS" } @$categories) {
- $item->{meleePower} = 20;
- $item->{tuMelee} = 15;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_SMGS" } @$categories) {
- $item->{meleePower} = 20;
- $item->{tuMelee} = 15;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_SHOTGUNS" } @$categories) {
- $item->{meleePower} = 50;
- $item->{tuMelee} = 40;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_RIFLES" } @$categories) {
- $item->{meleePower} = 50;
- $item->{tuMelee} = 40;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_SNIPER_RIFLES" } @$categories) {
- $item->{meleePower} = 50;
- $item->{tuMelee} = 40;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_CANNONS" } @$categories) {
- $item->{meleePower} = 65;
- $item->{tuMelee} = 50;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_MACHINE_GUNS" } @$categories) {
- $item->{meleePower} = 65;
- $item->{tuMelee} = 50;
- $item->{accuracyMelee} = 100;
- }
- if (any { $_ eq "STR_LAUNCHERS" } @$categories) {
- $item->{meleePower} = 80;
- $item->{tuMelee} = 80;
- $item->{accuracyMelee} = 100;
- }
- delete $item->{categories};
- push @$items_new, $item;
- }
- $data->{ $single_key } = $items_new;
- DumpFile "Gun_Melee_nonstandard.rul", $data;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement