… | |
… | |
120 | $self->name ("'The World' at +$x+$y"); |
120 | $self->name ("'The World' at +$x+$y"); |
121 | $self->msg ("worldmap dynamically created by map-world extension"); |
121 | $self->msg ("worldmap dynamically created by map-world extension"); |
122 | $self->outdoor (1); |
122 | $self->outdoor (1); |
123 | $self->default_region (undef); |
123 | $self->default_region (undef); |
124 | |
124 | |
125 | # $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; |
125 | $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; |
126 | # $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; |
126 | $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; |
127 | # $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; |
127 | $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; |
128 | # $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; |
128 | $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; |
129 | $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 100; |
|
|
130 | $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 129; |
|
|
131 | $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 129; |
|
|
132 | $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 100; |
|
|
133 | |
129 | |
134 | $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y |
130 | $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d.map", cf::datadir, cf::mapdir, $x, $y |
135 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
131 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
136 | |
132 | |
137 | 1 |
133 | 1 |
|
|
134 | } |
|
|
135 | |
|
|
136 | sub fill { |
|
|
137 | my ($self) = @_; |
|
|
138 | |
|
|
139 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
140 | Coro::cede; |
|
|
141 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
142 | my $ob = cf::object::new "deep_sea"; |
|
|
143 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
144 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
145 | } |
|
|
146 | } |
|
|
147 | $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
148 | $self->default_region (cf::region::find "panthalassia"); |
138 | } |
149 | } |
139 | |
150 | |
140 | sub load { |
151 | sub load { |
141 | my ($self) = @_; |
152 | my ($self) = @_; |
142 | |
153 | |
143 | if ($self->{load_path}) { |
154 | if ($self->{load_path}) { |
144 | $self->SUPER::load; |
155 | $self->SUPER::load; |
145 | } else { |
156 | } else { |
146 | $self->alloc; |
157 | $self->alloc; |
147 | |
158 | $self->fill; |
148 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
149 | Coro::cede; |
|
|
150 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
151 | my $ob = cf::object::new "deep_sea"; |
|
|
152 | $self->insert ($ob, $X, $Y); |
|
|
153 | } |
|
|
154 | } |
|
|
155 | $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
156 | $self->default_region (cf::region::find "ocean"); |
|
|
157 | |
|
|
158 | $self->in_memory (cf::MAP_IN_MEMORY); |
159 | $self->in_memory (cf::MAP_IN_MEMORY); |
159 | } |
160 | } |
160 | } |
161 | } |
161 | |
162 | |
162 | sub post_load { |
163 | sub post_load { |
… | |
… | |
164 | |
165 | |
165 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
166 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
166 | |
167 | |
167 | my ($x, $y) = $self->wxwy; |
168 | my ($x, $y) = $self->wxwy; |
168 | |
169 | |
169 | return |
|
|
170 | unless $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
170 | if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { |
|
|
171 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
|
|
172 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
|
|
173 | + ($x - 100) * $WORLD->{tile_w}; |
171 | |
174 | |
172 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
175 | my $reg; |
173 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
|
|
174 | + ($x - 100) * $WORLD->{tile_w}; |
|
|
175 | |
176 | |
176 | my $reg; |
177 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
178 | Coro::cede; |
|
|
179 | my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
180 | $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
181 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
182 | next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); |
|
|
183 | my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; |
|
|
184 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
185 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
186 | } |
|
|
187 | } |
177 | |
188 | |
178 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
189 | $self->set_regiondata ($reg, $WORLD->{reg_plt}); |
179 | Coro::cede; |
190 | } else { |
180 | my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
191 | $self->fill; |
181 | $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
182 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
183 | next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); |
|
|
184 | my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; |
|
|
185 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
186 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
187 | } |
|
|
188 | } |
192 | } |
189 | |
|
|
190 | $self->set_regiondata ($reg, $WORLD->{reg_plt}); |
|
|
191 | } |
193 | } |
192 | |
194 | |
193 | 1 |
195 | 1 |
194 | |
196 | |