… | |
… | |
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; |
… | |
… | |
297 | $self->decay_objects; |
298 | $self->decay_objects; |
298 | $self->update_buttons; |
299 | $self->update_buttons; |
299 | $self->set_darkness_map; |
300 | $self->set_darkness_map; |
300 | $self->difficulty ($self->estimate_difficulty) |
301 | $self->difficulty ($self->estimate_difficulty) |
301 | unless $self->difficulty; |
302 | unless $self->difficulty; |
|
|
303 | $self->activate; |
302 | |
304 | |
303 | $self->in_memory (cf::MAP_IN_MEMORY); |
305 | $self->in_memory (cf::MAP_IN_MEMORY); |
304 | } |
306 | } |
305 | |
307 | |
306 | sub cf::map::do_load { |
308 | sub cf::map::do_load { |
… | |
… | |
333 | } |
335 | } |
334 | |
336 | |
335 | sub cf::map::swap_out { |
337 | sub cf::map::swap_out { |
336 | my ($self) = @_; |
338 | my ($self) = @_; |
337 | |
339 | |
|
|
340 | return if $self->players; |
|
|
341 | |
338 | $self->save if $self->in_memory == cf::MAP_IN_MEMORY; |
342 | $self->save if $self->in_memory == cf::MAP_IN_MEMORY; |
339 | $self->clear; |
343 | $self->clear; |
340 | $self->in_memory (cf::MAP_SWAPPED); |
344 | $self->in_memory (cf::MAP_SWAPPED); |
341 | } |
345 | } |
342 | |
346 | |
… | |
… | |
371 | } |
375 | } |
372 | |
376 | |
373 | sub cf::object::player::enter_exit { |
377 | sub cf::object::player::enter_exit { |
374 | my ($ob, $exit) = @_; |
378 | my ($ob, $exit) = @_; |
375 | |
379 | |
|
|
380 | return unless $ob->type == cf::PLAYER; |
|
|
381 | |
376 | # if at login, move to interim map immediately |
382 | # if at login, move to interim map immediately |
377 | unless ($exit) { |
383 | unless ($exit) { |
378 | # used on login only |
384 | # used on login only |
379 | $ob->enter_map ($LINK_MAP, 0, 0); |
385 | $ob->enter_map ($LINK_MAP, 0, 0); |
380 | } |
386 | } |
381 | |
387 | |
|
|
388 | my ($oldmap, $oldx, $oldy) = ($ob->map, $ob->x, $ob->y); |
|
|
389 | |
382 | #TODO: do this in the background, freeze the player if required |
390 | #TODO: do this in the background, freeze the player if required |
383 | sync_job { |
391 | sync_job { |
384 | my ($map, $x, $y); |
392 | my ($map, $x, $y); |
385 | |
393 | |
386 | unless ($exit) { |
394 | unless ($exit) { |
387 | # used on login only(?) |
395 | # used on login only(?) |
388 | $map = cf::map::find_map_nb $ob->contr->maplevel; |
396 | $map = cf::map::find_map_nb $ob->contr->maplevel; |
389 | ($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 "!") { |
390 | } else { |
407 | } else { |
391 | 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; |
392 | |
409 | |
393 | $map = cf::map::find_map_nb $path->as_string; |
410 | $map = cf::map::find_map_nb $path->as_string; |
394 | $map = $map->customise_for ($ob) if $map; |
411 | $map = $map->customise_for ($ob) if $map; |
395 | ($x, $y) = ($exit->stats->hp, $exit->stats->sp); |
412 | ($x, $y) = ($exit->stats->hp, $exit->stats->sp); |
396 | } |
413 | } |
397 | |
414 | |
398 | unless ($map) { |
415 | unless ($map) { |
399 | $map = cf::map::find_map_nb $emergency_position->[0] |
|
|
400 | or die "FATAL: cannot load emergency map\n"; |
|
|
401 | $x = $emergency_position->[1]; |
|
|
402 | $y = $emergency_position->[2]; |
|
|
403 | } |
|
|
404 | |
|
|
405 | if ($map) { |
|
|
406 | warn "entering ", $map->path, " at ($x, $y)\n";#d# |
|
|
407 | $map->do_load_nb; |
|
|
408 | $ob->enter_map ($map, $x, $y); |
|
|
409 | } else { |
|
|
410 | $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); |
411 | } |
419 | } |
|
|
420 | |
|
|
421 | warn "entering ", $map->path, " at ($x, $y)\n";#d# |
|
|
422 | $map->do_load_nb; |
|
|
423 | $ob->enter_map ($map, $x, $y); |
412 | } |
424 | } |
413 | } |
425 | } |
414 | |
426 | |
415 | sub cf::map::customise_for { |
427 | sub cf::map::customise_for { |
416 | my ($map, $ob) = @_; |
428 | my ($map, $ob) = @_; |