… | |
… | |
496 | |
496 | |
497 | # the unique path, undef == no special unique path |
497 | # the unique path, undef == no special unique path |
498 | sub uniq_path { |
498 | sub uniq_path { |
499 | my ($self) = @_; |
499 | my ($self) = @_; |
500 | |
500 | |
|
|
501 | $self->{user_rel} || $self->{ext} |
|
|
502 | ? undef |
501 | sprintf "%s/%s/%s", cf::localdir, cf::uniquedir, $self->_escaped_path |
503 | : sprintf "%s/%s/%s", cf::localdir, cf::uniquedir, $self->_escaped_path |
|
|
504 | } |
|
|
505 | |
|
|
506 | sub customise_for { |
|
|
507 | my ($self, $map, $ob) = @_; |
|
|
508 | |
|
|
509 | if ($map->per_player) { |
|
|
510 | return cf::map::find ("~" . $ob->name . "/" . $map->{path}{path}); |
|
|
511 | } |
|
|
512 | |
|
|
513 | $map |
502 | } |
514 | } |
503 | |
515 | |
504 | # this is somewhat ugly, but style maps do need special treatment |
516 | # this is somewhat ugly, but style maps do need special treatment |
505 | sub is_style_map { |
517 | sub is_style_map { |
506 | $_[0]{path} =~ m{^/styles/} |
518 | $_[0]{path} =~ m{^/styles/} |
… | |
… | |
514 | |
526 | |
515 | sub load_temp { |
527 | sub load_temp { |
516 | my ($self) = @_; |
528 | my ($self) = @_; |
517 | |
529 | |
518 | &cf::map::load_map_header ($self->save_path) |
530 | &cf::map::load_map_header ($self->save_path) |
|
|
531 | } |
|
|
532 | |
|
|
533 | sub unlink_save { |
|
|
534 | my ($self) = @_; |
|
|
535 | |
|
|
536 | utf8::encode (my $save = $self->save_path); |
|
|
537 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink $save; |
|
|
538 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$save.pst"; |
519 | } |
539 | } |
520 | |
540 | |
521 | package cf; |
541 | package cf; |
522 | |
542 | |
523 | ############################################################################# |
543 | ############################################################################# |
… | |
… | |
1401 | |
1421 | |
1402 | if ($self->{path}->is_style_map) { |
1422 | if ($self->{path}->is_style_map) { |
1403 | $self->{deny_save} = 1; |
1423 | $self->{deny_save} = 1; |
1404 | $self->{deny_reset} = 1; |
1424 | $self->{deny_reset} = 1; |
1405 | } else { |
1425 | } else { |
|
|
1426 | $self->decay_objects; |
1406 | $self->fix_auto_apply; |
1427 | $self->fix_auto_apply; |
1407 | $self->decay_objects; |
|
|
1408 | $self->update_buttons; |
1428 | $self->update_buttons; |
1409 | $self->set_darkness_map; |
1429 | $self->set_darkness_map; |
1410 | $self->difficulty ($self->estimate_difficulty) |
1430 | $self->difficulty ($self->estimate_difficulty) |
1411 | unless $self->difficulty; |
1431 | unless $self->difficulty; |
1412 | $self->activate; |
1432 | $self->activate; |
… | |
… | |
1548 | my ($self) = @_; |
1568 | my ($self) = @_; |
1549 | |
1569 | |
1550 | $self->reset_at <= $cf::RUNTIME |
1570 | $self->reset_at <= $cf::RUNTIME |
1551 | } |
1571 | } |
1552 | |
1572 | |
1553 | sub unlink_save { |
|
|
1554 | my ($self) = @_; |
|
|
1555 | |
|
|
1556 | utf8::encode (my $save = $self->{path}->save_path); |
|
|
1557 | aioreq_pri 3; IO::AIO::aio_unlink $save; |
|
|
1558 | aioreq_pri 3; IO::AIO::aio_unlink "$save.pst"; |
|
|
1559 | } |
|
|
1560 | |
|
|
1561 | sub rename { |
1573 | sub rename { |
1562 | my ($self, $new_path) = @_; |
1574 | my ($self, $new_path) = @_; |
1563 | |
1575 | |
1564 | $self->unlink_save; |
1576 | $self->{path}->unlink_save; |
1565 | |
1577 | |
1566 | delete $cf::MAP{$self->path}; |
1578 | delete $cf::MAP{$self->path}; |
1567 | $self->{path} = new cf::path $new_path; |
1579 | $self->{path} = new cf::path $new_path; |
1568 | $self->path ($self->{path}->as_string); |
1580 | $self->path ($self->{path}->as_string); |
1569 | $cf::MAP{$self->path} = $self; |
1581 | $cf::MAP{$self->path} = $self; |
… | |
… | |
1583 | |
1595 | |
1584 | delete $cf::MAP{$self->path}; |
1596 | delete $cf::MAP{$self->path}; |
1585 | |
1597 | |
1586 | $_->clear_links_to ($self) for values %cf::MAP; |
1598 | $_->clear_links_to ($self) for values %cf::MAP; |
1587 | |
1599 | |
1588 | $self->unlink_save; |
1600 | $self->{path}->unlink_save; |
1589 | $self->destroy; |
1601 | $self->destroy; |
1590 | } |
1602 | } |
1591 | |
1603 | |
1592 | my $nuke_counter = "aaaa"; |
1604 | my $nuke_counter = "aaaa"; |
1593 | |
1605 | |
… | |
… | |
1596 | |
1608 | |
1597 | $self->{deny_save} = 1; |
1609 | $self->{deny_save} = 1; |
1598 | $self->reset_timeout (1); |
1610 | $self->reset_timeout (1); |
1599 | $self->rename ("{nuke}/" . ($nuke_counter++)); |
1611 | $self->rename ("{nuke}/" . ($nuke_counter++)); |
1600 | $self->reset; # polite request, might not happen |
1612 | $self->reset; # polite request, might not happen |
1601 | } |
|
|
1602 | |
|
|
1603 | sub customise_for { |
|
|
1604 | my ($map, $ob) = @_; |
|
|
1605 | |
|
|
1606 | if ($map->per_player) { |
|
|
1607 | return cf::map::find "~" . $ob->name . "/" . $map->{path}{path}; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | $map |
|
|
1611 | } |
1613 | } |
1612 | |
1614 | |
1613 | =item cf::map::unique_maps |
1615 | =item cf::map::unique_maps |
1614 | |
1616 | |
1615 | Returns an arrayref of cf::path's of all shared maps that have |
1617 | Returns an arrayref of cf::path's of all shared maps that have |
… | |
… | |
1815 | |
1817 | |
1816 | $self->enter_link; |
1818 | $self->enter_link; |
1817 | |
1819 | |
1818 | (async { |
1820 | (async { |
1819 | my $map = cf::map::find $path->as_string; |
1821 | my $map = cf::map::find $path->as_string; |
1820 | $map = $map->customise_for ($self) if $map; |
1822 | $map = $map->{path}->customise_for ($map, $self) if $map; |
1821 | |
1823 | |
1822 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1824 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1823 | # if $map; |
1825 | # if $map; |
1824 | |
1826 | |
1825 | $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1827 | $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
… | |
… | |
2468 | reentrant => 0, |
2470 | reentrant => 0, |
2469 | prio => 0, |
2471 | prio => 0, |
2470 | at => $NEXT_TICK || $TICK, |
2472 | at => $NEXT_TICK || $TICK, |
2471 | data => WF_AUTOCANCEL, |
2473 | data => WF_AUTOCANCEL, |
2472 | cb => sub { |
2474 | cb => sub { |
|
|
2475 | $NOW = Event::time; |
|
|
2476 | |
2473 | cf::server_tick; # one server iteration |
2477 | cf::server_tick; # one server iteration |
2474 | $RUNTIME += $TICK; |
2478 | $RUNTIME += $TICK; |
2475 | $NEXT_TICK += $TICK; |
2479 | $NEXT_TICK += $TICK; |
2476 | |
2480 | |
2477 | $WAIT_FOR_TICK->broadcast; |
2481 | $WAIT_FOR_TICK->broadcast; |