ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/mapscript.pm
(Generate patch)

Comparing deliantra/server/lib/cf/mapscript.pm (file contents):
Revision 1.3 by root, Thu Jan 8 19:23:44 2009 UTC vs.
Revision 1.4 by root, Thu Jan 8 21:35:54 2009 UTC

1#! perl 1#! perl
2 2
3=head1 NAME
4
5cf::mapscript
6
7=head1 DESCRIPTION
8
3# this implements the mapscript connectable 9This module implements the mapscript object.
10
11Map scripts are perl snippets that get executed whenever any connected
12element is triggered (e.g. a check inv, a lever etc.)
13
14=head1 ENVIRONMENT
15
16The map scripts are compiled and executed into a namespace with the
17following symbols available:
18
19=over 4
20
21=cut
4 22
5package safe::mapscript; 23package safe::mapscript;
6 24
7use strict qw(subs vars); 25use strict qw(subs vars);
8 26
27=item $self
28
29The mapscript object itself
30
31=item $state
32
33The state value (0 means release, <>0 means push/trigger/enable) that
34triggered the map script.
35
36=item $activator
37
38The object that was triggered (the lever, check inv element, npc etc.).
39
40=item $originator
41
42The object that triggered the activator, usually (but not always) the
43player who stepped on a check inv, pulled a lever etc. Can be C<undef>.
44
45=cut
46
9our ($self, $state, $activator, $originator); 47our ($self, $state, $activator, $originator);
48
49=item @obs = find $id_or_object
50
51Finds all objects with the given I<connected> C<$id>. If an object
52reference is passed, it will be returned unchanged.
53
54=cut
10 55
11sub find($) { 56sub find($) {
12 ref $_[0] ? $_[0] 57 ref $_[0] ? $_[0]
13 : $self->map->find_link ($_[0]) 58 : $self->map->find_link ($_[0])
14} 59}
15 60
16sub get($) { 61=item trigger $id_or_object[, $state]
17 (&find)[0]->value 62
18} 63Triggers the linked chain with the given I<connected> id, or the connected
64chain associated with the given object (if an objetc reference is passed),
65and passes the given state (or C<1>, if missing) to it.
66
67=cut
19 68
20sub trigger($;$) { 69sub trigger($;$) {
21 $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self); 70 $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self);
22} 71}
72
73=item timer $id_or_object, $seconds
74
75Starts the timer on the given mapscript object (usually, $id_or_object is
76C<$self>). When the timer expires on the mapscript object, it will trigger
77the script with C<$activator == $self> and C<$originator == undef>.
78
79=cut
23 80
24sub timer($$) { 81sub timer($$) {
25 my $ob = (&find)[0]; 82 my $ob = (&find)[0];
26 $ob->speed_left ($_[1] / -cf::TICK); 83 $ob->speed_left ($_[1] / -cf::TICK);
27 $ob->set_speed (1); 84 $ob->set_speed (1);
44 . "\n}" 101 . "\n}"
45 or sub { } 102 or sub { }
46 )->(); 103 )->();
47} 104}
48 105
106=back
107
108=head1 EXAMPLE
109
110Have a look at F<scorn/anthonty/portgate.map> for a nontrivial example.
111
112=cut
113
491; 1141;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines