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

Comparing deliantra/server/ext/00_map_handling.ext (file contents):
Revision 1.6 by root, Sat Dec 30 20:32:30 2006 UTC vs.
Revision 1.8 by root, Sun Dec 31 10:28:36 2006 UTC

138 exit 1; 138 exit 1;
139 } 139 }
140})->prio (Coro::PRIO_MAX); 140})->prio (Coro::PRIO_MAX);
141 141
142our $SCHEDULER = cf::coro { 142our $SCHEDULER = cf::coro {
143 Coro::Timer::sleep 3600;#d#TODO#for debugging only
143 while () { 144 while () {
144 Coro::Timer::sleep $SCHEDULE_INTERVAL; 145 Coro::Timer::sleep $SCHEDULE_INTERVAL;
145 146
146 write_runtime 147 write_runtime
147 or warn "unable to write runtime file: $!"; 148 or warn "unable to write runtime file: $!";
172 } 173 }
173 } 174 }
174}; 175};
175$SCHEDULER->prio (-2); 176$SCHEDULER->prio (-2);
176 177
178sub generate_random_map {
179 my ($path, $rmp) = @_;
180
181 # mit "rum" bekleckert, nicht
182 cf::map::_create_random_map
183 $path,
184 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
185 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle},
186 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
187 $rmp->{exit_on_final_map},
188 $rmp->{xsize}, $rmp->{ysize},
189 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
190 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
191 $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation},
192 $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp},
193 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
194 $rmp->{region}
195}
196
197sub parse_random_map_params {
198 my ($spec) = @_;
199
200 my $rmp;
201
202 for (split /\n/, $spec) {
203 my ($k, $v) = split /\s+/, $_, 2;
204
205 $rmp->{lc $k} = $v if (length $k) && (length $v);
206 }
207
208 $rmp
209}
210
211sub prepare_random_map {
212 my ($exit) = @_;
213
214 my $rmp = parse_random_map_params $exit->msg;
215 use Data::Dumper;
216 die Dumper $rmp;
217}
218
177sub sync_job(&) { 219sub sync_job(&) {
178 my ($job) = @_; 220 my ($job) = @_;
179 221
180 my $done; 222 my $done;
181 my @res; 223 my @res;
193 while (!$done) { 235 while (!$done) {
194 Coro::cede_notself; 236 Coro::cede_notself;
195 Event::one_event unless Coro::nready; 237 Event::one_event unless Coro::nready;
196 } 238 }
197 239
240 warn "sync<@res>\n";#d#
198 wantarray ? @res : $res[0] 241 wantarray ? @res : $res[0]
199} 242}
200 243
201# and all this just because we cannot iterate over 244# and all this just because we cannot iterate over
202# all maps in C++... 245# all maps in C++...
225 $map->{load_path} = $path; 268 $map->{load_path} = $path;
226 269
227 $map 270 $map
228} 271}
229 272
230sub cf::map::find_map_nb { 273sub cf::map::find_map {
231 my ($path, $origin) = @_; 274 my ($path, $origin) = @_;
232 275
233 warn "find_map_nb<$path,$origin>\n";#d# 276 warn "find_map<$path,$origin>\n";#d#
234 277
235 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path; 278 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path;
236 my $key = $path->as_string; 279 my $key = $path->as_string;
237 280
238 $cf::MAP{$key} || do { 281 $cf::MAP{$key} || do {
240 my $map = try_load_header $path->save_path; 283 my $map = try_load_header $path->save_path;
241 284
242 if (!$map) { 285 if (!$map) {
243 $map = try_load_header $path->load_path 286 $map = try_load_header $path->load_path
244 or return; 287 or return;
245 }
246 288
247 $map or return;
248
249 $map->instantiate; 289 $map->instantiate;
290
291 # per-player maps become, after loading, normal maps
292 $map->per_player (0) if $path->{user_rel};
293 }
294
250 $map->path ($key); 295 $map->path ($key);
251 $map->{path} = $path; 296 $map->{path} = $path;
252 297
253 $map->per_player (0) if $path->{user_rel};
254
255 $map->reset if $map->should_reset; 298 $map->reset if $map->should_reset;
256 299
257 $cf::MAP{$key} = $map 300 $cf::MAP{$key} = $map
258 } 301 }
259} 302}
260 303
261sub cf::map::find_map {
262 my ($path, $origin) = @_;
263
264 $path = new cf::path $path, $origin && $origin->path;
265 my $key = $path->as_string;
266
267 warn "find_map<$path,$origin>\n";#d#
268
269 $cf::MAP{$key} || sync_job {
270 cf::map::find_map_nb $path;
271 }
272}
273
274sub cf::map::do_load_nb { 304sub cf::map::load {
275 my ($self) = @_; 305 my ($self) = @_;
276 306
277 return 0 unless $self->in_memory == cf::MAP_SWAPPED; 307 return if $self->in_memory != cf::MAP_SWAPPED;
278 308
279 $self->in_memory (cf::MAP_LOADING); 309 $self->in_memory (cf::MAP_LOADING);
280 310
281 my $path = $self->{path}; 311 my $path = $self->{path};
282 312
303 $self->activate; 333 $self->activate;
304 334
305 $self->in_memory (cf::MAP_IN_MEMORY); 335 $self->in_memory (cf::MAP_IN_MEMORY);
306} 336}
307 337
308sub cf::map::do_load { 338sub cf::map::load_map_sync {
309 my ($self) = @_; 339 my ($path, $origin) = @_;
310 340
311 warn "do_load<$self>\n";#d# 341 warn "load_map_sync<$path, $origin>\n";#d#
312 342
313 sync_job { 343 sync_job {
314 cf::map::do_load_nb $self; 344 my $map = cf::map::find_map $path, $origin
345 or return;
346 $map->load;
347 $map
315 }; 348 }
316} 349}
317 350
318sub cf::map::save { 351sub cf::map::save {
319 my ($self) = @_; 352 my ($self) = @_;
320 353
336 369
337sub cf::map::swap_out { 370sub cf::map::swap_out {
338 my ($self) = @_; 371 my ($self) = @_;
339 372
340 return if $self->players; 373 return if $self->players;
341
342 $self->save if $self->in_memory == cf::MAP_IN_MEMORY; 374 return if $self->in_memory != cf::MAP_IN_MEMORY;
375
376 $self->save;
343 $self->clear; 377 $self->clear;
344 $self->in_memory (cf::MAP_SWAPPED); 378 $self->in_memory (cf::MAP_SWAPPED);
345} 379}
346 380
347sub cf::map::should_reset { 381sub cf::map::should_reset {
348 my ($map) = @_; 382 my ($map) = @_;
349 383
350 # TODO: safety, remove and allow resettable per-player maps 384 # TODO: safety, remove and allow resettable per-player maps
351 return if $map->{path}{user_rel};#d# 385 return if $map->{path}{user_rel};#d#
352 return if $map->per_player;
353 return unless $map->reset_timeout; 386 return unless $map->reset_timeout;
354 387
355 my $time = $map->fixed_resettime ? $map->reset_time : $map->last_access; 388 my $time = $map->fixed_resettime ? $map->reset_time : $map->last_access;
356 389
357 $time + $map->reset_timeout < $cf::RUNTIME 390 $time + $map->reset_timeout < $cf::RUNTIME
377sub cf::object::player::enter_exit { 410sub cf::object::player::enter_exit {
378 my ($ob, $exit) = @_; 411 my ($ob, $exit) = @_;
379 412
380 return unless $ob->type == cf::PLAYER; 413 return unless $ob->type == cf::PLAYER;
381 414
382 # if at login, move to interim map immediately
383 unless ($exit) {
384 # used on login only
385 $ob->enter_map ($LINK_MAP, 0, 0);
386 }
387
388 my ($oldmap, $oldx, $oldy) = ($ob->map, $ob->x, $ob->y); 415 my ($oldmap, $oldx, $oldy) = ($ob->map, $ob->x, $ob->y);
389 416
390 #TODO: do this in the background, freeze the player if required 417 #TODO: do this in the background, freeze the player if required
391 sync_job { 418 sync_job {
392 my ($map, $x, $y); 419 my ($map, $x, $y);
393 420
421 if ($exit->slaying eq "/!") {
422 prepare_random_map $exit;
423 }
424
425 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path;
426
427 $map = cf::map::find_map $path->as_string;
428 $map = $map->customise_for ($ob) if $map;
429 ($x, $y) = ($exit->stats->hp, $exit->stats->sp);
430
394 unless ($exit) { 431 unless ($map) {
395 # used on login only(?) 432 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
396 $map = cf::map::find_map_nb $ob->contr->maplevel; 433
397 ($x, $y) = ($ob->x, $ob->y); 434 # restore original map position
435 ($map, $x, $y) = ($oldmap, $oldx, $oldy);
398 436
399 unless ($map) { 437 unless ($map) {
400 $map = cf::map::find_map_nb $emergency_position->[0] 438 $map = cf::map::find_map $emergency_position->[0]
401 or die "FATAL: cannot load emergency map\n"; 439 or die "FATAL: cannot load emergency map\n";
402 $x = $emergency_position->[1]; 440 $x = $emergency_position->[1];
403 $y = $emergency_position->[2]; 441 $y = $emergency_position->[2];
404 } 442 }
405
406 } elsif ($exit->slaying eq "!") {
407 } else {
408 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path;
409
410 $map = cf::map::find_map_nb $path->as_string;
411 $map = $map->customise_for ($ob) if $map;
412 ($x, $y) = ($exit->stats->hp, $exit->stats->sp);
413 } 443 }
414 444
415 unless ($map) { 445 # use -1, -1 as default coordinates, not 0, 0
416 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); 446 ($x, $y) = ($map->enter_x, $map->enter_y)
417 # restore original map position 447 if $x <=0 && $y <= 0;
418 ($map, $x, $y) = ($oldmap, $oldx, $oldy);
419 }
420 448
421 warn "entering ", $map->path, " at ($x, $y)\n";#d# 449 warn "entering ", $map->path, " at ($x, $y)\n";#d#
422 $map->do_load_nb; 450 $map->load;
423 $ob->enter_map ($map, $x, $y); 451 $ob->enter_map ($map, $x, $y);
424 } 452 }
425} 453}
426 454
427sub cf::map::customise_for { 455sub cf::map::customise_for {
428 my ($map, $ob) = @_; 456 my ($map, $ob) = @_;
429 457
430 if ($map->per_player) { 458 if ($map->per_player) {
431 return cf::map::find_map_nb "~" . $ob->name . "/" . $map->{path}{path}; 459 return cf::map::find_map "~" . $ob->name . "/" . $map->{path}{path};
432 } 460 }
433 461
434 $map 462 $map
435} 463}
436 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines