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.4 by root, Thu Jan 8 21:35:54 2009 UTC vs.
Revision 1.9 by root, Fri Apr 30 18:28:16 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines