1 | package cf; |
1 | package cf; |
2 | |
2 | |
3 | use Symbol; |
3 | use Symbol; |
4 | use List::Util; |
4 | use List::Util; |
5 | use Storable; |
5 | use Storable; |
|
|
6 | |
|
|
7 | use Event; |
|
|
8 | $Event::Eval = 1; # no idea why this is required, but it is |
6 | |
9 | |
7 | use strict; |
10 | use strict; |
8 | |
11 | |
9 | our %COMMAND; |
12 | our %COMMAND; |
10 | our @EVENT; |
13 | our @EVENT; |
… | |
… | |
60 | |
63 | |
61 | # guessed hierarchies |
64 | # guessed hierarchies |
62 | |
65 | |
63 | @cf::object::player::ISA = 'cf::object'; |
66 | @cf::object::player::ISA = 'cf::object'; |
64 | @cf::object::map::ISA = 'cf::object'; |
67 | @cf::object::map::ISA = 'cf::object'; |
|
|
68 | |
|
|
69 | $Event::DIED = sub { |
|
|
70 | warn "error in event callback: @_"; |
|
|
71 | }; |
65 | |
72 | |
66 | my %ext_pkg; |
73 | my %ext_pkg; |
67 | my @exts; |
74 | my @exts; |
68 | my @hook; |
75 | my @hook; |
69 | my %command; |
76 | my %command; |
… | |
… | |
162 | |
169 | |
163 | sub unload_extension { |
170 | sub unload_extension { |
164 | my ($pkg) = @_; |
171 | my ($pkg) = @_; |
165 | |
172 | |
166 | warn "removing extension $pkg\n"; |
173 | warn "removing extension $pkg\n"; |
|
|
174 | |
|
|
175 | if (my $cb = $pkg->can ("on_unload")) { |
|
|
176 | $cb->($pkg); |
|
|
177 | } |
167 | |
178 | |
168 | # remove hooks |
179 | # remove hooks |
169 | for my $idx (0 .. $#EVENT) { |
180 | for my $idx (0 .. $#EVENT) { |
170 | delete $hook[$idx]{$pkg}; |
181 | delete $hook[$idx]{$pkg}; |
171 | } |
182 | } |
… | |
… | |
209 | if ($who->flag (FLAG_WIZ)) { |
220 | if ($who->flag (FLAG_WIZ)) { |
210 | $who->message ("reloading..."); |
221 | $who->message ("reloading..."); |
211 | |
222 | |
212 | warn "reloading...\n"; |
223 | warn "reloading...\n"; |
213 | eval { |
224 | eval { |
|
|
225 | $_->cancel for Event::all_watchers; |
|
|
226 | |
214 | unload_extension $_ for @exts; |
227 | unload_extension $_ for @exts; |
215 | delete $INC{"cf.pm"}; |
228 | delete $INC{"cf.pm"}; |
216 | |
229 | |
217 | # don't, removes xs symbols, too |
230 | # don't, removes xs symbols, too |
218 | #Symbol::delete_package $pkg; |
231 | #Symbol::delete_package __PACKAGE__; |
219 | |
232 | |
220 | require cf; |
233 | require cf; |
221 | }; |
234 | }; |
222 | warn $@ if $@; |
235 | warn $@ if $@; |
223 | $who->message ($@) if $@; |
236 | $who->message ($@) if $@; |
… | |
… | |
334 | for grep %$_, $ob, $ob->inv; |
347 | for grep %$_, $ob, $ob->inv; |
335 | |
348 | |
336 | unlink "$path.cfperl";#d##TODO#remove |
349 | unlink "$path.cfperl";#d##TODO#remove |
337 | }; |
350 | }; |
338 | |
351 | |
|
|
352 | ############################################################################# |
|
|
353 | # core extensions - in perl |
|
|
354 | |
|
|
355 | # rough implementation of a future "reply" method that works |
|
|
356 | # with dialog boxes. |
|
|
357 | sub cf::object::player::reply($$;$) { |
|
|
358 | my ($self, $msg, $flags) = @_; |
|
|
359 | |
|
|
360 | $flags = cf::NDI_WHITE unless @_ >= 3; |
|
|
361 | |
|
|
362 | $self->message ($msg, $flags); |
|
|
363 | } |
|
|
364 | |
|
|
365 | ############################################################################# |
|
|
366 | # initialisation |
|
|
367 | |
339 | register "<global>", __PACKAGE__; |
368 | register "<global>", __PACKAGE__; |
340 | |
369 | |
|
|
370 | unshift @INC, maps_directory "perl"; |
|
|
371 | |
341 | load_extensions; |
372 | load_extensions; |
342 | |
373 | |
343 | 1 |
374 | 1 |
344 | |
375 | |