1 | #! perl # mandatory |
1 | #! perl # mandatory |
2 | |
2 | |
3 | # manages the worldmap by directing to other handlers |
3 | # manages the worldmap by directing to other handlers |
4 | |
4 | |
5 | cf::map->register (qr{^/world/world_(-?\d+)_(-?\d+)(?:_(-?\d+))?$}, 100); |
5 | cf::map->register (qr{^/world/world_(-?\d+)_(-?\d+)(?:([+\-]\d+))?$}, 100); |
6 | |
6 | |
7 | # universal |
7 | # universal |
8 | our $TILE_W = 50; |
8 | our $TILE_W = 50; |
9 | our $TILE_H = 50; |
9 | our $TILE_H = 50; |
10 | |
10 | |
… | |
… | |
35 | } |
35 | } |
36 | |
36 | |
37 | sub format_xyz($$;$) { |
37 | sub format_xyz($$;$) { |
38 | sprintf "/world/world_%03d_%03d%s", |
38 | sprintf "/world/world_%03d_%03d%s", |
39 | $_[0], $_[1], |
39 | $_[0], $_[1], |
40 | $_[2] ? sprintf "_%03d", $_[2] : ""; |
40 | $_[2] ? sprintf "%+04d", $_[2] : ""; |
41 | } |
41 | } |
42 | |
42 | |
43 | ############################################################################# |
43 | ############################################################################# |
44 | |
44 | |
45 | sub init { |
45 | sub init { |
… | |
… | |
59 | |
59 | |
60 | bless $self, $meta->{pkg}; |
60 | bless $self, $meta->{pkg}; |
61 | |
61 | |
62 | $self->init_worldmap ($meta); |
62 | $self->init_worldmap ($meta); |
63 | |
63 | |
64 | last; |
64 | goto done; |
65 | } |
65 | } |
66 | } |
66 | } |
67 | |
67 | |
|
|
68 | bless $self, ext::map_world::empty::; |
|
|
69 | |
|
|
70 | done: |
68 | $self->SUPER::init; |
71 | $self->SUPER::init; |
69 | } |
72 | } |
70 | |
73 | |
71 | sub init_worldmap { |
74 | sub init_worldmap { |
72 | # only for handlers |
75 | # only for handlers |
… | |
… | |
84 | $self->msg ("worldmap dynamically created by map-world extension"); |
87 | $self->msg ("worldmap dynamically created by map-world extension"); |
85 | $self->outdoor ($self->{z} >= 0); |
88 | $self->outdoor ($self->{z} >= 0); |
86 | $self->default_region (cf::region::find "wilderness"); |
89 | $self->default_region (cf::region::find "wilderness"); |
87 | |
90 | |
88 | # all possible worldmap tiles also exist |
91 | # all possible worldmap tiles also exist |
89 | $self->tile_path (0, format_xyz $x, $y - 1, $z); |
92 | $self->tile_path (cf::TILE_NORTH, format_xyz $x, $y - 1, $z); |
90 | $self->tile_path (1, format_xyz $x + 1, $y, $z); |
|
|
91 | $self->tile_path (2, format_xyz $x, $y + 1, $z); |
93 | $self->tile_path (cf::TILE_SOUTH, format_xyz $x, $y + 1, $z); |
|
|
94 | $self->tile_path (cf::TILE_EAST , format_xyz $x + 1, $y, $z); |
92 | $self->tile_path (3, format_xyz $x - 1, $y, $z); |
95 | $self->tile_path (cf::TILE_WEST , format_xyz $x - 1, $y, $z); |
93 | $self->tile_path (4, format_xyz $x, $y, $z + 1); |
96 | $self->tile_path (cf::TILE_UP , format_xyz $x, $y, $z + 1); |
94 | $self->tile_path (5, format_xyz $x, $y, $z - 1); |
97 | $self->tile_path (cf::TILE_DOWN , format_xyz $x, $y, $z - 1); |
95 | |
98 | |
96 | # an overlay always wins |
99 | # an overlay always wins |
97 | my $overlay = sprintf "%s/%s.map", $cf::MAPDIR, format_xyz $x, $y, $z; |
100 | my $overlay = sprintf "%s/%s.map", $cf::MAPDIR, format_xyz $x, $y, $z; |
98 | |
101 | |
99 | $self->{load_path} = $overlay |
102 | $self->{load_path} = $overlay |
… | |
… | |
143 | |
146 | |
144 | $self->create_region_treasure |
147 | $self->create_region_treasure |
145 | if delete $self->{need_create_treasure}; |
148 | if delete $self->{need_create_treasure}; |
146 | } |
149 | } |
147 | |
150 | |
|
|
151 | package ext::map_world::empty; |
|
|
152 | |
|
|
153 | our @ISA = ext::map_world::; |
|
|
154 | |
|
|
155 | sub post_load_original { |
|
|
156 | $_[0]->fill; |
|
|
157 | } |
|
|
158 | |