1 ##########################################################################
3 # Copyright (c) 2003-2012 Aymargeddon Development Team
5 # This file is part of "Last days of Aymargeddon" - a massive multi player
6 # onine game of strategy
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 # See the GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ###########################################################################
26 # Here we gather some utility-functions
31 use FROGS::Config qw ($conf);
36 # parse the command-line (or any other string-array)
37 # and overwrites $::conf with the new values
38 # example: ./scheduler.pl -DURATION-PRAY=1000 -MANA-BLESS_PRIEST=10
42 my ($left,$right) = split /=/,$arg;
43 my @parts = split /-/, $left;
45 # TODO: generalization
47 $::conf->{"-$parts[1]"}->{"-$parts[2]"} = $right;
49 $::conf->{"-$parts[1]"} = $right;
54 # returns 1 if $scalar is in @list
56 my ($scalar, @list) = @_;
59 return 1 if $le eq $scalar;
64 # returns all elements of @$A which are _not_ in @$B
65 # in an array reference
76 push @A_without_B, $a unless exists $h{$a};
82 my ($string,$level) = @_;
84 my $abslevel = $level;
87 # TODO: dirty hack, use caller() instead
90 $do = 1 if $::conf->{-EPL_DEBUG} >= $abslevel;
92 $do = 1 if $::conf->{-DEBUG} >= $abslevel;
94 if($::conf->{-FULL_DEBUG_FILE}){
97 print FULL_LOG "$string\n";
99 print FULL_LOG "$string";
103 # negativ values for level prints no newline
114 my $file = $::conf->{-FULL_DEBUG_FILE};
115 open(FULL_LOG,">$file") or die "can't open $file: $!";
126 for my $elem (@list){
127 $min = $elem if $elem < $min;
136 for my $elem (@list){
137 $max = $elem if $elem > $max;
142 # returns a shuffled list
144 my $array_ref = shift;
146 my @shuffled = sort { int(rand(3)) - 1 } @$array_ref;