1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
# this module implements the part of the magic mapping spell that works on the world map |
4 |
|
|
# only. |
5 |
|
|
|
6 |
|
|
cf::object->attach ( |
7 |
|
|
type => cf::SPELL, |
8 |
|
|
subtype => cf::SP_MAGIC_MAPPING, |
9 |
|
|
on_cast_spell => sub { |
10 |
|
|
my ($spell, $who, $caster, $dir, $arg) = @_; |
11 |
|
|
|
12 |
root |
1.4 |
my $pl = $caster->contr |
13 |
|
|
or return; |
14 |
|
|
|
15 |
root |
1.3 |
my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
16 |
root |
1.1 |
|
17 |
|
|
# dirty check, should maybe allow tiled outdoor maps? |
18 |
|
|
$map->path =~ m%/world/world_% |
19 |
|
|
or return; |
20 |
|
|
|
21 |
|
|
my $bird = cf::object::new "magic_mapper"; |
22 |
|
|
my $dist = 0; |
23 |
root |
1.2 |
$caster->speed_left (-1); $pl->fire_on (0); $pl->run_on (0); |
24 |
|
|
|
25 |
root |
1.3 |
my $duration = $caster->casting_level ($spell) * 150 / 100; |
26 |
root |
1.1 |
|
27 |
|
|
$pl->ns->async (sub { |
28 |
root |
1.2 |
while (++$dist < $duration && $bird->valid) { |
29 |
root |
1.1 |
my $phi = 2 * $dist ** .5; |
30 |
|
|
my $dx = (sin $phi) * $phi * 2; |
31 |
|
|
my $dy = (cos $phi) * $phi * 2; |
32 |
|
|
|
33 |
root |
1.2 |
$bird->insert_ob_in_map_at ($map, $caster, cf::INS_ON_TOP, $x + $dx, $y + $dy) |
34 |
|
|
or last; |
35 |
root |
1.1 |
|
36 |
|
|
$pl->set_viewpoint ($bird); |
37 |
root |
1.2 |
$caster->speed_left (-1); |
38 |
root |
1.1 |
cf::wait_for_tick; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
$pl->set_viewpoint (undef); |
42 |
|
|
$caster->speed_left (0); |
43 |
|
|
$bird->destroy; |
44 |
|
|
}); |
45 |
|
|
|
46 |
|
|
cf::override 1; |
47 |
|
|
}, |
48 |
|
|
); |
49 |
|
|
|