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

filter: Statementstmt 0.0% 0 / 1092 Branchbran 0.0% 0 / 756 Conditioncond 0.0% 0 / 792 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 52 Podpod 0.0% 0 / 48 totaltotal 0.0% 0 / 2740 CC 379 SCAR 76.6
CC
379
Cov
0%
moveKnownDirSeen
7832.0
setCurrentRoom
2070.0
showPseudoStatement
1482.0
CRAP 2112.9
1 # Copyright (C) 2011-2021 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::Map
16 # The automapper object (separate and independent from the Automapper window object, GA::Win::Map)
17  
18 { package Games::Axmud::Obj::Map;
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 # Called by GA::Session->setupProfiles
34 #
35 # Creates a new instance of the automapper object, which monitors the character's current
36 # location in the world.
37 # The Automapper window itself is handled by GA::Win::Map. There is always an automapper
38 # object running, regardless of whether the Automapper window is open, or not
39 #
40 # Expected arguments
41 # $session - The parent GA::Session
42 #
43 # Return values
44 # 'undef' on improper arguments or if there is already an automapper object for this
45 # session
46 # Blessed reference to the newly-created object on success
47  
48 my ($class, $session, $check) = @_;
49  
50 # Check for improper arguments
51 if (! defined $class || ! defined $session || defined $check) {
52  
53 return $axmud::CLIENT->writeImproper($class . '->new', @_);
54 }
55  
56 # Setup
57 my $self = {
58 _objName => 'automapper',
59 _objClass => $class,
60 _parentFile => undef, # No parent file object
61 _parentWorld => undef, # No parent file object
62 _privFlag => TRUE, # All IVs are private
63  
64 # Perl object components
65 # ----------------------
66  
67 # The parent GA::Session
68 session => $session,
69 # The session's current world model object (set by GA::Session->setupProfiles)
70 worldModelObj => undef,
71 # The current Automapper window, GA::Map::Win, if open (undef, if not)
72 mapWin => undef,
73  
74 # Automapper object IVs
75 # ---------------------
76  
77 # Blessed reference of the current location (a GA::ModelObj::Room, 'undef' if there is
78 # no current location)
79 currentRoom => undef,
80 # Blessed reference of the last known location (a GA::ModelObj::Room), set when the
81 # automapper gets lost
82 lastKnownRoom => undef,
83 # When the user types a command like 'e;enter cave;n', a separate GA::Buffer::Cmd
84 # object is created for each of the three commands, and the object's ->interpretCmd
85 # gets called each time
86 # ->interpretCmd attemps to work out whether 'enter cave' is a movement command or not,
87 # but the automapper's ->currentRoom probably doesn't know anything about an exit
88 # called 'enter cave'
89 # $self->ghostRoom is set equal to $self->currentRoom whenever the Locator processes a
90 # room statement, and isn't expecting any more room statements
91 # Thereafter, each call to ->interpretCmd attemps to work out the destination room of
92 # the command; if a destination room is found, ->ghostRoom is set
93 # In that way, ->interpretCmd can check the exits from rooms other than the current
94 # room, and in the command 'e;enter cave;n' will correctly work out that 'enter cave'
95 # will be a movement command from that room, once the character reaches it
96 # ->ghostRoom is set to 'undef' whenever ->currentRoom is set to 'undef'
97 ghostRoom => undef,
98  
99 # An IV used for handling relative directions (for the handful of worlds that use them)
100 # The last known direction of travel in a cardinal or intercardinal direction, converted
101 # into a standard primary direction (i.e. if defined, the value is 'north', 'south',
102 # 'east', 'west', 'northeast', 'northwest', 'southeast' or 'southwest'
103 # Whenever $self->moveKnownDirSeen is called, that function tries to translate the
104 # direction of movement into one of the above. If it succeeds, this IV is set; if it
105 # fails, this IV is not set or reset (in other words, moving up or down doesn't change
106 # the value of the IV, but using assisted moves to go through an 'enter portal' exit
107 # object whose ->mapDir has been allocated as 'north' DOES change the value of the iV
108 # This value is independent of $self->currentRoom; for example, when the character is
109 # marked as lost, this value is not reset as well
110 facingDir => undef,
111  
112 # When the Automapper window isn't open, this object can track the character's position
113 # - but only when this flag is set to TRUE
114 # Initially set to FALSE by default. Set to FALSE when the Automapper window opens or to
115 # TRUE when the Automapper window closes (if $self->currentRoom is set by then). Set
116 # to TRUE and back to FALSE by $self->setCurrentRoom)
117 trackAloneFlag => FALSE,
118 # When the session's ->status is 'offline', $self->showPseudoStatement can construct a
119 # plausible room statement similar to what the user would see, if the character were
120 # to be wandering around the world
121 # The type of statement to construct: 'verbose', 'short' or 'brief'
122 pseudoStatementMode => 'verbose',
123  
124 # IVs to handle random exits of the type 'temp_region', once the characters goes through
125 # it: the room object containing the exit, and its destination room
126 tempRandomOriginRoom => undef,
127 tempRandomDestRoom => undef,
128 # The automapper window's ->mode when the character moved through the random exit, used
129 # to set the mode back to its original value (in the temporary region, we need the
130 # mode set to 'update')
131 # Set to 'follow', 'update' or 'undef' if the automapper window isn't open
132 tempRandomMode => undef,
133  
134 # In the world model's auto-compare and auto-rescue modes, new rooms (created by
135 # $self->createNewRoom) or just the current room are compared against other rooms in
136 # the world model. If there are any matches, this flag is set to TRUE. At all other
137 # times, this flag is set to FALSE
138 currentMatchFlag => FALSE,
139 # When $self->currentMatchFlag is TRUE, the matching list of rooms (when FALSE, an empty
140 # list)
141 currentMatchList => [],
142  
143 # IVs to handle auto-rescue mode, in which we switch to a temporary region and create a
144 # new room there, rather than marking the character as lost
145 # Flag set to TRUE if the automapper window was in 'follow mode' when auto-rescue mode
146 # was activated, and if we're allowed to temporarily switch it to 'update mode'
147 rescueFollowFlag => FALSE,
148 # The region object containing the room in which the character was marked lost
149 rescueLostRegionObj => undef,
150 # The temporary region object that was created
151 rescueTempRegionObj => undef,
152 # Flag set to TRUE when auto-rescue mode is activated. Once a merge operation has begun
153 # (a call to GA::Obj::WorldModel->mergeMap), it's set back to FALSE, so that
154 # $self->setCurrentRoom doesn't bother to check that the new current room is in the
155 # temporary region (ordinarily during auto-rescue mode, setting the current room to a
156 # room in a different region automatically disactivates auto-rescue mode)
157 rescueCheckFlag => FALSE,
158 };
159  
160 # Bless the window object into existence
161 bless $self, $class;
162 return $self;
163 }
164  
165 ##################
166 # Methods
167  
168 sub openWin {
169  
170 # Called by GA::Session->start and ->setupProfiles, and by GA::Cmd::OpenAutomapper->do
171 # If there is already an Automapper window open, reset it, and make this object its owner.
172 # Otherwise, create a new Automapper window
173 # NB When the window closes, GA::Win::Map calls $self->set_mapWin
174 #
175 # Expected arguments
176 # (none besides $self)
177 #
178 # Return values
179 # 'undef' on improper arguments or if there's an error resetting an existing Automapper
180 # window, or opening a new one
181 # 1 otherwise
182  
183 my ($self, $check) = @_;
184  
185 # Local variables
186 my ($winObj, $regionObj, $stripObj, $left, $right, $top, $bottom, $tableObj);
187  
188 # Check for improper arguments
189 if (defined $check) {
190  
191 return $axmud::CLIENT->writeImproper($self->_objClass . '->openWin', @_);
192 }
193  
194 if ($self->session->mapWin) {
195  
196 # There is already an Automapper window open. Reset it, and make this object the owner
197 if (! $self->session->mapWin->winReset($self)) {
198  
199 # Due to the error, we're force to close the window
200 $self->session->mapWin->winDestroy();
201  
202 return $self->writeError(
203 'Could not reset the Automapper window - window closed',
204 $self->_objClass . '->openWin',
205 );
206  
207 } else {
208  
209 # This object is now the window's owner
210 $self->ivPoke('mapWin', $self->session->mapWin);
211  
212 # Reset this object's IVs
213 $self->ivUndef('currentRoom');
214 $self->ivUndef('lastKnownRoom');
215 $self->ivUndef('ghostRoom');
216 $self->ivPoke('trackAloneFlag', FALSE);
217  
218 # If the Locator is running, it no longer knows the world model number of the
219 # current room
220 if ($self->session->locatorTask) {
221  
222 $self->session->locatorTask->resetModelRoom();
223 }
224 }
225  
226 } else {
227  
228 # Open a new Automapper window
229  
230 # Try to open a pseudo-window, if allowed
231 if (! $axmud::CLIENT->shareMainWinFlag && $self->worldModelObj->pseudoWinFlag) {
232  
233 # If there are any holders (GA::Table::Holder) with an ->id set to 'map', we can
234 # use the space they occupy, rather than looking for a new space
235 $stripObj = $self->session->mainWin->tableStripObj;
236 $tableObj = $stripObj->replaceHolder(
237 'map',
238 'Games::Axmud::Table::PseudoWin',
239 undef, # No ->objName
240 # ->initHash
241 'frame_title' => 'Automapper',
242 'win_type' => 'map',
243 'win_name' => 'map',
244 'owner' => $self->session,
245 'session' => $self->session,
246 );
247  
248 if (! $tableObj) {
249  
250 # Ask the session's 'main' window for the size and position of another table
251 # object, using the winmap's default winzone size, and check whether space
252 # exists for another table object
253 ($left, $right, $top, $bottom) = $stripObj->findPosn();
254  
255 if (defined $left) {
256  
257 # Create the GA::Table::PseudoWin object at the specified size and
258 # position
259 $tableObj = $stripObj->addTableObj(
260 'Games::Axmud::Table::PseudoWin',
261 $left,
262 $right,
263 $top,
264 $bottom,
265 undef, # No ->objName
266 # ->initHash
267 'frame_title' => 'Automapper',
268 'win_type' => 'map',
269 'win_name' => 'map',
270 'owner' => $self->session,
271 'session' => $self->session,
272 );
273 }
274 }
275  
276 if ($tableObj) {
277  
278 $winObj = $tableObj->pseudoWinObj;
279 }
280 }
281  
282 # If not allowed (or if a pseudo-window can't be opened), open a normal 'grid' window
283 if (! $winObj) {
284  
285 $winObj = $self->session->mainWin->workspaceObj->createGridWin(
286 'map', # Window type
287 'map', # Window name
288 'Automapper', # Window title
289 undef, # 'map' windows don't use winmaps
290 undef, # Use default package name, GA::Win::Map
291 undef, # No windows exists yet
292 undef, # Ditto
293 $self->session, # Owner is the GA::Session, not this object
294 $self->session, # Must be a session
295 $self->session->mainWin->workspaceObj->findWorkspaceGrid($self->session),
296 # Session's workspace grid object
297 );
298 }
299  
300 # If neither form of window can be opened, only then show an error
301 if (! $winObj) {
302  
303 return $self->writeError(
304 'Could not open the Automapper window',
305 $self->_objClass . '->openWin',
306 );
307 }
308  
309 # Update IVs (for both 'grid' windows and pseudo-windows)
310 $self->ivPoke('mapWin', $winObj);
311 $winObj->set_mapObj($self);
312  
313 # If this object's current room set, tell the Automapper window to draw that room's
314 # region and level now
315 if ($self->currentRoom) {
316  
317 $regionObj = $self->worldModelObj->ivShow('modelHash', $self->currentRoom->parent);
318 if ($regionObj) {
319  
320 $winObj->setCurrentRegion(
321 $regionObj->name,
322 TRUE, # Set the correct current level at the same time
323 );
324 }
325  
326 # Also switch to 'follow' mode, so that the automapper continues to track the
327 # character's location
328 $winObj->setMode('follow');
329 }
330 }
331  
332 return 1;
333 }
334  
335 sub setCurrentRoom {
336  
337 # Can be called by anything
338 # Sets the current location (a room object in the current world model)
339 # If the automapper is open, redraws both the old current location (if there is one), and
340 # the new one
341 #
342 # Expected arguments
343 # (none besides $self)
344 #
345 # Optional arguments
346 # $newRoomObj - The new current room (a GA::ModelObj::Room object). If 'undef', there is
347 # no current room
348 # $lostFunc - If defined, this automapper object is now 'lost' and $self->lastKnownRoom
349 # needs to be set. $lostFunc is a string describing the calling function
350 # (which is therefore available for debugging purposes, if necessary).
351 # Otherwise set to 'undef'; for example, when the Locator task is reset,
352 # this and subsequent arguments should all be 'undef'
353 # $rescueFlag - If TRUE, allow auto-rescue mode to activate, when applicable. FALSE (or
354 # 'undef') otherwise
355 # $newFlag - If TRUE, called by $self->createNewRoom (or by this function calling
356 # itself recursively, after an earlier call to $self->createNewRoom).
357 # FALSE (or 'undef') otherwise
358 # @matchList - When called by $self->createNewRoom (or by this function calling itself
359 # recursively, after an earlier call by $self->createNewRoom), a list
360 # containing any rooms matched against the new room (which might be an
361 # empty list, especially if no room comparison operation was performed);
362 # an empty list when called by any other function
363 #
364 # Return values
365 # 'undef' on improper arguments, if a world model room object matching $newRoomNum
366 # doesn't exist, or if it isn't a room object
367 # 1 otherwise
368  
369 my ($self, $newRoomObj, $lostFunc, $rescueFlag, $newFlag, @matchList) = @_;
370  
371 # Local variables
372 my (
373 $taskObj, $dictObj, $oldRoomObj, $currentRoomFlag, $anchorLine, $oldRegionObj,
374 $tempRegionObj, $tempRegionmapObj, $regionObj, $regionmapObj, $moveCount, $text,
375 );
376  
377 # (No improper arguments to check)
378  
379 # If the Automapper window's menu bar is open, we get a long stream of Gtk3 errors, so make
380 # sure it's closed
381 if ($self->mapWin) {
382  
383 $self->mapWin->menuBar->deactivate();
384 }
385  
386 # Import the Locator task (if it is running) and the session's current dictionary
387 $taskObj = $self->session->locatorTask;
388 $dictObj = $self->session->currentDict;
389  
390 # This IV is always set on a call to this function
391 if (! @matchList) {
392  
393 $self->ivPoke('currentMatchFlag', FALSE);
394 $self->ivEmpty('currentMatchList');
395  
396 } else {
397  
398 $self->ivPoke('currentMatchFlag', TRUE);
399 $self->ivPoke('currentMatchList', @matchList);
400 }
401  
402 # If there was a previous current location (or a room marked as the last known location),
403 # remember which one it is...
404 if ($self->currentRoom) {
405  
406 $oldRoomObj = $self->currentRoom;
407 $currentRoomFlag = TRUE;
408  
409 } elsif ($self->lastKnownRoom) {
410  
411 $oldRoomObj = $self->lastKnownRoom;
412 }
413  
414 # ...before setting the new current location
415 if ($newRoomObj) {
416  
417 $self->ivPoke('currentRoom', $newRoomObj);
418  
419 # In 'connect offline' mode, display a pseudo-room statement using details stored in the
420 # new current room (but only if $self->currentRoom was not already set, because in
421 # that case, the pseudo-room statement will have already been displayed by
422 # $self->pseudoWorldCmd)
423 if (! $currentRoomFlag && $self->session->status eq 'offline') {
424  
425 $anchorLine = $self->showPseudoStatement($dictObj, $newRoomObj);
426 if (! defined $anchorLine) {
427  
428 # Could not produce a pseudo-room statement because no room statement components
429 # of the statement type specified by $self->pseudoStatementMode are available
430 # In this unlikely situation, mark the character as lost. Call this function
431 # recursively, to make things easier
432 # The FALSE argument means 'don't allow auto-rescue mode'
433 return $self->setCurrentRoom(
434 undef,
435 $self->_objClass . '->setCurrentRoom',
436 FALSE,
437 );
438 }
439  
440 # The Locator task normally creates a non-model room when it spots a room statement.
441 # Instruct it create a non-model room based on $newRoomObj, and tell it to not
442 # look for room statements in the text just displayed by the call to
443 # ->showPseudoStatement
444 $taskObj->usePseudoStatement($dictObj, $newRoomObj, $anchorLine);
445 }
446  
447 # We don't need the last known location, if we are not lost
448 if ($self->lastKnownRoom) {
449  
450 $self->ivUndef('lastKnownRoom');
451 }
452  
453 # Also set the ghost room, whenever the current room is set (but only if the Automapper
454 # window is open, or if $self->trackAloneFlag is not set)
455 # (We don't reset the ghost room when the IF condition is FALSE, because it occasionally
456 # causes the automapper to get lost when moving in non-primary/non-secondary
457 # directions
458 if (
459 $taskObj
460 && ! $taskObj->moveList
461 && ($self->mapWin || $self->trackAloneFlag)
462 ) {
463 $self->setGhostRoom($newRoomObj);
464 }
465  
466 # Tell the automapper window to graffiti the room (when graffiti mode is on)
467 if (
468 $self->mapWin
469 && ($self->mapWin->mode eq 'follow' || $self->mapWin->mode eq 'update')
470 ) {
471 $self->mapWin->add_graffiti($newRoomObj);
472 }
473  
474 # If auto-rescue mode has been activated and the new current room isn't in the
475 # temporary region, then we need to disactivate auto-rescue mode immediately
476 # (Exception: one a merge operation has started, don't; just wait for the operation to
477 # finish, which disactivates auto-rescue mode anyway)
478 $regionObj = $self->worldModelObj->ivShow('modelHash', $newRoomObj->parent);
479 $regionmapObj = $self->worldModelObj->ivShow('regionmapHash', $regionObj->name);
480 if (
481 $self->rescueTempRegionObj
482 && $self->rescueCheckFlag
483 && $self->rescueTempRegionObj ne $regionObj
484 ) {
485 $self->reset_rescueRegion();
486 }
487  
488 # If called by anything other than $self->createNewRoom, and if allowed, compare the
489 # current room against other rooms (but don't bother if the Locator task is expecting
490 # further room statements)
491 if (
492 ! $newFlag
493 && $taskObj
494 && (scalar $taskObj->moveList) <= 1
495 && (
496 $self->worldModelObj->autoCompareMode eq 'current'
497 || (
498 $self->rescueTempRegionObj
499 && $self->rescueTempRegionObj->name eq $regionmapObj->name
500 )
501 )
502 ) {
503 if (! $self->worldModelObj->autoCompareAllFlag) {
504  
505 # Compare the new room against rooms in the same region, looking for a duplicate
506 # room. (The TRUE argument identifies this function as the caller)
507 @matchList = $self->autoCompareLocatorRoom($regionmapObj, FALSE, TRUE);
508  
509 } else {
510  
511 # Compare the new room against rooms in every region (starting with
512 # $regionmapObj), looking for a duplicate room
513 @matchList = $self->autoCompareLocatorRoom($regionmapObj, TRUE, TRUE);
514 }
515  
516 if (@matchList) {
517  
518 # Update IVs
519 $self->ivPoke('currentMatchFlag', TRUE);
520 $self->ivPoke('currentMatchList', @matchList);
521 }
522 }
523  
524 } else {
525  
526 $self->ivUndef('currentRoom');
527 $self->setGhostRoom(); # No ghost room
528 $self->ivPoke('trackAloneFlag', FALSE); # Stop 'track alone' mode, if it was on
529  
530 if ($oldRoomObj) {
531  
532 $oldRegionObj = $self->worldModelObj->ivShow('modelHash', $oldRoomObj->parent);
533 }
534  
535 # If auto-rescue mode is on, and if it's possible to do so, rather than marking the
536 # character as lost we create a temporary region and a new room in that region
537 if (
538 # Auto-rescue mode is permitted by the world model
539 $self->worldModelObj->autoRescueFlag
540 # In some situations, when character is lost, auto-rescue mode must not be activated
541 && $rescueFlag
542 # ...such as when the Locator task doesn't know the current location
543 && $taskObj
544 && $taskObj->roomObj
545 # ..such as in 'connect offline' mode
546 && $self->session->status ne 'offline'
547 # Don't activate auto-rescue mode if it's already activated (we don't want an
548 # endless series of temporary regions)
549 && ! $self->rescueLostRegionObj
550 # The automapper window must be open and in 'update' mode (or, if the world model
551 # flags permit, in 'follow' mode)
552 && $self->mapWin
553 && (
554 $self->mapWin->mode eq 'update'
555 || (
556 $self->mapWin->mode eq 'follow'
557 && $self->worldModelObj->autoRescueForceFlag
558 && ! $self->worldModelObj->disableUpdateModeFlag
559 )
560 )
561 ) {
562 # The automapper object is momentarily lost
563 $self->ivPoke('lastKnownRoom', $oldRoomObj);
564 # Play a sound effect, if sound is turned on
565 $axmud::CLIENT->playSound('lost');
566  
567 if ($self->mapWin->mode eq 'follow') {
568  
569 # Switch to 'update' mode temporarily; it's switched back to 'follow' mode when
570 # auto-rescue mode is disactivated
571 $self->mapWin->setMode('update');
572 # Update IV, so we can switch back to 'follow' mode when ready
573 $self->ivPoke('rescueFollowFlag', TRUE);
574 }
575  
576 # Create a new temporary region
577 $tempRegionObj = $self->worldModelObj->addRegion(
578 $self->session,
579 TRUE, # Update Automapper windows now
580 undef, # Generate a region name
581 undef, # No parent region
582 TRUE, # Temporary region
583 );
584  
585 if ($tempRegionObj) {
586  
587 # Create a new room in the temporary region
588 $tempRegionmapObj
589 = $self->worldModelObj->ivShow('regionmapHash', $tempRegionObj->name);
590 }
591  
592 if ($tempRegionmapObj) {
593  
594 # Update IVs now, so ->createNewRoom can use them
595 $self->ivPoke('rescueLostRegionObj', $oldRegionObj);
596 $self->ivPoke('rescueTempRegionObj', $tempRegionObj);
597 $self->ivPoke('rescueCheckFlag', TRUE);
598  
599 $newRoomObj = $self->createNewRoom(
600 $tempRegionmapObj,
601 $tempRegionmapObj->getGridCentre(), # Put new room at centre of region
602 'update', # Switch to 'update' mode
603 TRUE, # New room is current room
604 TRUE, # Room takes properties from Locator
605 );
606 }
607  
608 if ($newRoomObj) {
609  
610 $self->session->writeText(
611 'MAP: Auto-rescue mode activated (using temporary region \''
612 . $tempRegionObj->name . '\')',
613 );
614  
615 # Fire any hooks that are using the 'map_rescue_on' hook event
616 $self->session->checkHooks('map_rescue_on', $tempRegionmapObj->name);
617  
618 # $self->createNewRoom has already made a fresh call to this function, so there
619 # is nothing left to do
620 return 1;
621  
622 } else {
623  
624 # Very unlikely that the new room wasn't created, but if it wasn't, must destroy
625 # the temporary region (which resets $self->rescueLostRegionObj and
626 # ->rescueTempRegionObj)
627 if ($tempRegionObj) {
628  
629 $self->worldModelObj->deleteRegions(
630 $self->session,
631 TRUE, # Update automapper windows now
632 $tempRegionObj,
633 );
634 }
635 }
636 }
637  
638 # A temporary region wasn't created in the code just above
639 if ($lostFunc) {
640  
641 # The automapper object is lost
642 $self->ivPoke('lastKnownRoom', $oldRoomObj);
643  
644 # Display a message in the 'main' window...
645 $moveCount = $taskObj->ivNumber('moveList');
646 $text = 'MAP: The automapper has lost track of the current location';
647 if ($taskObj && $moveCount) {
648  
649 $text .= ' (Locator task was still expecting ';
650  
651 if ($moveCount == 1) {
652 $text .= '1 more room statement)';
653 } else {
654 $text .= $moveCount . ' more room statements)';
655 }
656 }
657  
658 $self->session->writeText($text);
659  
660 # ...and play a sound effect, if sound is turned on
661 $axmud::CLIENT->playSound('lost');
662  
663 # We can save the user the bother of having to reset the Locator task, before
664 # setting a new current room, by resetting the list of room statements the task
665 # is expecting
666 $taskObj->resetMoveList();
667  
668 } else {
669  
670 # The last known location must be explicitly reset
671 $self->ivUndef('lastKnownRoom');
672  
673 # Display a message in the 'main' window (if there was a current room when this
674 # function was called), but no sound effects this time
675 if ($currentRoomFlag) {
676  
677 $self->session->writeText('MAP: The automapper\'s current room has been reset');
678 }
679 }
680  
681 # If the Automapper window is open...
682 if ($self->mapWin) {
683  
684 # If the Automapper window is not in 'wait' mode, the mode must be changed to 'wait'
685 # mode ('update' mode would allow invalid changes to be written to the map, and
686 # 'follow' mode is confusing for the user if it's allowed to remain in place after
687 # getting lost)
688 if ($self->mapWin->mode ne 'wait') {
689  
690 $self->mapWin->setMode('wait');
691 }
692  
693 # Reset the window's title bar (in case it's showing the number of rooms the
694 # Locator was expecting)
695 $self->mapWin->setWinTitle();
696 }
697 }
698  
699 # If the Automapper window is open and the new current location isn't in the current
700 # regionmap, on the current level, then change one or both
701 if ($self->mapWin && $newRoomObj) {
702  
703 # Is the new room in the current region?
704 if (
705 ! $self->mapWin->currentRegionmap
706 || $self->mapWin->currentRegionmap->number != $newRoomObj->parent
707 ) {
708 # Switch region
709 $regionObj = $self->worldModelObj->ivShow('modelHash', $newRoomObj->parent);
710 $self->mapWin->setCurrentRegion(
711 $regionObj->name,
712 TRUE, # Set the correct current level at the same time
713 );
714  
715 } elsif ($self->mapWin->currentRegionmap->currentLevel ne $newRoomObj->zPosBlocks) {
716  
717 # Switch level
718 $self->mapWin->setCurrentLevel($newRoomObj->zPosBlocks);
719 }
720 }
721  
722 # If the character previously moved through a 'temp_region' random exit into a temporary
723 # region, check that this new room is in the same region
724 if (
725 $self->currentRoom
726 && $self->tempRandomDestRoom
727 && $self->tempRandomDestRoom->parent != $self->currentRoom->parent
728 ) {
729 # Delete the temporary region, which is no longer required
730 $self->worldModelObj->deleteRegions(
731 $self->session,
732 FALSE, # Don't update automapper yet
733 $self->worldModelObj->ivShow('modelHash', $self->tempRandomDestRoom->parent),
734 );
735  
736 # Reset IVs
737 $self->ivUndef('tempRandomOriginRoom');
738 $self->ivUndef('tempRandomDestRoom');
739 $self->ivUndef('tempRandomMode');
740 }
741  
742 # If the Automapper window is open, redraw the previous current location (if there was one)
743 # and the new current location (if there is one), both at the same time if possible
744 if ($self->mapWin) {
745  
746 # Final check that neither room has been deleted in the last few microseconds (we think
747 # this code can make a deleted room re-appear on the map, but we're not sure)
748 if ($oldRoomObj && ! $self->worldModelObj->ivExists('modelHash', $oldRoomObj->number)) {
749  
750 $oldRoomObj = undef;
751 }
752  
753 if ($newRoomObj && ! $self->worldModelObj->ivExists('modelHash', $newRoomObj->number)) {
754  
755 $newRoomObj = undef;
756 }
757  
758 if ($oldRoomObj && $newRoomObj) {
759  
760 # Draw both rooms together
761 $self->mapWin->markObjs(
762 'room', $oldRoomObj,
763 'room', $newRoomObj,
764 );
765  
766 } elsif ($oldRoomObj) {
767  
768 # Redraw the old room
769 $self->mapWin->markObjs('room', $oldRoomObj);
770  
771 } elsif ($newRoomObj) {
772  
773 # Redraw the new room
774 $self->mapWin->markObjs('room', $newRoomObj);
775 }
776  
777 if ($oldRoomObj || $newRoomObj) {
778  
779 $self->mapWin->doDraw();
780 }
781 }
782  
783 # If the Automapper window is not open, enable 'track alone' mode
784 if (! $self->mapWin && $newRoomObj) {
785  
786 $self->ivPoke('trackAloneFlag', TRUE);
787 }
788  
789 # Update the Locator task, if it's running
790 $self->updateLocator();
791  
792 # If the Automapper window is open...
793 if ($self->mapWin) {
794  
795 # In tracking mode, need to check the current location's position within the visible
796 # map, and move the scrollbars, if necessary
797 $self->mapWin->trackPosn();
798  
799 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
800 $self->mapWin->restrictWidgets();
801 }
802  
803 # Fire any hooks that are using the 'map_room' or 'map_lost' hook events
804 if ($newRoomObj) {
805  
806 $self->session->checkHooks('map_room', $self->currentRoom->number);
807  
808 } else {
809  
810 if ($self->lastKnownRoom) {
811 $self->session->checkHooks('map_no_room', $self->lastKnownRoom->number);
812 } else {
813 $self->session->checkHooks('map_no_room', 0);
814 }
815  
816 if ($lostFunc) {
817  
818 if ($currentRoomFlag) {
819 $self->session->checkHooks('map_lost', $oldRoomObj->number);
820 } else {
821 $self->session->checkHooks('map_lost', 0);
822 }
823 }
824 }
825  
826 return 1;
827 }
828  
829 sub setLastKnownRoom {
830  
831 # Can be called by anything
832 # Sets the last known room - the last known location before the automapper got lost
833 #
834 # Expected arguments
835 # (none besides $self)
836 #
837 # Optional arguments
838 # $newRoomObj - The new last known room (a GA::ModelObj::Room object). If 'undef', there
839 # is no last known room
840 #
841 # Return values
842 # 'undef' on improper arguments
843 # 1 otherwise
844  
845 my ($self, $newRoomObj, $check) = @_;
846  
847 # Local variables
848 my $oldRoomObj;
849  
850 # Check for improper arguments
851 if (defined $check) {
852  
853 return $axmud::CLIENT->writeImproper($self->_objClass . '->setLastKnownRoom', @_);
854 }
855  
856 $self->ivPoke('lastKnownRoom', $newRoomObj); # Now set to 'undef' if there is no ghost room
857  
858 return 1;
859 }
860  
861 sub setGhostRoom {
862  
863 # Can be called by anything. Not called by ->setCurrentRoom if the room has just been set as
864 # the current room
865 # Sets the ghost room - the presumed actual location of the character when a movement
866 # command is typed, and redraws both the old ghost room (if there is one), and the new one
867 # NB If the Automapper window is open and in 'wait mode', or if the window isn't open and
868 # $self->trackAloneFlag isn't set, the ghost room is reset, regardless of any arguments
869 # passed to this function (because we don't want the ghost room visibly moving around the
870 # map, when the user has clicked the 'wait' mode button)
871 #
872 # Expected arguments
873 # (none besides $self)
874 #
875 # Optional arguments
876 # $newRoomObj - The new ghost room (a GA::ModelObj::Room object). If 'undef', there is
877 # no ghost room
878 # $otherRoomObj - If specified, this represents an earlier ghost room which has not been
879 # redrawn yet, and is redrawn by this function
880 #
881 # Return values
882 # 'undef' on improper arguments
883 # 1 otherwise
884  
885 my ($self, $newRoomObj, $otherRoomObj, $check) = @_;
886  
887 # Local variables
888 my (
889 $oldRoomObj,
890 @drawList,
891 );
892  
893 # Check for improper arguments
894 if (defined $check) {
895  
896 return $axmud::CLIENT->writeImproper($self->_objClass . '->setGhostRoom', @_);
897 }
898  
899 # If there was a previous ghost room, remember which one it is...
900 if ($self->ghostRoom) {
901  
902 $oldRoomObj = $self->ghostRoom;
903 }
904  
905 # Special case: if not following or updating the map, reset the ghost room
906 if (
907 ($self->mapWin && $self->mapWin->mode eq 'wait')
908 || (! $self->mapWin && ! $self->trackAloneFlag)
909 ) {
910 $self->ivUndef('ghostRoom');
911  
912 } else {
913  
914 # Otherwise, set the new ghost room (if any)
915 $self->ivPoke('ghostRoom', $newRoomObj); # Now set to 'undef' if no ghost room
916 }
917  
918 # If the Automapper window is open, redraw the old ghost room (if there was one) and the new
919 # ghost room (if there is one), both at the same time if possible
920 # If either room isn't in the current regionmap, on the current level, then we don't need to
921 # redraw it
922 # If GA::Session->worldCmd was called, it has set GA::Session->worldCmdGhostRoom. The
923 # function might be processing multiple world commands, and we definitely don't want to
924 # redraw the ghost room dozens (or hundreds) of times. When GA::Session->worldCmdGhostRoom
925 # is set, don't redraw anything yet
926 if (
927 $self->mapWin
928 && $self->mapWin->currentRegionmap
929 && ! $self->session->worldCmdGhostRoom
930 ) {
931 if ($oldRoomObj) {
932  
933 if (
934 ($oldRoomObj->parent != $self->mapWin->currentRegionmap->number)
935 || ($oldRoomObj->zPosBlocks != $self->mapWin->currentRegionmap->currentLevel)
936 ) {
937 $oldRoomObj = undef; # Don't redraw it
938 }
939 }
940  
941 if ($newRoomObj) {
942  
943 if (
944 ($newRoomObj->parent != $self->mapWin->currentRegionmap->number)
945 || ($newRoomObj->zPosBlocks != $self->mapWin->currentRegionmap->currentLevel)
946 ) {
947 $newRoomObj = undef; # Don't redraw it
948 }
949 }
950  
951 # Final check that neither room has been deleted in the last few microseconds (we think
952 # this code can make a deleted room re-appear on the map, but we're not sure)
953 if ($oldRoomObj && ! $self->worldModelObj->ivExists('modelHash', $oldRoomObj->number)) {
954  
955 $oldRoomObj = undef;
956 }
957  
958 if ($newRoomObj && ! $self->worldModelObj->ivExists('modelHash', $newRoomObj->number)) {
959  
960 $newRoomObj = undef;
961 }
962  
963 if ($oldRoomObj) {
964  
965 push (@drawList, 'room', $oldRoomObj);
966 }
967  
968 if ($newRoomObj) {
969  
970 push (@drawList, 'room', $newRoomObj);
971 }
972  
973 if (
974 $otherRoomObj
975 && (! $oldRoomObj || $oldRoomObj ne $otherRoomObj)
976 && (! $newRoomObj || $newRoomObj ne $otherRoomObj)
977 ) {
978 push (@drawList, 'room', $otherRoomObj);
979 }
980  
981 if (@drawList) {
982  
983 $self->mapWin->markObjs(@drawList);
984 $self->mapWin->doDraw();
985 }
986 }
987  
988 return 1;
989 }
990  
991 sub updateLocator {
992  
993 # Can be called by anything, including many GA::Win::Map functions
994 # Updates the Locator task (if it is running) with this object's current location
995 #
996 # Expected arguments
997 # (none besides $self)
998 #
999 # Return values
1000 # 'undef' on improper arguments
1001 # 1 otherwise
1002  
1003 my ($self, $check) = @_;
1004  
1005 # Local variables
1006 my $taskObj;
1007  
1008 # Check for improper arguments
1009 if (defined $check) {
1010  
1011 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateLocator', @_);
1012 }
1013  
1014 $taskObj = $self->session->locatorTask;
1015 if ($taskObj) {
1016  
1017 # Tell the Locator which world model room is current
1018 if ($self->currentRoom) {
1019  
1020 $taskObj->set_modelNumber($self->currentRoom->number);
1021  
1022 # Copy the room tag into the Locator's non-model room, if there is a room tag (and
1023 # if the Locator has a non-model room)
1024 if ($taskObj->roomObj) {
1025  
1026 if ($self->currentRoom->roomTag) {
1027  
1028 $taskObj->roomObj->ivPoke('roomTag', $self->currentRoom->roomTag);
1029  
1030 } else {
1031  
1032 # The non-model room's room tag must be reset
1033 $taskObj->roomObj->ivUndef('roomTag');
1034 }
1035 }
1036  
1037 } else {
1038  
1039 $taskObj->set_modelNumber();
1040 if ($taskObj->roomObj) {
1041  
1042 # The room tag of the non-model room must be reset
1043 $taskObj->roomObj->ivUndef('roomTag');
1044 }
1045 }
1046  
1047 # Refresh the Locator task's window to display the changes
1048 $taskObj->refreshWin();
1049 }
1050  
1051 return 1;
1052 }
1053  
1054 # Locator task functions
1055  
1056 sub moveKnownDirSeen {
1057  
1058 # Called by GA::Task::Locator->processLine (at stage 3) when the character moves in a known
1059 # direction
1060 #
1061 # Expected arguments
1062 # $cmdObj - The GA::Buffer::Cmd object that stores the movement command
1063 #
1064 # Return values
1065 # 'undef' on improper arguments, if no changes are made to $self->currentRoom or if
1066 # a called function return 'undef'
1067 # 1 otherwise
1068  
1069 my ($self, $cmdObj, $check) = @_;
1070  
1071 # Local variables
1072 my (
1073 $dictObj, $testDir, $slot, $convertDir, $regionmapObj, $dir, $exitObj, $standardDir,
1074 $mapDir, $customDir, $dirType, $primaryFlag, $exitNum, $altExitObj, $altIndex,
1075 $transientFlag, $craftyExitObj, $destRoomObj, $vectorRef, $exitLength, $xPosBlocks,
1076 $yPosBlocks, $zPosBlocks, $number, $existRoomObj, $oppExitObj, $destWildMode,
1077 @patternList,
1078 );
1079  
1080 # Check for improper arguments
1081 if (! defined $cmdObj || defined $check) {
1082  
1083 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveKnownDirSeen', @_);
1084 }
1085  
1086 # Import the current dictionary (for convenience)
1087 $dictObj = $self->session->currentDict;
1088  
1089 # PART 1 - set the direction the character is facing, if possible
1090 #
1091 # If $cmdObjs represent movement in the direction north/northeast/east/southeast/south/
1092 # southwest/west/northwest, we can set the direction the character is facing now; the
1093 # setting can be refined later in this function, once an exit object has been identified
1094 # Otherwise, if the user has literally typed a relative direction like 'forward', then we
1095 # can set up the equivalent primary direction ready for PART 5
1096 $testDir = $dictObj->convertStandardDir($cmdObj->cmd);
1097 if (
1098 defined $testDir
1099 && $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $testDir)
1100 && $testDir ne 'up'
1101 && $testDir ne 'down'
1102 ) {
1103 $self->ivPoke('facingDir', $testDir);
1104  
1105 } else {
1106  
1107 # Is $cmdObj->cmd a relative direction like 'forward'?
1108 $slot = $dictObj->convertRelativeDir($cmdObj->cmd);
1109 if (defined $slot) {
1110  
1111 # $slot is in the range 0-7. Convert it into a standard primary direction like
1112 # 'north', depending on which way the character is currently facing
1113 $convertDir = $dictObj->rotateRelativeDir(
1114 $slot,
1115 $self->facingDir,
1116 );
1117  
1118 if (defined $convertDir) {
1119  
1120 # Translate the standard primary direction into the equivalent custom primary
1121 # direction, ready for PART 5
1122 $convertDir = $dictObj->ivShow('primaryDirHash', $convertDir);
1123 }
1124 }
1125 }
1126  
1127 # PART 2 - basic checks
1128 #
1129 # Do nothing if:
1130 # 1. The Automapper window is open and is in 'wait' mode
1131 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
1132 # 3. The current room isn't known (regardless of whether the Automapper window is open)
1133 if (
1134 ($self->mapWin && $self->mapWin->mode eq 'wait')
1135 || (! $self->mapWin && ! $self->trackAloneFlag)
1136 || ! $self->currentRoom
1137 ) {
1138 return undef;
1139 }
1140  
1141 # PART 3 - return from temporary regions
1142 #
1143 # If the character moved through a 'temp_region' random exit, check the Locator task's
1144 # current room. If it matches the random exit's parent room, then there's no need to worry
1145 # about updating the map; just move the player back to the original room and destroy the
1146 # temporary region
1147 if ($self->checkTempRandomReturn()) {
1148  
1149 return 1;
1150 }
1151  
1152 # PART 4 - get current room's region
1153 #
1154 # Get the current room's parent region and, from there, the regionmap
1155 $regionmapObj = $self->worldModelObj->findRegionmap($self->currentRoom->parent);
1156 if (! $regionmapObj) {
1157  
1158 # The current room doesn't appear to be in a region - so nothing we can do
1159 if ($self->worldModelObj->explainGetLostFlag) {
1160  
1161 $self->session->writeText(
1162 'MAP: Lost due to internal error (cannot find regionmap)',
1163 );
1164 }
1165  
1166 # The presence of a second argument means 'the character is lost'
1167 return $self->setCurrentRoom(
1168 undef,
1169 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1170 FALSE, # Don't use auto-rescue mode
1171 );
1172 }
1173  
1174 # PART 5 - get direction of movement
1175 #
1176 # Set $dir, the direction of movement, so that we can work out which exit object is being
1177 # used
1178 # Relative directions like 'forward' have already been translated into a custom primary
1179 # direction
1180 if ($convertDir) {
1181  
1182 $dir = $convertDir;
1183  
1184 # For assisted moves, we already know the exit object used (which will save us some time)
1185 } elsif ($cmdObj->assistedFlag) {
1186  
1187 $dir = $cmdObj->cmd;
1188 $exitObj = $cmdObj->assistedExitObj;
1189  
1190 # For redirect mode commands, use the original command, which should contain only a
1191 # direction
1192 } elsif ($cmdObj->redirectFlag) {
1193  
1194 $dir = $cmdObj->cmd;
1195  
1196 # For normal movement commands, the direction of movement has been stripped from
1197 # $cmdObj->cmd and stored in ->moveDir
1198 } else {
1199  
1200 $dir = $cmdObj->moveDir;
1201 }
1202  
1203 # PART 6 - identify an exit object (GA::Obj::Exit) matching the direction
1204 #
1205 # $dir can be any of the following:
1206 # (i) The original command used in an assisted move
1207 # - $standardDir, $mapDir and $customDir are set directly from the buffer object
1208 # (but $customDir is only set if it's a primary direction)
1209 #
1210 # (ii) A custom primary direction - one of the values in GA::Obj::Dict->primaryDirHash
1211 # (e.g. 'nord', sud') or ->primaryAbbrevHash (e.g. 'n', 's')
1212 # - $standardDir/$mapDir are set to the equivalent key (the words 'north', 'up'
1213 # etc)
1214 # - $customDir is set to the value of the key in ->primaryDirHash (so that if $dir
1215 # is 'n', $customDir gets set to the unabbreviated custom direction 'nord')
1216 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
1217 # $customDir)
1218 #
1219 # (iii) A recognised secondary direction - one of the values in
1220 # GA::Obj::Dict->secondaryDirHash (e.g. 'out') or ->secondaryAbbrevHash
1221 # (e.g. 'o')
1222 # - $standardDir is set to the equivalent key (the words 'in', 'entrance',
1223 # 'portal' etc)
1224 # - $mapDir / $customDir are not set (the key's corresponding value is always
1225 # equal to $dir)
1226 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
1227 # $standardDir)
1228 #
1229 # (iv) A direction not stored in the dictionary, such as 'enter well'
1230 # - Neither $standardDir nor $customDir are set
1231 # - For relative directions, $dir has already been set to the corresponding
1232 # custom primary direction
1233  
1234 if ($cmdObj->assistedFlag) {
1235  
1236 # (i) The original command used in an assisted move
1237 $standardDir = $cmdObj->assistedPrimary;
1238 $mapDir = $cmdObj->assistedPrimary;
1239 $customDir = $cmdObj->assistedExitObj->dir;
1240 if (! $dictObj->checkPrimaryDir($customDir)) {
1241  
1242 $customDir = undef; # Not a primary direction, so we don't need it here
1243 }
1244  
1245 } else {
1246  
1247 # If $dir is a custom primary or secondary direction...
1248 if ($dictObj->ivExists('combDirHash', $dir)) {
1249  
1250 # Get the custom direction's type (one of the values 'primaryDir', 'primaryAbbrev',
1251 # 'secondaryDir' or 'secondaryAbbrev'), which partially matches the name of the
1252 # hash IV which stores that type of direction
1253 $dirType = $dictObj->ivShow('combDirHash', $dir);
1254 $standardDir = $dictObj->ivShow('combRevDirHash', $dir);
1255  
1256 # (ii) Customised primary direction
1257 if ($dirType eq 'primaryDir' || $dirType eq 'primaryAbbrev') {
1258  
1259 $mapDir = $standardDir;
1260 $customDir = $dictObj->ivShow('primaryDirHash', $standardDir);
1261 # Make sure $dir isn't the abbreviated version of the direction
1262 $dir = $customDir;
1263 # For the benefit of basic mapping mode, set a flag
1264 $primaryFlag = TRUE;
1265  
1266 # (iii) Recognised secondary direction
1267 } elsif ($dirType eq 'secondaryDir' || $dirType eq 'secondaryAbbrev') {
1268  
1269 # Make sure $dir isn't the abbreviated version of the direction
1270 $dir = $dictObj->ivShow('secondaryDirHash', $standardDir);
1271 }
1272 }
1273  
1274 # Check the current room's exits. Does an exit in this direction already exist?
1275 if ($self->currentRoom->ivExists('exitNumHash', $dir)) {
1276  
1277 $exitNum = $self->currentRoom->ivShow('exitNumHash', $dir);
1278 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $exitNum);
1279  
1280 } else {
1281  
1282 OUTER: foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
1283  
1284 my ($otherExitObj, $index);
1285  
1286 $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
1287  
1288 # If $dir is a primary direction, see if an existing exit from the current room
1289 # has the same drawn map direction
1290 if (
1291 $standardDir
1292 && $customDir
1293 && $otherExitObj->mapDir
1294 && $otherExitObj->mapDir eq $customDir
1295 # (Don't leave using an exit attached to a shadow exit; leave via the shadow
1296 # exit instead)
1297 && (! $otherExitObj->shadowExit)
1298 ) {
1299 $exitObj = $otherExitObj;
1300 last OUTER;
1301 }
1302  
1303 # Otherwise, check against each exit's alternative nominal directions
1304 if (defined $otherExitObj->altDir) {
1305  
1306 $index = index ($otherExitObj->altDir, $dir);
1307 # Don't use the alternative direction unless we have to. If several exits
1308 # have matching alternative nominal directions, use the one in which the
1309 # matching portion occurs earliest in the string
1310 if (
1311 $index > -1
1312 && (! $altExitObj || $altIndex > $index)
1313 ) {
1314 $altExitObj = $otherExitObj;
1315 $altIndex = $index;
1316 }
1317 }
1318 }
1319  
1320 # Use the exit with the alternative nominal direction, if necessary
1321 if (! $exitObj && $altExitObj) {
1322  
1323 $exitObj = $altExitObj;
1324 }
1325 }
1326 }
1327  
1328 # PART 7 - If an exit matching the direction $dir doesn't exit, test $dir against
1329 # transient exit patterns
1330 @patternList = $self->session->currentWorld->transientExitPatternList;
1331 if (! $exitObj && @patternList) {
1332  
1333 do {
1334  
1335 my ($pattern, $roomNum, $roomObj, $result);
1336  
1337 $pattern = shift @patternList;
1338 $roomNum = shift @patternList;
1339  
1340 if ($pattern =~ m/$dir/) {
1341  
1342 # $dir is a transient exit which probably won't exist in the world model
1343 if (
1344 defined $roomNum
1345 && $axmud::CLIENT->intCheck($roomNum, 1)
1346 && $self->worldModelObj->ivExists('roomModelHash', $roomNum)
1347 ) {
1348 # Get the specified destination room
1349 $roomObj = $self->worldModelObj->ivShow('roomModelHash', $roomNum);
1350 # Compare it against the Locator task's current room. If it's a match,
1351 # then that's the new location
1352 if ($self->session->locatorTask && $self->session->locatorTask->roomObj) {
1353  
1354 ($result) = $self->session->worldModelObj->compareRooms(
1355 $self->session,
1356 $roomObj,
1357 undef, # Compare against the Locator task's current room
1358 TRUE, # Match dark rooms
1359 );
1360  
1361 if ($result) {
1362  
1363 return $self->setCurrentRoom($roomObj);
1364 }
1365  
1366 } else {
1367  
1368 # If the Locator task's current room isn't set, then just use the
1369 # specified destination room anyway
1370 return $self->setCurrentRoom($roomObj);
1371 }
1372 }
1373  
1374 # Otherwise, keep checking transient exit patterns, in case one of the
1375 # remaining patterns matches $dir and has a destination room we can use
1376 $transientFlag = TRUE;
1377 }
1378  
1379 } until (! @patternList);
1380  
1381 if ($transientFlag) {
1382  
1383 # $dir is a transient exit, but no valid destination room has been specified, so
1384 # we're now lost. Display an explanation, if allowed
1385 if ($self->worldModelObj->explainGetLostFlag) {
1386  
1387 $self->session->writeText(
1388 'MAP: Lost because of a departure through a transient exit',
1389 );
1390 }
1391  
1392 return $self->setCurrentRoom(
1393 undef,
1394 $self->_objClass . '->moveKnownDirSeen', # Defined string marks char as lost
1395 FALSE, # Don't use auto-rescue mode
1396 );
1397 }
1398 }
1399  
1400 # PART 8 - In crafty moves mode, if an exit matching the direction $dir doesn't exist,
1401 # create a hidden exit right now (even if the world itself doesn't include the
1402 # exit in its exit lists - I'm looking at you, Discworld!)
1403 if (
1404 ! $exitObj
1405 && $self->mapWin
1406 && $self->mapWin->mode eq 'update'
1407 && $self->worldModelObj->craftyMovesFlag
1408 && ! $self->worldModelObj->protectedMovesFlag
1409 # Don't do this when departing from wilderness rooms
1410 && $self->currentRoom->wildMode eq 'normal'
1411 ) {
1412 $exitObj = $self->worldModelObj->addExit(
1413 $self->session,
1414 FALSE, # Don't update Automapper window yet
1415 $self->currentRoom,
1416 $dir,
1417 $mapDir,
1418 );
1419  
1420 if ($exitObj) {
1421  
1422 $self->worldModelObj->setHiddenExit(
1423 FALSE, # Don't update Automapper window yet
1424 $exitObj,
1425 TRUE, # Hidden exit
1426 );
1427  
1428 # (Might want to create an exit from the opposite direction in the destination room,
1429 # too)
1430 $craftyExitObj = $exitObj;
1431 }
1432 }
1433  
1434 # PART 9 - set the direction the character is facing, if possible
1435 #
1436 # If an exit object has been identified, we can set the direction the character is facing
1437 # to the exit's ->mapDir (so, if an exit like 'enter portal' is being drawn as a 'west'
1438 # exit, the character is now facing west)
1439 # If an exit object has been identified, we can update $self->facingDir
1440 if (
1441 $exitObj
1442 && $exitObj->mapDir
1443 && $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $exitObj->mapDir)
1444 && $exitObj->mapDir ne 'up'
1445 && $exitObj->mapDir ne 'down'
1446 ) {
1447 $self->ivPoke('facingDir', $exitObj->mapDir);
1448 }
1449  
1450 # PART 10 - deal with impassable, mystery, random, unallocated and unallocated exits
1451 #
1452 # If the character is using an exit marked as impassable, then we're now lost
1453 if (
1454 $exitObj
1455 && ($exitObj->exitOrnament eq 'impass' || $exitObj->exitOrnament eq 'mystery')
1456 ) {
1457 # Show an explanation, if allowed
1458 if ($self->worldModelObj->explainGetLostFlag) {
1459  
1460 if ($exitObj->exitOrnament eq 'impass') {
1461  
1462 $self->session->writeText(
1463 'MAP: Lost because the character used an exit marked as \'mystery\'',
1464 );
1465  
1466 } else {
1467  
1468 $self->session->writeText(
1469 'MAP: Lost because the character used an exit marked as \'impassable\'',
1470 );
1471 }
1472 }
1473  
1474 # The presence of a second argument means 'the character is lost'
1475 return $self->setCurrentRoom(
1476 undef,
1477 $self->_objClass . '->moveKnownDirSeen', # Defined string marks character as lost
1478 FALSE, # Don't use auto-rescue mode
1479 );
1480  
1481 # If the character is using a random exit...
1482 } elsif ($exitObj && $exitObj->randomType ne 'none') {
1483  
1484 # Either locate the new current location, or mark the character as lost (depending on
1485 # the world model's IVs)
1486 return $self->reactRandomExit($exitObj);
1487  
1488 # If the character attemps to move through an unallocated exit, we are now lost
1489 } elsif ($exitObj && $exitObj->drawMode eq 'temp_alloc') {
1490  
1491 # Show an explanation, if allowed
1492 if ($self->worldModelObj->explainGetLostFlag) {
1493  
1494 $self->session->writeText(
1495 'MAP: Lost because the character used an unallocated exit',
1496 );
1497 }
1498  
1499 # The presence of a second argument means 'the character is lost'
1500 return $self->setCurrentRoom(
1501 undef,
1502 $self->_objClass . '->moveKnownDirSeen', # Defined string marks character as lost
1503 TRUE, # Use auto-rescue mode, if possible
1504 );
1505  
1506 # If the character attempts to move through an unallocatable exit which doesn't have a
1507 # destination room, we are now lost
1508 } elsif ($exitObj && $exitObj->drawMode eq 'temp_unalloc' && ! $exitObj->destRoom) {
1509  
1510 # Show an explanation, if allowed
1511 if ($self->worldModelObj->explainGetLostFlag) {
1512  
1513 $self->session->writeText(
1514 'MAP: Lost because the character used an unallocatable exit which doesn\'t'
1515 . ' have a destination room set',
1516 );
1517 }
1518  
1519 # The presence of a second argument means 'the character is lost'
1520 return $self->setCurrentRoom(
1521 undef,
1522 $self->_objClass . '->moveKnownDirSeen', # Defined string marks character as lost
1523 TRUE, # Use auto-rescue mode, if possible
1524 );
1525 }
1526  
1527 # PART 11 - deal with ordinary exits whose destination room is already set
1528 #
1529 # If an exit matching $dir exists, and it leads to a known room, we can use the room
1530 if ($exitObj && $exitObj->destRoom) {
1531  
1532 $destRoomObj = $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
1533 if ($destRoomObj) {
1534  
1535 return $self->useExistingRoom(
1536 $self->currentRoom,
1537 $destRoomObj,
1538 TRUE, # $destRoomObj is definitely the destination
1539 $dir,
1540 $customDir,
1541 $exitObj,
1542 );
1543 }
1544 }
1545  
1546 # PART 12 - check the location where we would expect a destination room to be placed for
1547 # movement in the direction $dir, and see if a room exists there
1548 #
1549 # For primary directions, check the gridblock to which the exit is supposed to lead and see
1550 # see if there's already a room at that location
1551 # (If the automapper window isn't open, we don't need this information)
1552 if ($self->mapWin) {
1553  
1554 if ($standardDir && $customDir) {
1555  
1556 # Work out the location's coordinates on the map
1557 $vectorRef = $self->mapWin->ivShow('constSpecialVectorHash', $standardDir);
1558  
1559 # For non-primary directions for which the exit has been allocated a map direction
1560 # (stored in ->mapDir), work out the gridblock to which the exit is supposed to lead
1561 } elsif ($exitObj && $exitObj->mapDir) {
1562  
1563 # Work out the location's coordinates on the map
1564 $vectorRef = $self->mapWin->ivShow('constSpecialVectorHash', $exitObj->mapDir);
1565 }
1566  
1567 if ($vectorRef) {
1568  
1569 $xPosBlocks = $self->currentRoom->xPosBlocks
1570 + ($$vectorRef[0] * $self->worldModelObj->horizontalExitLengthBlocks);
1571 $yPosBlocks = $self->currentRoom->yPosBlocks
1572 + ($$vectorRef[1] * $self->worldModelObj->horizontalExitLengthBlocks);
1573 $zPosBlocks = $self->currentRoom->zPosBlocks
1574 + ($$vectorRef[2] * $self->worldModelObj->verticalExitLengthBlocks);
1575 }
1576 }
1577  
1578 if (defined $xPosBlocks) {
1579  
1580 # Check that location actually fits on the map
1581 if (! $regionmapObj->checkGridBlock($xPosBlocks, $yPosBlocks, $zPosBlocks)) {
1582  
1583 # The Automapper window can't draw rooms outside the map, so the character is now
1584 # lost. Display an explanation, if allowed
1585 if ($self->worldModelObj->explainGetLostFlag) {
1586  
1587 $self->session->writeText(
1588 'MAP: Lost because new room\'s location is outside the region\'s'
1589 . ' boundaries (after a move in a primary direction)',
1590 );
1591 }
1592  
1593 # The presence of a second argument means 'the character is lost'
1594 return $self->setCurrentRoom(
1595 undef,
1596 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1597 TRUE, # Use auto-rescue mode, if possible
1598 );
1599  
1600 } else {
1601  
1602 # Otherwise, if there is a room at that location, we can use it
1603 $number = $regionmapObj->fetchRoom($xPosBlocks, $yPosBlocks, $zPosBlocks);
1604 if (defined $number) {
1605  
1606 $existRoomObj = $self->worldModelObj->ivShow('modelHash', $number);
1607 }
1608 }
1609 }
1610  
1611 # PART 13 - deal with movement between rooms, when one (or both) rooms is in wilderness
1612 # mode
1613 if ($existRoomObj) {
1614  
1615 # A room exists where we'd expect to find a destination room
1616  
1617 if (
1618 ($self->currentRoom->wildMode eq 'normal' && $existRoomObj->wildMode eq 'border')
1619 || ($self->currentRoom->wildMode eq 'border' && $existRoomObj->wildMode eq 'normal')
1620 ) {
1621 # Between 'normal' and 'border' rooms (in either direction), when the automapper
1622 # exists and is in 'update' mode, create an exit if one doesn't already exist
1623 if (
1624 ! $exitObj
1625 && $self->mapWin
1626 && $self->mapWin->mode eq 'update'
1627 && $primaryFlag
1628 ) {
1629 $exitObj = $self->worldModelObj->addExit(
1630 $self->session,
1631 FALSE, # Don't update Automapper window yet
1632 $self->currentRoom,
1633 $dir,
1634 $mapDir,
1635 );
1636 }
1637  
1638 if (! $exitObj) {
1639  
1640 # Between 'normal' and 'border' rooms, an exit object is required, so the
1641 # character is now lost. Display an explanation, if allowed
1642 if ($self->worldModelObj->explainGetLostFlag) {
1643  
1644 $self->session->writeText(
1645 'MAP: Lost because no exit object exists between a normal room and a'
1646 . ' wilderness border room',
1647 );
1648 }
1649  
1650 # The presence of a second argument means 'the character is lost'
1651 return $self->setCurrentRoom(
1652 undef,
1653 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1654 FALSE, # Don't use auto-rescue mode
1655 );
1656 }
1657  
1658 # If an exit from the destination room in the opposite direction already exists,
1659 # find it
1660 OUTER: foreach my $number ($existRoomObj->ivValues('exitNumHash')) {
1661  
1662 my $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
1663  
1664 if (
1665 $otherExitObj->mapDir
1666 && $otherExitObj->mapDir eq $dictObj->ivShow('primaryOppHash', $mapDir)
1667 # (Don't leave using an exit attached to a shadow exit; leave via the shadow
1668 # exit instead)
1669 && (! $otherExitObj->shadowExit)
1670 ) {
1671 $oppExitObj = $otherExitObj;
1672 last OUTER;
1673 }
1674 }
1675  
1676 # Otherwise, if ->autocompleteExitsFlag is set, create an exit in the opposite
1677 # direction and make them two-way exits
1678 if (! $oppExitObj && $self->worldModelObj->autocompleteExitsFlag) {
1679  
1680 # Create an opposite exit from the destination room, pointing back to the
1681 # current room
1682 $oppExitObj = $self->worldModelObj->addExit(
1683 $self->session,
1684 FALSE, # Don't update Automapper window yet
1685 $existRoomObj,
1686 $dictObj->ivShow('primaryOppHash', $mapDir),
1687 $axmud::CLIENT->ivShow('constOppDirHash', $mapDir),
1688 );
1689 }
1690  
1691 # Mark the exit from the 'normal' room leading to the 'border' room as a hidden exit
1692 # (it may or may not be hidden in the room statement, depending on the world;
1693 # marking it hidden takes care of both situations)
1694 if ($self->currentRoom->wildMode eq 'normal') {
1695  
1696 $self->worldModelObj->setHiddenExit(
1697 FALSE, # Don't update Automapper window yet
1698 $exitObj,
1699 TRUE, # Hidden exit
1700 );
1701  
1702 } elsif ($existRoomObj->wildMode eq 'normal' && $oppExitObj) {
1703  
1704 $self->worldModelObj->setHiddenExit(
1705 FALSE, # Don't update Automapper window yet
1706 $oppExitObj,
1707 TRUE, # Hidden exit
1708 );
1709 }
1710  
1711 # Use the existing room as the destination room
1712 return $self->useExistingRoom(
1713 $self->currentRoom,
1714 $existRoomObj,
1715 FALSE, # $existRoomObj is presumably the destination
1716 $dir,
1717 $customDir,
1718 $exitObj,
1719 );
1720  
1721 } elsif (
1722 $self->currentRoom->wildMode ne 'normal'
1723 && $existRoomObj->wildMode ne 'normal'
1724 ) {
1725 # Between 'border' and 'wild' rooms (in either direction), use the existing room as
1726 # the destination room
1727 return $self->useExistingRoom(
1728 $self->currentRoom,
1729 $existRoomObj,
1730 FALSE, # $existRoomObj is presumably the destination
1731 $dir,
1732 $customDir,
1733 undef, # No exit is drawn between 'wild' and 'border' rooms
1734 );
1735 }
1736  
1737 } elsif (! $existRoomObj && $self->mapWin && $self->mapWin->mode eq 'update') {
1738  
1739 # No room exists where we'd expect to find a destination room, but the automapper window
1740 # is open and in 'update' mode, so we can create one
1741  
1742 # Set the wilderness mode for the new destination room. If the painter is enabled, use
1743 # the mode it specifies; otherwise use the default mode
1744 if ($self->mapWin->painterFlag) {
1745 $destWildMode = $self->worldModelObj->painterObj->wildMode;
1746 } else {
1747 $destWildMode = 'normal';
1748 }
1749  
1750 if (
1751 ($self->currentRoom->wildMode eq 'normal' && $destWildMode eq 'border')
1752 || ($self->currentRoom->wildMode eq 'border' && $destWildMode eq 'normal')
1753 ) {
1754 # Between 'normal' and 'border' rooms (in either direction), create an exit
1755 # departing from the current room, if one doesn't already exist
1756 if (! $exitObj && $primaryFlag) {
1757  
1758 $exitObj = $self->worldModelObj->addExit(
1759 $self->session,
1760 FALSE, # Don't update Automapper window yet
1761 $self->currentRoom,
1762 $dir,
1763 $mapDir,
1764 );
1765 }
1766  
1767 if (! $exitObj) {
1768  
1769 # Between 'normal' and 'border' rooms, an exit object is required, so the
1770 # character is now lost. Display an explanation, if allowed
1771 if ($self->worldModelObj->explainGetLostFlag) {
1772  
1773 $self->session->writeText(
1774 'MAP: Lost because no exit object exists between a normal and a'
1775 . ' wilderness border room',
1776 );
1777 }
1778  
1779 # The presence of a second argument means 'the character is lost'
1780 return $self->setCurrentRoom(
1781 undef,
1782 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1783 FALSE, # Don't use auto-rescue mode
1784 );
1785 }
1786  
1787 # Create a destination room at the specified location, but don't give it the
1788 # properties of the Locator task's current room and don't update the map yet
1789 # NB Call ->createNewRoom directly, rather than calling it indirectly via a call to
1790 # $self->autoProcessNewRoom; in this situation, we're not concerned about the
1791 # special cases that ->autoProcessNewRoom handles. Also, a call to
1792 # ->autoProcessNewRoom will cause a one-way exit to be drawn on the map window,
1793 # then quickly redrawn as a two-way exit, which is very annoying
1794 $destRoomObj = $self->createNewRoom(
1795 $regionmapObj, # Use the same region as the current room
1796 $xPosBlocks, # Co-ordinates of room on the region's grid
1797 $yPosBlocks,
1798 $zPosBlocks,
1799 undef, # Don't change GA::Win::Map->mode
1800 FALSE, # New room is not current room (yet)
1801 FALSE, # New room doesn't take properties from Locator (yet)
1802 FALSE, # Don't update Automapper windows now
1803 );
1804  
1805 if (! $destRoomObj) {
1806  
1807 if ($self->worldModelObj->explainGetLostFlag) {
1808  
1809 $self->session->writeText(
1810 'MAP: Lost due to internal error (cannot create new room)',
1811 );
1812 }
1813  
1814 # The presence of a second argument means 'the character is lost'
1815 return $self->setCurrentRoom(
1816 undef,
1817 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1818 FALSE, # Don't use auto-rescue mode
1819 );
1820  
1821 return undef;
1822 }
1823  
1824 # Set the destination room's ->wildMode...
1825 $destRoomObj->ivPoke('wildMode', $destWildMode);
1826 # ...and now we can update its properties from the Locator task's current room,
1827 # because the exits are no longer copied
1828 $self->worldModelObj->updateRoom(
1829 $self->session,
1830 FALSE, # Don't update Automapper windows now
1831 $destRoomObj,
1832 );
1833  
1834 # If ->autocompleteExitsFlag is set, create an exit in the opposite direction and
1835 # make them two-way exits
1836 if ($self->worldModelObj->autocompleteExitsFlag) {
1837  
1838 # Create an opposite exit from the destination room, pointing back to the
1839 # current room
1840 $oppExitObj = $self->worldModelObj->addExit(
1841 $self->session,
1842 FALSE, # Don't update Automapper window yet
1843 $destRoomObj,
1844 $dictObj->ivShow('primaryOppHash', $mapDir),
1845 $axmud::CLIENT->ivShow('constOppDirHash', $mapDir),
1846 );
1847  
1848 if (! $oppExitObj) {
1849  
1850 if ($self->worldModelObj->explainGetLostFlag) {
1851  
1852 $self->session->writeText(
1853 'MAP: Lost due to internal error (cannot create new exit)',
1854 );
1855 }
1856  
1857 # The presence of a second argument means 'the character is lost'
1858 return $self->setCurrentRoom(
1859 undef,
1860 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1861 FALSE, # Don't use auto-rescue mode
1862 );
1863  
1864 return undef;
1865 }
1866 }
1867  
1868 # Use the destination room as the new current room, connecting the two rooms
1869 # together (with a one-way or two-way exit, as appropriate)
1870 return $self->useExistingRoom(
1871 $self->currentRoom,
1872 $destRoomObj,
1873 TRUE, # $destRoomObj is definitely the destination
1874 $dir,
1875 $customDir,
1876 $exitObj,
1877 );
1878  
1879 } elsif ($self->currentRoom->wildMode ne 'normal' && $destWildMode ne 'normal') {
1880  
1881 # Between 'border' and 'wild' rooms (in either direction), create a new room with
1882 # no exits
1883 $destRoomObj = $self->createNewRoom(
1884 $regionmapObj, # Use the same region as the current room
1885 $xPosBlocks, # Co-ordinates of room on the region's grid
1886 $yPosBlocks,
1887 $zPosBlocks,
1888 undef, # Don't change GA::Win::Map->mode
1889 FALSE, # New room is not current room (yet)
1890 FALSE, # New room doesn't take properties from Locator (yet)
1891 FALSE, # Don't update Automapper windows now
1892 );
1893  
1894 # Set the destination room's ->wildMode...
1895 $destRoomObj->ivPoke('wildMode', $destWildMode);
1896 # ...and now we can update its properties from the Locator task's current room,
1897 # because the exits are no longer copied
1898 $self->worldModelObj->updateRoom(
1899 $self->session,
1900 FALSE, # Don't update Automapper windows now
1901 $destRoomObj,
1902 );
1903  
1904 # Use the destination room as the new current room without connecting the two rooms
1905 # together
1906 return $self->useExistingRoom(
1907 $self->currentRoom,
1908 $destRoomObj,
1909 TRUE, # $destRoomObj is definitely the destination
1910 $dir,
1911 $customDir,
1912 undef, # Definitely no exit object
1913 );
1914 }
1915 }
1916  
1917 # PART 14 - in basic mapping mode and when the character is following someone/something,
1918 # we can create an exit right now, if one doesn't already exist (assuming
1919 # that the automapper window is open and in 'update' mode)
1920 #
1921 # In Basic mapping mode - for worlds in which room statements don't include a list of exits
1922 # - if the character moves in a primary direction, we must create a new exit in that
1923 # direction
1924 # This also applies if the room statement was a follow anchor pattern, caused by the
1925 # character following someone to a new room, and no new room statement is expected
1926 # (but only if the world model flag permits it)
1927 if (
1928 ! $exitObj
1929 && $self->mapWin
1930 && $self->mapWin->mode eq 'update'
1931 && $primaryFlag
1932 && (
1933 $self->session->currentWorld->basicMappingFlag
1934 || ($cmdObj->followAnchorFlag && $self->worldModelObj->followAnchorFlag)
1935 )
1936 ) {
1937 $exitObj = $self->worldModelObj->addExit(
1938 $self->session,
1939 FALSE, # Don't update Automapper window yet
1940 $self->currentRoom,
1941 $dir,
1942 $mapDir,
1943 );
1944  
1945 # If the destination room is about to be created, this new exit will be one-way. If
1946 # ->autocompleteExitsFlag is set, it's nicer to create a two-way exit
1947 if ($self->worldModelObj->autocompleteExitsFlag) {
1948  
1949 # Create a destination room at the specified location and give it the properties of
1950 # the Locator task's current room, but don't update the map yet
1951 # NB Call ->createNewRoom directly, rather than calling it indirectly via a call to
1952 # $self->autoProcessNewRoom; in this situation, we're not concerned about the
1953 # special cases that ->autoProcessNewRoom handles. Also, a call to
1954 # ->autoProcessNewRoom will cause a one-way exit to be drawn on the map window,
1955 # then quickly redrawn as a two-way exit, which is very annoying
1956 $destRoomObj = $self->createNewRoom(
1957 $regionmapObj, # Use the same region as the current room
1958 $xPosBlocks, # Co-ordinates of room on the region's grid
1959 $yPosBlocks,
1960 $zPosBlocks,
1961 undef, # Don't change GA:Map::Win->mode
1962 FALSE, # New room is not current room (yet)
1963 TRUE, # New room takes properties from Locator
1964 FALSE, # Don't update Automapper windows now
1965 );
1966  
1967 if (! $destRoomObj) {
1968  
1969 if ($self->worldModelObj->explainGetLostFlag) {
1970  
1971 $self->session->writeText(
1972 'MAP: Lost due to internal error (cannot create new room)',
1973 );
1974 }
1975  
1976 # The presence of a second argument means 'the character is lost'
1977 return $self->setCurrentRoom(
1978 undef,
1979 $self->_objClass . '->moveKnownDirSeen', # Character now lost
1980 FALSE, # Don't use auto-rescue mode
1981 );
1982 }
1983  
1984 # Create an opposite exit from the destination room, pointing back to the
1985 # current room
1986 $oppExitObj = $self->worldModelObj->addExit(
1987 $self->session,
1988 FALSE, # Don't update Automapper window yet
1989 $destRoomObj,
1990 $dictObj->ivShow('primaryOppHash', $mapDir),
1991 $axmud::CLIENT->ivShow('constOppDirHash', $mapDir),
1992 );
1993  
1994 if (! $oppExitObj) {
1995  
1996 if ($self->worldModelObj->explainGetLostFlag) {
1997  
1998 $self->session->writeText(
1999 'MAP: Lost due to internal error (cannot create new exit)',
2000 );
2001 }
2002  
2003 # The presence of a second argument means 'the character is lost'
2004 return $self->setCurrentRoom(
2005 undef,
2006 $self->_objClass . '->moveKnownDirSeen', # Character now lost
2007 FALSE, # Don't use auto-rescue mode
2008 );
2009  
2010 } else {
2011  
2012 # Connect the two rooms together, creating a two-way exit between them, and
2013 # make the destination room the new current room
2014 return $self->useExistingRoom(
2015 $self->currentRoom,
2016 $destRoomObj,
2017 TRUE, # $destRoomObj is definitely the destination
2018 $dir,
2019 $customDir,
2020 $exitObj,
2021 );
2022 }
2023 }
2024 }
2025  
2026 # PART 15 - if we identified a possible destination room in PART 12, we can use it
2027 if ($existRoomObj) {
2028  
2029 # Use it
2030 return $self->useExistingRoom(
2031 $self->currentRoom,
2032 $existRoomObj,
2033 FALSE, # $existRoomObj is presumably the destination
2034 $dir,
2035 $customDir,
2036 $exitObj,
2037 $craftyExitObj,
2038 );
2039 }
2040  
2041 # PART 16 - no possible destination room exists; either create a new room, or mark the
2042 # character as being lost
2043 if (! $self->mapWin) {
2044  
2045 # New rooms can't be created when the Automapper window isn't open, so the character is
2046 # now lost. Display an explanation, if allowed
2047 if ($self->worldModelObj->explainGetLostFlag) {
2048  
2049 $self->session->writeText(
2050 'MAP: Lost because new rooms can\'t be added to the world model when the'
2051 . ' Automapper window isn\'t open',
2052 );
2053 }
2054  
2055 # The presence of a second argument means 'the character is lost'
2056 return $self->setCurrentRoom(
2057 undef,
2058 $self->_objClass . '->moveKnownDirSeen', # Character now lost
2059 FALSE, # Don't use auto-rescue mode
2060 );
2061  
2062 } elsif (! $exitObj) {
2063  
2064 # Can't connect a departure room to an arrival room, if we don't know which exit is
2065 # being used - it may be the result of a world command like 'move box', which has been
2066 # interpreted (incorrectly) as a movement command
2067 # The character is now lost. Display an explanation, if allowed
2068 if ($self->worldModelObj->explainGetLostFlag) {
2069  
2070 $self->session->writeText(
2071 'MAP: Lost because of a departure in an unknown direction',
2072 );
2073 }
2074  
2075 # The presence of a second argument means 'the character is lost'
2076 return $self->setCurrentRoom(
2077 undef,
2078 $self->_objClass . '->moveKnownDirSeen', # Character now lost
2079 TRUE, # Use auto-rescue mode, if possible
2080 );
2081  
2082 } elsif ($self->mapWin->mode eq 'follow') {
2083  
2084 # The automapper can't create new rooms in 'follow' mode, so the character is now lost.
2085 # Display an explanation, if allowed
2086 if ($self->worldModelObj->explainGetLostFlag) {
2087  
2088 $self->session->writeText(
2089 'MAP: Lost because the Automapper window can\'t create new rooms in'
2090 . ' \'follow\' mode',
2091 );
2092 }
2093  
2094 # The presence of a second argument means 'the character is lost'
2095 return $self->setCurrentRoom(
2096 undef,
2097 $self->_objClass . '->moveKnownDirSeen', # Character now lost
2098 FALSE, # Don't use auto-rescue mode
2099 );
2100  
2101 } elsif ($self->mapWin->mode eq 'update') {
2102  
2103 # Not in basic mapping mode and the character is not following someone/something
2104 # Check that we can create a new room and, if so, create it
2105 if (
2106 ! $self->autoProcessNewRoom(
2107 $dir,
2108 $regionmapObj,
2109 $xPosBlocks,
2110 $yPosBlocks,
2111 $zPosBlocks,
2112 $mapDir,
2113 $customDir,
2114 $exitObj,
2115 )
2116 ) {
2117 if ($self->worldModelObj->explainGetLostFlag) {
2118  
2119 $self->session->writeText(
2120 'MAP: Lost due to internal error (cannot process new room)',
2121 );
2122 }
2123  
2124 # The presence of a second argument means 'the character is lost'
2125 return $self->setCurrentRoom(
2126 undef,
2127 $self->_objClass . '->moveKnownDirSeen', # Character now lost
2128 FALSE, # Don't use auto-rescue mode
2129 );
2130 }
2131 }
2132  
2133 return 1;
2134 }
2135  
2136 sub moveUnknownDirSeen {
2137  
2138 # Called by GA::Task::Locator->processLine (at stage 3) when the character moves in an
2139 # unknown direction
2140 #
2141 # Expected arguments
2142 # (none besides $self)
2143 #
2144 # Return values
2145 # 'undef' on improper arguments or if no changes are made to $self->currentRoom
2146 # 1 otherwise
2147  
2148 my ($self, $check) = @_;
2149  
2150 # Check for improper arguments
2151 if (defined $check) {
2152  
2153 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveUnknownDirSeen', @_);
2154 }
2155  
2156 # Do nothing if:
2157 # 1. The Automapper window is open and is in 'wait' mode
2158 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
2159 # 3. The current room isn't known (regardless of whether the Automapper window is open)
2160 if (
2161 ($self->mapWin && $self->mapWin->mode eq 'wait')
2162 || (! $self->mapWin && ! $self->trackAloneFlag)
2163 || ! $self->currentRoom
2164 ) {
2165 return undef;
2166 }
2167  
2168 # If the character moved through a 'temp_region' random exit, check the Locator task's
2169 # current room. If it matches the random exit's parent room, then there's no need to worry
2170 # about updating the map; just move the player back to the original room and destroy the
2171 # temporary region
2172 if ($self->checkTempRandomReturn()) {
2173  
2174 return 1;
2175 }
2176  
2177 # Otherwise, we are now lost. Display an explanatory message, if necessary
2178 if ($self->worldModelObj->explainGetLostFlag) {
2179  
2180 $self->session->writeText('MAP: Lost after a move in an unknown direction');
2181 }
2182  
2183 return $self->setCurrentRoom(
2184 undef,
2185 $self->_objClass . '->moveUnknownDirSeen', # Character now lost
2186 TRUE, # Use auto-rescue mode, if possible
2187 );
2188  
2189 return 1;
2190 }
2191  
2192 sub teleportSeen {
2193  
2194 # Called by GA::Task::Locator->processLine (at stage 3) when the character teleports to a
2195 # known destination
2196 # This is a slimmed-down version of $self->moveKnownDirSeen
2197 #
2198 # Expected arguments
2199 # $cmdObj - The GA::Buffer::Cmd object that stores the movement command
2200 #
2201 # Return values
2202 # 'undef' on improper arguments or if no changes are made to $self->currentRoom
2203 # 1 otherwise
2204  
2205 my ($self, $cmdObj, $check) = @_;
2206  
2207 # Local variables
2208 my $destRoomObj;
2209  
2210 # Check for improper arguments
2211 if (! defined $cmdObj || defined $check) {
2212  
2213 return $axmud::CLIENT->writeImproper($self->_objClass . '->teleportSeen', @_);
2214 }
2215  
2216 # Do nothing if:
2217 # 1. The Automapper window is open and is in 'wait' mode
2218 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
2219 # 3. The current room isn't known (regardless of whether the Automapper window is open)
2220 if (
2221 ($self->mapWin && $self->mapWin->mode eq 'wait')
2222 || (! $self->mapWin && ! $self->trackAloneFlag)
2223 || ! $self->currentRoom
2224 ) {
2225 return undef;
2226 }
2227  
2228 # Check that the destination room still exists (just in case)
2229 # NB This function doesn't create a new world model room, if the Automapper window is in
2230 # 'update' mode
2231 $destRoomObj = $self->worldModelObj->ivShow('modelHash', $cmdObj->teleportDestRoom);
2232 if (! $destRoomObj || $destRoomObj->category ne 'room') {
2233  
2234 # Show an explanation, if allowed
2235 if ($self->worldModelObj->explainGetLostFlag) {
2236  
2237 $self->session->writeText(
2238 'MAP: Lost because the character tried to teleport to a room that no longer'
2239 . ' exists',
2240 );
2241 }
2242  
2243 # The TRUE argument means 'the character is lost'
2244 return $self->setCurrentRoom(
2245 undef,
2246 $self->_objClass . '->teleportSeen', # Defined string marks character as lost
2247 TRUE, # Use auto-rescue mode, if possible
2248 );
2249  
2250 } else {
2251  
2252 # Use the destination room
2253 return $self->useExistingRoom(
2254 $self->currentRoom,
2255 $destRoomObj,
2256 TRUE, # $destRoomObj is definitely the destination
2257 $cmdObj->cmd,
2258 );
2259 }
2260  
2261 return 1;
2262 }
2263  
2264 sub lookGlanceSeen {
2265  
2266 # Called by GA::Task::Locator->processLine (at stage 3) as the result of a look/glance
2267 # command (i.e. the character hasn't moved)
2268 #
2269 # Expected arguments
2270 # $cmdObj - The GA::Buffer::Cmd object that stores the look/glance command (not
2271 # required by this function, actually)
2272 #
2273 # Return values
2274 # 'undef' on improper arguments or if no changes are made to $self->currentRoom
2275 # 1 otherwise
2276  
2277 my ($self, $cmdObj, $check) = @_;
2278  
2279 # Check for improper arguments
2280 if (! defined $cmdObj || defined $check) {
2281  
2282 return $axmud::CLIENT->writeImproper($self->_objClass . '->lookGlanceSeen', @_);
2283 }
2284  
2285 # Do nothing if:
2286 # 1. The Automapper window is open and is in 'wait' mode
2287 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
2288 # 3. The current room isn't known (regardless of whether the Automapper window is open)
2289 if (
2290 ($self->mapWin && $self->mapWin->mode eq 'wait')
2291 || (! $self->mapWin && ! $self->trackAloneFlag)
2292 || ! $self->currentRoom
2293 ) {
2294 return undef;
2295 }
2296  
2297 # Update the existing room to give it the same properties as the Locator's non-model
2298 # room (where appropriate)
2299 $self->updateRoom($self->currentRoom);
2300 # Mark the objects to be redrawn (in every Automapper window)
2301 $self->worldModelObj->updateMaps('room', $self->currentRoom);
2302  
2303 # The Locator task has a non-model room matching the automapper's ->currentRoom, so
2304 # remind the Locator of which world model room is the matching one
2305 $self->updateLocator();
2306  
2307 return 1;
2308 }
2309  
2310 sub failedExitSeen {
2311  
2312 # Called by GA::Task::Locator->processLine (at stage 3) when the character fails to move
2313 # (because a known failed exit pattern is seen)
2314 #
2315 # Expected arguments
2316 # $pattern - One of the patterns from the world profile's ->doorPatternList or
2317 # ->failExitPatternList
2318 #
2319 # Optional arguments
2320 # $dir - The presumed direction of the failed move (matches GA::Obj::Exit->dir).
2321 # If 'undef', it is probably because two failed exit patterns (or a failed
2322 # exit and a closed door pattern) appeared one after the other; the
2323 # Locator interpreted the first one as a failed move, but doesn't know
2324 # what kind of move caused the second one
2325 #
2326 # Return values
2327 # 'undef' on improper arguments, if the failed exit can't be processed or if an exit
2328 # object corresponding to the direction $dir can't be found
2329 # 1 otherwise
2330  
2331 my ($self, $pattern, $dir, $check) = @_;
2332  
2333 # Local variables
2334 my (
2335 $worldObj, $dictObj, $dirType, $recogniseFlag, $standard,
2336 @redrawList,
2337 );
2338  
2339 # Check for improper arguments
2340 if (! defined $pattern || defined $check) {
2341  
2342 return $axmud::CLIENT->writeImproper($self->_objClass . '->failedExitSeen', @_);
2343 }
2344  
2345 # Do nothing if:
2346 # 1. The Automapper window is open and is in 'wait' mode
2347 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
2348 # 3. The current room isn't known (regardless of whether the Automapper window is open)
2349 # 4. $dir was set to 'undef' - if the Locator isn't sure to which room a failed exit
2350 # pattern belongs, we can't work it out, either
2351 if (
2352 ($self->mapWin && $self->mapWin->mode eq 'wait')
2353 || (! $self->mapWin && ! $self->trackAloneFlag)
2354 || ! $self->currentRoom
2355 || ! defined $dir
2356 ) {
2357 return undef;
2358 }
2359  
2360 # Import the current world profile and current dictionary (for convenience)
2361 $worldObj = $self->session->currentWorld;
2362 $dictObj = $self->session->currentDict;
2363  
2364 # If $dir is a primary/secondary/relative direction, but abbreviated, unabbreviate it
2365 if ($dictObj->ivExists('combDirHash', $dir)) {
2366  
2367 $recogniseFlag = TRUE;
2368 $dir = $dictObj->unabbrevDir($dir);
2369 }
2370  
2371 # Find the current room's exit object corresponding to the direction $dir
2372 foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
2373  
2374 my ($exitObj, $twinExitObj);
2375  
2376 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
2377 if ($exitObj && $exitObj->dir eq $dir) {
2378  
2379 # $exitObj is the exit responsible. Give it an ornament (but only when the
2380 # Automapper window is open and is in 'update' mode)
2381 if ($self->mapWin && $self->mapWin->mode eq 'update') {
2382  
2383 if (defined $worldObj->ivFind('lockedPatternList', $pattern)) {
2384  
2385 # Set the exit as lockable
2386 $self->worldModelObj->setExitOrnament(
2387 FALSE, # Don't update Automapper windows now
2388 $exitObj,
2389 'lock',
2390 );
2391  
2392 } elsif (defined $worldObj->ivFind('doorPatternList', $pattern)) {
2393  
2394 # Set the exit as openable
2395 $self->worldModelObj->setExitOrnament(
2396 FALSE, # Don't update Automapper windows now
2397 $exitObj,
2398 'open',
2399 );
2400 }
2401 }
2402  
2403 # If there are no more room statements expected, we know exactly where the
2404 # character's current location is, and so it's safe to set the ghost room as the
2405 # current room (allowing the next movement command entered by the user to be used
2406 # in an assisted move)
2407 # Otherwise, the ghost room needs to be reset entirely
2408 if (
2409 $self->session->locatorTask
2410 && ! $self->session->locatorTask->moveList
2411 ) {
2412 $self->setGhostRoom($self->currentRoom);
2413 } else {
2414 $self->setGhostRoom();
2415 }
2416  
2417 # Mark the room as needing to be redrawn. Also mark the exit's destination room, if
2418 # there is one, so that (for example) when an exit becomes impassable, the twin
2419 # exit is drawn properly
2420 push (@redrawList,
2421 'room',
2422 $self->worldModelObj->ivShow('modelHash', $exitObj->parent),
2423 );
2424  
2425 if ($exitObj->twinExit) {
2426  
2427 $twinExitObj = $self->worldModelObj->ivShow('exitModelHash',$exitObj->twinExit);
2428 if ($twinExitObj) {
2429  
2430 push (@redrawList,
2431 'room',
2432 $self->worldModelObj->ivShow('modelHash', $twinExitObj->parent),
2433 );
2434 }
2435 }
2436  
2437 # Mark the objects to be redrawn (in every Automapper window)
2438 $self->worldModelObj->updateMaps(@redrawList);
2439  
2440 return 1;
2441 }
2442 }
2443  
2444 # No exit object exists in the direction $dir
2445 # For primary/secondary directions, make a record of the failed exit, if allowed to do so
2446 # (in Axmud terminology this is called a checked direction)
2447 if ($recogniseFlag && $self->worldModelObj->collectCheckedDirsFlag) {
2448  
2449 if ($self->currentRoom->ivExists('checkedDirHash', $dir)) {
2450 $self->currentRoom->ivIncHash('checkedDirHash', $dir);
2451 } else {
2452 $self->currentRoom->ivAdd('checkedDirHash', $dir, 1);
2453 }
2454  
2455 # Mark the room to be redrawn (in every Automapper window)
2456 $self->worldModelObj->updateMaps('room', $self->currentRoom);
2457 }
2458  
2459 # Corresponding exit object not found
2460 return undef;
2461 }
2462  
2463 sub involuntaryExitSeen {
2464  
2465 # Called by GA::Task::Locator->processLine (at stage 3) when the character moves
2466 # involuntarily (i.e. when a known involuntary exit pattern is seen)
2467 #
2468 # Expected arguments
2469 # (none besides $self)
2470 #
2471 # Return values
2472 # 'undef' on improper arguments or if no changes are made to $self->currentRoom
2473 # 1 otherwise
2474  
2475 my ($self, $check) = @_;
2476  
2477 # Check for improper arguments
2478 if (defined $check) {
2479  
2480 return $axmud::CLIENT->writeImproper($self->_objClass . '->involuntaryExitSeen', @_);
2481 }
2482  
2483 # Do nothing if:
2484 # 1. The Automapper window is open and is in 'wait' mode
2485 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
2486 # 3. The current room isn't known (regardless of whether the Automapper window is open)
2487 if (
2488 ($self->mapWin && $self->mapWin->mode eq 'wait')
2489 || (! $self->mapWin && ! $self->trackAloneFlag)
2490 || ! $self->currentRoom
2491 ) {
2492 return undef;
2493 }
2494  
2495 # We are now lost. Display an explanatory message, if necessary
2496 if ($self->worldModelObj->explainGetLostFlag) {
2497  
2498 $self->session->writeText('MAP: Lost because an involuntary exit was detected');
2499 }
2500  
2501 return $self->setCurrentRoom(
2502 undef,
2503 $self->_objClass . '->involuntaryExitSeen', # Character now lost
2504 TRUE, # Use auto-rescue mode, if possible
2505 );
2506  
2507 return 1;
2508 }
2509  
2510 # Locator task support functions
2511  
2512 sub identifyDestination {
2513  
2514 # Called by GA::Task::Locator->doStage (at stage 3), before checking incoming lines for
2515 # room statements
2516 # Given a movement command, stored in a GA::Buffer::Cmd object, identifies the likely
2517 # destination if the character uses that movement command. This function is a cut-down
2518 # version of $self->moveKnownDirSeen, preserving only essential functionality)
2519 #
2520 # Expected arguments
2521 # $cmdObj - The GA::Buffer::Cmd object that stores the movement command
2522 #
2523 # Return values
2524 # 'undef' on improper arguments, if no exit object can be identified, or if the exit
2525 # object has no destination room
2526 # Otherwise, returns the likely destination room model object
2527  
2528 my ($self, $cmdObj, $check) = @_;
2529  
2530 # Local variables
2531 my (
2532 $dictObj, $slot, $convertDir, $exitObj, $dir, $dirType, $standardDir, $customDir,
2533 $exitNum,
2534 );
2535  
2536 # Check for improper arguments
2537 if (! defined $cmdObj || defined $check) {
2538  
2539 return $axmud::CLIENT->writeImproper($self->_objClass . '->identifyDestination', @_);
2540 }
2541  
2542 # Import the current dictionary (for convenience)
2543 $dictObj = $self->session->currentDict;
2544  
2545 # PART 1 - look/glance commands
2546  
2547 # If it's a look/glance command, then there's no change of room
2548 if ($cmdObj->lookFlag || $cmdObj->glanceFlag) {
2549  
2550 return $self->currentRoom;
2551 }
2552  
2553 # PART 2 - identify relative directions
2554  
2555 # Is $cmdObj->cmd a relative direction like 'forward'?
2556 $slot = $dictObj->convertRelativeDir($cmdObj->cmd);
2557 if (defined $slot) {
2558  
2559 # $slot is in the range 0-7. Convert it into a standard primary direction like
2560 # 'north', depending on which way the character is currently facing
2561 $convertDir = $dictObj->rotateRelativeDir(
2562 $slot,
2563 $self->facingDir,
2564 );
2565  
2566 if (defined $convertDir) {
2567  
2568 # Translate the standard primary direction into the equivalent custom primary
2569 # direction, ready for PART 3
2570 $convertDir = $dictObj->ivShow('primaryDirHash', $convertDir);
2571 }
2572 }
2573  
2574 # PART 3 - get direction of movement
2575 #
2576 # Set $dir, the direction of movement, so that we can work out which exit object is being
2577 # used
2578 # Relative directions like 'forward' have already been translated into a custom primary
2579 # direction
2580 if ($convertDir) {
2581  
2582 $dir = $convertDir;
2583  
2584 # For assisted moves, we already know the exit object used (which will save us some time)
2585 } elsif ($cmdObj->assistedFlag) {
2586  
2587 $exitObj = $cmdObj->assistedExitObj;
2588 if ($exitObj->destRoom) {
2589  
2590 return $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
2591  
2592 } else {
2593  
2594 return undef;
2595 }
2596  
2597 # For redirect mode commands, use the original command, which should contain only a
2598 # direction
2599 } elsif ($cmdObj->redirectFlag) {
2600  
2601 $dir = $cmdObj->cmd;
2602  
2603 # For normal movement commands, the direction of movement has been stripped from
2604 # $cmdObj->cmd and stored in ->moveDir
2605 } else {
2606  
2607 $dir = $cmdObj->moveDir;
2608 }
2609  
2610 # PART 4 - identify an exit object (GA::Obj::Exit) matching the direction
2611 #
2612 # $dir can be any of the following:
2613 # (i) The original command used in an assisted move
2614 # - (this possibility has already been eliminated)
2615 #
2616 # (ii) A custom primary direction - one of the values in GA::Obj::Dict->primaryDirHash
2617 # (e.g. 'nord', sud') or ->primaryAbbrevHash (e.g. 'n', 's')
2618 # - $standardDir/$mapDir are set to the equivalent key (the words 'north', 'up'
2619 # etc)
2620 # - $customDir is set to the value of the key in ->primaryDirHash (so that if $dir
2621 # is 'n', $customDir gets set to the unabbreviated custom direction 'nord')
2622 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
2623 # $customDir)
2624 #
2625 # (iii) A recognised secondary direction - one of the values in
2626 # GA::Obj::Dict->secondaryDirHash (e.g. 'out') or ->secondaryAbbrevHash
2627 # (e.g. 'o')
2628 # - $standardDir is set to the equivalent key (the words 'in', 'entrance',
2629 # 'portal' etc)
2630 # - $mapDir / $customDir are not set (the key's corresponding value is always
2631 # equal to $dir)
2632 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
2633 # $standardDir)
2634 #
2635 # (iv) A direction not stored in the dictionary, such as 'enter well'
2636 # - Neither $standardDir nor $customDir are set
2637 # - For relative directions, $dir has already been set to the corresponding
2638 # custom primary direction
2639  
2640 # If $dir is a custom primary or secondary direction...
2641 if ($dictObj->ivExists('combDirHash', $dir)) {
2642  
2643 # Get the custom direction's type (one of the values 'primaryDir', 'primaryAbbrev',
2644 # 'secondaryDir' or 'secondaryAbbrev'), which partially matches the name of the
2645 # hash IV which stores that type of direction
2646 $dirType = $dictObj->ivShow('combDirHash', $dir);
2647 $standardDir = $dictObj->ivShow('combRevDirHash', $dir);
2648  
2649 # (ii) Customised primary direction
2650 if ($dirType eq 'primaryDir' || $dirType eq 'primaryAbbrev') {
2651  
2652 $customDir = $dictObj->ivShow('primaryDirHash', $standardDir);
2653 # Make sure $dir isn't the abbreviated version of the direction
2654 $dir = $customDir;
2655  
2656 # (iii) Recognised secondary direction
2657 } elsif ($dirType eq 'secondaryDir' || $dirType eq 'secondaryAbbrev') {
2658  
2659 # Make sure $dir isn't the abbreviated version of the direction
2660 $dir = $dictObj->ivShow('secondaryDirHash', $standardDir);
2661 }
2662 }
2663  
2664 # Check the current room's exits. Does an exit in this direction already exist?
2665 if ($self->currentRoom->ivExists('exitNumHash', $dir)) {
2666  
2667 $exitNum = $self->currentRoom->ivShow('exitNumHash', $dir);
2668 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $exitNum);
2669  
2670 # Otherwise, if $dir is a primary direction, see if an existing exit from the current
2671 # room has the same drawn map direction
2672 } elsif ($standardDir && $customDir) {
2673  
2674 OUTER: foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
2675  
2676 my $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
2677  
2678 if (
2679 $otherExitObj->mapDir
2680 && $otherExitObj->mapDir eq $customDir
2681 # (Don't leave using an exit attached to a shadow exit; leave via the shadow
2682 # exit instead)
2683 && (! $otherExitObj->shadowExit)
2684 ) {
2685 $exitObj = $otherExitObj;
2686 last OUTER;
2687 }
2688 }
2689 }
2690  
2691 # PART 5 - Return the result
2692 if ($exitObj && $exitObj->destRoom) {
2693  
2694 return $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
2695  
2696 } else {
2697  
2698 return undef;
2699 }
2700 }
2701  
2702 sub autoProcessNewRoom {
2703  
2704 # Called by GA::Obj::Map->moveKnownDirSeen when the Automapper window is in 'update' mode
2705 # and the character's move requires us to (probably) create a new room
2706 #
2707 # Expected arguments
2708 # $dir - The command that we think was responsible for the move ('north', 'up',
2709 # 'cross bridge' etc)
2710 # $regionmapObj - The current room's regionmap (the new room will be placed in the same
2711 # region)
2712 # $xPosBlocks, $yPosBlocks, $zPosBlocks
2713 # - The grid coordinates of the new room's likely position, as calculated
2714 # by the calling function
2715 #
2716 # Optional arguments
2717 # $mapDir - For primary directions, the standard form of $customDir. Set to
2718 # 'undef' for non-primary directions
2719 # $customDir - For primary directions, set to the unabbreviated form of $dir (so its
2720 # value may be the same as $dir, or not). Set to 'undef' for
2721 # non-primary directions
2722 # $exitObj - The GA::Obj::Exit corresponding to the direction of the move, if
2723 # known (otherwise set to 'undef')
2724 # $bypassFlag - TRUE when called by $self->useExistingRoom after some kind of room
2725 # slide operation, in which case it's not necessary for this function
2726 # to check for special cases. FALSE (or 'undef') otherwise
2727 #
2728 # Return values
2729 # 'undef' on improper arguments
2730 # 1 otherwise
2731  
2732 my (
2733 $self, $dir, $regionmapObj, $xPosBlocks, $yPosBlocks, $zPosBlocks, $mapDir, $customDir,
2734 $exitObj, $bypassFlag, $check,
2735 ) = @_;
2736  
2737 # Local variables
2738 my (
2739 $successFlag, $listRef, $xPos, $yPos, $zPos, $count, $foundRoomObj, $exitFlag,
2740 $exitLength, $maxLength,
2741 %uncertainHash,
2742 );
2743  
2744 # Check for improper arguments
2745 if (
2746 ! defined $dir || ! defined $regionmapObj || ! defined $xPosBlocks
2747 || ! defined $yPosBlocks || ! defined $zPosBlocks || defined $check
2748 ) {
2749 return $axmud::CLIENT->writeImproper($self->_objClass . '->autoProcessNewRoom', @_);
2750 }
2751  
2752 # Deal with two special cases, both of which depend on the value of the world model's
2753 # ->intelligentExitsFlag
2754  
2755 # 1. There are two rooms, A and B. A has an uncertain exit which leads to B, but A is also a
2756 # broken exit. Should B lead back to A, or does it actually lead to a new room?
2757 if (
2758 ! $bypassFlag
2759 && $exitObj
2760 && ! $exitObj->destRoom
2761 && $exitObj->randomType eq 'none' # $exitObj is incomplete
2762 && $self->currentRoom->uncertainExitHash
2763 ) {
2764 # The current room is room B, and its exit which might lead back to room A in the
2765 # direction $dir is $exitObj
2766 OUTER: foreach my $oppExitNumber ($self->currentRoom->ivKeys('uncertainExitHash')) {
2767  
2768 my ($checkExitNum, $oppExitObj, $oppRoomObj);
2769  
2770 $checkExitNum = $self->currentRoom->ivShow('uncertainExitHash', $oppExitNumber);
2771 if ($checkExitNum != $exitObj->number) {
2772  
2773 # The room A uncertain exit isn't possibly connected to $exitObj
2774 next OUTER;
2775 }
2776  
2777 # Get the exit from room A
2778 $oppExitObj = $self->worldModelObj->ivShow('exitModelHash', $oppExitNumber);
2779 if ($oppExitObj && ($oppExitObj->brokenFlag || $oppExitObj->regionFlag)) {
2780  
2781 # Get room A
2782 $oppRoomObj = $self->worldModelObj->ivShow('modelHash', $oppExitObj->parent);
2783  
2784 # Check if the exit is in the right opposite direction
2785 if ($self->worldModelObj->checkOppPrimary($exitObj, $oppRoomObj)) {
2786  
2787 if ($self->worldModelObj->intelligentExitsFlag) {
2788  
2789 # Instead of creating a new room, we should use the existing room,
2790 # $oppRoomObj, creating a (broken) two-way exit
2791  
2792 # Connect the current location to the existing room, if they're not
2793 # already connected (and if they are, make it a two-way exit)z
2794 $self->worldModelObj->connectRooms(
2795 $self->session,
2796 FALSE, # Don't update Automapper windows now
2797 $self->currentRoom,
2798 $oppRoomObj,
2799 $dir,
2800 $mapDir,
2801 $exitObj,
2802 );
2803  
2804 # Mark the exit from B to A as a broken/region exit, too
2805 if ($oppExitObj->brokenFlag) {
2806  
2807 $self->worldModelObj->setBrokenExit(
2808 FALSE, # Don't update Automapper windows now
2809 $exitObj,
2810 );
2811  
2812 } elsif ($oppExitObj->regionFlag) {
2813  
2814 $self->worldModelObj->setRegionExit(
2815 FALSE, # Don't update Automapper windows now
2816 $exitObj,
2817 );
2818 }
2819  
2820 # Update the number of character visits to this room (if allowed)
2821 $self->worldModelObj->updateVisitCount(
2822 $self->session,
2823 # Don't update Automapper windows now (the call to ->updateRoom will
2824 # do that)
2825 FALSE,
2826 $oppRoomObj->number,
2827 );
2828  
2829 # Update the existing room to give it the same properties as the
2830 # Locator's non-model room (where appropriate)
2831 $self->updateRoom($oppRoomObj);
2832  
2833 # Paint the room, if required to do so
2834 if (
2835 $self->mapWin->painterFlag
2836 && $self->worldModelObj->paintAllRoomsFlag
2837 ) {
2838 $self->mapWin->paintRoom($oppRoomObj);
2839 }
2840  
2841 # The call to ->updateRoom marks $oppRoomObj as needing to be redrawn in
2842 # every Automapper window; make sure $self->currentRoom is also
2843 # redrawn in every Automapper window
2844 $self->worldModelObj->updateMaps('room', $self->currentRoom);
2845  
2846 # In both 'update' mode and 'follow' mode, $existingRoom is the new
2847 # location
2848 $self->setCurrentRoom($oppRoomObj);
2849  
2850 $successFlag = TRUE;
2851 last OUTER;
2852  
2853 } else {
2854  
2855 # Intelligent uncertain exits are disabled. Convert the uncertain exit
2856 # to a one-way exit
2857 $self->worldModelObj->convertUncertainExit(
2858 # Don't update Automapper windows now (the call to ->createNewRoom
2859 # will do that)
2860 FALSE,
2861 $oppExitObj,
2862 $self->currentRoom,
2863 );
2864 }
2865 }
2866 }
2867 }
2868 }
2869  
2870 # 2. There are two rooms, A and B. B is one gridblock north of A and the 'north' exit from A
2871 # to B is not a broken (or region) exit. The exit length is currently set to 2 gridblocks.
2872 # When we go south from B, should it lead to room A - ignoring the exit length, and using
2873 # the first room in the direction 'south' it finds - or should a new room be created 1
2874 # gridblock south of A, with a broken exit leading to it?
2875 if (! $bypassFlag && ! $successFlag && $exitObj) {
2876  
2877 $exitLength = $self->worldModelObj->getExitLength($exitObj);
2878  
2879 if (
2880 ! $exitObj->destRoom
2881 && $exitObj->randomType eq 'none' # $exitObj is incomplete
2882 && $exitLength > 1
2883 && $exitObj->dir
2884 && $exitObj->mapDir
2885 ) {
2886 # The current room is room B, and its exit which might lead back to room A in the
2887 # direction $dir is $exitObj
2888 # We need to check the gridblocks between the one occupied by room B, and the one
2889 # at which a new room, C, would be created (described by $xPosBlocks, $yPosBlocks,
2890 # $zPosBlocks, supplied by the calling function), stopping at the first room we
2891 # find (which will be room A)
2892  
2893 # Import a vector hash, in the form
2894 # %vectorHash => {
2895 # north => [0, -1, 0],
2896 # northnortheast => [1, -2, 0],
2897 # northeast => [1, -1, 0],
2898 # eastnortheast => [2, -1, 0],
2899 # east => [1, 0, 0],
2900 # eastsoutheast => [2, 1, 0],
2901 # southeast => [1, 1, 0],
2902 # southsoutheast => [1, 2, 0],
2903 # south => [0, 1, 0],
2904 # southsouthwest => [-1, 2, 0],
2905 # southwest => [-1, 1, 0],
2906 # westsouthwest => [-2, 1, 0],
2907 # west => [-1, 0, 0],
2908 # westnorthwest => [-2, -1, 0],
2909 # northwest => [-1, -1, 0],
2910 # northnorthwest => [-1, -2, 0],
2911 # up => [0, 0, 1],
2912 # down => [0, 0, -1],
2913 # },
2914 # Extract from %vectorHash the list corresponding to the $exitObj's primary
2915 # direction
2916 $listRef = $self->mapWin->ivShow('constSpecialVectorHash', $exitObj->mapDir);
2917  
2918 # Check every gridblock between B and C, looking for room A
2919 $xPos = $self->currentRoom->xPosBlocks;
2920 $yPos = $self->currentRoom->yPosBlocks;
2921 $zPos = $self->currentRoom->zPosBlocks;
2922 $count = 0;
2923  
2924 do {
2925  
2926 my $number;
2927  
2928 $xPos += $$listRef[0];
2929 $yPos += $$listRef[1];
2930 $zPos += $$listRef[2];
2931 $count++;
2932  
2933 # Don't look at room C...
2934 if ($xPos != $xPosBlocks && $yPos != $yPosBlocks && $zPos != $zPosBlocks) {
2935  
2936 $exitFlag = TRUE;
2937  
2938 } else {
2939  
2940 # If there's a room A at this gridblock, store it in $foundRoom
2941 $number = $regionmapObj->fetchRoom($xPos, $yPos, $zPos);
2942 if (defined $number) {
2943  
2944 $foundRoomObj = $self->worldModelObj->ivShow('modelHash', $number);
2945 }
2946 }
2947  
2948 } until ($foundRoomObj || $exitFlag || $count >= $exitLength);
2949  
2950 if ($foundRoomObj) {
2951  
2952 # We've found a room A directly between rooms B and C
2953 # If the 'intelligent uncertain exits' flag is set, connect B to A rather than
2954 # to C, ignoring the exit length specified by the world model's
2955 # ->horizontalExitLengthBlocks or ->verticalExitLengthBlocks
2956 if ($self->worldModelObj->intelligentExitsFlag) {
2957  
2958 $self->useExistingRoom(
2959 $self->currentRoom,
2960 $foundRoomObj,
2961 TRUE, # $foundRoomObj is definitely the destination
2962 $dir,
2963 $customDir,
2964 $exitObj,
2965 );
2966  
2967 $successFlag = TRUE;
2968  
2969 } else {
2970  
2971 # Mark the exit as a broken exit. In a moment, a new room will be drawn
2972 # as usual
2973 $self->worldModelObj->setBrokenExit(
2974 FALSE, # Don't update Automapper windows now
2975 $exitObj,
2976 );
2977  
2978 # If there is an incoming uncertain exit in the opposite direction, it must
2979 # be converted to a one-way exit
2980 %uncertainHash = $self->currentRoom->uncertainExitHash;
2981 foreach my $uncertainExitNum (keys %uncertainHash) {
2982  
2983 my ($oppExitNum, $oppExitObj, $uncertainExitObj);
2984  
2985 $oppExitNum = $uncertainHash{$uncertainExitNum};
2986  
2987 if ($oppExitNum == $exitObj->number) {
2988  
2989 # Convert it a one-way exit
2990 $uncertainExitObj = $self->worldModelObj->ivShow(
2991 'exitModelHash',
2992 $uncertainExitNum,
2993 );
2994  
2995 if ($uncertainExitObj) {
2996  
2997 $self->worldModelObj->convertUncertainExit(
2998 TRUE, # Update Automapper windows now
2999 $uncertainExitObj,
3000 $self->currentRoom,
3001 );
3002 }
3003 }
3004 }
3005 }
3006 }
3007 }
3008 }
3009  
3010 if (! $successFlag) {
3011  
3012 # In 'update' mode, for a movement in a primary direction, create a new room at the
3013 # specified location, make it the current room, give it the properties of the
3014 # Locator task's current room, and update the map
3015 if (
3016 ! $self->createNewRoom(
3017 $regionmapObj, # Use the same region as the current room
3018 $xPosBlocks, # Co-ordinates of room on the region's grid
3019 $yPosBlocks,
3020 $zPosBlocks,
3021 undef, # Don't change GA::Win::Map->mode
3022 TRUE, # New room is current room
3023 TRUE, # New room takes properties from Locator
3024 $self->currentRoom,
3025 $dir, # Connect rooms together...
3026 $mapDir, # ('undef' if $dir is a non-primary direction)
3027 $exitObj, # ...using existing exit (if set)
3028 $bypassFlag, # Force a two-way exit, if the flag is TRUE
3029 )
3030 ) {
3031 return undef;
3032 }
3033  
3034 # Check the world model for Axbasic scripts and, if any are found, execute them
3035 if ($self->worldModelObj->allowModelScriptFlag) {
3036  
3037 foreach my $script ($self->worldModelObj->newRoomScriptList) {
3038  
3039 $self->session->pseudoCmd('runscript ' . $script);
3040 }
3041 }
3042 }
3043  
3044 return 1;
3045 }
3046  
3047 sub createNewRoom {
3048  
3049 # Called by $self->moveKnownDirSeen, ->autoProcessNewRoom and ->reactRandomExit
3050 # Also called by GA::Win::Map->enableCanvasPopupMenu, ->canvasEventHandler,
3051 # ->addFirstRoomCallback, ->addRoomAtBlockCallback
3052 # Creates a new room - adding a new object to the world model. At the moment, new rooms can
3053 # only be created when the automapper window is open, but this function checks for that
3054 # (just in case of future changes)
3055 # If the process fails, deletes the world model object (if already created) and displays an
3056 # error
3057 #
3058 # Expected arguments
3059 # $regionmapObj - The GA::Obj::Regionmap in which the new room will be created. Usually
3060 # (but not always) matches the regionmap visible in the automapper
3061 # window for this session
3062 # $xPosBlocks, $yPosBlocks, $zPosBlocks
3063 # - The coordinates of the new room on the regionmap's grid
3064 #
3065 # Optional arguments
3066 # $mode - The new automapper window's ->mode after the room has been created. If
3067 # 'undef', the window's ->mode isn't changed
3068 # $currentFlag - If set to TRUE, the new room is made the current location (if FALSE
3069 # or 'undef', the current location isn't changed)
3070 # $updateFlag - If set to TRUE, the room's properties are updated to match those of
3071 # the Locator task's current room (depending on certain flags, and
3072 # only when $currentFlag is TRUE; otherwise set to FALSE or 'undef')
3073 # $connectRoomObj - The room from which the character just departed ('undef' if not known)
3074 # $dir - The command used to move (e.g. 'n', 'enter well' - matches
3075 # GA::Obj::Exit->dir) ('undef' if unknown)
3076 # $mapDir - How the exit is drawn on the map - one of Axmud's standard primary
3077 # directions (e.g. 'north', 'south', 'up) ('undef' if unknown)
3078 # $exitObj - The GA::Obj::Exit through which the character moved (if 'undef', a new
3079 # exit object can be created)
3080 # $forceFlag - If TRUE, the exit object is automatically converted into a two-way
3081 # exit, if possible (if FALSE or 'undef', the usual settings apply)
3082 #
3083 # Return values
3084 # 'undef' on improper arguments or if the new room isn't created
3085 # Otherwise returns the GA::ModelObj::Room created
3086  
3087 my (
3088 $self, $regionmapObj, $xPosBlocks, $yPosBlocks, $zPosBlocks, $mode, $currentFlag,
3089 $updateFlag, $connectRoomObj, $dir, $mapDir, $exitObj, $forceFlag, $check,
3090 ) = @_;
3091  
3092 # Local variables
3093 my (
3094 $mergeFlag, $text, $result, $newRoomObj, $filePath, $virtualPath, $choice,
3095 @matchList, @selectList, @otherRoomList, @labelList,
3096 );
3097  
3098 # Check for improper arguments
3099 if (
3100 ! defined $regionmapObj || ! defined $xPosBlocks || ! defined $yPosBlocks
3101 || ! defined $zPosBlocks || defined $check
3102 ) {
3103 return $axmud::CLIENT->writeImproper($self->_objClass . '->createNewRoom', @_);
3104 }
3105  
3106 # Compare the Locator tasks's current room against other rooms (but don't bother if the
3107 # task is expecting more room statements)
3108 if ($updateFlag && $self->mapWin && $self->session->locatorTask->moveList <= 1) {
3109  
3110 # If auto-rescue mode has been activated and if this new room is to be created in the
3111 # temporary region...
3112 if (
3113 $self->rescueTempRegionObj
3114 && $self->rescueTempRegionObj->name eq $regionmapObj->name
3115 ) {
3116 # Compare the new room against rooms in the previous region, looking for matching
3117 # rooms
3118 @matchList = $self->autoCompareLocatorRoom(
3119 $self->worldModelObj->ivShow('regionmapHash', $self->rescueLostRegionObj->name),
3120 );
3121  
3122 if (
3123 $self->worldModelObj->autoRescueFirstFlag
3124 && (scalar @matchList) == 1
3125 && $regionmapObj->gridRoomHash
3126 # (Don't auto-merge when the Locator task is expecting more room statements)
3127 && $self->session->locatorTask->moveList <= 1
3128 ) {
3129 # The new room isn't the first room in the temporary region, and it matches
3130 # exactly one room in the previous region
3131 # As soon as the new room has been created, everything in the temporary region
3132 # can be merged back into the previous region
3133 $mergeFlag = TRUE;
3134 }
3135  
3136 } elsif ($self->worldModelObj->autoCompareMode ne 'default') {
3137  
3138 if (! $self->worldModelObj->autoCompareAllFlag) {
3139  
3140 # Compare the new room against rooms in the same region, looking for a duplicate
3141 # room
3142 @matchList = $self->autoCompareLocatorRoom($regionmapObj);
3143  
3144 } else {
3145  
3146 # Compare the new room against rooms in every region (starting with
3147 # $regionmapObj), looking for a duplicate room
3148 @matchList = $self->autoCompareLocatorRoom($regionmapObj, TRUE);
3149 }
3150 }
3151 }
3152  
3153 # Create the room object. Tell the world model not to update automappers immediately - we
3154 # might want to mark the room as current
3155 $newRoomObj = $self->worldModelObj->addRoom(
3156 $self->session,
3157 TRUE, # Update Automapper windows now
3158 $regionmapObj->name,
3159 $xPosBlocks,
3160 $yPosBlocks,
3161 $zPosBlocks,
3162 );
3163  
3164 if (! $newRoomObj) {
3165  
3166 # Operation failed
3167 if ($self->mapWin) {
3168  
3169 $self->mapWin->showMsgDialogue(
3170 'New room',
3171 'error',
3172 'Could not create the new room',
3173 'ok',
3174 );
3175  
3176 } else {
3177  
3178 $self->session->writeText('MAP: Could not create a new room');
3179 }
3180  
3181 return undef;
3182 }
3183  
3184 # Set the automapper's mode, if a new mode was specified
3185 if ($mode && $self->mapWin) {
3186  
3187 $self->mapWin->setMode($mode);
3188 }
3189  
3190 # Set the current location (which causes both the previous current location, if there was
3191 # one, and the new current location to be redrawn)
3192 if ($currentFlag) {
3193  
3194 # Update the number of character visits to this room, if allowed
3195 $self->worldModelObj->updateVisitCount(
3196 $self->session,
3197 # Don't update Automapper windows now (the call to ->updateRoom will do that)
3198 FALSE,
3199 $newRoomObj->number,
3200 );
3201  
3202 # Paint the room, if required to do so
3203 if ($self->mapWin && $self->mapWin->painterFlag) {
3204  
3205 $self->mapWin->paintRoom($newRoomObj);
3206 }
3207  
3208 # If necessary, give the new room the properties of the Locator task's current room
3209 if ($updateFlag) {
3210  
3211 $self->updateRoom($newRoomObj, $connectRoomObj, $exitObj, $mapDir);
3212 }
3213  
3214 # If the previous room is known, connect it to this room
3215 if ($connectRoomObj && $dir) {
3216  
3217 $self->worldModelObj->connectRooms(
3218 $self->session,
3219 TRUE, # Update Automapper windows now (for the benefit of $connectRoomObj)
3220 $connectRoomObj,
3221 $newRoomObj,
3222 $dir,
3223 $mapDir,
3224 $exitObj,
3225 undef,
3226 $forceFlag,
3227 );
3228 }
3229  
3230 # Set the current location. The TRUE argument identifies this function as the caller
3231 $self->setCurrentRoom($newRoomObj, undef, FALSE, TRUE, @matchList);
3232  
3233 } else {
3234  
3235 # Just draw the new room (in every Automapper window)
3236 $self->worldModelObj->updateMaps('room', $newRoomObj);
3237 }
3238  
3239 if ($mergeFlag) {
3240  
3241 # Auto-rescue mode was already activated, and all rooms/labels in the temporary region
3242 # can now be merged back into the previous region
3243  
3244 # Prompt the user for confirmation, if required
3245 if ($self->worldModelObj->autoRescuePromptFlag) {
3246  
3247 $choice = $self->mapWin->showMsgDialogue(
3248 'Merge/move room',
3249 'question',
3250 'The current room matches (just) one room in the previous region. Do you want'
3251 . ' merge everything in the temporary region back into the previous region?',
3252 'yes-no',
3253 );
3254  
3255 if (! defined $choice || $choice eq 'no') {
3256  
3257 # Stop trying to auto-merge rooms, and treat the temporary region like any other
3258 # temporary region
3259 $self->reset_rescueRegion();
3260 }
3261 }
3262  
3263 if (
3264 ! $self->worldModelObj->autoRescuePromptFlag
3265 || (defined $choice && $choice eq 'yes')
3266 ) {
3267 # Get a list of all rooms in this region (besides $newRoomObj), and another list of
3268 # all labels
3269 foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) {
3270  
3271 if ($roomNum ne $newRoomObj->number) {
3272  
3273 push (@otherRoomList, $self->worldModelObj->ivShow('modelHash', $roomNum));
3274 }
3275 }
3276  
3277 @labelList = $regionmapObj->ivValues('gridLabelHash');
3278  
3279 # Perform the merge
3280 if (
3281 ! $self->worldModelObj->mergeMap(
3282 $self->session,
3283 $matchList[0], # The target (surviving) room
3284 $newRoomObj, # The new room which will be merged into it
3285 \@otherRoomList,
3286 \@labelList,
3287 )
3288 ) {
3289 $self->session->writeText(
3290 'MAP: Automapper was unable to merge room(s) from the temporary region back'
3291 . ' into the previous region \'' . $self->rescueLostRegionObj->name . '\'',
3292 );
3293  
3294 # Stop trying to auto-merge rooms, and treat the temporary region like any other
3295 # temporary region
3296 $self->reset_rescueRegion();
3297  
3298 } else {
3299  
3300 $self->session->writeText(
3301 'MAP: Automapper has merged room(s) from the temporary region back into the'
3302 . ' previous region \'' . $self->rescueLostRegionObj->name . '\'',
3303 );
3304  
3305 # Merge operation succeeded, so we can discard the temporary region
3306 $self->worldModelObj->deleteRegions(
3307 $self->session,
3308 TRUE, # Update automapper windows now
3309 $self->rescueTempRegionObj,
3310 );
3311  
3312 # Our IVs should have been reset, but there's no harm in checking
3313 $self->reset_rescueRegion();
3314 }
3315 }
3316 }
3317  
3318 # DEBUG
3319 if ($axmud::TEST_MODEL_FLAG && ! $self->worldModelObj->testModel($self->session)) {
3320  
3321 $self->session->writeDebug(
3322 'NEW ROOM MODEL TEST: World model test failed at '
3323 . $axmud::CLIENT->localTime(),
3324 );
3325  
3326 $axmud::CLIENT->playSound('alarm');
3327  
3328 # Test failed. Don't keep running tests
3329 $axmud::TEST_MODEL_FLAG = FALSE;
3330 }
3331 # DEBUG
3332  
3333 return $newRoomObj;
3334 }
3335  
3336 sub useExistingRoom {
3337  
3338 # Called by $self->moveKnownDirSeen when it has decided that the move from one room
3339 # ($departRoomObj) in the direction $dir has resulted in arrival at the room
3340 # $arriveRoomObj
3341 # Also called by $self->teleportSeen and ->autoProcessNewRoom
3342 #
3343 # After checking the arrival room matches the one we were expecting, updates the automapper
3344 # object and/or automapper window as required
3345 #
3346 # Expected arguments
3347 # $departRoomObj - The GA::ModelObj::Room from which the character left
3348 # $arriveRoomObj - The GA::ModelObj::Room at which the character has definitely (or
3349 # presumably) arrived
3350 # $fixedFlag - TRUE if $arriveRoomObj is definitely the destination room (for
3351 # example, because the exit object specifies it as the destination
3352 # room); FALSE if it's only presumed to be the destination room
3353 # $dir - The command that we think was responsible for the move ('north', 'up',
3354 # 'cross bridge' etc)
3355 #
3356 # Optional arguments
3357 # $customDir - How the exit is drawn on the map - matches a value in
3358 # GA::Obj::Dict->primaryDirHash (e.g. 'north', 'south', 'up'). If
3359 # 'undef', the exit can't be drawn on the map
3360 # $exitObj - An existing GA::Obj::Exit to use, if known. If none is specified,
3361 # the destination room's ->exitNumHash is consulted to provide it
3362 # $craftyExitObj - Set when called from $self->moveKnownDirSeen, after a hidden exit in
3363 # the departure room has been created in crafty moves mode (this
3364 # function might want to create a twin exit for it)
3365 #
3366 # Return values
3367 # 'undef' on improper arguments
3368 # 1 otherwise
3369  
3370 my (
3371 $self, $departRoomObj, $arriveRoomObj, $fixedFlag, $dir, $customDir, $exitObj,
3372 $craftyExitObj, $check,
3373 ) = @_;
3374  
3375 # Local variables
3376 my (
3377 $standardDir, $result, $msg, $regionmapObj, $oppDir, $oppExitObj, $vectorRef,
3378 $movedRoomObj, $xPosBlocks, $yPosBlocks, $zPosBlocks,
3379 );
3380  
3381 # Check for improper arguments
3382 if (
3383 ! defined $departRoomObj || ! defined $arriveRoomObj || ! defined $fixedFlag
3384 || ! defined $dir || defined $check
3385 ) {
3386 return $axmud::CLIENT->writeImproper($self->_objClass . '->useExistingRoom', @_);
3387 }
3388  
3389 # If $customDir was specified, convert it to a standard primary direction
3390 if ($customDir) {
3391  
3392 $standardDir = $self->session->currentDict->ivShow('combRevDirHash', $customDir);
3393 }
3394  
3395 # If the Locator task has created a non-model room object for the current room, see if
3396 # it matches $arriveRoomObj
3397 # The TRUE argument means that a dark or unspecified non-model room matches any model room
3398 # If $result is FALSE, then $msg contains the error message that we need to display
3399 ($result, $msg) = $self->worldModelObj->compareRooms(
3400 $self->session,
3401 $arriveRoomObj,
3402 undef, # Compare against the Locator task's current room
3403 TRUE, # Match dark rooms
3404 );
3405  
3406 if (! $result) {
3407  
3408 # (Convert $customDir back into a standard direction, if possible)
3409 if ($customDir) {
3410  
3411 $standardDir = $self->session->currentDict->convertStandardDir($customDir);
3412 }
3413  
3414 if (! $standardDir && $exitObj && $exitObj->mapDir) {
3415  
3416 # (If non-primary directorions have been allocated a map direction, use that
3417 # instead)
3418 $standardDir = $exitObj->mapDir;
3419 }
3420  
3421 if (
3422 # If the calling function believes $arriveRoomObj is definitely the arrival room
3423 $fixedFlag
3424 # ...or if the automapper window isn't in 'update' mode
3425 || ! $self->mapWin
3426 || $self->mapWin->mode ne 'update'
3427 # ...or if the departure exit can't actually be drawn on the map using a primary
3428 # direction
3429 || ! $customDir
3430 || ! $standardDir
3431 ) {
3432 # The existing room isn't the one we were expecting, so the automapper is now lost
3433 if ($self->worldModelObj->explainGetLostFlag && $msg) {
3434  
3435 $self->session->writeText('MAP: ' . $msg);
3436 }
3437  
3438 return $self->setCurrentRoom(
3439 undef,
3440 # Character now lost
3441 $self->_objClass . '->useExistingRoom',
3442 # Use auto-rescue mode, if possible (the called function will check whether
3443 # the automapper window is in 'update' mode, or not, before using auto-rescue
3444 # mode)
3445 TRUE,
3446 );
3447 }
3448  
3449 # The existing room isn't the one we were expecting, but it might be possible to slide
3450 # $departRoomObj or $arriveRoomObj into a new position, or to find an empty gridblock
3451 # where the new room can be created
3452 ($xPosBlocks, $yPosBlocks, $zPosBlocks, $movedRoomObj)
3453 = $self->worldModelObj->slideRoom(
3454 $self->session,
3455 TRUE, # Update automapper windows now
3456 $departRoomObj,
3457 $arriveRoomObj,
3458 $standardDir,
3459 );
3460  
3461 if (! defined $xPosBlocks) {
3462  
3463 # The existing room isn't the one we were expecting and it's not possible to slide
3464 # anything around, nor to change where a new room could be created, so the
3465 # automapper is now lost
3466 if ($self->worldModelObj->explainGetLostFlag && $msg) {
3467  
3468 $self->session->writeText('MAP: ' . $msg);
3469 }
3470  
3471 return $self->setCurrentRoom(
3472 undef,
3473 $self->_objClass . '->useExistingRoom', # Character now lost
3474 TRUE, # Use auto-rescue mode, if possible
3475 );
3476  
3477 } elsif (defined $movedRoomObj) {
3478  
3479 # Otherwise, one of two rooms has been slid into a new gridblock, leaving room for
3480 # us to create a new destination room
3481 # Work out the departure room's coordinates on the map
3482 $vectorRef = $self->mapWin->ivShow('constSpecialVectorHash', $standardDir);
3483  
3484 $xPosBlocks = $departRoomObj->xPosBlocks
3485 + ($$vectorRef[0] * $self->worldModelObj->horizontalExitLengthBlocks);
3486 $yPosBlocks = $departRoomObj->yPosBlocks
3487 + ($$vectorRef[1] * $self->worldModelObj->horizontalExitLengthBlocks);
3488 $zPosBlocks = $departRoomObj->zPosBlocks
3489 + ($$vectorRef[2] * $self->worldModelObj->verticalExitLengthBlocks);
3490 }
3491  
3492  
3493 # Set some variables, ready for the call to $self->autoProcessNewRoom
3494 $regionmapObj = $self->worldModelObj->findRegionmap($departRoomObj->parent);
3495  
3496 # Check that we can create a new room and, if so, create it
3497 if (
3498 ! $self->autoProcessNewRoom(
3499 $dir,
3500 $regionmapObj,
3501 $xPosBlocks,
3502 $yPosBlocks,
3503 $zPosBlocks,
3504 $standardDir,
3505 $customDir,
3506 $exitObj,
3507 TRUE, # Bypass the special case checks, go straight to ->createNewRoom
3508 )
3509 ) {
3510 if ($self->worldModelObj->explainGetLostFlag) {
3511  
3512 $self->session->writeText(
3513 'MAP: Lost due to internal error (cannot process new room)',
3514 );
3515 }
3516  
3517 # The presence of a second argument means 'the character is lost'
3518 return $self->setCurrentRoom(
3519 undef,
3520 $self->_objClass . '->useExistingRoom', # Character now lost
3521 FALSE, # Don't use auto-rescue mode
3522 );
3523 }
3524  
3525 } else {
3526  
3527 # The Locator task's room matches $arriveRoomObj. If the Automapper window is open and
3528 # and in 'update' mode, update the map
3529 if ($self->mapWin && $self->mapWin->mode eq 'update') {
3530  
3531 if (
3532 $craftyExitObj
3533 && $standardDir
3534 && $self->worldModelObj->autocompleteExitsFlag
3535 && $arriveRoomObj->wildMode eq 'normal'
3536 ) {
3537 # In crafty moves mode a hidden exit was created from $departRoomObj. Because
3538 # ->autocompleteExitsFlag is set, create a twin exit for it (if an exit in
3539 # the right direction doesn't already exist)
3540 $oppDir = $self->session->currentDict->ivShow(
3541 'combOppDirHash',
3542 $craftyExitObj->dir,
3543 );
3544  
3545 if ($oppDir && ! $arriveRoomObj->ivExists('exitNumHash', $oppDir)) {
3546  
3547 $oppExitObj = $self->worldModelObj->addExit(
3548 $self->session,
3549 FALSE, # Don't update Automapper window yet
3550 $arriveRoomObj,
3551 $oppDir,
3552 $axmud::CLIENT->ivShow('constOppDirHash', $standardDir),
3553 );
3554  
3555 if ($oppExitObj) {
3556  
3557 $self->worldModelObj->setHiddenExit(
3558 FALSE, # Don't update Automapper window yet
3559 $oppExitObj,
3560 TRUE, # Hidden exit
3561 );
3562 }
3563 }
3564 }
3565  
3566 # Connect the two rooms if they're not already connected (and if they are, make
3567 # the exit between them two-way exits)
3568 # NB Don't connect two rooms if either one is in wilderness mode
3569 if (
3570 ($departRoomObj->wildMode eq 'normal' && $arriveRoomObj->wildMode ne 'wild')
3571 || ($arriveRoomObj->wildMode eq 'normal' && $departRoomObj->wildMode ne 'wild')
3572 ) {
3573  
3574 $self->worldModelObj->connectRooms(
3575 $self->session,
3576 TRUE, # Update Automapper windows now (for benefit of $departRoomObj)
3577 $departRoomObj,
3578 $arriveRoomObj,
3579 $dir,
3580 $standardDir,
3581 $exitObj,
3582 );
3583 }
3584 }
3585  
3586 # Update the number of character visits to this room (if allowed)
3587 $self->worldModelObj->updateVisitCount(
3588 $self->session,
3589 # Don't update Automapper windows now (the call to ->updateRoom will do that)
3590 FALSE,
3591 $arriveRoomObj->number,
3592 );
3593  
3594 # Update the arrival room to give it the same properties as the Locator's non-model
3595 # room (where appropriate)
3596 $self->updateRoom($arriveRoomObj);
3597  
3598 # Paint the room, if required to do so
3599 if (
3600 $self->mapWin
3601 && $self->mapWin->painterFlag
3602 && $self->worldModelObj->paintAllRoomsFlag
3603 && $self->mapWin->mode eq 'update'
3604 ) {
3605 $self->mapWin->paintRoom($arriveRoomObj);
3606 }
3607  
3608 # $arriveRoomObj is the new location
3609 $self->setCurrentRoom($arriveRoomObj);
3610  
3611 # Check for room scripts
3612 if ($self->worldModelObj->allowRoomScriptFlag) {
3613  
3614 # Check the GA::ModelObj::Room for Axbasic scripts and, if any are found, execute
3615 # them
3616 foreach my $script ($arriveRoomObj->arriveScriptList) {
3617  
3618 $self->session->pseudoCmd('runscript ' . $script);
3619 }
3620 }
3621  
3622 if ($self->worldModelObj->allowModelScriptFlag) {
3623  
3624 # Check the world model for Axbasic scripts and, if any are found, execute
3625 # them
3626 foreach my $script ($self->worldModelObj->arriveScriptList) {
3627  
3628 $self->session->pseudoCmd('runscript ' . $script);
3629 }
3630 }
3631 }
3632  
3633 return 1;
3634 }
3635  
3636 sub reactRandomExit {
3637  
3638 # Called by $self->moveKnownDirSeen to decide what to do, when the character uses a random
3639 # exit (one whose ->randomType is not 'none')
3640 #
3641 # Expected arguments
3642 # $exitObj - The GA::Obj::Exit used
3643 #
3644 # Return values
3645 # 'undef' on improper arguments or if there's an error calling $self->setCurrentRoom
3646 # 1 otherwise
3647  
3648 my ($self, $exitObj, $check) = @_;
3649  
3650 # Local variables
3651 my (
3652 $regionmapObj, $lostMsg, $regionObj, $originRoomObj, $originMode, $tempObj,
3653 @locateList, @foundList, @selectList,
3654 );
3655  
3656 # Check for improper arguments
3657 if (! defined $exitObj || defined $check) {
3658  
3659 return $axmud::CLIENT->writeImproper($self->_objClass . '->reactRandomExit', @_);
3660 }
3661  
3662 # Get the current room's parent region and regionmap
3663 $regionmapObj = $self->worldModelObj->findRegionmap($self->currentRoom->parent);
3664  
3665 # Random exit type 'same_region' - exit leads to a random location in the same region
3666 if ($exitObj->randomType eq 'same_region') {
3667  
3668 if ($self->worldModelObj->locateRandomInRegionFlag) {
3669  
3670 # Try to locate the new current room. Get a list of room numbers in the current
3671 # region
3672 @locateList = $regionmapObj->ivValues('gridRoomHash');
3673  
3674 # If the region contains more rooms than the locate operation limit, don't try to
3675 # locate the current location, but mark the character as lost
3676 if (
3677 $self->worldModelObj->locateMaxObjects
3678 && $self->worldModelObj->locateMaxObjects < @locateList
3679 ) {
3680 $lostMsg = 'MAP: Lost because the character used a random exit leading to the'
3681 . ' same region, which contains more than '
3682 . $self->worldModelObj->locateMaxObjects . 'rooms';
3683 }
3684  
3685 } else {
3686  
3687 # Write a message that would be displayed, if
3688 # GA::Obj::WorldModel->explainGetLostFlag were set
3689 $lostMsg = 'MAP: Lost because the character used a random exit leading to the same'
3690 . ' region',
3691 }
3692  
3693 # Random exit type 'any_region' - exit leads to a random location anywhere in the world
3694 } elsif ($exitObj->randomType eq 'any_region') {
3695  
3696 if ($self->worldModelObj->locateRandomAnywhereFlag) {
3697  
3698 @locateList = $self->worldModelObj->ivKeys('roomModelHash');
3699  
3700 if (
3701 $self->worldModelObj->locateMaxObjects
3702 && $self->worldModelObj->locateMaxObjects < @locateList
3703 ) {
3704 $lostMsg = 'MAP: Lost because the character used a random exit leading to any'
3705 . ' region, which collectively contain more than '
3706 . $self->worldModelObj->locateMaxObjects . 'rooms';
3707 }
3708  
3709 } else {
3710  
3711 $lostMsg = 'MAP: Lost because the character used a random exit leading to any'
3712 . ' region',
3713 }
3714  
3715 # Random exit type 'temp_region' - exit leads to a destination room in a new temporary
3716 # region
3717 } elsif ($exitObj->randomType eq 'temp_region') {
3718  
3719 # Can only create new rooms when the automapper window is open (can't do it when
3720 # $self->trackAloneFlag is TRUE)
3721 if (! $self->mapWin) {
3722  
3723 $lostMsg = 'MAP: Lost because random exit leads to a temporary region, but can only'
3724 . ' only create new rooms and regions when the automapper window is'
3725 . ' open';
3726  
3727 } else {
3728  
3729 # Create a new temporary region,
3730 $regionObj = $self->worldModelObj->addRegion(
3731 $self->session,
3732 TRUE, # Update Automapper windows now
3733 undef, # Generate a region name
3734 undef, # No parent region
3735 TRUE, # Temporary region
3736 );
3737  
3738 if (! $regionObj) {
3739  
3740 $lostMsg = 'MAP: Lost because random exit leads to a temporary region, but'
3741 . ' could not create a new temporary region',
3742  
3743 } else {
3744  
3745 $originRoomObj = $self->currentRoom;
3746 if ($self->mapWin) {
3747  
3748 $originMode = $self->mapWin->mode;
3749 }
3750  
3751 # Create a new room in the temporary region
3752 $tempObj = $self->worldModelObj->ivShow('regionmapHash', $regionObj->name);
3753 if (
3754 ! $self->createNewRoom(
3755 $tempObj,
3756 $tempObj->getGridCentre(), # Put new room at centre of region
3757 'update', # Switch to 'update' mode
3758 TRUE, # New room is current room
3759 TRUE, # Room takes properties from Locator
3760 )
3761 ) {
3762 $lostMsg = 'MAP: Lost due to internal error (cannot process new room)';
3763  
3764 } else {
3765  
3766 # The automapper window's mode must be switched to 'update', if it's not
3767 # already
3768 if ($self->mapWin && $self->mapWin->mode eq 'follow') {
3769  
3770 $self->mapWin->setMode('update');
3771 }
3772  
3773 # Update IVs, ready for the character to return the original room
3774 $self->ivPoke('tempRandomOriginRoom', $originRoomObj);
3775 $self->ivPoke('tempRandomDestRoom', $self->currentRoom);
3776 $self->ivPoke('tempRandomMode', $originMode);
3777  
3778 # The new current room is already set, so that's the end of the operation
3779 return 1;
3780 }
3781 }
3782 }
3783  
3784 # Random exit type 'room_list' - exit leads to one of a defined list of rooms (no limit to
3785 # the number of rooms to search, in this case)
3786 } else {
3787  
3788 @locateList = $exitObj->randomDestList;
3789 if (! @locateList) {
3790  
3791 $lostMsg = 'MAP: Lost because the character used a random exit with no destination'
3792 . ' rooms set',
3793 }
3794 }
3795  
3796 # Mark the character as lost, if necessary
3797 if ($lostMsg) {
3798  
3799 # Display the message only if the flag is set
3800 if ($self->worldModelObj->explainGetLostFlag) {
3801  
3802 $self->session->writeText($lostMsg);
3803 }
3804  
3805 return $self->setCurrentRoom(
3806 undef,
3807 $self->_objClass . '->reactRandomExit', # Character now lost
3808 TRUE, # Use auto-rescue mode, if possible
3809 );
3810  
3811 } else {
3812  
3813 # Try to locate the new current room. Put any matching rooms into @foundList so that,
3814 # if there is more than one matching room, we can choose which room to use
3815 OUTER: foreach my $roomNum (@locateList) {
3816  
3817 my $roomObj = $self->worldModelObj->ivShow('modelHash', $roomNum);
3818  
3819 if ($self->worldModelObj->locateRoom($self->session, $roomObj)) {
3820  
3821 push (@foundList, $roomObj);
3822  
3823 # For random exit type 3, we use the first room found
3824 if ($exitObj->randomType eq 'room_list') {
3825  
3826 last OUTER;
3827 }
3828 }
3829 }
3830  
3831 if (! @foundList) {
3832  
3833 # No matching rooms found; character is now lost
3834 if ($self->worldModelObj->explainGetLostFlag) {
3835  
3836 $self->session->writeText(
3837 'MAP: Lost because the character used a random exit, but no matching rooms'
3838 . ' were found',
3839 );
3840 }
3841  
3842 return $self->setCurrentRoom(
3843 undef,
3844 $self->_objClass . '->reactRandomExit', # Character now lost
3845 TRUE, # Use auto-rescue mode, if possible
3846 );
3847  
3848 } elsif (@foundList == 1) {
3849  
3850 # This is the new current room
3851 return $self->setCurrentRoom($foundList[0]);
3852  
3853 } else {
3854  
3855 # There is more than one matching room. Select all the matching rooms, so the user
3856 # can decide which to use (if the Automapper window is open)
3857  
3858 if ($self->mapWin) {
3859  
3860 # First unselect any currently selected objects
3861 $self->mapWin->setSelectedObj();
3862  
3863 # Select all of the matching rooms. $self->setSelectedObj expects a list in the
3864 # form:
3865 # (room_object, 'room', room_object, 'room', ...)
3866 foreach my $roomObj (@foundList) {
3867  
3868 push (@selectList, $roomObj, 'room');
3869 }
3870  
3871 $self->mapWin->setSelectedObj(
3872 \@selectList,
3873 TRUE, # Select multiple objects
3874 );
3875 }
3876  
3877 if ($self->worldModelObj->explainGetLostFlag) {
3878  
3879 $self->session->writeText(
3880 'MAP: Lost because the character used a random exit, and there is more than'
3881 . ' one possible new location',
3882 );
3883 }
3884  
3885 return $self->setCurrentRoom(
3886 undef,
3887 $self->_objClass . '->reactRandomExit', # Character now lost
3888 TRUE, # Use auto-rescue mode, if possible
3889 );
3890 }
3891 }
3892 }
3893  
3894 sub updateRoom {
3895  
3896 # Called by $self->moveKnownDirSeen, $self->lookGlanceSeen and $self->createNewRoom in order
3897 # to update the properties of a room object in the world model to match those of the
3898 # Locator task's non-model current room
3899 # If the Automapper window is open and is in 'update' mode, GA::Obj::WorldModel is called
3900 # to do the bulk of the updating
3901 #
3902 # Expected arguments
3903 # $modelRoomObj
3904 # - A GA::ModelObj::Room in the world model
3905 #
3906 # Optional arguments
3907 # $connectRoomObj, $connectExitObj, $mapDir
3908 # - When called by $self->createNewRoom, the room from which we arrived and the exit/
3909 # standard direction used to depart from it (if known). Used when temporarily
3910 # allocating primary directions to unallocated exits
3911 #
3912 # Return values
3913 # 'undef' on improper arguments
3914 # 1 otherwise
3915  
3916 my ($self, $modelRoomObj, $connectRoomObj, $connectExitObj, $mapDir, $check) = @_;
3917  
3918 # Check for improper arguments
3919 if (! defined $modelRoomObj || defined $check) {
3920  
3921 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRoom', @_);
3922 }
3923  
3924 # If the Automapper window is open (and in 'follow' or 'update' mode), or if the Automapper
3925 # window is closed but we're tracking the character's location, update the region's count
3926 # of living and non-living things in the current room
3927 if (
3928 ($self->mapWin && ($self->mapWin->mode eq 'follow' || $self->mapWin->mode eq 'update'))
3929 || (! $self->mapWin && $self->trackAloneFlag)
3930 ) {
3931 $self->worldModelObj->countRoomContents($self->session, $modelRoomObj);
3932 }
3933  
3934 # If the Automapper window is open (and in 'update' room), we can update the room's
3935 # properties
3936 if ($self->mapWin && $self->mapWin->mode eq 'update') {
3937  
3938 $self->worldModelObj->updateRoom(
3939 $self->session,
3940 TRUE, # Update Automapper windows now
3941 $modelRoomObj,
3942 $connectRoomObj,
3943 $connectExitObj,
3944 $mapDir,
3945 );
3946 }
3947  
3948 # Update complete
3949 return 1;
3950 }
3951  
3952 sub autoCompareLocatorRoom {
3953  
3954 # Called by $self->createNewRoom and ->setCurrentRoom
3955 # Compares the Locator's current room against all rooms in the same regionmap. Returns a
3956 # list of all the matching rooms
3957 #
3958 # Expected arguments
3959 # $regionmapObj - The GA::Obj::Regionmap containing the current room
3960 #
3961 # Optional arguments
3962 # $allFlag - If set to TRUE, compares the Locator's current room against all rooms
3963 # in the world model, starting with rooms in $regionmapObj. If FALSE
3964 # (or 'undef'), only rooms in $regionmapObj are compared
3965 # $currentFlag - Set to TRUE when called by $self->setCurrentRoom, in which case the
3966 # Locator's current room should be compared against $self->currentRoom
3967 #
3968 # Return values
3969 # An empty list on improper arguments or if there are no matching rooms
3970 # Otherwise returns a list of blessed references to matching GA::ModelObj::Room objects
3971  
3972 my ($self, $regionmapObj, $allFlag, $currentFlag, $check) = @_;
3973  
3974 # Local variables
3975 my (
3976 $count,
3977 @emptyList, @regionmapList, @returnList, @selectList,
3978 );
3979  
3980 # Check for improper arguments
3981 if (! defined $regionmapObj || defined $check) {
3982  
3983 $axmud::CLIENT->writeImproper($self->_objClass . '->autoCompareLocatorRoom', @_);
3984 return @emptyList;
3985 }
3986  
3987 # Don't do anything if the Locator task isn't running or doesn't know about the current room
3988 if (! $self->session->locatorTask || ! $self->session->locatorTask->roomObj) {
3989  
3990 return @emptyList;
3991 }
3992  
3993 # Compile a list of regionmaps to check
3994 push (@regionmapList, $regionmapObj);
3995 if ($allFlag) {
3996  
3997 foreach my $otherObj (
3998 sort {lc($a->name) cmp lc($b->name)}
3999 ($self->worldModelObj->ivValues('regionmapHash'))
4000 ) {
4001 if ($otherObj ne $regionmapObj) {
4002  
4003 push (@regionmapList, $otherObj);
4004 }
4005 }
4006 }
4007  
4008 # Get a list of rooms in the same regionmap
4009 $count = 0;
4010 OUTER: foreach my $thisRegionmapObj (@regionmapList) {
4011  
4012 my @roomList = $thisRegionmapObj->ivValues('gridRoomHash');
4013 INNER: foreach my $roomNum (@roomList) {
4014  
4015 my ($roomObj, $result);
4016  
4017 $roomObj = $self->worldModelObj->ivShow('modelHash', $roomNum);
4018  
4019 if (! $currentFlag || $self->currentRoom ne $roomObj) {
4020  
4021 # Compare the two rooms
4022 ($result) = $self->worldModelObj->compareRooms($self->session, $roomObj);
4023 if ($result) {
4024  
4025 # $roomObj matches the Locator's current room
4026 push (@returnList, $roomObj);
4027 $count++;
4028  
4029 if (
4030 $self->worldModelObj->autoCompareMax
4031 && $self->worldModelObj->autoCompareMax <= $count
4032 ) {
4033 # We've reached the maximum number of comparisons
4034 last OUTER;
4035 }
4036 }
4037 }
4038 }
4039 }
4040  
4041 if (@returnList) {
4042  
4043 # Select all the matching rooms
4044 # GA::Win::Map->setSelectedObj expects a list in the form
4045 # (room_object, 'room', room_object, 'room', ...)
4046 foreach my $obj (@returnList) {
4047  
4048 push (@selectList, $obj, 'room');
4049 }
4050  
4051 # First unselect all selected objects, then selecting just the matching rooms
4052 if ($self->mapWin->currentRegionmap) {
4053  
4054 $self->mapWin->setSelectedObj();
4055 $self->mapWin->setSelectedObj(
4056 \@selectList,
4057 TRUE, # Select multiple objects
4058 );
4059 }
4060 }
4061  
4062 return @returnList;
4063 }
4064  
4065 sub checkTempRandomReturn {
4066  
4067 # Called by $self->moveKnownDirSeen and ->moveUnknownDirSeen
4068 # If the character moved through a 'temp_region' random exit, check the Locator task's
4069 # current room. If it matches the random exit's parent room, then there's no need to worry
4070 # about updating the map; just move the player back to the original room and destroy the
4071 # temporary region
4072 #
4073 # Expected arguments
4074 # (none besides $self)
4075 #
4076 # Return values
4077 # 'undef' on improper arguments or if the situation described above doesn't apply
4078 # 1 if the the character has been moved back to the original room
4079  
4080 my ($self, $check) = @_;
4081  
4082 # Local variables
4083 my ($result, $originRoom, $destRoom, $mode);
4084  
4085 # Check for improper arguments
4086 if (defined $check) {
4087  
4088 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkTempRandomReturn', @_);
4089 }
4090  
4091 if (
4092 ! $self->session->locatorTask
4093 || ! $self->session->locatorTask->roomObj
4094 || ! $self->tempRandomOriginRoom
4095 ) {
4096 return undef;
4097 }
4098  
4099 ($result) = $self->worldModelObj->compareRooms($self->session, $self->tempRandomOriginRoom);
4100 if (! $result) {
4101  
4102 return undef;
4103 }
4104  
4105 # Reset IVs for the function's we're about to call, keeping a temporary local copy for
4106 # ourselves
4107 $originRoom = $self->tempRandomOriginRoom;
4108 $destRoom = $self->tempRandomDestRoom;
4109 $mode = $self->tempRandomMode;
4110  
4111 $self->ivUndef('tempRandomOriginRoom');
4112 $self->ivUndef('tempRandomDestRoom');
4113 $self->ivUndef('tempRandomMode');
4114  
4115 # Move the character to the original room
4116 $self->setCurrentRoom($originRoom);
4117 # Delete the temporary region we've just moved from
4118 $self->worldModelObj->deleteRegions(
4119 $self->session,
4120 TRUE, # Update automapper now
4121 $self->worldModelObj->ivShow('modelHash', $destRoom->parent),
4122 );
4123  
4124 # If the automapper window is open (and was open, when we first moved through the random
4125 # exit), restore its ->mode
4126 if ($self->mapWin && $mode && $self->mapWin->mode ne $mode) {
4127  
4128 $self->mapWin->setMode($mode);
4129 }
4130  
4131 # Return 1 so the calling function knows it doesn't have to worry about updating the world
4132 # model
4133 return 1;
4134 }
4135  
4136 # 'Connect offline' session mode functions
4137  
4138 sub showPseudoStatement {
4139  
4140 # Called by $self->setCurrentRoom and ->pseudoWorldCmd
4141 # When the current session's ->status is 'offline', we can simulate the room statements that
4142 # the user would see, if the character was actually wandering around the world
4143 # Use the details stored in the current world profile and a specified room model object to
4144 # construct a plausible room statement, and display it in the 'main' window
4145 #
4146 # Expected arguments
4147 # $dictObj - The session's current dictionary
4148 # $modelRoomObj - A GA::ModelObj::Room in the world model
4149 #
4150 # Return values
4151 # 'undef' on improper arguments or if the current world profile doesn't specify room
4152 # statement components for the type of room statement specified by
4153 # $self->pseudoStatementMode
4154 # Otherwise, returns the display buffer line (matches a key in
4155 # GA::Session->displayBufferHash) of the pseudo-statement's anchor line
4156  
4157 my ($self, $dictObj, $modelRoomObj, $check) = @_;
4158  
4159 # Local variables
4160 my (
4161 $worldObj, $wmObj, $string, $anchorOffset, $anchorNum, $bufferAnchorNum,
4162 @componentList, @lineList,
4163 %checkHash,
4164 );
4165  
4166 # Check for improper arguments
4167 if (! defined $dictObj || ! defined $modelRoomObj || defined $check) {
4168  
4169 return $axmud::CLIENT->writeImproper($self->_objClass . '->showPseudoStatement', @_);
4170 }
4171  
4172 # Import the current world profile and world model object (for convenience)
4173 $worldObj = $self->session->currentWorld;
4174 $wmObj = $self->session->worldModelObj;
4175  
4176 # A string to display after the title or verbose descrip components
4177 $string = ' [';
4178 if ($modelRoomObj->roomTag) {
4179  
4180 if ($wmObj->capitalisedRoomTagFlag) {
4181 $string .= uc($modelRoomObj->roomTag) . ' ';
4182 } else {
4183 $string .= $modelRoomObj->roomTag . ' ';
4184 }
4185 }
4186  
4187 $string .= '#' . $modelRoomObj->number . ']';
4188  
4189 # Import a list of room statement components for the type of statement specified by
4190 # $self->pseudoStatementMode
4191 if ($self->pseudoStatementMode eq 'verbose') {
4192  
4193 @componentList = $worldObj->verboseComponentList;
4194 $anchorOffset = $worldObj->verboseAnchorOffset;
4195  
4196 } elsif ($self->pseudoStatementMode eq 'short') {
4197  
4198 @componentList = $worldObj->shortComponentList;
4199 $anchorOffset = $worldObj->shortAnchorOffset;
4200  
4201 } elsif ($self->pseudoStatementMode eq 'brief') {
4202  
4203 @componentList = $worldObj->briefComponentList;
4204 $anchorOffset = $worldObj->briefAnchorOffset;
4205 }
4206  
4207 if (! @componentList) {
4208  
4209 # No room statement components have been specified for this type of room statement
4210 return undef;
4211 }
4212  
4213 # Process each component in turn, constructing a plausible statement constisting of one or
4214 # more lines stored in @lineList
4215 OUTER: foreach my $component (@componentList) {
4216  
4217 my (
4218 $componentObj, $lightStatus, $matchFlag, $titleString, $exitString, $delim,
4219 @descripList, @abbrevList,
4220 );
4221  
4222 # $component can be any custom-named key in GA::Profile::World->componentHash; get the
4223 # corresponding GA::Obj::Component object
4224 $componentObj = $worldObj->ivShow('componentHash', $component);
4225  
4226 # Some worlds might use multiple components of the same type (for example, two
4227 # 'verb_descrip' components)
4228 # Here, we only care about the first occurence of each component type. If $component is
4229 # 'anchor', then there will be no $componentObj, so we first have to check for that
4230 if ($componentObj) {
4231  
4232 if (exists $checkHash{$componentObj->type}) {
4233 next OUTER;
4234 } else {
4235 $checkHash{$componentObj->type} = undef;
4236 }
4237 }
4238  
4239 if ($component eq 'anchor') {
4240  
4241 # We need to remember which line in @lineList is the anchor line.
4242 if ($anchorOffset == -1) {
4243  
4244 # The anchor line shares a line with the component before it
4245 $anchorNum = scalar @lineList;
4246  
4247 } else {
4248  
4249 # The anchor line shares a line with the component after it, or is on its own
4250 # line
4251 $anchorNum = (scalar @lineList + 1);
4252 }
4253  
4254 } elsif ($componentObj->type eq 'verb_title' || $componentObj->type eq 'brief_title') {
4255  
4256 # Use the first available room title
4257 if ($modelRoomObj->titleList) {
4258 push (@lineList, $modelRoomObj->ivFirst('titleList') . $string);
4259 } else {
4260 push (@lineList, '<no room title>' . $string);
4261 }
4262  
4263 # (Only show $string once)
4264 $string = '';
4265  
4266 } elsif ($componentObj->type eq 'verb_descrip') {
4267  
4268 if ($modelRoomObj->descripHash) {
4269  
4270 # Use the verbose description matching the current light status; otherwise, use
4271 # the first verbose description matching a standard light status if possible.
4272 # If all else fails, use a random verbose description
4273 $lightStatus = $wmObj->lightStatus;
4274 if ($modelRoomObj->ivExists('descripHash', $lightStatus)) {
4275  
4276 push (
4277 @lineList,
4278 $modelRoomObj->ivShow('descripHash', $lightStatus) . $string,
4279 );
4280  
4281 } else {
4282  
4283 INNER: foreach my $otherStatus ($wmObj->lightStatusList) {
4284  
4285 if ($modelRoomObj->ivExists('descripHash', $otherStatus)) {
4286  
4287 push (
4288 @lineList,
4289 $modelRoomObj->ivShow('descripHash', $otherStatus),
4290 );
4291  
4292 $matchFlag = TRUE;
4293 last INNER;
4294 }
4295 }
4296  
4297 if (! $matchFlag) {
4298  
4299 # Use a random description
4300 @descripList = $modelRoomObj->ivValues('descripHash');
4301 push (@lineList, $descripList[0] . $string);
4302 }
4303 }
4304  
4305 } else {
4306  
4307 push (@lineList, '<no verbose description>' . $string);
4308 }
4309  
4310 # (Only show $string once)
4311 $string = '';
4312  
4313 } elsif ($componentObj->type eq 'verb_exit') {
4314  
4315 $exitString = 'Exits: ';
4316  
4317 if ($modelRoomObj->sortedExitList) {
4318 $exitString .= join(', ', $modelRoomObj->sortedExitList);
4319 } else {
4320 $exitString .= '<no exits>';
4321 }
4322  
4323 push (@lineList, $exitString);
4324  
4325 } elsif (
4326 $componentObj->type eq 'verb_content'
4327 || $componentObj->type eq 'brief_content'
4328 ) {
4329 # No way to tell whether the patterns in GA::Profile::World->contentPatternList
4330 # appear at the beginning of a line, in the middle or at the end, so just display
4331 # a straight list of objects
4332 INNER: foreach my $number ($modelRoomObj->ivKeys('childHash')) {
4333  
4334 my $obj = $wmObj->ivShow('modelHash', $number);
4335  
4336 if ($obj->baseString) {
4337 push(@lineList, ucfirst ($obj->name) . ' (' . $obj->baseString . ')');
4338 } elsif ($obj->name) {
4339 push (@lineList, ucfirst($obj->name));
4340 }
4341 }
4342  
4343 } elsif (
4344 $componentObj->type eq 'brief_exit'
4345 || $componentObj->type eq 'brief_title_exit'
4346 || $componentObj->type eq 'brief_exit_title'
4347 ) {
4348 # Get a room title and an exit list, then combine them into a single string, in the
4349 # right order
4350 $titleString = '';
4351 $exitString = '';
4352  
4353 # Use the first available room title
4354 if ($modelRoomObj->titleList) {
4355 $titleString = $modelRoomObj->ivFirst('titleList');
4356 } else {
4357 $titleString = '<no room title>';
4358 }
4359  
4360 # Get a list of exits
4361 if ($worldObj->briefExitDelimiterList) {
4362 $delim = $worldObj->ivFirst('briefExitDelimiterList');
4363 } else {
4364 $delim = ' '; # Last resort - use a space between exits
4365 }
4366  
4367 # if ($worldObj->briefExitLeftMarkerList) {
4368 #
4369 # $exitString .= $worldObj->ivFirst('briefExitLeftMarkerList');
4370 # }
4371  
4372 if ($modelRoomObj->sortedExitList) {
4373  
4374 # Convert exits to their abbreviated forms, if possible
4375 foreach my $exitName ($modelRoomObj->sortedExitList) {
4376  
4377 push (@abbrevList, $dictObj->abbrevDir($exitName));
4378 }
4379  
4380 $exitString .= join($delim, @abbrevList);
4381  
4382 } else {
4383  
4384 $exitString .= '<no exits>';
4385 }
4386  
4387 # if ($worldObj->briefExitRightMarkerList) {
4388 #
4389 # $exitString .= $worldObj->ivFirst('briefExitRightMarkerList');
4390 # }
4391  
4392 # Combine the strings in the right order
4393 if ($componentObj->type eq 'brief_exit') {
4394 push (@lineList, $exitString);
4395 } elsif ($componentObj->type eq 'brief_title_exit') {
4396 push (@lineList, $titleString . ' / ' . $exitString);
4397 } elsif ($componentObj->type eq 'brief_exit_title') {
4398 push (@lineList, $exitString . ' / ' . $titleString);
4399 }
4400  
4401 } elsif ($componentObj->type eq 'mudlib_path') {
4402  
4403 if ($modelRoomObj->sourceCodePath) {
4404 push (@lineList, $modelRoomObj->sourceCodePath);
4405 } else {
4406 push (@lineList, '<no path>');
4407 }
4408 }
4409 }
4410  
4411 if (@lineList) {
4412  
4413 # Insert an empty line, so that there's a gap between room statements
4414 $self->session->processIncomingData("\n");
4415  
4416 # Display the pseudo-room statement in the 'main' window
4417 for (my $count = 0; $count < scalar @lineList; $count++) {
4418  
4419 my $line = $lineList[$count];
4420  
4421 # If the regexes used to compose $line used an initial ^ or a final $ character,
4422 # remove them
4423 if (substr($line, 0, 1) eq '^') {
4424  
4425 $line = substr($line, 1);
4426 }
4427  
4428 # Also swap any '\ ' special characters for plain spaces
4429 $line =~ s/\\ / /g;
4430  
4431 if (substr($line, -1, 1) eq '$') {
4432  
4433 $line = substr($line, 0, ((length $line) - 1));
4434 }
4435  
4436 $self->session->processIncomingData("$line\n");
4437  
4438 if ($count == $anchorNum) {
4439  
4440 # This was the anchor line; remember the line's number in the display buffer
4441 $bufferAnchorNum = $self->session->displayBufferCount;
4442 }
4443 }
4444  
4445 } else {
4446  
4447 # If all else fails, show this bare-bones room statement
4448 $self->session->processIncomingData(
4449 '<current room #' . $modelRoomObj->number . ' \'' . $modelRoomObj->name . "\'>\n",
4450 );
4451 }
4452  
4453 if (! defined $bufferAnchorNum) {
4454  
4455 # As an emergency fallback, use the last line of the pseudo-statement as the anchor line
4456 $bufferAnchorNum = $self->session->displayBufferCount;
4457 }
4458  
4459 return $bufferAnchorNum;
4460 }
4461  
4462 sub pseudoWorldCmd {
4463  
4464 # Called by GA::Session->dispatchCmd, ->checkRedirect or ->checkAssisted, when the
4465 # session's status is 'offline', and when this automapper has a ->currentRoom set
4466 # The most recently-processed world command has been stored in the session's command buffer;
4467 # the buffer object may consist of one or more commands, depending on whether assisted
4468 # moves were processed
4469 # If the world command from which the buffer object was created (i.e. the command after
4470 # processing by aliases, but before processing by redirect mode / assisted moves) matches
4471 # any of the current room's exits, simulate a move using that exit
4472 #
4473 # Expected arguments
4474 # (none besides $self)
4475 #
4476 # Optional arguments
4477 # $cmdObj - The GA::Buffer::Cmd object created for the world command. If 'undef', this
4478 # function finds it
4479 #
4480 # Return values
4481 # 'undef' on improper arguments or if no simulated move occurs
4482 # 1 otherwise
4483  
4484 my ($self, $cmdObj, $check) = @_;
4485  
4486 # Local variables
4487 my (
4488 $dictObj, $tempType, $dir, $exitObj, $primaryDir, $dirType, $exitNum, $destRoomObj,
4489 $msg, $anchorLine,
4490 );
4491  
4492 # Check for improper arguments
4493 if (defined $check) {
4494  
4495 return $axmud::CLIENT->writeImproper($self->_objClass . '->pseudoWorldCmd', @_);
4496 }
4497  
4498 # Find the command buffer object, if not specified
4499 if (! $cmdObj) {
4500  
4501 $cmdObj = $self->session->ivShow(
4502 'cmdBufferHash',
4503 $self->session->cmdBufferLast,
4504 );
4505 }
4506  
4507 # Import the current dictionary
4508 $dictObj = $self->session->currentDict;
4509  
4510 # (The rest of the function is adapted from $self->moveKnownDirSeen)
4511  
4512 # Do nothing if:
4513 # 1. The Automapper window is open and is in 'wait' mode
4514 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
4515 # 3. The current room isn't known (regardless of whether the Automapper window is open)
4516 # 4. The command buffer object wasn't created by a look, glance or movement command
4517 if (
4518 ($self->mapWin && $self->mapWin->mode eq 'wait')
4519 || (! $self->mapWin && ! $self->trackAloneFlag)
4520 || ! $self->currentRoom
4521 || (! $cmdObj->moveFlag && ! $cmdObj->lookFlag && ! $cmdObj->glanceFlag)
4522 ) {
4523 return undef;
4524 }
4525  
4526 # For look/glance commands, re-display the current room's pseudo-room statement
4527 if ($cmdObj->lookFlag || $cmdObj->glanceFlag) {
4528  
4529 # Temporarily alter the value stored in $self->pseudoStatementMode, so that we can show
4530 # a verbose (or short verbose) room statement in response to a 'look' command, and
4531 # a brief statement in response to a 'glance' command (but only if those types of
4532 # room statement are available in the current world profile)
4533 if (
4534 ($self->pseudoStatementMode eq 'verbose' || $self->pseudoStatementMode eq 'short')
4535 && $cmdObj->glanceFlag
4536 && $self->session->currentWorld->briefComponentList
4537 ) {
4538 $tempType = $self->pseudoStatementMode;
4539 $self->ivPoke('pseudoStatementMode', 'brief')
4540  
4541 } elsif (
4542 $self->pseudoStatementMode eq 'brief'
4543 && $cmdObj->lookFlag
4544 && $self->session->currentWorld->verboseComponentList
4545 ) {
4546 $tempType = 'brief';
4547 $self->ivPoke('pseudoStatementMode', 'verbose')
4548 }
4549  
4550 $anchorLine = $self->showPseudoStatement($dictObj, $self->currentRoom);
4551 if (! defined $anchorLine) {
4552  
4553 # Could not produce a pseudo-room statement because no room statement components
4554 # of the statement type specified by $self->pseudoStatementMode are available
4555 # In this unlikely situation, mark the character as lost
4556 return $self->setCurrentRoom(
4557 undef,
4558 $self->_objClass . '->pseudoWorldCmd',
4559 FALSE, # Don't use auto-rescue mode
4560 );
4561 }
4562  
4563 # The Locator task normally creates a non-model room when it spots a room statement.
4564 # Instruct it create a non-model room based on $newRoomObj, and tell it to not look
4565 # for room statements in the text just displayed by the call to ->showPseudoStatement
4566 # (It's necessary to do this, even though the new non-model room will probably be
4567 # identical to the first one - it stops the Locator from looking for anchor lines
4568 # in the text produced by the call to ->showPseudoStatement)
4569 $self->session->locatorTask->usePseudoStatement(
4570 $dictObj,
4571 $self->currentRoom,
4572 $anchorLine,
4573 );
4574  
4575 # Restore the old value of $self->pseudoStatementMode, if it was temporarily changed
4576 if (defined $tempType) {
4577  
4578 $self->ivPoke('pseudoStatementMode', $tempType);
4579 }
4580  
4581 return 1;
4582 }
4583  
4584 # Set $dir, the direction of movement, so that we can work out which exit object is being
4585 # used. For assisted moves, we already know the exit object used (which will save us some
4586 # time)
4587 if ($cmdObj->assistedFlag) {
4588  
4589 $dir = $cmdObj->cmd;
4590 $exitObj = $cmdObj->assistedExitObj;
4591 $primaryDir = $cmdObj->assistedPrimary;
4592  
4593 } else {
4594  
4595 # For redirect mode commands, use the original command, which should contain only a
4596 # direction
4597 if ($cmdObj->redirectFlag) {
4598  
4599 $dir = $cmdObj->cmd;
4600  
4601 # For normal movement commands, the direction of movement has been stripped from
4602 # $cmdObj->cmd and stored in ->moveDir
4603 } else {
4604  
4605 $dir = $cmdObj->moveDir;
4606 }
4607  
4608 # If $dir is a primary direction, get the standard primary direction
4609 if ($dictObj->ivExists('combDirHash', $dir)) {
4610  
4611 $dirType = $dictObj->ivShow('combDirHash', $dir);
4612 if ($dirType eq 'primaryDir' || $dirType eq 'primaryAbbrev') {
4613  
4614 $primaryDir = $dictObj->ivShow('combRevDirHash', $dir);
4615 }
4616 }
4617  
4618 # Check the current room's exits. Does an exit in this direction already exist?
4619 if ($self->currentRoom->ivExists('exitNumHash', $dir)) {
4620  
4621 $exitNum = $self->currentRoom->ivShow('exitNumHash', $dir);
4622 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $exitNum);
4623  
4624 # Otherwise, if $dir is a primary direction, see if an existing exit from the current
4625 # room has the same drawn map direction
4626 } elsif ($primaryDir) {
4627  
4628 OUTER: foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
4629  
4630 my $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
4631  
4632 if (
4633 $otherExitObj->mapDir
4634 && $otherExitObj->mapDir eq $primaryDir
4635 # Don't leave using an exit attached to a shadow exit; leave via the
4636 # shadow exit instead)
4637 && (! $otherExitObj->shadowExit)
4638 ) {
4639 $exitObj = $otherExitObj;
4640 last OUTER;
4641 }
4642 }
4643 }
4644 }
4645  
4646 if (! $exitObj) {
4647  
4648 # Failsafe - do nothing if no exit found
4649 return undef;
4650  
4651 # In 'connect offline' mode, movements through exits which are marked impassable/mystery,
4652 # which are random exits or which have no destination room mean that the character is now
4653 # 'lost'
4654 } elsif (
4655 $exitObj->exitOrnament eq 'impass'
4656 || $exitObj->exitOrnament eq 'mystery'
4657 || $exitObj->randomType ne 'none'
4658 || ! $exitObj->destRoom
4659 ) {
4660 # Show an explanation, if allowed
4661 if ($self->worldModelObj->explainGetLostFlag) {
4662  
4663 if ($exitObj->exitOrnament eq 'impass') {
4664  
4665 $msg = 'MAP: Lost because the character used an exit marked as \'impassable\'';
4666  
4667 } elsif ($exitObj->exitOrnament eq 'mystery') {
4668  
4669 $msg = 'MAP: Lost because the character used an exit marked as \'mystery\'';
4670  
4671 } elsif ($exitObj->randomType ne 'none') {
4672  
4673 $msg = 'MAP: Lost because the character used a random exit while in \'connect'
4674 . ' offline\' mode';
4675  
4676 } else {
4677  
4678 $msg = 'MAP: Lost because the character used an exit with no destination in'
4679 . ' \'connect offline\' mode';
4680 }
4681  
4682 $self->session->writeText($msg);
4683 }
4684  
4685 # The TRUE argument means 'the character is lost'
4686 return $self->setCurrentRoom(
4687 undef,
4688 $self->_objClass . '->pseudoWorldCmd', # Defined string marks character as lost
4689 FALSE, # Don't use auto-rescue mode
4690 );
4691  
4692 } else {
4693  
4694 # Get the destination room
4695 $destRoomObj = $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
4696 # Simulate the world sending the new room statement to us
4697 $anchorLine = $self->showPseudoStatement($dictObj, $destRoomObj);
4698  
4699 # The Locator task normally creates a non-model room when it spots a room statement.
4700 # Instruct it create a non-model room based on $newRoomObj, and tell it to not look
4701 # for room statements in the text just displayed by the call to ->showPseudoStatement
4702 $self->session->locatorTask->usePseudoStatement($dictObj, $destRoomObj, $anchorLine);
4703 # $destRoomObj is the new location
4704 $self->setCurrentRoom($destRoomObj);
4705  
4706 return 1;
4707 }
4708 }
4709  
4710 ##################
4711 # Accessors - set
4712  
4713 sub set_facingDir {
4714  
4715 my ($self, $dir, $check) = @_;
4716  
4717 # Check for improper arguments
4718 if (defined $check) {
4719  
4720 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_facingDir', @_);
4721 }
4722  
4723 # If $dir is specified, check it's one of the permitted standard primary directiosn
4724 if (
4725 defined $dir
4726 && (
4727 ! $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $dir)
4728 || $dir eq 'up'
4729 || $dir eq 'down'
4730 )
4731 ) {
4732 return undef;
4733 }
4734  
4735 # Update IVs
4736 $self->ivPoke('facingDir', $dir); # Can be 'undef', but otherw
4737  
4738 return 1;
4739 }
4740  
4741 sub set_mapWin {
4742  
4743 my ($self, $winObj, $check) = @_;
4744  
4745 # Check for improper arguments
4746 if (defined $check) {
4747  
4748 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_mapWin', @_);
4749 }
4750  
4751 # Update IVs
4752 $self->ivPoke('mapWin', $winObj); # Can be 'undef'
4753  
4754 return 1;
4755 }
4756  
4757 sub set_pseudoStatementMode {
4758  
4759 my ($self, $mode, $check) = @_;
4760  
4761 # Check for improper arguments
4762 if (! defined $mode || defined $check) {
4763  
4764 return $axmud::CLIENT->writeImproper(
4765 $self->_objClass . '->set_pseudoStatementMode',
4766 @_,
4767 );
4768 }
4769  
4770 if ($mode ne 'verbose' && $mode ne 'short' && $mode ne 'brief') {
4771  
4772 return undef;
4773  
4774 } else {
4775  
4776 $self->ivPoke('pseudoStatementMode', $mode);
4777 return 1;
4778 }
4779 }
4780  
4781 sub reset_rescueCheckFlag {
4782  
4783 # Called by GA::Obj::WorldModel->mergeMap
4784  
4785 my ($self, $check) = @_;
4786  
4787 # Check for improper arguments
4788 if (defined $check) {
4789  
4790 return $axmud::CLIENT->writeImproper(
4791 $self->_objClass . '->reset_rescueCheckFlag',
4792 @_,
4793 );
4794 }
4795  
4796 if ($self->rescueCheckFlag) {
4797  
4798 # Fire any hooks that are using the 'map_rescue_merge' hook event
4799 $self->session->checkHooks('map_rescue_merge');
4800 }
4801  
4802 $self->ivPoke('rescueCheckFlag', FALSE);
4803  
4804 return 1;
4805 }
4806  
4807 sub reset_rescueRegion {
4808  
4809 # Called by GA::Obj::WorldModel->deleteRegions, when a region matching one of the following
4810 # IVs is deleted
4811 # Also called by numerous GA::Obj::Map and GA::Obj::Win functions to disactivate auto-rescue
4812 # mode
4813  
4814 my ($self, $check) = @_;
4815  
4816 # Check for improper arguments
4817 if (defined $check) {
4818  
4819 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_rescueRegion', @_);
4820 }
4821  
4822 # Show a confirmation, if auto-rescue mode was activated
4823 if ($self->rescueLostRegionObj) {
4824  
4825 $self->session->writeText('MAP: Auto-rescue mode disactivated');
4826  
4827 # Fire any hooks that are using the 'map_rescue_off' hook event
4828 $self->session->checkHooks('map_rescue_off');
4829 }
4830  
4831 if (
4832 $self->rescueFollowFlag
4833 && $self->mapWin
4834 && $self->mapWin->mode eq 'update'
4835 ) {
4836 # Switch back to 'follow' mode, which was the mode in use when auto-rescue mode was
4837 # activated
4838 $self->mapWin->setMode('follow');
4839 }
4840  
4841 # Reset IVs
4842 $self->ivPoke('rescueFollowFlag', FALSE);
4843 $self->ivUndef('rescueLostRegionObj');
4844 $self->ivUndef('rescueTempRegionObj');
4845 $self->ivPoke('rescueCheckFlag', FALSE);
4846  
4847 return 1;
4848 }
4849  
4850 sub reset_tempRandom {
4851  
4852 # Called by GA::Obj::WorldModel->deleteObj, when a room matching one of the following IVs
4853 # is deleted
4854 # Also called by $self->set_trackAloneFlag
4855 # In that case, we can forget about returning to the original location
4856  
4857 my ($self, $check) = @_;
4858  
4859 # Check for improper arguments
4860 if (defined $check) {
4861  
4862 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_tempRandom', @_);
4863 }
4864  
4865 # Just reset the IVs and forget about them
4866 $self->ivUndef('tempRandomOriginRoom');
4867 $self->ivUndef('tempRandomDestRoom');
4868 $self->ivUndef('tempRandomMode');
4869  
4870 return 1;
4871 }
4872  
4873 sub set_trackAloneFlag {
4874  
4875 # Called by GA::Win::Map to make sure the value of $self->trackAloneFlag is correct when
4876 # the window opens/closes
4877  
4878 my ($self, $flag, $check) = @_;
4879  
4880 # Check for improper arguments
4881 if (! defined $flag || defined $check) {
4882  
4883 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_trackAloneFlag', @_);
4884 }
4885  
4886 # If the character previously moved through a 'temp_region' random exit into a temporary
4887 # region, we can simply delete the temporary region when the automapper window closes
4888 if ($self->tempRandomOriginRoom) {
4889  
4890 # Delete the temporary region. If $self->currentRoom was in that region, it's reset too
4891 $self->worldModelObj->deleteRegions(
4892 $self->session,
4893 FALSE, # Don't update automapper yet
4894 $self->worldModelObj->ivShow('modelHash', $self->tempRandomDestRoom->parent),
4895 );
4896  
4897 # Reset IVs
4898 $self->ivUndef('tempRandomOriginRoom');
4899 $self->ivUndef('tempRandomDestRoom');
4900 $self->ivUndef('tempRandomMode');
4901  
4902 # There's no longer any position to track
4903 $flag = FALSE;
4904 }
4905  
4906 if ($flag) {
4907 $self->ivPoke('trackAloneFlag', TRUE);
4908 } else {
4909 $self->ivPoke('trackAloneFlag', FALSE);
4910 }
4911  
4912 # Reset other IVs when the window opens/closes
4913 $self->reset_tempRandom();
4914 $self->reset_rescueRegion();
4915  
4916 return 1;
4917 }
4918  
4919 sub set_worldModelObj {
4920  
4921 my ($self, $worldModelObj, $check) = @_;
4922  
4923 # Check for improper arguments
4924 if (! defined $worldModelObj || defined $check) {
4925  
4926 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_worldModelObj', @_);
4927 }
4928  
4929 $self->ivPoke('worldModelObj', $worldModelObj);
4930  
4931 # Reset the current room
4932 $self->setCurrentRoom();
4933  
4934 # Inform the Automapper window, if it is open
4935 if ($self->mapWin) {
4936  
4937 $self->mapWin->set_worldModelObj($worldModelObj);
4938 }
4939  
4940 return 1;
4941 }
4942  
4943 ##################
4944 # Accessors - get
4945  
4946 sub session
4947 { $_[0]->{session} }
4948 sub worldModelObj
4949 { $_[0]->{worldModelObj} }
4950 sub mapWin
4951 { $_[0]->{mapWin} }
4952  
4953 sub currentRoom
4954 { $_[0]->{currentRoom} }
4955 sub lastKnownRoom
4956 { $_[0]->{lastKnownRoom} }
4957 sub ghostRoom
4958 { $_[0]->{ghostRoom} }
4959  
4960 sub facingDir
4961 { $_[0]->{facingDir} }
4962  
4963 sub trackAloneFlag
4964 { $_[0]->{trackAloneFlag} }
4965 sub pseudoStatementMode
4966 { $_[0]->{pseudoStatementMode} }
4967  
4968 sub tempRandomOriginRoom
4969 { $_[0]->{tempRandomOriginRoom} }
4970 sub tempRandomDestRoom
4971 { $_[0]->{tempRandomDestRoom} }
4972 sub tempRandomMode
4973 { $_[0]->{tempRandomMode} }
4974  
4975 sub currentMatchFlag
4976 { $_[0]->{currentMatchFlag} }
4977 sub currentMatchList
4978 { my $self = shift; return @{$self->{currentMatchList}}; }
4979  
4980 sub rescueFollowFlag
4981 { $_[0]->{rescueFollowFlag} }
4982 sub rescueLostRegionObj
4983 { $_[0]->{rescueLostRegionObj} }
4984 sub rescueTempRegionObj
4985 { $_[0]->{rescueTempRegionObj} }
4986 sub rescueCheckFlag
4987 { $_[0]->{rescueCheckFlag} }
4988 }
4989  
4990 # Package must return a true value
4991 1