ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-random.ext
(Generate patch)

Comparing deliantra/server/ext/map-random.ext (file contents):
Revision 1.38 by root, Fri Mar 26 00:26:48 2010 UTC vs.
Revision 1.39 by root, Sat Mar 27 20:12:24 2010 UTC

54 $self->activate; 54 $self->activate;
55 55
56 1 56 1
57} 57}
58 58
59sub select_random_map {
60 my ($maps, $difficulty) = @_;
61
62 # because I am lazy, I ignore the weighting
63
64 my @maps = keys %$maps;
65
66 cf::map::find "/styles/$maps[cf::rmg_rndm scalar @maps]"
67}
68
59# called by the random map generator 69# called by the random map generator
60sub find_style_; 70sub find_style_;
61sub find_style_($$) { 71sub find_style_($$) {
62 my ($path, $difficulty) = @_; 72 my ($path, $difficulty) = @_;
63 73
64 my $map; 74 my $map;
75
76 # see if there is a metafile
77 if (0 < aio_load "$cf::MAPDIR/$path.rmg", my $meta) {
78 $meta = cf::decode_json $meta;
79
80 # only "maps" is supported
81 if ($meta->{maps}) {
82 $map = select_random_map $meta->{maps}, $difficulty;
83 }
84 }
65 85
66 $map = cf::map::find $path 86 $map = cf::map::find $path
67 unless aio_stat "$cf::MAPDIR/$path.map"; 87 unless aio_stat "$cf::MAPDIR/$path.map";
68 88
69 unless ($map) { 89 unless ($map) {
106sub find_style($$$) { 126sub find_style($$$) {
107 my ($dir, $name, $difficulty) = @_; 127 my ($dir, $name, $difficulty) = @_;
108 128
109 cf::cede_to_tick; 129 cf::cede_to_tick;
110 130
131 my $map;
132
133 if ($name) {
111 my $map = find_style_ $name ? "$dir/$name" : $dir, $difficulty; 134 $map = find_style_ "$dir/$name", $difficulty;
135 } else {
136 $map = (find_style_ "$dir/default", $difficulty)
137 || (find_style_ $dir, $difficulty);
138 }
112 139
113 if ($map) { 140 if ($map) {
114 $map->load; 141 $map->load;
115 $map->deactivate; 142 $map->deactivate;
116 } 143 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines