blib/lib/Games/Axmud/Obj/Exit.pm untested

filter: Statementstmt 0.0% 0 / 240 Branchbran 0.0% 0 / 148 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 0.0% 0 / 45 Podpod 0.0% 0 / 42 totaltotal 0.0% 0 / 571 CC 75 SCAR 51.4
CC
75
Cov
0%
getAssisted
702.0
new
90.0
compress
90.0
CRAP 170.5
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::Exit
16 # An exit in the exit model
17  
18 { package Games::Axmud::Obj::Exit;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Prepare a new instance of the exit object (which represents an exit between two rooms in
34 # the world, one of which may be unknown)
35 #
36 # Expected arguments
37 # $session - The parent GA::Session (not stored as an IV)
38 # $dir - The exit's nominal direction - the one that would be expected to
39 # appear in the parent room's list of exits, e.g. 'north', 'portal'
40 # (absolute max length 64 chars; can include spaces and
41 # non-alphanumeric characters)
42 # $mode - 'model' for an exit model object (stored in
43 # GA::Obj::WorldModel->exitModelHash), 'non_model' for non-model
44 # exit object, for example one used by the Locator task, or 'global'
45 # for the exit object stored in the global variable $DEFAULT_EXIT (and
46 # which provides default values for all exit object IVs)
47 #
48 # Optional arguments
49 # $parentRoom - World model number of the parent room ('undef' if there isn't a parent
50 # room or it this is a non-exit model object)
51 #
52 # Return values
53 # 'undef' on improper arguments or if $nomDir is invalid
54 # Blessed reference to the newly-created object on success
55  
56 my ($class, $session, $dir, $mode, $parentRoom, $check) = @_;
57  
58 # Local variables
59 my $string;
60  
61 # Check for improper arguments
62 if (
63 ! defined $class || ! defined $session || ! defined $dir || ! defined $mode
64 || defined $check
65 ) {
66 return $axmud::CLIENT->writeImproper($class . '->new', @_);
67 }
68  
69 # Check that $dir isn't longer than the maximum
70 if (length ($dir) > 64) {
71  
72 if (! $session->loginFlag) {
73  
74 # Not logged in yet - the illegal direction is probably some graphics displayed by
75 # the world on connection, not something that's part of a list of exits
76 # Don't display an error message
77 return undef;
78  
79 } elsif ($axmud::CLIENT->debugExitFlag) {
80  
81 # Reduce $dir to a manageably short string, so that the error message doesn't
82 # take up several lines
83 $dir = substr($dir, 0, 64);
84 # Reduce uninformative whitespace
85 $dir =~ s/\s+/ /g;
86  
87 # If the automapper has a current room, we should use it in the error message
88 if ($session->mapObj->currentRoom) {
89 $string = ' (automapper current room: ' . $session->mapObj->currentRoom->number
90 . ')';
91 } else {
92 $string = '';
93 }
94  
95 return $session->mainWin->writeDebug(
96 'Illegal direction \'' . $dir . '...\' (max 64 chars)' . $string,
97 );
98  
99 } else {
100  
101 # No debug message to display
102 return undef;
103 }
104 }
105  
106 # For very large world models (10,000+ rooms), some computers tend to run out of memory
107 # which produces a Perl error and a crash
108 # In response, we try to reduce the size of the world model as much as possible. Most of the
109 # memory used is for room objects (GA::ModelObj::Room) and exit objects. Most of the
110 # memory used by each of those objects is for IVs with default values
111 # Therefore, we remove most of the IVs altogether, restoring them only if some part of the
112 # Axmud code sets the IV to a non-default value. Default values for each IV are obtained
113 # from an exit object stored in a global variable, $DEFAULT_EXIT, instead of from the exit
114 # object itself
115 my $self;
116  
117 if ($mode eq 'global') {
118  
119 # This object is to be stored in the global variable, $DEFAULT_EXIT. Therefore it has
120 # default values for all IVs
121 $self = {
122 _objName => 'exit',
123 _objClass => $class,
124 _parentFile => undef,
125 _parentWorld => undef,
126 _privFlag => FALSE, # All IVs are public
127  
128 # Compatibility IVs
129 # -----------------
130  
131 # Used for compatibility with model objects (inheriting GA::Generic::ModelObj)
132 name => 'exit',
133 category => 'exit',
134 modelFlag => FALSE,
135 number => undef,
136 parent => undef,
137  
138 # Exit IVs
139 # --------
140  
141 # Private property hash - customisable hash of properties for the exit
142 privateHash => {},
143  
144 # IVs unique to exit model objects
145 # What type of exit this is - 'primaryDir', 'primaryAbbrev', 'secondaryDir',
146 # 'secondaryAbbrev', 'relativeDir', 'relativeAbbrev'
147 # 'undef' for other kinds of exit, or if type unknown. Matches a value in the
148 # dictionary object's ->combDirHash)
149 exitType => undef,
150  
151 # The exit's nominal direction - the one that would be expected to appear in the
152 # parent room's list of exits, e.g. 'north', 'portal' (absolute max length 32
153 # chars; can include spaces and non-alphanumeric characters)
154 dir => undef,
155 # A string if alternative nominal directions (for worlds like Discworld, in which
156 # the same exit might be called 'forwards' or 'backwards', depending on which
157 # direction the character arrived from)
158 # The nominal direction (->dir) of exits in the Locator task's current room is
159 # compared against model exits' ->altDir in a Perl index operation. If ->dir is
160 # found somewhere in ->altDir, the exits are a match (e.g. ->dir 'right', ->altDir
161 # 'left right' produces a match)
162 # Set to 'undef' for all exits that don't have alternative nominal directions
163 altDir => undef,
164 # For primary directions, the standard primary direction that corresponds to
165 # $self->dir (which is a custom primary direction)
166 # For other directions, one of eighteen standard primary directions (north,
167 # northeast, east, southeast, south, southwest, west, northwest, up, down, and
168 # northnortheast etc) which isn't already in use, and which the automapper can use
169 # to draw this direction
170 # (Set to 'undef' if the exit is unallocatable, i.e. there are no available primary
171 # directions that can be allocated to it)
172 mapDir => undef,
173 # When ->dir isn't a primary direction, ->mapDir is temporarily allocated one of
174 # the sixteen available cardinal directions (the primary directions minus 'up' and
175 # 'down'), so the exit can be drawn on the map
176 # This IV tracks what is happening and tells the automapper how to draw the exit
177 # 'primary' - ->dir is a primary direction
178 # 'temp_alloc' - ->dir is not a primary direction. The exit has been allocated a
179 # temporary cardinal direction from one of the sixteen available cardinal
180 # directions (those not in use by other exits); this temporary direction is
181 # stored in ->mapDir
182 # 'temp_unalloc' - ->dir is not a primary direction. The exit has not been
183 # allocated a temporary cardinal direction because none of them are available
184 # (all in use by by other exits); ->mapDir is still 'undef'
185 # 'perm_alloc' - the user has allocated a permanent primary direction (the
186 # automapper can only allocate the sixteen cardinal directions as temporary
187 # directions, but the user can allocate all eighteen primary directions),
188 # which is stored in ->mapDir
189 drawMode => 'primary',
190  
191 # The exit's tag, if it has been given one, used to display the destination region.
192 # Maximum 40 characters (allows for the region name, which has a maximum of 32
193 # chars, plus a word like 'to')
194 exitTag => undef,
195 # The offset (in pixels) where the exit tag is drawn on the map. (0, 0) means draw
196 # the tag at the standard position; (10, -10) means draw it 10 pixels to the
197 # right, 10 pixels higher
198 exitTagXOffset => 0,
199 exitTagYOffset => 0,
200  
201 # Flag set to TRUE if this exit should be drawn as a broken exit (leads to a room at
202 # an arbitrary position in the same region), FALSE if not a broken exit
203 brokenFlag => FALSE,
204 # Flag set to TRUE if this is a broken exit that should be drawn as a bent line; set
205 # to FALSE if the exit should be drawn as a simple square, attached to its room
206 bentFlag => FALSE,
207 # For bent broken exits, a list of offsets in the form (x, y, x, y...) indicating
208 # the bends in the line, relative to the start of the bending section of the exit
209 # (at the edge of the parent room's gridblock). An empty list of the 'bent'
210 # section is straight
211 bendOffsetList => [],
212 # Flag set to TRUE if this exit is a region exit (leads to a room in a different
213 # region), FALSE if not a region exit
214 regionFlag => FALSE,
215 # For a region that has 100s of region exits, the world model would have to
216 # recalculate thousands of region paths every time someone deletes an exit. So
217 # that we can drastically reduce this number, when a region has several region
218 # exits all leading to the same other region, only one of them is usually marked
219 # as being a 'super-region' exit (the one used for pathfinding). The user can
220 # change the super-region exit, or add additional ones, if they want
221 # Flag set to TRUE if this is a region exit AND a super-region exit; FALSE otherwise
222 superFlag => FALSE,
223 # Flag set to TRUE if this exit was a super-region exit, but was converted to a
224 # normal exit by the user; it can only be converted back to a super-region exit by
225 # the user (and can't be converted automatically by, for example,
226 # GA::Obj::WorldModel->updateRegionPaths). Set to FALSE otherwise
227 notSuperFlag => FALSE,
228 # Flag set to TRUE if the exit is 'hidden' - i.e. doesn't appear in the room's exit
229 # list, but exists nonetheless (NB this isn't an ornament)
230 hiddenFlag => FALSE,
231 # What kind of random exit this is:
232 # 'none' - not a random exit
233 # 'same_region' - a random exit leading somewhere in the same region
234 # 'any_region' - a random exit leading anywhere
235 # 'temp_region' - a random exit leading to a temporary region, which should be
236 # created when the character passes through the exit, and destroyed when the
237 # player passes back through the exit to the original room
238 # 'room_list' - a random exit leading to one of a defined list of rooms
239 randomType => 'none',
240 # For ->randomType 'room_list', a list of destination room numbers. Ignored when
241 # ->randomType is not 'room_list'. When the character moves through a random exit,
242 # the Locator task's current room is compared to each of these rooms, in the order
243 # in which they're stored
244 randomDestList => [],
245  
246 # Number of the world model room, to which this exit leads ('undef' if unknown)
247 destRoom => undef,
248 # Exit model number of the destination room's exit that is the opposite of this one
249 # ('undef' if this isn't a known two-way exit)
250 twinExit => undef,
251 # Flag set to TRUE if this is a known uni-directional exit (e.g. you can go north
252 # from A to B, but you can't go south from B to A), FALSE if not
253 oneWayFlag => FALSE,
254 # For one-way exits, the primary direction in which the far end of a one-way exit is
255 # drawn (i.e. where it touches the destination room). By default, the opposite of
256 # this exit's ->mapDir (so if the exit leads east, it touches the destination room
257 # at the point, where a hypothetical west exit would be drawn)
258 # For non-one way exits, set to 'undef'
259 # NB For unallocated exits, ->mapDir is 'undef', so ->oneWayDir gets set to an
260 # emergency default value, 'north'
261 oneWayDir => undef,
262 # Flag set to TRUE if this is a retracing exit (a special kind of one-way exit which
263 # leads back to the room), FALSE if not. When this flag is set, ->oneWayFlag is
264 # not set
265 retraceFlag => FALSE,
266 # If this exit leads to exactly the same room as another one (e.g. if 'enter cave'
267 # leads to the same room as 'west'), there's no need to draw both of them on the
268 # map. If 'enter cave' is this exit, then 'west' is this exit's 'shadow exit';
269 # this exit is not drawn by the map (because 'west' will be drawn instead)
270 # The exit model number of the shadow exit (or 'undef' if no shadow exit)
271 shadowExit => undef,
272  
273 # What type of exit ornament this exit has:
274 # 'none' - has no ornament
275 # 'break' - exit is a door which can be broken down (if locked)
276 # 'pick' - exit is some kind of lockable door, that has a pickable lock
277 # 'lock' - exit is some kind of lockable door
278 # 'open' - exit is some kind of openable door
279 # 'impass' - exit is completely impassable
280 # 'mystery' - the method of going through the exit is currently unknown
281 exitOrnament => 'none',
282 # The exit's current state, if known. Possible values are those specified by
283 # GA::Client->constExitStateHash: 'normal' (exit is passable or state not known),
284 # 'open' (exit is an open door), 'closed' (exit is a closed door), 'locked' (exit
285 # is a locked door), 'secret' (exit is secret, not normally visible),
286 # 'secret_open' (exit is a secret open door), 'secret_closed' (exit is a secret
287 # closed door'), 'secret_locked' (exit is a secret locked door), 'impass' (exit is
288 # impassable), 'dark' (exit's destination room is dark), 'danger' (exit's
289 # destination room is dangerous), 'emphasis' (world emphasises the exit in some
290 # way, for example to show an important route), 'other' (some other situation,
291 # known only to the user, when the exit is surrounded by exit state strings
292 # defined in GA::Profile::World->exitStateOtherList)
293 # NB ->exitState is never set to 'ignore'. That value is used by
294 # GA::Profile::World->exitStateStringList for any symbols that look like an exit
295 # state (e.g. the bracktes in '[east]'), but which should be ignored
296 # NB ->exitState is never set to one of the custom strings allowed by
297 # GA::Profile::World->exitStateStringList. If a custom string is specified there,
298 # this IV is set to the default value of 'normal'
299 exitState => 'normal',
300 # Any information about the exit (usually a string describing the destination, or
301 # occasionally the destination type). Set only if one of the patterns in
302 # GA::Profile::World->exitInfoPatternList matches the exit, when it appears in a
303 # room statement exit list; the first group substring (if any) is used to set this
304 # IV
305 exitInfo => undef,
306  
307 # Hash of commands used during assisted moves, in the form
308 # $assistedHash{profile_name} = sequence_of_commands
309 # e.g.
310 # $assistedHash{'wizard'} = 'wave wand;fly across river'
311 # $assistedHash{'bilbo'} = 'wear ring;squeeze past guards'
312 # During an assisted move, the key-value pair for the highest-priority current
313 # profile found in the hash is used. If none are found, the IVs below are
314 # consulted; if all else fails, the value of $self->dir is used (see the comments
315 # in $self->getAssisted() for a full explanation)
316 assistedHash => {},
317 # Commands to get past a door. The hash is empty by default, meaning that the
318 # standard break/pick/unlock/open/close/lock command, defined by command cages, is
319 # used
320 # Otherwise it contains one or more key-value pairs in the general form
321 # $doorHash{door_type} = command_to_get_through_the_door
322 # 'door_type' can be any of the following
323 # break e.g. 'break door with crowbar'
324 # pick e.g. 'pick north door with red lockpick'
325 # unlock e.g. 'unlock north door with red key'
326 # open e.g. 'open north door'
327 # close e.g. 'close north door'
328 # lock e.g. 'lock north door with red key'
329 doorHash => {},
330 };
331  
332 } elsif ($mode eq 'model') {
333  
334 # This object is stored in the world model, i.e. in GA::Obj::WorldModel->exitModelHash
335 $self = {
336 # _objName => 'exit',
337 # _objClass => $class,
338 _parentFile => 'worldmodel',
339 _parentWorld => $session->currentWorld->name,
340 # _privFlag => FALSE, # All IVs are public
341  
342 # Compatibility IVs
343 # -----------------
344  
345 # Used for compatibility with model objects (inheriting GA::Generic::ModelObj)
346 modelFlag => TRUE,
347 number => undef, # Set later
348 parent => $parentRoom,
349  
350 # Exit IVs
351 # --------
352 dir => $dir,
353 };
354  
355 } elsif ($mode eq 'non_model') {
356  
357 # This object is not stored in the world model (e.g. exit objects used by the Locator
358 # task)
359 $self = {
360 # _objName => 'exit',
361 # _objClass => $class,
362 _parentFile => undef,
363 _parentWorld => undef,
364 # _privFlag => FALSE, # All IVs are public
365  
366 # Compatibility IVs
367 # -----------------
368  
369 # Used for compatibility with model objects (inheriting GA::Generic::ModelObj)
370 modelFlag => FALSE,
371 number => undef, # Set later
372 parent => undef,
373  
374 # Exit IVs
375 # --------
376 dir => $dir,
377 };
378 }
379  
380 # Bless the object into existence
381 bless $self, $class;
382 return $self;
383 }
384  
385 sub compress {
386  
387 # Called by GA::Obj::File->updateExtractedData and GA::Cmd::CompressModel->do
388 # Drastically reduce the amount of memory used by each exit object by completely removing
389 # IVs whose values are the default values for an exit object (the code obtains the
390 # default values from the exit object stored in the global variable $DEFAULT_EXIT,
391 # instead)
392 #
393 # Expected arguments
394 # (none besides $self)
395 #
396 # Return values
397 # 'undef' on improper arguments
398 # 1 otherwise
399  
400 my ($self, $check) = @_;
401  
402 # Local variables
403 my %hash;
404  
405 # Check for improper arguments
406 if (defined $check) {
407  
408 return $axmud::CLIENT->writeImproper($self->_objClass . '->compress', @_);
409 }
410  
411 # Deal with universal IVs
412 foreach my $iv ( qw (_objName _objClass _privFlag) ) {
413  
414 delete $self->{$iv};
415 }
416  
417 # Deal with flag scalars which are FALSE by default
418 foreach my $iv (
419 qw (
420 brokenFlag bentFlag regionFlag superFlag notSuperFlag hiddenFlag oneWayFlag
421 retraceFlag
422 )
423 ) {
424 if (exists $self->{$iv} && ! $self->{$iv}) {
425  
426 delete $self->{$iv};
427 }
428 }
429  
430 # Deal with non-flag scalars which are undefined by default
431 foreach my $iv (
432 qw (
433 exitType altDir mapDir exitTag destRoom twinExit oneWayDir shadowExit exitInfo
434 )
435 ) {
436 if (exists $self->{$iv} && ! defined $self->{$iv}) {
437  
438 delete $self->{$iv};
439 }
440 }
441  
442 # Deal with non-flag scalars which have a defined value by default
443 %hash = (
444 'name' => 'exit',
445 'category' => 'exit',
446 'drawMode' => 'primary',
447 'exitTagXOffset' => 0,
448 'exitTagYOffset' => 0,
449 'randomType' => 'none',
450 'exitOrnament' => 'none',
451 'exitState' => 'normal',
452 );
453  
454 foreach my $iv (keys %hash) {
455  
456 if (exists $self->{$iv} && $self->{$iv} eq $hash{$iv}) {
457  
458 delete $self->{$iv};
459 }
460 }
461  
462 # Deal with lists which are empty by default
463 foreach my $iv (
464 qw (
465 bendOffsetList randomDestList
466 )
467 ) {
468 if (exists $self->{$iv}) {
469  
470 my $listRef = $self->{$iv};
471 if (! @$listRef) {
472  
473 delete $self->{$iv};
474 }
475 }
476 }
477  
478 # Deal with hashes which are empty by default
479 foreach my $iv (
480 qw (
481 privateHash assistedHash doorHash
482 )
483 ) {
484 if (exists $self->{$iv}) {
485  
486 my $hashRef = $self->{$iv};
487 if (! %$hashRef) {
488  
489 delete $self->{$iv};
490 }
491 }
492 }
493  
494 # Operation complete
495 return 1;
496 }
497  
498 ##################
499 # Methods
500  
501 sub getAssisted {
502  
503 # Called by GA::Session->checkAssistedMove
504 # Checks several of this object's IVs and returns a sequence of one or more commands,
505 # separated by Axmud's command separator, as a string
506 #
507 # The IVs are checked in the order
508 # 1. ->assistedHash
509 # 2. ->doorHash
510 # 3. ->dir
511 #
512 # Expected arguments
513 # $session - The calling function's GA::Session
514 #
515 # Return values
516 # 'undef' on improper arguments or if no assisted move can be found
517 # Otherwise, a sequence of one or more commands, e.g. 'open door;north'
518  
519 my ($self, $session, $check) = @_;
520  
521 # Local variables
522 my (
523 $wmObj, $cmd, $cmdString,
524 @priorityList, @breakList, @pickList, @unlockList, @openList, @closeList, @lockList,
525 @cmdList,
526 );
527  
528 # Check for improper arguments
529 if (! defined $session || defined $check) {
530  
531 return $axmud::CLIENT->writeImproper($self->_objClass . '->getAssisted', @_);
532 }
533  
534 # Import the world model object (for convenience)
535 $wmObj = $session->worldModelObj;
536  
537 # 1. ->assistedHash
538 # -----------------
539  
540 # Import the session's profile priority list
541 @priorityList = $session->profPriorityList;
542  
543 # Check each category of profile in turn
544 foreach my $category (@priorityList) {
545  
546 my $profObj = $session->ivShow('currentProfHash', $category);
547 if ($profObj && $self->ivExists('assistedHash', $profObj->name)) {
548  
549 # A complete assisted move is available for this profile
550 return $self->ivShow('assistedHash', $profObj->name);
551 }
552 }
553  
554 # 2. ->doorHash
555 # -------------
556  
557 # Only consult the IVs for which the corresponding part 2 IVs yielded nothing
558  
559 if ($wmObj->assistedBreakFlag && $self->exitOrnament eq 'break' && ! @breakList) {
560  
561 $cmd = $self->ivShow('doorHash', 'break');
562 if (defined $cmd) {
563  
564 push (@breakList, $cmd);
565  
566 } else {
567  
568 # Use the command cage's standard 'break' command, if it is set
569 $cmd = $session->prepareCmd('break', 'direction', $self->dir);
570 if (defined $cmd) {
571  
572 push (@breakList, $cmd);
573 }
574 }
575 }
576  
577 if ($wmObj->assistedPickFlag && $self->exitOrnament eq 'pick' && ! @pickList) {
578  
579 $cmd = $self->ivShow('doorHash', 'pick');
580 if (defined $cmd) {
581  
582 push (@breakList, $cmd);
583  
584 } else {
585  
586 # Use the command cage's standard 'pick' command, if it is set
587 $cmd = $session->prepareCmd('pick', 'direction', $self->dir);
588 if (defined $cmd) {
589  
590 push (@pickList, $cmd);
591 }
592 }
593 }
594  
595 if ($wmObj->assistedUnlockFlag && $self->exitOrnament eq 'lock' && ! @unlockList) {
596  
597 $cmd = $self->ivShow('doorHash', 'unlock');
598 if (defined $cmd) {
599  
600 push (@breakList, $cmd);
601  
602 } else {
603  
604 # Use the command cage's standard 'unlock' command, if it is set
605 $cmd = $session->prepareCmd('unlock', 'direction', $self->dir);
606 if (defined $cmd) {
607  
608 push (@unlockList, $cmd);
609 }
610 }
611 }
612  
613 if ($wmObj->assistedOpenFlag && $self->exitOrnament eq 'open' && ! @openList) {
614  
615 $cmd = $self->ivShow('doorHash', 'open');
616 if (defined $cmd) {
617  
618 push (@breakList, $cmd);
619  
620 } else {
621  
622 # Use the command cage's standard 'open_dir' command, if it is set
623 $cmd = $session->prepareCmd('open_dir', 'direction', $self->dir);
624 if (defined $cmd) {
625  
626 push (@openList, $cmd);
627 }
628 }
629 }
630  
631 if ($wmObj->assistedCloseFlag && $self->exitOrnament eq 'open' && ! @closeList) {
632  
633 $cmd = $self->ivShow('doorHash', 'close');
634 if (defined $cmd) {
635  
636 push (@breakList, $cmd);
637  
638 } else {
639  
640 # Use the command cage's standard 'close_dir' command, if it is set
641 $cmd = $session->prepareCmd('close_dir', 'direction', $self->dir);
642 if (defined $cmd) {
643  
644 push (@closeList, $cmd);
645 }
646 }
647 }
648  
649 if ($wmObj->assistedLockFlag && $self->exitOrnament eq 'lock' && ! @lockList) {
650  
651 $cmd = $self->ivShow('doorHash', 'lock');
652 if (defined $cmd) {
653  
654 push (@breakList, $cmd);
655  
656 } else {
657  
658 # Use the command cage's standard 'lock' command, if it is set
659 $cmd = $session->prepareCmd('lock', 'direction', $self->dir);
660 if (defined $cmd) {
661  
662 push (@lockList, $cmd);
663 }
664 }
665 }
666  
667 # (Obviously, there's no standard command for 'mystery' exits)
668  
669 # 3. ->dir
670 # --------
671  
672 # Now, combine the six lists into a single list and insert the actual direction of movement,
673 # $self->dir, in the right place
674  
675 if (@breakList) {
676  
677 # Don't try to close or lock a door which has been broken down
678 @cmdList = (@breakList, $self->dir);
679  
680 } elsif (@pickList) {
681  
682 @cmdList = (@pickList, @openList, $self->dir, @closeList, @lockList);
683  
684 } elsif (@unlockList) {
685  
686 @cmdList = (@unlockList, @openList, $self->dir, @closeList, @lockList);
687  
688 } elsif (@openList) {
689  
690 @cmdList = (@openList, @closeList, $self->dir, @lockList);
691 }
692  
693 if (! @cmdList) {
694  
695 return undef;
696  
697 } else {
698  
699 # Combine the commands (and sequences of commands) into a single string, with each
700 # individual world command separated from the next one by Axmud's command separator
701 $cmdString = join($axmud::CLIENT->cmdSep, @cmdList);
702  
703 # Return the string
704 return $cmdString;
705 }
706 }
707  
708 ##################
709 # Accessors - set
710  
711 ##################
712 # Accessors - get
713  
714 # To conserve memory, IVs with default values don't exist in the blessed reference; instead, we
715 # obtain them from a default exit object stored in the global variable $DEFAULT_EXIT
716  
717 sub _objName {
718 if ( ! exists $_[0]->{_objName} )
719 { $axmud::DEFAULT_EXIT->{_objName} } else { $_[0]->{_objName} }
720 }
721 sub _objClass {
722 if ( ! exists $_[0]->{_objClass} )
723 { $axmud::DEFAULT_EXIT->{_objClass} } else { $_[0]->{_objClass} }
724 }
725 sub _parentFile
726 { $_[0]->{_parentFile} }
727 sub _parentWorld
728 { $_[0]->{_parentWorld} }
729 sub _privFlag {
730 if ( ! exists $_[0]->{_privFlag} )
731 { $axmud::DEFAULT_EXIT->{_privFlag} } else { $_[0]->{_privFlag} }
732 }
733  
734 sub name {
735 if ( ! exists $_[0]->{name} )
736 { $axmud::DEFAULT_EXIT->{name} } else { $_[0]->{name} }
737 }
738 sub category {
739 if ( ! exists $_[0]->{category} )
740 { $axmud::DEFAULT_EXIT->{category} } else { $_[0]->{category} }
741 }
742 sub modelFlag
743 { $_[0]->{modelFlag} }
744 sub number
745 { $_[0]->{number} }
746 sub parent
747 { $_[0]->{parent} }
748  
749 sub privateHash {
750 my $self = shift;
751 if ( ! exists $self->{privateHash} )
752 { return %{$axmud::DEFAULT_EXIT->{privateHash}}; }
753 else
754 { return %{$self->{privateHash}}; }
755 }
756  
757 sub exitType {
758 if ( ! exists $_[0]->{exitType} )
759 { $axmud::DEFAULT_EXIT->{exitType} } else { $_[0]->{exitType} }
760 }
761  
762 sub dir
763 { $_[0]->{dir} }
764 sub altDir {
765 if ( ! exists $_[0]->{altDir} )
766 { $axmud::DEFAULT_EXIT->{altDir} } else { $_[0]->{altDir} }
767 }
768 sub mapDir {
769 if ( ! exists $_[0]->{mapDir} )
770 { $axmud::DEFAULT_EXIT->{mapDir} } else { $_[0]->{mapDir} }
771 }
772 sub drawMode {
773 if ( ! exists $_[0]->{drawMode} )
774 { $axmud::DEFAULT_EXIT->{drawMode} } else { $_[0]->{drawMode} }
775 }
776  
777 sub exitTag {
778 if ( ! exists $_[0]->{exitTag} )
779 { $axmud::DEFAULT_EXIT->{exitTag} } else { $_[0]->{exitTag} }
780 }
781 sub exitTagXOffset {
782 if ( ! exists $_[0]->{exitTagXOffset} )
783 { $axmud::DEFAULT_EXIT->{exitTagXOffset} } else { $_[0]->{exitTagXOffset} }
784 }
785 sub exitTagYOffset {
786 if ( ! exists $_[0]->{exitTagYOffset} )
787 { $axmud::DEFAULT_EXIT->{exitTagYOffset} } else { $_[0]->{exitTagYOffset} }
788 }
789  
790 sub brokenFlag {
791 if ( ! exists $_[0]->{brokenFlag} )
792 { $axmud::DEFAULT_EXIT->{brokenFlag} } else { $_[0]->{brokenFlag} }
793 }
794 sub bentFlag {
795 if ( ! exists $_[0]->{bentFlag} )
796 { $axmud::DEFAULT_EXIT->{bentFlag} } else { $_[0]->{bentFlag} }
797 }
798 sub bendOffsetList {
799 my $self = shift;
800 if ( ! exists $self->{bendOffsetList} )
801 { return @{$axmud::DEFAULT_EXIT->{bendOffsetList}}; }
802 else
803 { return @{$self->{bendOffsetList}}; }
804 }
805 sub regionFlag {
806 if ( ! exists $_[0]->{regionFlag} )
807 { $axmud::DEFAULT_EXIT->{regionFlag} } else { $_[0]->{regionFlag} }
808 }
809 sub superFlag {
810 if ( ! exists $_[0]->{superFlag} )
811 { $axmud::DEFAULT_EXIT->{superFlag} } else { $_[0]->{superFlag} }
812 }
813 sub notSuperFlag {
814 if ( ! exists $_[0]->{notSuperFlag} )
815 { $axmud::DEFAULT_EXIT->{notSuperFlag} } else { $_[0]->{notSuperFlag} }
816 }
817 sub hiddenFlag {
818 if ( ! exists $_[0]->{hiddenFlag} )
819 { $axmud::DEFAULT_EXIT->{hiddenFlag} } else { $_[0]->{hiddenFlag} }
820 }
821 sub randomType {
822 if ( ! exists $_[0]->{randomType} )
823 { $axmud::DEFAULT_EXIT->{randomType} } else { $_[0]->{randomType} }
824 }
825 sub randomDestList {
826 my $self = shift;
827 if ( ! exists $self->{randomDestList} )
828 { return @{$axmud::DEFAULT_EXIT->{randomDestList}}; }
829 else
830 { return @{$self->{randomDestList}}; }
831 }
832  
833 sub destRoom {
834 if ( ! exists $_[0]->{destRoom} )
835 { $axmud::DEFAULT_EXIT->{destRoom} } else { $_[0]->{destRoom} }
836 }
837 sub twinExit {
838 if ( ! exists $_[0]->{twinExit} )
839 { $axmud::DEFAULT_EXIT->{twinExit} } else { $_[0]->{twinExit} }
840 }
841 sub oneWayFlag {
842 if ( ! exists $_[0]->{oneWayFlag} )
843 { $axmud::DEFAULT_EXIT->{oneWayFlag} } else { $_[0]->{oneWayFlag} }
844 }
845 sub oneWayDir {
846 if ( ! exists $_[0]->{oneWayDir} )
847 { $axmud::DEFAULT_EXIT->{oneWayDir} } else { $_[0]->{oneWayDir} }
848 }
849 sub retraceFlag {
850 if ( ! exists $_[0]->{retraceFlag} )
851 { $axmud::DEFAULT_EXIT->{retraceFlag} } else { $_[0]->{retraceFlag} }
852 }
853 sub shadowExit {
854 if ( ! exists $_[0]->{shadowExit} )
855 { $axmud::DEFAULT_EXIT->{shadowExit} } else { $_[0]->{shadowExit} }
856 }
857  
858 sub exitOrnament {
859 if ( ! exists $_[0]->{exitOrnament} )
860 { $axmud::DEFAULT_EXIT->{exitOrnament} } else { $_[0]->{exitOrnament} }
861 }
862 sub exitState {
863 if ( ! exists $_[0]->{exitState} )
864 { $axmud::DEFAULT_EXIT->{exitState} } else { $_[0]->{exitState} }
865 }
866 sub exitInfo {
867 if ( ! exists $_[0]->{exitInfo} )
868 { $axmud::DEFAULT_EXIT->{exitInfo} } else { $_[0]->{exitInfo} }
869 }
870  
871 sub assistedHash {
872 my $self = shift;
873 if ( ! exists $self->{assistedHash} )
874 { return %{$axmud::DEFAULT_EXIT->{assistedHash}}; }
875 else
876 { return %{$self->{assistedHash}}; }
877 }
878 sub doorHash {
879 my $self = shift;
880 if ( ! exists $self->{doorHash} )
881 { return %{$axmud::DEFAULT_EXIT->{doorHash}}; }
882 else
883 { return %{$self->{doorHash}}; }
884 }
885 }
886  
887 # Package must return a true value
888 1