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.5 by root, Thu Jul 16 21:42:56 2009 UTC vs.
Revision 1.10 by root, Sat Apr 23 04:56:52 2011 UTC

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
5cf::mapscript 25cf::mapscript
6 26
18 38
19=over 4 39=over 4
20 40
21=cut 41=cut
22 42
23package safe::mapscript; 43package cf::mapscript::eval;
24 44
25use strict qw(subs vars); 45use common::sense;
26 46
27=item $self 47=item $self
28 48
29The mapscript object itself 49The mapscript object itself.
30 50
31=item $state 51=item $state
32 52
33The state value (0 means release, <>0 means push/trigger/enable) that 53The state value (0 means release, <>0 means push/trigger/enable) that
34triggered the map script. 54triggered the map script.
42The object that triggered the activator, usually (but not always) the 62The 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>. 63player who stepped on a check inv, pulled a lever etc. Can be C<undef>.
44 64
45=cut 65=cut
46 66
47our ($self, $state, $activator, $originator); 67use vars qw($self $state $activator $originator);
48 68
49=item @obs = find $id_or_object 69=item @obs = find $id_or_object
50 70
51Finds all objects with the given I<connected> C<$id>. If an object 71Finds all objects with the given I<connected> C<$id>. If an object
52reference is passed, it will be returned unchanged. 72reference 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
63Triggers the linked chain with the given I<connected> id, or the connected 83Triggers the linked chain with the given I<connected> id, or the connected
64chain associated with the given object (if an objetc reference is passed), 84chain associated with the given object (if an object reference is passed),
65and passes the given state (or C<1>, if missing) to it. 85and passes the given state (or C<1>, if missing) to it.
66 86
67=cut 87=cut
68 88
69sub trigger($;$) { 89sub 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
75Starts the timer on the given mapscript object (usually, $id_or_object is 95Starts the timer on the given mapscript object (usually, C<$id_or_object> is
76C<$self>). When the timer expires on the mapscript object, it will trigger 96C<$self>). When the timer expires on the mapscript object, it will trigger
77the script with C<$activator == $self> and C<$originator == undef>. 97the 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
87package cf::mapscript; 107package cf::mapscript;
88 108
89use strict qw(subs vars); 109use common::sense;
110
111*{"main::safe::cf::mapscript::eval::"} = \%{"main::cf::mapscript::eval::"};
90 112
91our %CACHE; 113our %CACHE;
92 114
93sub activate($$$) { 115sub 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 )->();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines