… | |
… | |
147 | or warn "unable to write runtime file: $!"; |
147 | or warn "unable to write runtime file: $!"; |
148 | |
148 | |
149 | for my $map (values %cf::MAP) { |
149 | for my $map (values %cf::MAP) { |
150 | eval { |
150 | eval { |
151 | next if $map->in_memory != cf::MAP_IN_MEMORY; |
151 | next if $map->in_memory != cf::MAP_IN_MEMORY; |
|
|
152 | next if $map->players; |
152 | my $last_access = $map->last_access; |
153 | my $last_access = $map->last_access; |
153 | # not yet, because maps might become visible to players nearby |
154 | # not yet, because maps might become visible to players nearby |
154 | # we need a tiled meta map for this to work |
155 | # we need a tiled meta map for this to work |
155 | # if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) { |
156 | # if ($last_access + $DEACTIVATE_TIMEOUT <= $cf::RUNTIME) { |
156 | # $map->deactivate; |
157 | # $map->deactivate; |
… | |
… | |
334 | } |
335 | } |
335 | |
336 | |
336 | sub cf::map::swap_out { |
337 | sub cf::map::swap_out { |
337 | my ($self) = @_; |
338 | my ($self) = @_; |
338 | |
339 | |
|
|
340 | return if $self->players; |
|
|
341 | |
339 | $self->save if $self->in_memory == cf::MAP_IN_MEMORY; |
342 | $self->save if $self->in_memory == cf::MAP_IN_MEMORY; |
340 | $self->clear; |
343 | $self->clear; |
341 | $self->in_memory (cf::MAP_SWAPPED); |
344 | $self->in_memory (cf::MAP_SWAPPED); |
342 | } |
345 | } |
343 | |
346 | |
… | |
… | |
372 | } |
375 | } |
373 | |
376 | |
374 | sub cf::object::player::enter_exit { |
377 | sub cf::object::player::enter_exit { |
375 | my ($ob, $exit) = @_; |
378 | my ($ob, $exit) = @_; |
376 | |
379 | |
|
|
380 | return unless $ob->type == cf::PLAYER; |
|
|
381 | |
377 | # if at login, move to interim map immediately |
382 | # if at login, move to interim map immediately |
378 | unless ($exit) { |
383 | unless ($exit) { |
379 | # used on login only |
384 | # used on login only |
380 | $ob->enter_map ($LINK_MAP, 0, 0); |
385 | $ob->enter_map ($LINK_MAP, 0, 0); |
381 | } |
386 | } |
382 | |
387 | |
|
|
388 | my ($oldmap, $oldx, $oldy) = ($ob->map, $ob->x, $ob->y); |
|
|
389 | |
383 | #TODO: do this in the background, freeze the player if required |
390 | #TODO: do this in the background, freeze the player if required |
384 | sync_job { |
391 | sync_job { |
385 | my ($map, $x, $y); |
392 | my ($map, $x, $y); |
386 | |
393 | |
387 | unless ($exit) { |
394 | unless ($exit) { |
388 | # used on login only(?) |
395 | # used on login only(?) |
389 | $map = cf::map::find_map_nb $ob->contr->maplevel; |
396 | $map = cf::map::find_map_nb $ob->contr->maplevel; |
390 | ($x, $y) = ($ob->x, $ob->y); |
397 | ($x, $y) = ($ob->x, $ob->y); |
|
|
398 | |
|
|
399 | unless ($map) { |
|
|
400 | $map = cf::map::find_map_nb $emergency_position->[0] |
|
|
401 | or die "FATAL: cannot load emergency map\n"; |
|
|
402 | $x = $emergency_position->[1]; |
|
|
403 | $y = $emergency_position->[2]; |
|
|
404 | } |
|
|
405 | |
|
|
406 | } elsif ($exit->slaying eq "!") { |
391 | } else { |
407 | } else { |
392 | my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; |
408 | my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; |
393 | |
409 | |
394 | $map = cf::map::find_map_nb $path->as_string; |
410 | $map = cf::map::find_map_nb $path->as_string; |
395 | $map = $map->customise_for ($ob) if $map; |
411 | $map = $map->customise_for ($ob) if $map; |
396 | ($x, $y) = ($exit->stats->hp, $exit->stats->sp); |
412 | ($x, $y) = ($exit->stats->hp, $exit->stats->sp); |
397 | } |
413 | } |
398 | |
414 | |
399 | unless ($map) { |
415 | unless ($map) { |
400 | $map = cf::map::find_map_nb $emergency_position->[0] |
|
|
401 | or die "FATAL: cannot load emergency map\n"; |
|
|
402 | $x = $emergency_position->[1]; |
|
|
403 | $y = $emergency_position->[2]; |
|
|
404 | } |
|
|
405 | |
|
|
406 | if ($map) { |
|
|
407 | warn "entering ", $map->path, " at ($x, $y)\n";#d# |
|
|
408 | $map->do_load_nb; |
|
|
409 | $ob->enter_map ($map, $x, $y); |
|
|
410 | } else { |
|
|
411 | $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
416 | $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
417 | # restore original map position |
|
|
418 | ($map, $x, $y) = ($oldmap, $oldx, $oldy); |
412 | } |
419 | } |
|
|
420 | |
|
|
421 | warn "entering ", $map->path, " at ($x, $y)\n";#d# |
|
|
422 | $map->do_load_nb; |
|
|
423 | $ob->enter_map ($map, $x, $y); |
413 | } |
424 | } |
414 | } |
425 | } |
415 | |
426 | |
416 | sub cf::map::customise_for { |
427 | sub cf::map::customise_for { |
417 | my ($map, $ob) = @_; |
428 | my ($map, $ob) = @_; |