1 | #! perl |
|
|
2 | |
|
|
3 | # |
1 | # |
4 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
5 | # |
3 | # |
6 | # Copyright (©) 2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
7 | # |
5 | # |
8 | # Deliantra is free software: you can redistribute it and/or modify it under |
6 | # 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 |
7 | # 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 |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
11 | # option) any later version. |
9 | # option) any later version. |
… | |
… | |
40 | |
38 | |
41 | =over 4 |
39 | =over 4 |
42 | |
40 | |
43 | =cut |
41 | =cut |
44 | |
42 | |
45 | package safe::mapscript; |
43 | package cf::mapscript::eval; |
46 | |
44 | |
47 | use common::sense; |
45 | use common::sense; |
48 | |
46 | |
49 | =item $self |
47 | =item $self |
50 | |
48 | |
… | |
… | |
64 | The object that triggered the activator, usually (but not always) the |
62 | The object that triggered the activator, usually (but not always) the |
65 | 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>. |
66 | |
64 | |
67 | =cut |
65 | =cut |
68 | |
66 | |
69 | our ($self, $state, $activator, $originator); |
67 | use vars qw($self $state $activator $originator); |
70 | |
68 | |
71 | =item @obs = find $id_or_object |
69 | =item @obs = find $id_or_object |
72 | |
70 | |
73 | 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 |
74 | reference is passed, it will be returned unchanged. |
72 | reference is passed, it will be returned unchanged. |
… | |
… | |
81 | } |
79 | } |
82 | |
80 | |
83 | =item trigger $id_or_object[, $state] |
81 | =item trigger $id_or_object[, $state] |
84 | |
82 | |
85 | 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 |
86 | 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), |
87 | 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. |
88 | |
86 | |
89 | =cut |
87 | =cut |
90 | |
88 | |
91 | sub trigger($;$) { |
89 | sub trigger($;$) { |
92 | $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self); |
90 | $self->map->trigger ($_[0], $#_ ? $_[1] : 1, $self); |
93 | } |
91 | } |
94 | |
92 | |
95 | =item timer $id_or_object, $seconds |
93 | =item timer $id_or_object, $seconds |
96 | |
94 | |
97 | 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 |
98 | 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 |
99 | the script with C<$activator == $self> and C<$originator == undef>. |
97 | the script with C<$activator == $self> and C<$originator == undef>. |
100 | |
98 | |
101 | =cut |
99 | =cut |
102 | |
100 | |
… | |
… | |
106 | $ob->set_speed (1); |
104 | $ob->set_speed (1); |
107 | } |
105 | } |
108 | |
106 | |
109 | package cf::mapscript; |
107 | package cf::mapscript; |
110 | |
108 | |
111 | use strict qw(subs vars); |
109 | use common::sense; |
|
|
110 | |
|
|
111 | *{"main::safe::cf::mapscript::eval::"} = \%{"main::cf::mapscript::eval::"}; |
112 | |
112 | |
113 | our %CACHE; |
113 | our %CACHE; |
114 | |
114 | |
115 | sub activate($$$) { |
115 | sub activate($$$) { |
|
|
116 | package cf::mapscript::eval; |
|
|
117 | |
116 | ($self, $state, $activator, $originator) = @_; |
118 | ($self, $state, $activator, $originator) = @_; |
117 | |
119 | |
118 | ( |
120 | ( |
119 | $CACHE{$self->msg} ||= cf::safe_eval |
121 | $CACHE{$self->msg} ||= cf::safe_eval |
120 | "package mapscript; sub {\n" |
122 | "package cf::mapscript::eval; sub {\n" |
121 | . "#line 1 '" . ($self->debug_desc) . "'\n" |
123 | . "#line 1 '" . ($self->debug_desc) . "'\n" |
122 | . $self->msg |
124 | . $self->msg |
123 | . "\n}" |
125 | . "\n}" |
124 | or sub { } |
126 | or sub { } |
125 | )->(); |
127 | )->(); |