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