1 ##########################################################################
3 # Copyright (c) 2003 Aymargeddon Development Team
6 # "FROGS" = Framework for Realtime Online Games of Strategy
8 # FROGS is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the Free
10 # Software Foundation; either version 2 of the License, or (at your option)
13 # FROGS is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc., 675
19 # Mass Ave, Cambridge, MA 02139, USA.
21 ###########################################################################
25 # Here we gather some utility-functions
30 use FROGS::Config qw ($conf);
35 # parse the command-line (or any other string-array)
36 # and overwrites $::conf with the new values
37 # example: ./scheduler.pl -DURATION-PRAY=1000 -MANA-BLESS_PRIEST=10
41 my ($left,$right) = split /=/,$arg;
42 my @parts = split /-/, $left;
44 # TODO: generalization
46 $::conf->{"-$parts[1]"}->{"-$parts[2]"} = $right;
48 $::conf->{"-$parts[1]"} = $right;
53 # returns 1 if $scalar is in @list
55 my ($scalar, @list) = @_;
58 return 1 if $le eq $scalar;
63 # returns all elements of @$A which are _not_ in @$B
64 # in an array reference
75 push @A_without_B, $a unless exists $h{$a};
81 my ($string,$level) = @_;
83 my $abslevel = $level;
86 # TODO: dirty hack, use caller() instead
89 $do = 1 if $::conf->{-EPL_DEBUG} >= $abslevel;
91 $do = 1 if $::conf->{-DEBUG} >= $abslevel;
93 if($::conf->{-FULL_DEBUG_FILE}){
96 print FULL_LOG "$string\n";
98 print FULL_LOG "$string";
102 # negativ values for level prints no newline
113 my $file = $::conf->{-FULL_DEBUG_FILE};
114 open(FULL_LOG,">$file") or die "can't open $file: $!";
125 for my $elem (@list){
126 $min = $elem if $elem < $min;
135 for my $elem (@list){
136 $max = $elem if $elem > $max;
141 # returns a shuffled list
143 my $array_ref = shift;
145 my @shuffled = sort { int(rand(3)) - 1 } @$array_ref;