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.1 by root, Thu Jan 8 03:03:24 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, $activator, $state); 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
55
56sub find($) {
57 ref $_[0] ? $_[0]
58 : $self->map->find_link ($_[0])
59}
60
61=item trigger $id_or_object[, $state]
62
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
68
69sub trigger($;$) {
70 $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self);
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
80
81sub timer($$) {
82 my $ob = (&find)[0];
83 $ob->speed_left ($_[1] / -cf::TICK);
84 $ob->set_speed (1);
85}
10 86
11package cf::mapscript; 87package cf::mapscript;
12 88
13use strict qw(subs vars); 89use strict qw(subs vars);
14 90
91our %CACHE;
92
15sub activate($$$) { 93sub activate($$$) {
16 ($self, $activator, $state) = @_; 94 ($self, $state, $activator, $originator) = @_;
17
18 warn "$self->{msg} $self->{on_activate}\n";#d#
19 95
20 ( 96 (
21 $self->{on_activate} ||= cf::safe_eval 97 $CACHE{$self->msg} ||= cf::safe_eval
22 "package mapscript; sub {\n" 98 "package mapscript; sub {\n"
23 . "#line 1 '" . ($self->debug_desc) . "'\n" 99 . "#line 1 '" . ($self->debug_desc) . "'\n"
24 . $self->msg 100 . $self->msg
25 . "\n}" 101 . "\n}"
26 or sub { } 102 or sub { }
27 )->(); 103 )->();
28} 104}
29 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
301; 1141;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines