… | |
… | |
8 | use Storable; |
8 | use Storable; |
9 | use Opcode; |
9 | use Opcode; |
10 | use Safe; |
10 | use Safe; |
11 | use Safe::Hole; |
11 | use Safe::Hole; |
12 | |
12 | |
13 | use Coro 3.4 (); |
13 | use Coro 3.5 (); |
14 | use Coro::Event; |
14 | use Coro::Event; |
15 | use Coro::Timer; |
15 | use Coro::Timer; |
16 | use Coro::Signal; |
16 | use Coro::Signal; |
17 | use Coro::Semaphore; |
17 | use Coro::Semaphore; |
18 | use Coro::AIO; |
18 | use Coro::AIO; |
… | |
… | |
1176 | } |
1176 | } |
1177 | |
1177 | |
1178 | sub normalise { |
1178 | sub normalise { |
1179 | my ($path, $base) = @_; |
1179 | my ($path, $base) = @_; |
1180 | |
1180 | |
|
|
1181 | $path = "$path"; # make sure its a string |
|
|
1182 | |
1181 | # map plan: |
1183 | # map plan: |
1182 | # |
1184 | # |
1183 | # /! non-realised random map exit (special hack!) |
1185 | # /! non-realised random map exit (special hack!) |
1184 | # {... are special paths that are not being touched |
1186 | # {... are special paths that are not being touched |
1185 | # ?xxx/... are special absolute paths |
1187 | # ?xxx/... are special absolute paths |
… | |
… | |
1221 | $self->init; # pass $1 etc. |
1223 | $self->init; # pass $1 etc. |
1222 | return $self; |
1224 | return $self; |
1223 | } |
1225 | } |
1224 | } |
1226 | } |
1225 | |
1227 | |
1226 | Carp::carp "unable to resolve path '$path'."; |
1228 | Carp::carp "unable to resolve path '$path' (base '$base')."; |
1227 | () |
1229 | () |
1228 | } |
1230 | } |
1229 | |
1231 | |
1230 | sub init { |
1232 | sub init { |
1231 | my ($self) = @_; |
1233 | my ($self) = @_; |
… | |
… | |
1360 | $map->{last_save} = $cf::RUNTIME; |
1362 | $map->{last_save} = $cf::RUNTIME; |
1361 | |
1363 | |
1362 | $map->load_header |
1364 | $map->load_header |
1363 | or return; |
1365 | or return; |
1364 | |
1366 | |
1365 | if ($map->should_reset) { |
1367 | if ($map->should_reset && 0) {#d#TODO# disabled, crashy (locking issue?) |
1366 | # doing this can freeze the server in a sync job, obviously |
1368 | # doing this can freeze the server in a sync job, obviously |
1367 | #$cf::WAIT_FOR_TICK->wait; |
1369 | #$cf::WAIT_FOR_TICK->wait; |
1368 | $map->reset; |
1370 | $map->reset; |
1369 | undef $guard; |
1371 | undef $guard; |
1370 | $map = find $path |
1372 | return find $path; |
1371 | or return; |
|
|
1372 | } |
1373 | } |
1373 | |
1374 | |
1374 | $cf::MAP{$path} = $map |
1375 | $cf::MAP{$path} = $map |
1375 | } |
1376 | } |
1376 | } |
1377 | } |
… | |
… | |
1378 | sub pre_load { } |
1379 | sub pre_load { } |
1379 | sub post_load { } |
1380 | sub post_load { } |
1380 | |
1381 | |
1381 | sub load { |
1382 | sub load { |
1382 | my ($self) = @_; |
1383 | my ($self) = @_; |
|
|
1384 | |
|
|
1385 | local $self->{deny_reset} = 1; # loading can take a long time |
1383 | |
1386 | |
1384 | my $path = $self->{path}; |
1387 | my $path = $self->{path}; |
1385 | my $guard = cf::lock_acquire "map_load:$path"; |
1388 | my $guard = cf::lock_acquire "map_load:$path"; |
1386 | |
1389 | |
1387 | return if $self->in_memory != cf::MAP_SWAPPED; |
1390 | return if $self->in_memory != cf::MAP_SWAPPED; |
… | |
… | |
1730 | =cut |
1733 | =cut |
1731 | |
1734 | |
1732 | sub link_map { |
1735 | sub link_map { |
1733 | unless ($LINK_MAP) { |
1736 | unless ($LINK_MAP) { |
1734 | $LINK_MAP = cf::map::find "{link}" |
1737 | $LINK_MAP = cf::map::find "{link}" |
1735 | or do { warn "FATAL: unable to provide {link} map, exiting."; exit 1 }; |
1738 | or cf::cleanup "FATAL: unable to provide {link} map, exiting."; |
1736 | $LINK_MAP->load; |
1739 | $LINK_MAP->load; |
1737 | } |
1740 | } |
1738 | |
1741 | |
1739 | $LINK_MAP |
1742 | $LINK_MAP |
1740 | } |
1743 | } |
… | |
… | |
1747 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
1750 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
1748 | |
1751 | |
1749 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
1752 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
1750 | if $self->map; |
1753 | if $self->map; |
1751 | |
1754 | |
1752 | $self->enter_map ($LINK_MAP || link_map, 20, 20); |
1755 | $self->enter_map ($LINK_MAP || link_map, 10, 10); |
1753 | } |
1756 | } |
1754 | |
1757 | |
1755 | sub cf::object::player::leave_link { |
1758 | sub cf::object::player::leave_link { |
1756 | my ($self, $map, $x, $y) = @_; |
1759 | my ($self, $map, $x, $y) = @_; |
1757 | |
1760 | |
… | |
… | |
1824 | my ($self, $path, $x, $y) = @_; |
1827 | my ($self, $path, $x, $y) = @_; |
1825 | |
1828 | |
1826 | $self->enter_link; |
1829 | $self->enter_link; |
1827 | |
1830 | |
1828 | (async { |
1831 | (async { |
|
|
1832 | my $map = eval { |
1829 | my $map = cf::map::find $path; |
1833 | my $map = cf::map::find $path; |
1830 | $map = $map->customise_for ($self) if $map; |
1834 | $map = $map->customise_for ($self) if $map; |
1831 | |
1835 | $map |
1832 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1836 | } or |
1833 | # if $map; |
|
|
1834 | |
|
|
1835 | $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1837 | $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1836 | |
1838 | |
1837 | $self->leave_link ($map, $x, $y); |
1839 | $self->leave_link ($map, $x, $y); |
1838 | })->prio (1); |
1840 | })->prio (1); |
1839 | } |
1841 | } |
1840 | |
1842 | |
… | |
… | |
1871 | # that depends on the exit object |
1873 | # that depends on the exit object |
1872 | |
1874 | |
1873 | my $rmp = parse_random_map_params $exit->msg; |
1875 | my $rmp = parse_random_map_params $exit->msg; |
1874 | |
1876 | |
1875 | if ($exit->map) { |
1877 | if ($exit->map) { |
1876 | $rmp->{region} = $exit->map->region_name; |
1878 | $rmp->{region} = $exit->region->name; |
1877 | $rmp->{origin_map} = $exit->map->path; |
1879 | $rmp->{origin_map} = $exit->map->path; |
1878 | $rmp->{origin_x} = $exit->x; |
1880 | $rmp->{origin_x} = $exit->x; |
1879 | $rmp->{origin_y} = $exit->y; |
1881 | $rmp->{origin_y} = $exit->y; |
1880 | } |
1882 | } |
1881 | |
1883 | |
… | |
… | |
1898 | sub cf::object::player::enter_exit { |
1900 | sub cf::object::player::enter_exit { |
1899 | my ($self, $exit) = @_; |
1901 | my ($self, $exit) = @_; |
1900 | |
1902 | |
1901 | return unless $self->type == cf::PLAYER; |
1903 | return unless $self->type == cf::PLAYER; |
1902 | |
1904 | |
|
|
1905 | if ($exit->slaying eq "/!") { |
|
|
1906 | #TODO: this should de-fi-ni-te-ly not be a sync-job |
|
|
1907 | cf::sync_job { prepare_random_map $exit }; |
|
|
1908 | } |
|
|
1909 | |
|
|
1910 | my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
|
|
1911 | my $hp = $exit->stats->hp; |
|
|
1912 | my $sp = $exit->stats->sp; |
|
|
1913 | |
1903 | $self->enter_link; |
1914 | $self->enter_link; |
1904 | |
1915 | |
1905 | (async { |
1916 | (async { |
1906 | $self->deactivate_recursive; # just to be sure |
1917 | $self->deactivate_recursive; # just to be sure |
1907 | unless (eval { |
1918 | unless (eval { |
1908 | prepare_random_map $exit |
1919 | $self->goto ($slaying, $hp, $sp); |
1909 | if $exit->slaying eq "/!"; |
|
|
1910 | |
|
|
1911 | my $path = new_from_path cf::map $exit->slaying, $exit->map && $exit->map->path; |
|
|
1912 | $self->goto ($path, $exit->stats->hp, $exit->stats->sp); |
|
|
1913 | |
1920 | |
1914 | 1; |
1921 | 1; |
1915 | }) { |
1922 | }) { |
1916 | $self->message ("Something went wrong deep within the crossfire server. " |
1923 | $self->message ("Something went wrong deep within the crossfire server. " |
1917 | . "I'll try to bring you back to the map you were before. " |
1924 | . "I'll try to bring you back to the map you were before. " |