1 | #! perl |
1 | # |
|
|
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | # |
|
|
4 | # Copyright (©) 2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | # |
|
|
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
|
|
7 | # the terms of the Affero GNU General Public License as published by the |
|
|
8 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
9 | # option) any later version. |
|
|
10 | # |
|
|
11 | # This program is distributed in the hope that it will be useful, |
|
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
14 | # GNU General Public License for more details. |
|
|
15 | # |
|
|
16 | # You should have received a copy of the Affero GNU General Public License |
|
|
17 | # and the GNU General Public License along with this program. If not, see |
|
|
18 | # <http://www.gnu.org/licenses/>. |
|
|
19 | # |
|
|
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
21 | # |
2 | |
22 | |
3 | =head1 NAME |
23 | =head1 NAME |
4 | |
24 | |
5 | cf::mapscript |
25 | cf::mapscript |
6 | |
26 | |
… | |
… | |
18 | |
38 | |
19 | =over 4 |
39 | =over 4 |
20 | |
40 | |
21 | =cut |
41 | =cut |
22 | |
42 | |
23 | package safe::mapscript; |
43 | package cf::mapscript::eval; |
24 | |
44 | |
25 | use strict qw(subs vars); |
45 | use common::sense; |
26 | |
46 | |
27 | =item $self |
47 | =item $self |
28 | |
48 | |
29 | The mapscript object itself |
49 | The mapscript object itself. |
30 | |
50 | |
31 | =item $state |
51 | =item $state |
32 | |
52 | |
33 | The state value (0 means release, <>0 means push/trigger/enable) that |
53 | The state value (0 means release, <>0 means push/trigger/enable) that |
34 | triggered the map script. |
54 | triggered the map script. |
… | |
… | |
42 | The object that triggered the activator, usually (but not always) the |
62 | The object that triggered the activator, usually (but not always) the |
43 | player who stepped on a check inv, pulled a lever etc. Can be C<undef>. |
63 | player who stepped on a check inv, pulled a lever etc. Can be C<undef>. |
44 | |
64 | |
45 | =cut |
65 | =cut |
46 | |
66 | |
47 | our ($self, $state, $activator, $originator); |
67 | use vars qw($self $state $activator $originator); |
48 | |
68 | |
49 | =item @obs = find $id_or_object |
69 | =item @obs = find $id_or_object |
50 | |
70 | |
51 | Finds all objects with the given I<connected> C<$id>. If an object |
71 | Finds all objects with the given I<connected> C<$id>. If an object |
52 | reference is passed, it will be returned unchanged. |
72 | reference is passed, it will be returned unchanged. |
… | |
… | |
59 | } |
79 | } |
60 | |
80 | |
61 | =item trigger $id_or_object[, $state] |
81 | =item trigger $id_or_object[, $state] |
62 | |
82 | |
63 | Triggers the linked chain with the given I<connected> id, or the connected |
83 | Triggers the linked chain with the given I<connected> id, or the connected |
64 | chain associated with the given object (if an objetc reference is passed), |
84 | chain associated with the given object (if an object reference is passed), |
65 | and passes the given state (or C<1>, if missing) to it. |
85 | and passes the given state (or C<1>, if missing) to it. |
66 | |
86 | |
67 | =cut |
87 | =cut |
68 | |
88 | |
69 | sub trigger($;$) { |
89 | sub trigger($;$) { |
70 | $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self); |
90 | $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self); |
71 | } |
91 | } |
72 | |
92 | |
73 | =item timer $id_or_object, $seconds |
93 | =item timer $id_or_object, $seconds |
74 | |
94 | |
75 | Starts the timer on the given mapscript object (usually, $id_or_object is |
95 | Starts the timer on the given mapscript object (usually, C<$id_or_object> is |
76 | C<$self>). When the timer expires on the mapscript object, it will trigger |
96 | C<$self>). When the timer expires on the mapscript object, it will trigger |
77 | the script with C<$activator == $self> and C<$originator == undef>. |
97 | the script with C<$activator == $self> and C<$originator == undef>. |
78 | |
98 | |
79 | =cut |
99 | =cut |
80 | |
100 | |
… | |
… | |
84 | $ob->set_speed (1); |
104 | $ob->set_speed (1); |
85 | } |
105 | } |
86 | |
106 | |
87 | package cf::mapscript; |
107 | package cf::mapscript; |
88 | |
108 | |
89 | use strict qw(subs vars); |
109 | use common::sense; |
|
|
110 | |
|
|
111 | *{"main::safe::cf::mapscript::eval::"} = \%{"main::cf::mapscript::eval::"}; |
90 | |
112 | |
91 | our %CACHE; |
113 | our %CACHE; |
92 | |
114 | |
93 | sub activate($$$) { |
115 | sub activate($$$) { |
|
|
116 | package cf::mapscript::eval; |
|
|
117 | |
94 | ($self, $state, $activator, $originator) = @_; |
118 | ($self, $state, $activator, $originator) = @_; |
95 | |
119 | |
96 | ( |
120 | ( |
97 | $CACHE{$self->msg} ||= cf::safe_eval |
121 | $CACHE{$self->msg} ||= cf::safe_eval |
98 | "package mapscript; sub {\n" |
122 | "package cf::mapscript::eval; sub {\n" |
99 | . "#line 1 '" . ($self->debug_desc) . "'\n" |
123 | . "#line 1 '" . ($self->debug_desc) . "'\n" |
100 | . $self->msg |
124 | . $self->msg |
101 | . "\n}" |
125 | . "\n}" |
102 | or sub { } |
126 | or sub { } |
103 | )->(); |
127 | )->(); |