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

filter: Statementstmt 0.0% 0 / 1093 Branchbran 0.0% 0 / 760 Conditioncond 0.0% 0 / 792 MC/DCmcdc 0.0% 0 / 439 Subroutinesub 0.0% 0 / 51 Podpod 0.0% 0 / 48 totaltotal 0.0% 0 / 3183 CC 381 SCAR 76.6
CC
381
Cov
0%
moveKnownDirSeen
7832.0
setCurrentRoom
2070.0
showPseudoStatement
1482.0
CRAP 2112.2
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::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 - teleport commands
2554  
2555 # If it's a teleport command, we already know the destination room (or not)
2556 if ($cmdObj->teleportFlag) {
2557  
2558 if (defined $cmdObj->teleportDestRoom) {
2559 return $self->worldModelObj->ivShow('modelHash', $cmdObj->teleportDestRoom);
2560 } else {
2561 return undef;
2562 }
2563 }
2564  
2565 # PART 3 - identify relative directions
2566  
2567 # Is $cmdObj->cmd a relative direction like 'forward'?
2568 $slot = $dictObj->convertRelativeDir($cmdObj->cmd);
2569 if (defined $slot) {
2570  
2571 # $slot is in the range 0-7. Convert it into a standard primary direction like
2572 # 'north', depending on which way the character is currently facing
2573 $convertDir = $dictObj->rotateRelativeDir(
2574 $slot,
2575 $self->facingDir,
2576 );
2577  
2578 if (defined $convertDir) {
2579  
2580 # Translate the standard primary direction into the equivalent custom primary
2581 # direction, ready for PART 3
2582 $convertDir = $dictObj->ivShow('primaryDirHash', $convertDir);
2583 }
2584 }
2585  
2586 # PART 4 - get direction of movement
2587 #
2588 # Set $dir, the direction of movement, so that we can work out which exit object is being
2589 # used
2590 # Relative directions like 'forward' have already been translated into a custom primary
2591 # direction
2592 if ($convertDir) {
2593  
2594 $dir = $convertDir;
2595  
2596 # For assisted moves, we already know the exit object used (which will save us some time)
2597 } elsif ($cmdObj->assistedFlag) {
2598  
2599 $exitObj = $cmdObj->assistedExitObj;
2600 if ($exitObj->destRoom) {
2601  
2602 return $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
2603  
2604 } else {
2605  
2606 return undef;
2607 }
2608  
2609 # For redirect mode commands, use the original command, which should contain only a
2610 # direction
2611 } elsif ($cmdObj->redirectFlag) {
2612  
2613 $dir = $cmdObj->cmd;
2614  
2615 # For normal movement commands, the direction of movement has been stripped from
2616 # $cmdObj->cmd and stored in ->moveDir
2617 } else {
2618  
2619 $dir = $cmdObj->moveDir;
2620 }
2621  
2622 # PART 5 - identify an exit object (GA::Obj::Exit) matching the direction
2623 #
2624 # $dir can be any of the following:
2625 # (i) The original command used in an assisted move
2626 # - (this possibility has already been eliminated)
2627 #
2628 # (ii) A custom primary direction - one of the values in GA::Obj::Dict->primaryDirHash
2629 # (e.g. 'nord', sud') or ->primaryAbbrevHash (e.g. 'n', 's')
2630 # - $standardDir/$mapDir are set to the equivalent key (the words 'north', 'up'
2631 # etc)
2632 # - $customDir is set to the value of the key in ->primaryDirHash (so that if $dir
2633 # is 'n', $customDir gets set to the unabbreviated custom direction 'nord')
2634 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
2635 # $customDir)
2636 #
2637 # (iii) A recognised secondary direction - one of the values in
2638 # GA::Obj::Dict->secondaryDirHash (e.g. 'out') or ->secondaryAbbrevHash
2639 # (e.g. 'o')
2640 # - $standardDir is set to the equivalent key (the words 'in', 'entrance',
2641 # 'portal' etc)
2642 # - $mapDir / $customDir are not set (the key's corresponding value is always
2643 # equal to $dir)
2644 # - If $dir is abbreviated, it is unabbreviated (so its value is the same as
2645 # $standardDir)
2646 #
2647 # (iv) A direction not stored in the dictionary, such as 'enter well'
2648 # - Neither $standardDir nor $customDir are set
2649 # - For relative directions, $dir has already been set to the corresponding
2650 # custom primary direction
2651  
2652 # If $dir is a custom primary or secondary direction...
2653 if ($dictObj->ivExists('combDirHash', $dir)) {
2654  
2655 # Get the custom direction's type (one of the values 'primaryDir', 'primaryAbbrev',
2656 # 'secondaryDir' or 'secondaryAbbrev'), which partially matches the name of the
2657 # hash IV which stores that type of direction
2658 $dirType = $dictObj->ivShow('combDirHash', $dir);
2659 $standardDir = $dictObj->ivShow('combRevDirHash', $dir);
2660  
2661 # (ii) Customised primary direction
2662 if ($dirType eq 'primaryDir' || $dirType eq 'primaryAbbrev') {
2663  
2664 $customDir = $dictObj->ivShow('primaryDirHash', $standardDir);
2665 # Make sure $dir isn't the abbreviated version of the direction
2666 $dir = $customDir;
2667  
2668 # (iii) Recognised secondary direction
2669 } elsif ($dirType eq 'secondaryDir' || $dirType eq 'secondaryAbbrev') {
2670  
2671 # Make sure $dir isn't the abbreviated version of the direction
2672 $dir = $dictObj->ivShow('secondaryDirHash', $standardDir);
2673 }
2674 }
2675  
2676 # Check the current room's exits. Does an exit in this direction already exist?
2677 if ($self->currentRoom->ivExists('exitNumHash', $dir)) {
2678  
2679 $exitNum = $self->currentRoom->ivShow('exitNumHash', $dir);
2680 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $exitNum);
2681  
2682 # Otherwise, if $dir is a primary direction, see if an existing exit from the current
2683 # room has the same drawn map direction
2684 } elsif ($standardDir && $customDir) {
2685  
2686 OUTER: foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
2687  
2688 my $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
2689  
2690 if (
2691 $otherExitObj->mapDir
2692 && $otherExitObj->mapDir eq $customDir
2693 # (Don't leave using an exit attached to a shadow exit; leave via the shadow
2694 # exit instead)
2695 && (! $otherExitObj->shadowExit)
2696 ) {
2697 $exitObj = $otherExitObj;
2698 last OUTER;
2699 }
2700 }
2701 }
2702  
2703 # PART 5 - Return the result
2704 if ($exitObj && $exitObj->destRoom) {
2705  
2706 return $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
2707  
2708 } else {
2709  
2710 return undef;
2711 }
2712 }
2713  
2714 sub autoProcessNewRoom {
2715  
2716 # Called by GA::Obj::Map->moveKnownDirSeen when the Automapper window is in 'update' mode
2717 # and the character's move requires us to (probably) create a new room
2718 #
2719 # Expected arguments
2720 # $dir - The command that we think was responsible for the move ('north', 'up',
2721 # 'cross bridge' etc)
2722 # $regionmapObj - The current room's regionmap (the new room will be placed in the same
2723 # region)
2724 # $xPosBlocks, $yPosBlocks, $zPosBlocks
2725 # - The grid coordinates of the new room's likely position, as calculated
2726 # by the calling function
2727 #
2728 # Optional arguments
2729 # $mapDir - For primary directions, the standard form of $customDir. Set to
2730 # 'undef' for non-primary directions
2731 # $customDir - For primary directions, set to the unabbreviated form of $dir (so its
2732 # value may be the same as $dir, or not). Set to 'undef' for
2733 # non-primary directions
2734 # $exitObj - The GA::Obj::Exit corresponding to the direction of the move, if
2735 # known (otherwise set to 'undef')
2736 # $bypassFlag - TRUE when called by $self->useExistingRoom after some kind of room
2737 # slide operation, in which case it's not necessary for this function
2738 # to check for special cases. FALSE (or 'undef') otherwise
2739 #
2740 # Return values
2741 # 'undef' on improper arguments
2742 # 1 otherwise
2743  
2744 my (
2745 $self, $dir, $regionmapObj, $xPosBlocks, $yPosBlocks, $zPosBlocks, $mapDir, $customDir,
2746 $exitObj, $bypassFlag, $check,
2747 ) = @_;
2748  
2749 # Local variables
2750 my (
2751 $successFlag, $listRef, $xPos, $yPos, $zPos, $count, $foundRoomObj, $exitFlag,
2752 $exitLength, $maxLength,
2753 %uncertainHash,
2754 );
2755  
2756 # Check for improper arguments
2757 if (
2758 ! defined $dir || ! defined $regionmapObj || ! defined $xPosBlocks
2759 || ! defined $yPosBlocks || ! defined $zPosBlocks || defined $check
2760 ) {
2761 return $axmud::CLIENT->writeImproper($self->_objClass . '->autoProcessNewRoom', @_);
2762 }
2763  
2764 # Deal with two special cases, both of which depend on the value of the world model's
2765 # ->intelligentExitsFlag
2766  
2767 # 1. There are two rooms, A and B. A has an uncertain exit which leads to B, but A is also a
2768 # broken exit. Should B lead back to A, or does it actually lead to a new room?
2769 if (
2770 ! $bypassFlag
2771 && $exitObj
2772 && ! $exitObj->destRoom
2773 && $exitObj->randomType eq 'none' # $exitObj is incomplete
2774 && $self->currentRoom->uncertainExitHash
2775 ) {
2776 # The current room is room B, and its exit which might lead back to room A in the
2777 # direction $dir is $exitObj
2778 OUTER: foreach my $oppExitNumber ($self->currentRoom->ivKeys('uncertainExitHash')) {
2779  
2780 my ($checkExitNum, $oppExitObj, $oppRoomObj);
2781  
2782 $checkExitNum = $self->currentRoom->ivShow('uncertainExitHash', $oppExitNumber);
2783 if ($checkExitNum != $exitObj->number) {
2784  
2785 # The room A uncertain exit isn't possibly connected to $exitObj
2786 next OUTER;
2787 }
2788  
2789 # Get the exit from room A
2790 $oppExitObj = $self->worldModelObj->ivShow('exitModelHash', $oppExitNumber);
2791 if ($oppExitObj && ($oppExitObj->brokenFlag || $oppExitObj->regionFlag)) {
2792  
2793 # Get room A
2794 $oppRoomObj = $self->worldModelObj->ivShow('modelHash', $oppExitObj->parent);
2795  
2796 # Check if the exit is in the right opposite direction
2797 if ($self->worldModelObj->checkOppPrimary($exitObj, $oppRoomObj)) {
2798  
2799 if ($self->worldModelObj->intelligentExitsFlag) {
2800  
2801 # Instead of creating a new room, we should use the existing room,
2802 # $oppRoomObj, creating a (broken) two-way exit
2803  
2804 # Connect the current location to the existing room, if they're not
2805 # already connected (and if they are, make it a two-way exit)z
2806 $self->worldModelObj->connectRooms(
2807 $self->session,
2808 FALSE, # Don't update Automapper windows now
2809 $self->currentRoom,
2810 $oppRoomObj,
2811 $dir,
2812 $mapDir,
2813 $exitObj,
2814 );
2815  
2816 # Mark the exit from B to A as a broken/region exit, too
2817 if ($oppExitObj->brokenFlag) {
2818  
2819 $self->worldModelObj->setBrokenExit(
2820 FALSE, # Don't update Automapper windows now
2821 $exitObj,
2822 );
2823  
2824 } elsif ($oppExitObj->regionFlag) {
2825  
2826 $self->worldModelObj->setRegionExit(
2827 FALSE, # Don't update Automapper windows now
2828 $exitObj,
2829 );
2830 }
2831  
2832 # Update the number of character visits to this room (if allowed)
2833 $self->worldModelObj->updateVisitCount(
2834 $self->session,
2835 # Don't update Automapper windows now (the call to ->updateRoom will
2836 # do that)
2837 FALSE,
2838 $oppRoomObj->number,
2839 );
2840  
2841 # Update the existing room to give it the same properties as the
2842 # Locator's non-model room (where appropriate)
2843 $self->updateRoom($oppRoomObj);
2844  
2845 # Paint the room, if required to do so
2846 if (
2847 $self->mapWin->painterFlag
2848 && $self->worldModelObj->paintAllRoomsFlag
2849 ) {
2850 $self->mapWin->paintRoom($oppRoomObj);
2851 }
2852  
2853 # The call to ->updateRoom marks $oppRoomObj as needing to be redrawn in
2854 # every Automapper window; make sure $self->currentRoom is also
2855 # redrawn in every Automapper window
2856 $self->worldModelObj->updateMaps('room', $self->currentRoom);
2857  
2858 # In both 'update' mode and 'follow' mode, $existingRoom is the new
2859 # location
2860 $self->setCurrentRoom($oppRoomObj);
2861  
2862 $successFlag = TRUE;
2863 last OUTER;
2864  
2865 } else {
2866  
2867 # Intelligent uncertain exits are disabled. Convert the uncertain exit
2868 # to a one-way exit
2869 $self->worldModelObj->convertUncertainExit(
2870 # Don't update Automapper windows now (the call to ->createNewRoom
2871 # will do that)
2872 FALSE,
2873 $oppExitObj,
2874 $self->currentRoom,
2875 );
2876 }
2877 }
2878 }
2879 }
2880 }
2881  
2882 # 2. There are two rooms, A and B. B is one gridblock north of A and the 'north' exit from A
2883 # to B is not a broken (or region) exit. The exit length is currently set to 2 gridblocks.
2884 # When we go south from B, should it lead to room A - ignoring the exit length, and using
2885 # the first room in the direction 'south' it finds - or should a new room be created 1
2886 # gridblock south of A, with a broken exit leading to it?
2887 if (! $bypassFlag && ! $successFlag && $exitObj) {
2888  
2889 $exitLength = $self->worldModelObj->getExitLength($exitObj);
2890  
2891 if (
2892 ! $exitObj->destRoom
2893 && $exitObj->randomType eq 'none' # $exitObj is incomplete
2894 && $exitLength > 1
2895 && $exitObj->dir
2896 && $exitObj->mapDir
2897 ) {
2898 # The current room is room B, and its exit which might lead back to room A in the
2899 # direction $dir is $exitObj
2900 # We need to check the gridblocks between the one occupied by room B, and the one
2901 # at which a new room, C, would be created (described by $xPosBlocks, $yPosBlocks,
2902 # $zPosBlocks, supplied by the calling function), stopping at the first room we
2903 # find (which will be room A)
2904  
2905 # Import a vector hash, in the form
2906 # %vectorHash => {
2907 # north => [0, -1, 0],
2908 # northnortheast => [1, -2, 0],
2909 # northeast => [1, -1, 0],
2910 # eastnortheast => [2, -1, 0],
2911 # east => [1, 0, 0],
2912 # eastsoutheast => [2, 1, 0],
2913 # southeast => [1, 1, 0],
2914 # southsoutheast => [1, 2, 0],
2915 # south => [0, 1, 0],
2916 # southsouthwest => [-1, 2, 0],
2917 # southwest => [-1, 1, 0],
2918 # westsouthwest => [-2, 1, 0],
2919 # west => [-1, 0, 0],
2920 # westnorthwest => [-2, -1, 0],
2921 # northwest => [-1, -1, 0],
2922 # northnorthwest => [-1, -2, 0],
2923 # up => [0, 0, 1],
2924 # down => [0, 0, -1],
2925 # },
2926 # Extract from %vectorHash the list corresponding to the $exitObj's primary
2927 # direction
2928 $listRef = $self->mapWin->ivShow('constSpecialVectorHash', $exitObj->mapDir);
2929  
2930 # Check every gridblock between B and C, looking for room A
2931 $xPos = $self->currentRoom->xPosBlocks;
2932 $yPos = $self->currentRoom->yPosBlocks;
2933 $zPos = $self->currentRoom->zPosBlocks;
2934 $count = 0;
2935  
2936 do {
2937  
2938 my $number;
2939  
2940 $xPos += $$listRef[0];
2941 $yPos += $$listRef[1];
2942 $zPos += $$listRef[2];
2943 $count++;
2944  
2945 # Don't look at room C...
2946 if ($xPos != $xPosBlocks && $yPos != $yPosBlocks && $zPos != $zPosBlocks) {
2947  
2948 $exitFlag = TRUE;
2949  
2950 } else {
2951  
2952 # If there's a room A at this gridblock, store it in $foundRoom
2953 $number = $regionmapObj->fetchRoom($xPos, $yPos, $zPos);
2954 if (defined $number) {
2955  
2956 $foundRoomObj = $self->worldModelObj->ivShow('modelHash', $number);
2957 }
2958 }
2959  
2960 } until ($foundRoomObj || $exitFlag || $count >= $exitLength);
2961  
2962 if ($foundRoomObj) {
2963  
2964 # We've found a room A directly between rooms B and C
2965 # If the 'intelligent uncertain exits' flag is set, connect B to A rather than
2966 # to C, ignoring the exit length specified by the world model's
2967 # ->horizontalExitLengthBlocks or ->verticalExitLengthBlocks
2968 if ($self->worldModelObj->intelligentExitsFlag) {
2969  
2970 $self->useExistingRoom(
2971 $self->currentRoom,
2972 $foundRoomObj,
2973 TRUE, # $foundRoomObj is definitely the destination
2974 $dir,
2975 $customDir,
2976 $exitObj,
2977 );
2978  
2979 $successFlag = TRUE;
2980  
2981 } else {
2982  
2983 # Mark the exit as a broken exit. In a moment, a new room will be drawn
2984 # as usual
2985 $self->worldModelObj->setBrokenExit(
2986 FALSE, # Don't update Automapper windows now
2987 $exitObj,
2988 );
2989  
2990 # If there is an incoming uncertain exit in the opposite direction, it must
2991 # be converted to a one-way exit
2992 %uncertainHash = $self->currentRoom->uncertainExitHash;
2993 foreach my $uncertainExitNum (keys %uncertainHash) {
2994  
2995 my ($oppExitNum, $oppExitObj, $uncertainExitObj);
2996  
2997 $oppExitNum = $uncertainHash{$uncertainExitNum};
2998  
2999 if ($oppExitNum == $exitObj->number) {
3000  
3001 # Convert it a one-way exit
3002 $uncertainExitObj = $self->worldModelObj->ivShow(
3003 'exitModelHash',
3004 $uncertainExitNum,
3005 );
3006  
3007 if ($uncertainExitObj) {
3008  
3009 $self->worldModelObj->convertUncertainExit(
3010 TRUE, # Update Automapper windows now
3011 $uncertainExitObj,
3012 $self->currentRoom,
3013 );
3014 }
3015 }
3016 }
3017 }
3018 }
3019 }
3020 }
3021  
3022 if (! $successFlag) {
3023  
3024 # In 'update' mode, for a movement in a primary direction, create a new room at the
3025 # specified location, make it the current room, give it the properties of the
3026 # Locator task's current room, and update the map
3027 if (
3028 ! $self->createNewRoom(
3029 $regionmapObj, # Use the same region as the current room
3030 $xPosBlocks, # Co-ordinates of room on the region's grid
3031 $yPosBlocks,
3032 $zPosBlocks,
3033 undef, # Don't change GA::Win::Map->mode
3034 TRUE, # New room is current room
3035 TRUE, # New room takes properties from Locator
3036 $self->currentRoom,
3037 $dir, # Connect rooms together...
3038 $mapDir, # ('undef' if $dir is a non-primary direction)
3039 $exitObj, # ...using existing exit (if set)
3040 $bypassFlag, # Force a two-way exit, if the flag is TRUE
3041 )
3042 ) {
3043 return undef;
3044 }
3045  
3046 # Check the world model for Axbasic scripts and, if any are found, execute them
3047 if ($self->worldModelObj->allowModelScriptFlag) {
3048  
3049 foreach my $script ($self->worldModelObj->newRoomScriptList) {
3050  
3051 $self->session->pseudoCmd('runscript ' . $script);
3052 }
3053 }
3054 }
3055  
3056 return 1;
3057 }
3058  
3059 sub createNewRoom {
3060  
3061 # Called by $self->moveKnownDirSeen, ->autoProcessNewRoom and ->reactRandomExit
3062 # Also called by GA::Win::Map->enableCanvasPopupMenu, ->canvasEventHandler,
3063 # ->addFirstRoomCallback, ->addRoomAtBlockCallback
3064 # Creates a new room - adding a new object to the world model. At the moment, new rooms can
3065 # only be created when the automapper window is open, but this function checks for that
3066 # (just in case of future changes)
3067 # If the process fails, deletes the world model object (if already created) and displays an
3068 # error
3069 #
3070 # Expected arguments
3071 # $regionmapObj - The GA::Obj::Regionmap in which the new room will be created. Usually
3072 # (but not always) matches the regionmap visible in the automapper
3073 # window for this session
3074 # $xPosBlocks, $yPosBlocks, $zPosBlocks
3075 # - The coordinates of the new room on the regionmap's grid
3076 #
3077 # Optional arguments
3078 # $mode - The new automapper window's ->mode after the room has been created. If
3079 # 'undef', the window's ->mode isn't changed
3080 # $currentFlag - If set to TRUE, the new room is made the current location (if FALSE
3081 # or 'undef', the current location isn't changed)
3082 # $updateFlag - If set to TRUE, the room's properties are updated to match those of
3083 # the Locator task's current room (depending on certain flags, and
3084 # only when $currentFlag is TRUE; otherwise set to FALSE or 'undef')
3085 # $connectRoomObj - The room from which the character just departed ('undef' if not known)
3086 # $dir - The command used to move (e.g. 'n', 'enter well' - matches
3087 # GA::Obj::Exit->dir) ('undef' if unknown)
3088 # $mapDir - How the exit is drawn on the map - one of Axmud's standard primary
3089 # directions (e.g. 'north', 'south', 'up) ('undef' if unknown)
3090 # $exitObj - The GA::Obj::Exit through which the character moved (if 'undef', a new
3091 # exit object can be created)
3092 # $forceFlag - If TRUE, the exit object is automatically converted into a two-way
3093 # exit, if possible (if FALSE or 'undef', the usual settings apply)
3094 #
3095 # Return values
3096 # 'undef' on improper arguments or if the new room isn't created
3097 # Otherwise returns the GA::ModelObj::Room created
3098  
3099 my (
3100 $self, $regionmapObj, $xPosBlocks, $yPosBlocks, $zPosBlocks, $mode, $currentFlag,
3101 $updateFlag, $connectRoomObj, $dir, $mapDir, $exitObj, $forceFlag, $check,
3102 ) = @_;
3103  
3104 # Local variables
3105 my (
3106 $mergeFlag, $text, $result, $newRoomObj, $filePath, $virtualPath, $choice,
3107 @matchList, @selectList, @otherRoomList, @labelList,
3108 );
3109  
3110 # Check for improper arguments
3111 if (
3112 ! defined $regionmapObj || ! defined $xPosBlocks || ! defined $yPosBlocks
3113 || ! defined $zPosBlocks || defined $check
3114 ) {
3115 return $axmud::CLIENT->writeImproper($self->_objClass . '->createNewRoom', @_);
3116 }
3117  
3118 # Compare the Locator tasks's current room against other rooms (but don't bother if the
3119 # task is expecting more room statements)
3120 if ($updateFlag && $self->mapWin && $self->session->locatorTask->moveList <= 1) {
3121  
3122 # If auto-rescue mode has been activated and if this new room is to be created in the
3123 # temporary region...
3124 if (
3125 $self->rescueTempRegionObj
3126 && $self->rescueTempRegionObj->name eq $regionmapObj->name
3127 ) {
3128 # Compare the new room against rooms in the previous region, looking for matching
3129 # rooms
3130 @matchList = $self->autoCompareLocatorRoom(
3131 $self->worldModelObj->ivShow('regionmapHash', $self->rescueLostRegionObj->name),
3132 );
3133  
3134 if (
3135 $self->worldModelObj->autoRescueFirstFlag
3136 && (scalar @matchList) == 1
3137 && $regionmapObj->gridRoomHash
3138 # (Don't auto-merge when the Locator task is expecting more room statements)
3139 && $self->session->locatorTask->moveList <= 1
3140 ) {
3141 # The new room isn't the first room in the temporary region, and it matches
3142 # exactly one room in the previous region
3143 # As soon as the new room has been created, everything in the temporary region
3144 # can be merged back into the previous region
3145 $mergeFlag = TRUE;
3146 }
3147  
3148 } elsif ($self->worldModelObj->autoCompareMode ne 'default') {
3149  
3150 if (! $self->worldModelObj->autoCompareAllFlag) {
3151  
3152 # Compare the new room against rooms in the same region, looking for a duplicate
3153 # room
3154 @matchList = $self->autoCompareLocatorRoom($regionmapObj);
3155  
3156 } else {
3157  
3158 # Compare the new room against rooms in every region (starting with
3159 # $regionmapObj), looking for a duplicate room
3160 @matchList = $self->autoCompareLocatorRoom($regionmapObj, TRUE);
3161 }
3162 }
3163 }
3164  
3165 # Create the room object. Tell the world model not to update automappers immediately - we
3166 # might want to mark the room as current
3167 $newRoomObj = $self->worldModelObj->addRoom(
3168 $self->session,
3169 TRUE, # Update Automapper windows now
3170 $regionmapObj->name,
3171 $xPosBlocks,
3172 $yPosBlocks,
3173 $zPosBlocks,
3174 );
3175  
3176 if (! $newRoomObj) {
3177  
3178 # Operation failed
3179 if ($self->mapWin) {
3180  
3181 $self->mapWin->showMsgDialogue(
3182 'New room',
3183 'error',
3184 'Could not create the new room',
3185 'ok',
3186 );
3187  
3188 } else {
3189  
3190 $self->session->writeText('MAP: Could not create a new room');
3191 }
3192  
3193 return undef;
3194 }
3195  
3196 # Set the automapper's mode, if a new mode was specified
3197 if ($mode && $self->mapWin) {
3198  
3199 $self->mapWin->setMode($mode);
3200 }
3201  
3202 # Set the current location (which causes both the previous current location, if there was
3203 # one, and the new current location to be redrawn)
3204 if ($currentFlag) {
3205  
3206 # Update the number of character visits to this room, if allowed
3207 $self->worldModelObj->updateVisitCount(
3208 $self->session,
3209 # Don't update Automapper windows now (the call to ->updateRoom will do that)
3210 FALSE,
3211 $newRoomObj->number,
3212 );
3213  
3214 # Paint the room, if required to do so
3215 if ($self->mapWin && $self->mapWin->painterFlag) {
3216  
3217 $self->mapWin->paintRoom($newRoomObj);
3218 }
3219  
3220 # If necessary, give the new room the properties of the Locator task's current room
3221 if ($updateFlag) {
3222  
3223 $self->updateRoom($newRoomObj, $connectRoomObj, $exitObj, $mapDir);
3224 }
3225  
3226 # If the previous room is known, connect it to this room
3227 if ($connectRoomObj && $dir) {
3228  
3229 $self->worldModelObj->connectRooms(
3230 $self->session,
3231 TRUE, # Update Automapper windows now (for the benefit of $connectRoomObj)
3232 $connectRoomObj,
3233 $newRoomObj,
3234 $dir,
3235 $mapDir,
3236 $exitObj,
3237 undef,
3238 $forceFlag,
3239 );
3240 }
3241  
3242 # Set the current location. The TRUE argument identifies this function as the caller
3243 $self->setCurrentRoom($newRoomObj, undef, FALSE, TRUE, @matchList);
3244  
3245 } else {
3246  
3247 # Just draw the new room (in every Automapper window)
3248 $self->worldModelObj->updateMaps('room', $newRoomObj);
3249 }
3250  
3251 if ($mergeFlag) {
3252  
3253 # Auto-rescue mode was already activated, and all rooms/labels in the temporary region
3254 # can now be merged back into the previous region
3255  
3256 # Prompt the user for confirmation, if required
3257 if ($self->worldModelObj->autoRescuePromptFlag) {
3258  
3259 $choice = $self->mapWin->showMsgDialogue(
3260 'Merge/move room',
3261 'question',
3262 'The current room matches (just) one room in the previous region. Do you want'
3263 . ' merge everything in the temporary region back into the previous region?',
3264 'yes-no',
3265 );
3266  
3267 if (! defined $choice || $choice eq 'no') {
3268  
3269 # Stop trying to auto-merge rooms, and treat the temporary region like any other
3270 # temporary region
3271 $self->reset_rescueRegion();
3272 }
3273 }
3274  
3275 if (
3276 ! $self->worldModelObj->autoRescuePromptFlag
3277 || (defined $choice && $choice eq 'yes')
3278 ) {
3279 # Get a list of all rooms in this region (besides $newRoomObj), and another list of
3280 # all labels
3281 foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) {
3282  
3283 if ($roomNum ne $newRoomObj->number) {
3284  
3285 push (@otherRoomList, $self->worldModelObj->ivShow('modelHash', $roomNum));
3286 }
3287 }
3288  
3289 @labelList = $regionmapObj->ivValues('gridLabelHash');
3290  
3291 # Perform the merge
3292 if (
3293 ! $self->worldModelObj->mergeMap(
3294 $self->session,
3295 $matchList[0], # The target (surviving) room
3296 $newRoomObj, # The new room which will be merged into it
3297 \@otherRoomList,
3298 \@labelList,
3299 )
3300 ) {
3301 $self->session->writeText(
3302 'MAP: Automapper was unable to merge room(s) from the temporary region back'
3303 . ' into the previous region \'' . $self->rescueLostRegionObj->name . '\'',
3304 );
3305  
3306 # Stop trying to auto-merge rooms, and treat the temporary region like any other
3307 # temporary region
3308 $self->reset_rescueRegion();
3309  
3310 } else {
3311  
3312 $self->session->writeText(
3313 'MAP: Automapper has merged room(s) from the temporary region back into the'
3314 . ' previous region \'' . $self->rescueLostRegionObj->name . '\'',
3315 );
3316  
3317 # Merge operation succeeded, so we can discard the temporary region
3318 $self->worldModelObj->deleteRegions(
3319 $self->session,
3320 TRUE, # Update automapper windows now
3321 $self->rescueTempRegionObj,
3322 );
3323  
3324 # Our IVs should have been reset, but there's no harm in checking
3325 $self->reset_rescueRegion();
3326 }
3327 }
3328 }
3329  
3330 # DEBUG
3331 if ($axmud::TEST_MODEL_FLAG && ! $self->worldModelObj->testModel($self->session)) {
3332  
3333 $self->session->writeDebug(
3334 'NEW ROOM MODEL TEST: World model test failed at '
3335 . $axmud::CLIENT->localTime(),
3336 );
3337  
3338 $axmud::CLIENT->playSound('alarm');
3339  
3340 # Test failed. Don't keep running tests
3341 $axmud::TEST_MODEL_FLAG = FALSE;
3342 }
3343 # DEBUG
3344  
3345 return $newRoomObj;
3346 }
3347  
3348 sub useExistingRoom {
3349  
3350 # Called by $self->moveKnownDirSeen when it has decided that the move from one room
3351 # ($departRoomObj) in the direction $dir has resulted in arrival at the room
3352 # $arriveRoomObj
3353 # Also called by $self->teleportSeen and ->autoProcessNewRoom
3354 #
3355 # After checking the arrival room matches the one we were expecting, updates the automapper
3356 # object and/or automapper window as required
3357 #
3358 # Expected arguments
3359 # $departRoomObj - The GA::ModelObj::Room from which the character left
3360 # $arriveRoomObj - The GA::ModelObj::Room at which the character has definitely (or
3361 # presumably) arrived
3362 # $fixedFlag - TRUE if $arriveRoomObj is definitely the destination room (for
3363 # example, because the exit object specifies it as the destination
3364 # room); FALSE if it's only presumed to be the destination room
3365 # $dir - The command that we think was responsible for the move ('north', 'up',
3366 # 'cross bridge' etc)
3367 #
3368 # Optional arguments
3369 # $customDir - How the exit is drawn on the map - matches a value in
3370 # GA::Obj::Dict->primaryDirHash (e.g. 'north', 'south', 'up'). If
3371 # 'undef', the exit can't be drawn on the map
3372 # $exitObj - An existing GA::Obj::Exit to use, if known. If none is specified,
3373 # the destination room's ->exitNumHash is consulted to provide it
3374 # $craftyExitObj - Set when called from $self->moveKnownDirSeen, after a hidden exit in
3375 # the departure room has been created in crafty moves mode (this
3376 # function might want to create a twin exit for it)
3377 #
3378 # Return values
3379 # 'undef' on improper arguments
3380 # 1 otherwise
3381  
3382 my (
3383 $self, $departRoomObj, $arriveRoomObj, $fixedFlag, $dir, $customDir, $exitObj,
3384 $craftyExitObj, $check,
3385 ) = @_;
3386  
3387 # Local variables
3388 my (
3389 $standardDir, $result, $msg, $regionmapObj, $oppDir, $oppExitObj, $vectorRef,
3390 $movedRoomObj, $xPosBlocks, $yPosBlocks, $zPosBlocks,
3391 );
3392  
3393 # Check for improper arguments
3394 if (
3395 ! defined $departRoomObj || ! defined $arriveRoomObj || ! defined $fixedFlag
3396 || ! defined $dir || defined $check
3397 ) {
3398 return $axmud::CLIENT->writeImproper($self->_objClass . '->useExistingRoom', @_);
3399 }
3400  
3401 # If $customDir was specified, convert it to a standard primary direction
3402 if ($customDir) {
3403  
3404 $standardDir = $self->session->currentDict->ivShow('combRevDirHash', $customDir);
3405 }
3406  
3407 # If the Locator task has created a non-model room object for the current room, see if
3408 # it matches $arriveRoomObj
3409 # The TRUE argument means that a dark or unspecified non-model room matches any model room
3410 # If $result is FALSE, then $msg contains the error message that we need to display
3411 ($result, $msg) = $self->worldModelObj->compareRooms(
3412 $self->session,
3413 $arriveRoomObj,
3414 undef, # Compare against the Locator task's current room
3415 TRUE, # Match dark rooms
3416 );
3417  
3418 if (! $result) {
3419  
3420 # (Convert $customDir back into a standard direction, if possible)
3421 if ($customDir) {
3422  
3423 $standardDir = $self->session->currentDict->convertStandardDir($customDir);
3424 }
3425  
3426 if (! $standardDir && $exitObj && $exitObj->mapDir) {
3427  
3428 # (If non-primary directorions have been allocated a map direction, use that
3429 # instead)
3430 $standardDir = $exitObj->mapDir;
3431 }
3432  
3433 if (
3434 # If the calling function believes $arriveRoomObj is definitely the arrival room
3435 $fixedFlag
3436 # ...or if the automapper window isn't in 'update' mode
3437 || ! $self->mapWin
3438 || $self->mapWin->mode ne 'update'
3439 # ...or if the departure exit can't actually be drawn on the map using a primary
3440 # direction
3441 || ! $customDir
3442 || ! $standardDir
3443 ) {
3444 # The existing room isn't the one we were expecting, so the automapper is now lost
3445 if ($self->worldModelObj->explainGetLostFlag && $msg) {
3446  
3447 $self->session->writeText('MAP: ' . $msg);
3448 }
3449  
3450 return $self->setCurrentRoom(
3451 undef,
3452 # Character now lost
3453 $self->_objClass . '->useExistingRoom',
3454 # Use auto-rescue mode, if possible (the called function will check whether
3455 # the automapper window is in 'update' mode, or not, before using auto-rescue
3456 # mode)
3457 TRUE,
3458 );
3459 }
3460  
3461 # The existing room isn't the one we were expecting, but it might be possible to slide
3462 # $departRoomObj or $arriveRoomObj into a new position, or to find an empty gridblock
3463 # where the new room can be created
3464 ($xPosBlocks, $yPosBlocks, $zPosBlocks, $movedRoomObj)
3465 = $self->worldModelObj->slideRoom(
3466 $self->session,
3467 TRUE, # Update automapper windows now
3468 $departRoomObj,
3469 $arriveRoomObj,
3470 $standardDir,
3471 );
3472  
3473 if (! defined $xPosBlocks) {
3474  
3475 # The existing room isn't the one we were expecting and it's not possible to slide
3476 # anything around, nor to change where a new room could be created, so the
3477 # automapper is now lost
3478 if ($self->worldModelObj->explainGetLostFlag && $msg) {
3479  
3480 $self->session->writeText('MAP: ' . $msg);
3481 }
3482  
3483 return $self->setCurrentRoom(
3484 undef,
3485 $self->_objClass . '->useExistingRoom', # Character now lost
3486 TRUE, # Use auto-rescue mode, if possible
3487 );
3488  
3489 } elsif (defined $movedRoomObj) {
3490  
3491 # Otherwise, one of two rooms has been slid into a new gridblock, leaving room for
3492 # us to create a new destination room
3493 # Work out the departure room's coordinates on the map
3494 $vectorRef = $self->mapWin->ivShow('constSpecialVectorHash', $standardDir);
3495  
3496 $xPosBlocks = $departRoomObj->xPosBlocks
3497 + ($$vectorRef[0] * $self->worldModelObj->horizontalExitLengthBlocks);
3498 $yPosBlocks = $departRoomObj->yPosBlocks
3499 + ($$vectorRef[1] * $self->worldModelObj->horizontalExitLengthBlocks);
3500 $zPosBlocks = $departRoomObj->zPosBlocks
3501 + ($$vectorRef[2] * $self->worldModelObj->verticalExitLengthBlocks);
3502 }
3503  
3504  
3505 # Set some variables, ready for the call to $self->autoProcessNewRoom
3506 $regionmapObj = $self->worldModelObj->findRegionmap($departRoomObj->parent);
3507  
3508 # Check that we can create a new room and, if so, create it
3509 if (
3510 ! $self->autoProcessNewRoom(
3511 $dir,
3512 $regionmapObj,
3513 $xPosBlocks,
3514 $yPosBlocks,
3515 $zPosBlocks,
3516 $standardDir,
3517 $customDir,
3518 $exitObj,
3519 TRUE, # Bypass the special case checks, go straight to ->createNewRoom
3520 )
3521 ) {
3522 if ($self->worldModelObj->explainGetLostFlag) {
3523  
3524 $self->session->writeText(
3525 'MAP: Lost due to internal error (cannot process new room)',
3526 );
3527 }
3528  
3529 # The presence of a second argument means 'the character is lost'
3530 return $self->setCurrentRoom(
3531 undef,
3532 $self->_objClass . '->useExistingRoom', # Character now lost
3533 FALSE, # Don't use auto-rescue mode
3534 );
3535 }
3536  
3537 } else {
3538  
3539 # The Locator task's room matches $arriveRoomObj. If the Automapper window is open and
3540 # and in 'update' mode, update the map
3541 if ($self->mapWin && $self->mapWin->mode eq 'update') {
3542  
3543 if (
3544 $craftyExitObj
3545 && $standardDir
3546 && $self->worldModelObj->autocompleteExitsFlag
3547 && $arriveRoomObj->wildMode eq 'normal'
3548 ) {
3549 # In crafty moves mode a hidden exit was created from $departRoomObj. Because
3550 # ->autocompleteExitsFlag is set, create a twin exit for it (if an exit in
3551 # the right direction doesn't already exist)
3552 $oppDir = $self->session->currentDict->ivShow(
3553 'combOppDirHash',
3554 $craftyExitObj->dir,
3555 );
3556  
3557 if ($oppDir && ! $arriveRoomObj->ivExists('exitNumHash', $oppDir)) {
3558  
3559 $oppExitObj = $self->worldModelObj->addExit(
3560 $self->session,
3561 FALSE, # Don't update Automapper window yet
3562 $arriveRoomObj,
3563 $oppDir,
3564 $axmud::CLIENT->ivShow('constOppDirHash', $standardDir),
3565 );
3566  
3567 if ($oppExitObj) {
3568  
3569 $self->worldModelObj->setHiddenExit(
3570 FALSE, # Don't update Automapper window yet
3571 $oppExitObj,
3572 TRUE, # Hidden exit
3573 );
3574 }
3575 }
3576 }
3577  
3578 # Connect the two rooms if they're not already connected (and if they are, make
3579 # the exit between them two-way exits)
3580 # NB Don't connect two rooms if either one is in wilderness mode
3581 if (
3582 ($departRoomObj->wildMode eq 'normal' && $arriveRoomObj->wildMode ne 'wild')
3583 || ($arriveRoomObj->wildMode eq 'normal' && $departRoomObj->wildMode ne 'wild')
3584 ) {
3585  
3586 $self->worldModelObj->connectRooms(
3587 $self->session,
3588 TRUE, # Update Automapper windows now (for benefit of $departRoomObj)
3589 $departRoomObj,
3590 $arriveRoomObj,
3591 $dir,
3592 $standardDir,
3593 $exitObj,
3594 );
3595 }
3596 }
3597  
3598 # Update the number of character visits to this room (if allowed)
3599 $self->worldModelObj->updateVisitCount(
3600 $self->session,
3601 # Don't update Automapper windows now (the call to ->updateRoom will do that)
3602 FALSE,
3603 $arriveRoomObj->number,
3604 );
3605  
3606 # Update the arrival room to give it the same properties as the Locator's non-model
3607 # room (where appropriate)
3608 $self->updateRoom($arriveRoomObj);
3609  
3610 # Paint the room, if required to do so
3611 if (
3612 $self->mapWin
3613 && $self->mapWin->painterFlag
3614 && $self->worldModelObj->paintAllRoomsFlag
3615 && $self->mapWin->mode eq 'update'
3616 ) {
3617 $self->mapWin->paintRoom($arriveRoomObj);
3618 }
3619  
3620 # $arriveRoomObj is the new location
3621 $self->setCurrentRoom($arriveRoomObj);
3622  
3623 # Check for room scripts
3624 if ($self->worldModelObj->allowRoomScriptFlag) {
3625  
3626 # Check the GA::ModelObj::Room for Axbasic scripts and, if any are found, execute
3627 # them
3628 foreach my $script ($arriveRoomObj->arriveScriptList) {
3629  
3630 $self->session->pseudoCmd('runscript ' . $script);
3631 }
3632 }
3633  
3634 if ($self->worldModelObj->allowModelScriptFlag) {
3635  
3636 # Check the world model for Axbasic scripts and, if any are found, execute
3637 # them
3638 foreach my $script ($self->worldModelObj->arriveScriptList) {
3639  
3640 $self->session->pseudoCmd('runscript ' . $script);
3641 }
3642 }
3643 }
3644  
3645 return 1;
3646 }
3647  
3648 sub reactRandomExit {
3649  
3650 # Called by $self->moveKnownDirSeen to decide what to do, when the character uses a random
3651 # exit (one whose ->randomType is not 'none')
3652 #
3653 # Expected arguments
3654 # $exitObj - The GA::Obj::Exit used
3655 #
3656 # Return values
3657 # 'undef' on improper arguments or if there's an error calling $self->setCurrentRoom
3658 # 1 otherwise
3659  
3660 my ($self, $exitObj, $check) = @_;
3661  
3662 # Local variables
3663 my (
3664 $regionmapObj, $lostMsg, $regionObj, $originRoomObj, $originMode, $tempObj,
3665 @locateList, @foundList, @selectList,
3666 );
3667  
3668 # Check for improper arguments
3669 if (! defined $exitObj || defined $check) {
3670  
3671 return $axmud::CLIENT->writeImproper($self->_objClass . '->reactRandomExit', @_);
3672 }
3673  
3674 # Get the current room's parent region and regionmap
3675 $regionmapObj = $self->worldModelObj->findRegionmap($self->currentRoom->parent);
3676  
3677 # Random exit type 'same_region' - exit leads to a random location in the same region
3678 if ($exitObj->randomType eq 'same_region') {
3679  
3680 if ($self->worldModelObj->locateRandomInRegionFlag) {
3681  
3682 # Try to locate the new current room. Get a list of room numbers in the current
3683 # region
3684 @locateList = $regionmapObj->ivValues('gridRoomHash');
3685  
3686 # If the region contains more rooms than the locate operation limit, don't try to
3687 # locate the current location, but mark the character as lost
3688 if (
3689 $self->worldModelObj->locateMaxObjects
3690 && $self->worldModelObj->locateMaxObjects < @locateList
3691 ) {
3692 $lostMsg = 'MAP: Lost because the character used a random exit leading to the'
3693 . ' same region, which contains more than '
3694 . $self->worldModelObj->locateMaxObjects . 'rooms';
3695 }
3696  
3697 } else {
3698  
3699 # Write a message that would be displayed, if
3700 # GA::Obj::WorldModel->explainGetLostFlag were set
3701 $lostMsg = 'MAP: Lost because the character used a random exit leading to the same'
3702 . ' region',
3703 }
3704  
3705 # Random exit type 'any_region' - exit leads to a random location anywhere in the world
3706 } elsif ($exitObj->randomType eq 'any_region') {
3707  
3708 if ($self->worldModelObj->locateRandomAnywhereFlag) {
3709  
3710 @locateList = $self->worldModelObj->ivKeys('roomModelHash');
3711  
3712 if (
3713 $self->worldModelObj->locateMaxObjects
3714 && $self->worldModelObj->locateMaxObjects < @locateList
3715 ) {
3716 $lostMsg = 'MAP: Lost because the character used a random exit leading to any'
3717 . ' region, which collectively contain more than '
3718 . $self->worldModelObj->locateMaxObjects . 'rooms';
3719 }
3720  
3721 } else {
3722  
3723 $lostMsg = 'MAP: Lost because the character used a random exit leading to any'
3724 . ' region',
3725 }
3726  
3727 # Random exit type 'temp_region' - exit leads to a destination room in a new temporary
3728 # region
3729 } elsif ($exitObj->randomType eq 'temp_region') {
3730  
3731 # Can only create new rooms when the automapper window is open (can't do it when
3732 # $self->trackAloneFlag is TRUE)
3733 if (! $self->mapWin) {
3734  
3735 $lostMsg = 'MAP: Lost because random exit leads to a temporary region, but can only'
3736 . ' only create new rooms and regions when the automapper window is'
3737 . ' open';
3738  
3739 } else {
3740  
3741 # Create a new temporary region,
3742 $regionObj = $self->worldModelObj->addRegion(
3743 $self->session,
3744 TRUE, # Update Automapper windows now
3745 undef, # Generate a region name
3746 undef, # No parent region
3747 TRUE, # Temporary region
3748 );
3749  
3750 if (! $regionObj) {
3751  
3752 $lostMsg = 'MAP: Lost because random exit leads to a temporary region, but'
3753 . ' could not create a new temporary region',
3754  
3755 } else {
3756  
3757 $originRoomObj = $self->currentRoom;
3758 if ($self->mapWin) {
3759  
3760 $originMode = $self->mapWin->mode;
3761 }
3762  
3763 # Create a new room in the temporary region
3764 $tempObj = $self->worldModelObj->ivShow('regionmapHash', $regionObj->name);
3765 if (
3766 ! $self->createNewRoom(
3767 $tempObj,
3768 $tempObj->getGridCentre(), # Put new room at centre of region
3769 'update', # Switch to 'update' mode
3770 TRUE, # New room is current room
3771 TRUE, # Room takes properties from Locator
3772 )
3773 ) {
3774 $lostMsg = 'MAP: Lost due to internal error (cannot process new room)';
3775  
3776 } else {
3777  
3778 # The automapper window's mode must be switched to 'update', if it's not
3779 # already
3780 if ($self->mapWin && $self->mapWin->mode eq 'follow') {
3781  
3782 $self->mapWin->setMode('update');
3783 }
3784  
3785 # Update IVs, ready for the character to return the original room
3786 $self->ivPoke('tempRandomOriginRoom', $originRoomObj);
3787 $self->ivPoke('tempRandomDestRoom', $self->currentRoom);
3788 $self->ivPoke('tempRandomMode', $originMode);
3789  
3790 # The new current room is already set, so that's the end of the operation
3791 return 1;
3792 }
3793 }
3794 }
3795  
3796 # Random exit type 'room_list' - exit leads to one of a defined list of rooms (no limit to
3797 # the number of rooms to search, in this case)
3798 } else {
3799  
3800 @locateList = $exitObj->randomDestList;
3801 if (! @locateList) {
3802  
3803 $lostMsg = 'MAP: Lost because the character used a random exit with no destination'
3804 . ' rooms set',
3805 }
3806 }
3807  
3808 # Mark the character as lost, if necessary
3809 if ($lostMsg) {
3810  
3811 # Display the message only if the flag is set
3812 if ($self->worldModelObj->explainGetLostFlag) {
3813  
3814 $self->session->writeText($lostMsg);
3815 }
3816  
3817 return $self->setCurrentRoom(
3818 undef,
3819 $self->_objClass . '->reactRandomExit', # Character now lost
3820 TRUE, # Use auto-rescue mode, if possible
3821 );
3822  
3823 } else {
3824  
3825 # Try to locate the new current room. Put any matching rooms into @foundList so that,
3826 # if there is more than one matching room, we can choose which room to use
3827 OUTER: foreach my $roomNum (@locateList) {
3828  
3829 my $roomObj = $self->worldModelObj->ivShow('modelHash', $roomNum);
3830  
3831 if ($self->worldModelObj->locateRoom($self->session, $roomObj)) {
3832  
3833 push (@foundList, $roomObj);
3834  
3835 # For random exit type 3, we use the first room found
3836 if ($exitObj->randomType eq 'room_list') {
3837  
3838 last OUTER;
3839 }
3840 }
3841 }
3842  
3843 if (! @foundList) {
3844  
3845 # No matching rooms found; character is now lost
3846 if ($self->worldModelObj->explainGetLostFlag) {
3847  
3848 $self->session->writeText(
3849 'MAP: Lost because the character used a random exit, but no matching rooms'
3850 . ' were found',
3851 );
3852 }
3853  
3854 return $self->setCurrentRoom(
3855 undef,
3856 $self->_objClass . '->reactRandomExit', # Character now lost
3857 TRUE, # Use auto-rescue mode, if possible
3858 );
3859  
3860 } elsif (@foundList == 1) {
3861  
3862 # This is the new current room
3863 return $self->setCurrentRoom($foundList[0]);
3864  
3865 } else {
3866  
3867 # There is more than one matching room. Select all the matching rooms, so the user
3868 # can decide which to use (if the Automapper window is open)
3869  
3870 if ($self->mapWin) {
3871  
3872 # First unselect any currently selected objects
3873 $self->mapWin->setSelectedObj();
3874  
3875 # Select all of the matching rooms. $self->setSelectedObj expects a list in the
3876 # form:
3877 # (room_object, 'room', room_object, 'room', ...)
3878 foreach my $roomObj (@foundList) {
3879  
3880 push (@selectList, $roomObj, 'room');
3881 }
3882  
3883 $self->mapWin->setSelectedObj(
3884 \@selectList,
3885 TRUE, # Select multiple objects
3886 );
3887 }
3888  
3889 if ($self->worldModelObj->explainGetLostFlag) {
3890  
3891 $self->session->writeText(
3892 'MAP: Lost because the character used a random exit, and there is more than'
3893 . ' one possible new location',
3894 );
3895 }
3896  
3897 return $self->setCurrentRoom(
3898 undef,
3899 $self->_objClass . '->reactRandomExit', # Character now lost
3900 TRUE, # Use auto-rescue mode, if possible
3901 );
3902 }
3903 }
3904 }
3905  
3906 sub updateRoom {
3907  
3908 # Called by $self->moveKnownDirSeen, $self->lookGlanceSeen and $self->createNewRoom in order
3909 # to update the properties of a room object in the world model to match those of the
3910 # Locator task's non-model current room
3911 # If the Automapper window is open and is in 'update' mode, GA::Obj::WorldModel is called
3912 # to do the bulk of the updating
3913 #
3914 # Expected arguments
3915 # $modelRoomObj
3916 # - A GA::ModelObj::Room in the world model
3917 #
3918 # Optional arguments
3919 # $connectRoomObj, $connectExitObj, $mapDir
3920 # - When called by $self->createNewRoom, the room from which we arrived and the exit/
3921 # standard direction used to depart from it (if known). Used when temporarily
3922 # allocating primary directions to unallocated exits
3923 #
3924 # Return values
3925 # 'undef' on improper arguments
3926 # 1 otherwise
3927  
3928 my ($self, $modelRoomObj, $connectRoomObj, $connectExitObj, $mapDir, $check) = @_;
3929  
3930 # Check for improper arguments
3931 if (! defined $modelRoomObj || defined $check) {
3932  
3933 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRoom', @_);
3934 }
3935  
3936 # If the Automapper window is open (and in 'follow' or 'update' mode), or if the Automapper
3937 # window is closed but we're tracking the character's location, update the region's count
3938 # of living and non-living things in the current room
3939 if (
3940 ($self->mapWin && ($self->mapWin->mode eq 'follow' || $self->mapWin->mode eq 'update'))
3941 || (! $self->mapWin && $self->trackAloneFlag)
3942 ) {
3943 $self->worldModelObj->countRoomContents($self->session, $modelRoomObj);
3944 }
3945  
3946 # If the Automapper window is open (and in 'update' room), we can update the room's
3947 # properties
3948 if ($self->mapWin && $self->mapWin->mode eq 'update') {
3949  
3950 $self->worldModelObj->updateRoom(
3951 $self->session,
3952 TRUE, # Update Automapper windows now
3953 $modelRoomObj,
3954 $connectRoomObj,
3955 $connectExitObj,
3956 $mapDir,
3957 );
3958 }
3959  
3960 # Update complete
3961 return 1;
3962 }
3963  
3964 sub autoCompareLocatorRoom {
3965  
3966 # Called by $self->createNewRoom and ->setCurrentRoom
3967 # Compares the Locator's current room against all rooms in the same regionmap. Returns a
3968 # list of all the matching rooms
3969 #
3970 # Expected arguments
3971 # $regionmapObj - The GA::Obj::Regionmap containing the current room
3972 #
3973 # Optional arguments
3974 # $allFlag - If set to TRUE, compares the Locator's current room against all rooms
3975 # in the world model, starting with rooms in $regionmapObj. If FALSE
3976 # (or 'undef'), only rooms in $regionmapObj are compared
3977 # $currentFlag - Set to TRUE when called by $self->setCurrentRoom, in which case the
3978 # Locator's current room should be compared against $self->currentRoom
3979 #
3980 # Return values
3981 # An empty list on improper arguments or if there are no matching rooms
3982 # Otherwise returns a list of blessed references to matching GA::ModelObj::Room objects
3983  
3984 my ($self, $regionmapObj, $allFlag, $currentFlag, $check) = @_;
3985  
3986 # Local variables
3987 my (
3988 $count,
3989 @emptyList, @regionmapList, @returnList, @selectList,
3990 );
3991  
3992 # Check for improper arguments
3993 if (! defined $regionmapObj || defined $check) {
3994  
3995 $axmud::CLIENT->writeImproper($self->_objClass . '->autoCompareLocatorRoom', @_);
3996 return @emptyList;
3997 }
3998  
3999 # Don't do anything if the Locator task isn't running or doesn't know about the current room
4000 if (! $self->session->locatorTask || ! $self->session->locatorTask->roomObj) {
4001  
4002 return @emptyList;
4003 }
4004  
4005 # Compile a list of regionmaps to check
4006 push (@regionmapList, $regionmapObj);
4007 if ($allFlag) {
4008  
4009 foreach my $otherObj (
4010 sort {lc($a->name) cmp lc($b->name)}
4011 ($self->worldModelObj->ivValues('regionmapHash'))
4012 ) {
4013 if ($otherObj ne $regionmapObj) {
4014  
4015 push (@regionmapList, $otherObj);
4016 }
4017 }
4018 }
4019  
4020 # Get a list of rooms in the same regionmap
4021 $count = 0;
4022 OUTER: foreach my $thisRegionmapObj (@regionmapList) {
4023  
4024 my @roomList = $thisRegionmapObj->ivValues('gridRoomHash');
4025 INNER: foreach my $roomNum (@roomList) {
4026  
4027 my ($roomObj, $result);
4028  
4029 $roomObj = $self->worldModelObj->ivShow('modelHash', $roomNum);
4030  
4031 if (! $currentFlag || $self->currentRoom ne $roomObj) {
4032  
4033 # Compare the two rooms
4034 ($result) = $self->worldModelObj->compareRooms($self->session, $roomObj);
4035 if ($result) {
4036  
4037 # $roomObj matches the Locator's current room
4038 push (@returnList, $roomObj);
4039 $count++;
4040  
4041 if (
4042 $self->worldModelObj->autoCompareMax
4043 && $self->worldModelObj->autoCompareMax <= $count
4044 ) {
4045 # We've reached the maximum number of comparisons
4046 last OUTER;
4047 }
4048 }
4049 }
4050 }
4051 }
4052  
4053 if (@returnList) {
4054  
4055 # Select all the matching rooms
4056 # GA::Win::Map->setSelectedObj expects a list in the form
4057 # (room_object, 'room', room_object, 'room', ...)
4058 foreach my $obj (@returnList) {
4059  
4060 push (@selectList, $obj, 'room');
4061 }
4062  
4063 # First unselect all selected objects, then selecting just the matching rooms
4064 if ($self->mapWin->currentRegionmap) {
4065  
4066 $self->mapWin->setSelectedObj();
4067 $self->mapWin->setSelectedObj(
4068 \@selectList,
4069 TRUE, # Select multiple objects
4070 );
4071 }
4072 }
4073  
4074 return @returnList;
4075 }
4076  
4077 sub checkTempRandomReturn {
4078  
4079 # Called by $self->moveKnownDirSeen and ->moveUnknownDirSeen
4080 # If the character moved through a 'temp_region' random exit, check the Locator task's
4081 # current room. If it matches the random exit's parent room, then there's no need to worry
4082 # about updating the map; just move the player back to the original room and destroy the
4083 # temporary region
4084 #
4085 # Expected arguments
4086 # (none besides $self)
4087 #
4088 # Return values
4089 # 'undef' on improper arguments or if the situation described above doesn't apply
4090 # 1 if the the character has been moved back to the original room
4091  
4092 my ($self, $check) = @_;
4093  
4094 # Local variables
4095 my ($result, $originRoom, $destRoom, $mode);
4096  
4097 # Check for improper arguments
4098 if (defined $check) {
4099  
4100 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkTempRandomReturn', @_);
4101 }
4102  
4103 if (
4104 ! $self->session->locatorTask
4105 || ! $self->session->locatorTask->roomObj
4106 || ! $self->tempRandomOriginRoom
4107 ) {
4108 return undef;
4109 }
4110  
4111 ($result) = $self->worldModelObj->compareRooms($self->session, $self->tempRandomOriginRoom);
4112 if (! $result) {
4113  
4114 return undef;
4115 }
4116  
4117 # Reset IVs for the function's we're about to call, keeping a temporary local copy for
4118 # ourselves
4119 $originRoom = $self->tempRandomOriginRoom;
4120 $destRoom = $self->tempRandomDestRoom;
4121 $mode = $self->tempRandomMode;
4122  
4123 $self->ivUndef('tempRandomOriginRoom');
4124 $self->ivUndef('tempRandomDestRoom');
4125 $self->ivUndef('tempRandomMode');
4126  
4127 # Move the character to the original room
4128 $self->setCurrentRoom($originRoom);
4129 # Delete the temporary region we've just moved from
4130 $self->worldModelObj->deleteRegions(
4131 $self->session,
4132 TRUE, # Update automapper now
4133 $self->worldModelObj->ivShow('modelHash', $destRoom->parent),
4134 );
4135  
4136 # If the automapper window is open (and was open, when we first moved through the random
4137 # exit), restore its ->mode
4138 if ($self->mapWin && $mode && $self->mapWin->mode ne $mode) {
4139  
4140 $self->mapWin->setMode($mode);
4141 }
4142  
4143 # Return 1 so the calling function knows it doesn't have to worry about updating the world
4144 # model
4145 return 1;
4146 }
4147  
4148 # 'Connect offline' session mode functions
4149  
4150 sub showPseudoStatement {
4151  
4152 # Called by $self->setCurrentRoom and ->pseudoWorldCmd
4153 # When the current session's ->status is 'offline', we can simulate the room statements that
4154 # the user would see, if the character was actually wandering around the world
4155 # Use the details stored in the current world profile and a specified room model object to
4156 # construct a plausible room statement, and display it in the 'main' window
4157 #
4158 # Expected arguments
4159 # $dictObj - The session's current dictionary
4160 # $modelRoomObj - A GA::ModelObj::Room in the world model
4161 #
4162 # Return values
4163 # 'undef' on improper arguments or if the current world profile doesn't specify room
4164 # statement components for the type of room statement specified by
4165 # $self->pseudoStatementMode
4166 # Otherwise, returns the display buffer line (matches a key in
4167 # GA::Session->displayBufferHash) of the pseudo-statement's anchor line
4168  
4169 my ($self, $dictObj, $modelRoomObj, $check) = @_;
4170  
4171 # Local variables
4172 my (
4173 $worldObj, $wmObj, $string, $anchorOffset, $anchorNum, $bufferAnchorNum,
4174 @componentList, @lineList,
4175 %checkHash,
4176 );
4177  
4178 # Check for improper arguments
4179 if (! defined $dictObj || ! defined $modelRoomObj || defined $check) {
4180  
4181 return $axmud::CLIENT->writeImproper($self->_objClass . '->showPseudoStatement', @_);
4182 }
4183  
4184 # Import the current world profile and world model object (for convenience)
4185 $worldObj = $self->session->currentWorld;
4186 $wmObj = $self->session->worldModelObj;
4187  
4188 # A string to display after the title or verbose descrip components
4189 $string = ' [';
4190 if ($modelRoomObj->roomTag) {
4191  
4192 if ($wmObj->capitalisedRoomTagFlag) {
4193 $string .= uc($modelRoomObj->roomTag) . ' ';
4194 } else {
4195 $string .= $modelRoomObj->roomTag . ' ';
4196 }
4197 }
4198  
4199 $string .= '#' . $modelRoomObj->number . ']';
4200  
4201 # Import a list of room statement components for the type of statement specified by
4202 # $self->pseudoStatementMode
4203 if ($self->pseudoStatementMode eq 'verbose') {
4204  
4205 @componentList = $worldObj->verboseComponentList;
4206 $anchorOffset = $worldObj->verboseAnchorOffset;
4207  
4208 } elsif ($self->pseudoStatementMode eq 'short') {
4209  
4210 @componentList = $worldObj->shortComponentList;
4211 $anchorOffset = $worldObj->shortAnchorOffset;
4212  
4213 } elsif ($self->pseudoStatementMode eq 'brief') {
4214  
4215 @componentList = $worldObj->briefComponentList;
4216 $anchorOffset = $worldObj->briefAnchorOffset;
4217 }
4218  
4219 if (! @componentList) {
4220  
4221 # No room statement components have been specified for this type of room statement
4222 return undef;
4223 }
4224  
4225 # Process each component in turn, constructing a plausible statement constisting of one or
4226 # more lines stored in @lineList
4227 OUTER: foreach my $component (@componentList) {
4228  
4229 my (
4230 $componentObj, $lightStatus, $matchFlag, $titleString, $exitString, $delim,
4231 @descripList, @abbrevList,
4232 );
4233  
4234 # $component can be any custom-named key in GA::Profile::World->componentHash; get the
4235 # corresponding GA::Obj::Component object
4236 $componentObj = $worldObj->ivShow('componentHash', $component);
4237  
4238 # Some worlds might use multiple components of the same type (for example, two
4239 # 'verb_descrip' components)
4240 # Here, we only care about the first occurence of each component type. If $component is
4241 # 'anchor', then there will be no $componentObj, so we first have to check for that
4242 if ($componentObj) {
4243  
4244 if (exists $checkHash{$componentObj->type}) {
4245 next OUTER;
4246 } else {
4247 $checkHash{$componentObj->type} = undef;
4248 }
4249 }
4250  
4251 if ($component eq 'anchor') {
4252  
4253 # We need to remember which line in @lineList is the anchor line.
4254 if ($anchorOffset == -1) {
4255  
4256 # The anchor line shares a line with the component before it
4257 $anchorNum = scalar @lineList;
4258  
4259 } else {
4260  
4261 # The anchor line shares a line with the component after it, or is on its own
4262 # line
4263 $anchorNum = (scalar @lineList + 1);
4264 }
4265  
4266 } elsif ($componentObj->type eq 'verb_title' || $componentObj->type eq 'brief_title') {
4267  
4268 # Use the first available room title
4269 if ($modelRoomObj->titleList) {
4270 push (@lineList, $modelRoomObj->ivFirst('titleList') . $string);
4271 } else {
4272 push (@lineList, '<no room title>' . $string);
4273 }
4274  
4275 # (Only show $string once)
4276 $string = '';
4277  
4278 } elsif ($componentObj->type eq 'verb_descrip') {
4279  
4280 if ($modelRoomObj->descripHash) {
4281  
4282 # Use the verbose description matching the current light status; otherwise, use
4283 # the first verbose description matching a standard light status if possible.
4284 # If all else fails, use a random verbose description
4285 $lightStatus = $wmObj->lightStatus;
4286 if ($modelRoomObj->ivExists('descripHash', $lightStatus)) {
4287  
4288 push (
4289 @lineList,
4290 $modelRoomObj->ivShow('descripHash', $lightStatus) . $string,
4291 );
4292  
4293 } else {
4294  
4295 INNER: foreach my $otherStatus ($wmObj->lightStatusList) {
4296  
4297 if ($modelRoomObj->ivExists('descripHash', $otherStatus)) {
4298  
4299 push (
4300 @lineList,
4301 $modelRoomObj->ivShow('descripHash', $otherStatus),
4302 );
4303  
4304 $matchFlag = TRUE;
4305 last INNER;
4306 }
4307 }
4308  
4309 if (! $matchFlag) {
4310  
4311 # Use a random description
4312 @descripList = $modelRoomObj->ivValues('descripHash');
4313 push (@lineList, $descripList[0] . $string);
4314 }
4315 }
4316  
4317 } else {
4318  
4319 push (@lineList, '<no verbose description>' . $string);
4320 }
4321  
4322 # (Only show $string once)
4323 $string = '';
4324  
4325 } elsif ($componentObj->type eq 'verb_exit') {
4326  
4327 $exitString = 'Exits: ';
4328  
4329 if ($modelRoomObj->sortedExitList) {
4330 $exitString .= join(', ', $modelRoomObj->sortedExitList);
4331 } else {
4332 $exitString .= '<no exits>';
4333 }
4334  
4335 push (@lineList, $exitString);
4336  
4337 } elsif (
4338 $componentObj->type eq 'verb_content'
4339 || $componentObj->type eq 'brief_content'
4340 ) {
4341 # No way to tell whether the patterns in GA::Profile::World->contentPatternList
4342 # appear at the beginning of a line, in the middle or at the end, so just display
4343 # a straight list of objects
4344 INNER: foreach my $number ($modelRoomObj->ivKeys('childHash')) {
4345  
4346 my $obj = $wmObj->ivShow('modelHash', $number);
4347  
4348 if ($obj->baseString) {
4349 push(@lineList, ucfirst ($obj->name) . ' (' . $obj->baseString . ')');
4350 } elsif ($obj->name) {
4351 push (@lineList, ucfirst($obj->name));
4352 }
4353 }
4354  
4355 } elsif (
4356 $componentObj->type eq 'brief_exit'
4357 || $componentObj->type eq 'brief_title_exit'
4358 || $componentObj->type eq 'brief_exit_title'
4359 ) {
4360 # Get a room title and an exit list, then combine them into a single string, in the
4361 # right order
4362 $titleString = '';
4363 $exitString = '';
4364  
4365 # Use the first available room title
4366 if ($modelRoomObj->titleList) {
4367 $titleString = $modelRoomObj->ivFirst('titleList');
4368 } else {
4369 $titleString = '<no room title>';
4370 }
4371  
4372 # Get a list of exits
4373 if ($worldObj->briefExitDelimiterList) {
4374 $delim = $worldObj->ivFirst('briefExitDelimiterList');
4375 } else {
4376 $delim = ' '; # Last resort - use a space between exits
4377 }
4378  
4379 # if ($worldObj->briefExitLeftMarkerList) {
4380 #
4381 # $exitString .= $worldObj->ivFirst('briefExitLeftMarkerList');
4382 # }
4383  
4384 if ($modelRoomObj->sortedExitList) {
4385  
4386 # Convert exits to their abbreviated forms, if possible
4387 foreach my $exitName ($modelRoomObj->sortedExitList) {
4388  
4389 push (@abbrevList, $dictObj->abbrevDir($exitName));
4390 }
4391  
4392 $exitString .= join($delim, @abbrevList);
4393  
4394 } else {
4395  
4396 $exitString .= '<no exits>';
4397 }
4398  
4399 # if ($worldObj->briefExitRightMarkerList) {
4400 #
4401 # $exitString .= $worldObj->ivFirst('briefExitRightMarkerList');
4402 # }
4403  
4404 # Combine the strings in the right order
4405 if ($componentObj->type eq 'brief_exit') {
4406 push (@lineList, $exitString);
4407 } elsif ($componentObj->type eq 'brief_title_exit') {
4408 push (@lineList, $titleString . ' / ' . $exitString);
4409 } elsif ($componentObj->type eq 'brief_exit_title') {
4410 push (@lineList, $exitString . ' / ' . $titleString);
4411 }
4412  
4413 } elsif ($componentObj->type eq 'mudlib_path') {
4414  
4415 if ($modelRoomObj->sourceCodePath) {
4416 push (@lineList, $modelRoomObj->sourceCodePath);
4417 } else {
4418 push (@lineList, '<no path>');
4419 }
4420 }
4421 }
4422  
4423 if (@lineList) {
4424  
4425 # Insert an empty line, so that there's a gap between room statements
4426 $self->session->processIncomingData("\n");
4427  
4428 # Display the pseudo-room statement in the 'main' window
4429 for (my $count = 0; $count < scalar @lineList; $count++) {
4430  
4431 my $line = $lineList[$count];
4432  
4433 # If the regexes used to compose $line used an initial ^ or a final $ character,
4434 # remove them
4435 if (substr($line, 0, 1) eq '^') {
4436  
4437 $line = substr($line, 1);
4438 }
4439  
4440 # Also swap any '\ ' special characters for plain spaces
4441 $line =~ s/\\ / /g;
4442  
4443 if (substr($line, -1, 1) eq '$') {
4444  
4445 $line = substr($line, 0, ((length $line) - 1));
4446 }
4447  
4448 $self->session->processIncomingData("$line\n");
4449  
4450 if ($count == $anchorNum) {
4451  
4452 # This was the anchor line; remember the line's number in the display buffer
4453 $bufferAnchorNum = $self->session->displayBufferCount;
4454 }
4455 }
4456  
4457 } else {
4458  
4459 # If all else fails, show this bare-bones room statement
4460 $self->session->processIncomingData(
4461 '<current room #' . $modelRoomObj->number . ' \'' . $modelRoomObj->name . "\'>\n",
4462 );
4463 }
4464  
4465 if (! defined $bufferAnchorNum) {
4466  
4467 # As an emergency fallback, use the last line of the pseudo-statement as the anchor line
4468 $bufferAnchorNum = $self->session->displayBufferCount;
4469 }
4470  
4471 return $bufferAnchorNum;
4472 }
4473  
4474 sub pseudoWorldCmd {
4475  
4476 # Called by GA::Session->dispatchCmd, ->checkRedirect or ->checkAssisted, when the
4477 # session's status is 'offline', and when this automapper has a ->currentRoom set
4478 # The most recently-processed world command has been stored in the session's command buffer;
4479 # the buffer object may consist of one or more commands, depending on whether assisted
4480 # moves were processed
4481 # If the world command from which the buffer object was created (i.e. the command after
4482 # processing by aliases, but before processing by redirect mode / assisted moves) matches
4483 # any of the current room's exits, simulate a move using that exit
4484 #
4485 # Expected arguments
4486 # (none besides $self)
4487 #
4488 # Optional arguments
4489 # $cmdObj - The GA::Buffer::Cmd object created for the world command. If 'undef', this
4490 # function finds it
4491 #
4492 # Return values
4493 # 'undef' on improper arguments or if no simulated move occurs
4494 # 1 otherwise
4495  
4496 my ($self, $cmdObj, $check) = @_;
4497  
4498 # Local variables
4499 my (
4500 $dictObj, $tempType, $dir, $exitObj, $primaryDir, $dirType, $exitNum, $destRoomObj,
4501 $msg, $anchorLine,
4502 );
4503  
4504 # Check for improper arguments
4505 if (defined $check) {
4506  
4507 return $axmud::CLIENT->writeImproper($self->_objClass . '->pseudoWorldCmd', @_);
4508 }
4509  
4510 # Find the command buffer object, if not specified
4511 if (! $cmdObj) {
4512  
4513 $cmdObj = $self->session->ivShow(
4514 'cmdBufferHash',
4515 $self->session->cmdBufferLast,
4516 );
4517 }
4518  
4519 # Import the current dictionary
4520 $dictObj = $self->session->currentDict;
4521  
4522 # (The rest of the function is adapted from $self->moveKnownDirSeen)
4523  
4524 # Do nothing if:
4525 # 1. The Automapper window is open and is in 'wait' mode
4526 # 2. The Automapper window isn't open, and $self->trackAloneFlag is FALSE
4527 # 3. The current room isn't known (regardless of whether the Automapper window is open)
4528 # 4. The command buffer object wasn't created by a look, glance or movement command
4529 if (
4530 ($self->mapWin && $self->mapWin->mode eq 'wait')
4531 || (! $self->mapWin && ! $self->trackAloneFlag)
4532 || ! $self->currentRoom
4533 || (! $cmdObj->moveFlag && ! $cmdObj->lookFlag && ! $cmdObj->glanceFlag)
4534 ) {
4535 return undef;
4536 }
4537  
4538 # For look/glance commands, re-display the current room's pseudo-room statement
4539 if ($cmdObj->lookFlag || $cmdObj->glanceFlag) {
4540  
4541 # Temporarily alter the value stored in $self->pseudoStatementMode, so that we can show
4542 # a verbose (or short verbose) room statement in response to a 'look' command, and
4543 # a brief statement in response to a 'glance' command (but only if those types of
4544 # room statement are available in the current world profile)
4545 if (
4546 ($self->pseudoStatementMode eq 'verbose' || $self->pseudoStatementMode eq 'short')
4547 && $cmdObj->glanceFlag
4548 && $self->session->currentWorld->briefComponentList
4549 ) {
4550 $tempType = $self->pseudoStatementMode;
4551 $self->ivPoke('pseudoStatementMode', 'brief')
4552  
4553 } elsif (
4554 $self->pseudoStatementMode eq 'brief'
4555 && $cmdObj->lookFlag
4556 && $self->session->currentWorld->verboseComponentList
4557 ) {
4558 $tempType = 'brief';
4559 $self->ivPoke('pseudoStatementMode', 'verbose')
4560 }
4561  
4562 $anchorLine = $self->showPseudoStatement($dictObj, $self->currentRoom);
4563 if (! defined $anchorLine) {
4564  
4565 # Could not produce a pseudo-room statement because no room statement components
4566 # of the statement type specified by $self->pseudoStatementMode are available
4567 # In this unlikely situation, mark the character as lost
4568 return $self->setCurrentRoom(
4569 undef,
4570 $self->_objClass . '->pseudoWorldCmd',
4571 FALSE, # Don't use auto-rescue mode
4572 );
4573 }
4574  
4575 # The Locator task normally creates a non-model room when it spots a room statement.
4576 # Instruct it create a non-model room based on $newRoomObj, and tell it to not look
4577 # for room statements in the text just displayed by the call to ->showPseudoStatement
4578 # (It's necessary to do this, even though the new non-model room will probably be
4579 # identical to the first one - it stops the Locator from looking for anchor lines
4580 # in the text produced by the call to ->showPseudoStatement)
4581 $self->session->locatorTask->usePseudoStatement(
4582 $dictObj,
4583 $self->currentRoom,
4584 $anchorLine,
4585 );
4586  
4587 # Restore the old value of $self->pseudoStatementMode, if it was temporarily changed
4588 if (defined $tempType) {
4589  
4590 $self->ivPoke('pseudoStatementMode', $tempType);
4591 }
4592  
4593 return 1;
4594 }
4595  
4596 # Set $dir, the direction of movement, so that we can work out which exit object is being
4597 # used. For assisted moves, we already know the exit object used (which will save us some
4598 # time)
4599 if ($cmdObj->assistedFlag) {
4600  
4601 $dir = $cmdObj->cmd;
4602 $exitObj = $cmdObj->assistedExitObj;
4603 $primaryDir = $cmdObj->assistedPrimary;
4604  
4605 } else {
4606  
4607 # For redirect mode commands, use the original command, which should contain only a
4608 # direction
4609 if ($cmdObj->redirectFlag) {
4610  
4611 $dir = $cmdObj->cmd;
4612  
4613 # For normal movement commands, the direction of movement has been stripped from
4614 # $cmdObj->cmd and stored in ->moveDir
4615 } else {
4616  
4617 $dir = $cmdObj->moveDir;
4618 }
4619  
4620 # If $dir is a primary direction, get the standard primary direction
4621 if ($dictObj->ivExists('combDirHash', $dir)) {
4622  
4623 $dirType = $dictObj->ivShow('combDirHash', $dir);
4624 if ($dirType eq 'primaryDir' || $dirType eq 'primaryAbbrev') {
4625  
4626 $primaryDir = $dictObj->ivShow('combRevDirHash', $dir);
4627 }
4628 }
4629  
4630 # Check the current room's exits. Does an exit in this direction already exist?
4631 if ($self->currentRoom->ivExists('exitNumHash', $dir)) {
4632  
4633 $exitNum = $self->currentRoom->ivShow('exitNumHash', $dir);
4634 $exitObj = $self->worldModelObj->ivShow('exitModelHash', $exitNum);
4635  
4636 # Otherwise, if $dir is a primary direction, see if an existing exit from the current
4637 # room has the same drawn map direction
4638 } elsif ($primaryDir) {
4639  
4640 OUTER: foreach my $number ($self->currentRoom->ivValues('exitNumHash')) {
4641  
4642 my $otherExitObj = $self->worldModelObj->ivShow('exitModelHash', $number);
4643  
4644 if (
4645 $otherExitObj->mapDir
4646 && $otherExitObj->mapDir eq $primaryDir
4647 # Don't leave using an exit attached to a shadow exit; leave via the
4648 # shadow exit instead)
4649 && (! $otherExitObj->shadowExit)
4650 ) {
4651 $exitObj = $otherExitObj;
4652 last OUTER;
4653 }
4654 }
4655 }
4656 }
4657  
4658 if (! $exitObj) {
4659  
4660 # Failsafe - do nothing if no exit found
4661 return undef;
4662  
4663 # In 'connect offline' mode, movements through exits which are marked impassable/mystery,
4664 # which are random exits or which have no destination room mean that the character is now
4665 # 'lost'
4666 } elsif (
4667 $exitObj->exitOrnament eq 'impass'
4668 || $exitObj->exitOrnament eq 'mystery'
4669 || $exitObj->randomType ne 'none'
4670 || ! $exitObj->destRoom
4671 ) {
4672 # Show an explanation, if allowed
4673 if ($self->worldModelObj->explainGetLostFlag) {
4674  
4675 if ($exitObj->exitOrnament eq 'impass') {
4676  
4677 $msg = 'MAP: Lost because the character used an exit marked as \'impassable\'';
4678  
4679 } elsif ($exitObj->exitOrnament eq 'mystery') {
4680  
4681 $msg = 'MAP: Lost because the character used an exit marked as \'mystery\'';
4682  
4683 } elsif ($exitObj->randomType ne 'none') {
4684  
4685 $msg = 'MAP: Lost because the character used a random exit while in \'connect'
4686 . ' offline\' mode';
4687  
4688 } else {
4689  
4690 $msg = 'MAP: Lost because the character used an exit with no destination in'
4691 . ' \'connect offline\' mode';
4692 }
4693  
4694 $self->session->writeText($msg);
4695 }
4696  
4697 # The TRUE argument means 'the character is lost'
4698 return $self->setCurrentRoom(
4699 undef,
4700 $self->_objClass . '->pseudoWorldCmd', # Defined string marks character as lost
4701 FALSE, # Don't use auto-rescue mode
4702 );
4703  
4704 } else {
4705  
4706 # Get the destination room
4707 $destRoomObj = $self->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
4708 # Simulate the world sending the new room statement to us
4709 $anchorLine = $self->showPseudoStatement($dictObj, $destRoomObj);
4710  
4711 # The Locator task normally creates a non-model room when it spots a room statement.
4712 # Instruct it create a non-model room based on $newRoomObj, and tell it to not look
4713 # for room statements in the text just displayed by the call to ->showPseudoStatement
4714 $self->session->locatorTask->usePseudoStatement($dictObj, $destRoomObj, $anchorLine);
4715 # $destRoomObj is the new location
4716 $self->setCurrentRoom($destRoomObj);
4717  
4718 return 1;
4719 }
4720 }
4721  
4722 ##################
4723 # Accessors - set
4724  
4725 sub set_facingDir {
4726  
4727 my ($self, $dir, $check) = @_;
4728  
4729 # Check for improper arguments
4730 if (defined $check) {
4731  
4732 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_facingDir', @_);
4733 }
4734  
4735 # If $dir is specified, check it's one of the permitted standard primary directiosn
4736 if (
4737 defined $dir
4738 && (
4739 ! $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $dir)
4740 || $dir eq 'up'
4741 || $dir eq 'down'
4742 )
4743 ) {
4744 return undef;
4745 }
4746  
4747 # Update IVs
4748 $self->ivPoke('facingDir', $dir); # Can be 'undef', but otherw
4749  
4750 return 1;
4751 }
4752  
4753 sub set_mapWin {
4754  
4755 my ($self, $winObj, $check) = @_;
4756  
4757 # Check for improper arguments
4758 if (defined $check) {
4759  
4760 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_mapWin', @_);
4761 }
4762  
4763 # Update IVs
4764 $self->ivPoke('mapWin', $winObj); # Can be 'undef'
4765  
4766 return 1;
4767 }
4768  
4769 sub set_pseudoStatementMode {
4770  
4771 my ($self, $mode, $check) = @_;
4772  
4773 # Check for improper arguments
4774 if (! defined $mode || defined $check) {
4775  
4776 return $axmud::CLIENT->writeImproper(
4777 $self->_objClass . '->set_pseudoStatementMode',
4778 @_,
4779 );
4780 }
4781  
4782 if ($mode ne 'verbose' && $mode ne 'short' && $mode ne 'brief') {
4783  
4784 return undef;
4785  
4786 } else {
4787  
4788 $self->ivPoke('pseudoStatementMode', $mode);
4789 return 1;
4790 }
4791 }
4792  
4793 sub reset_rescueCheckFlag {
4794  
4795 # Called by GA::Obj::WorldModel->mergeMap
4796  
4797 my ($self, $check) = @_;
4798  
4799 # Check for improper arguments
4800 if (defined $check) {
4801  
4802 return $axmud::CLIENT->writeImproper(
4803 $self->_objClass . '->reset_rescueCheckFlag',
4804 @_,
4805 );
4806 }
4807  
4808 if ($self->rescueCheckFlag) {
4809  
4810 # Fire any hooks that are using the 'map_rescue_merge' hook event
4811 $self->session->checkHooks('map_rescue_merge');
4812 }
4813  
4814 $self->ivPoke('rescueCheckFlag', FALSE);
4815  
4816 return 1;
4817 }
4818  
4819 sub reset_rescueRegion {
4820  
4821 # Called by GA::Obj::WorldModel->deleteRegions, when a region matching one of the following
4822 # IVs is deleted
4823 # Also called by numerous GA::Obj::Map and GA::Obj::Win functions to disactivate auto-rescue
4824 # mode
4825  
4826 my ($self, $check) = @_;
4827  
4828 # Check for improper arguments
4829 if (defined $check) {
4830  
4831 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_rescueRegion', @_);
4832 }
4833  
4834 # Show a confirmation, if auto-rescue mode was activated
4835 if ($self->rescueLostRegionObj) {
4836  
4837 $self->session->writeText('MAP: Auto-rescue mode disactivated');
4838  
4839 # Fire any hooks that are using the 'map_rescue_off' hook event
4840 $self->session->checkHooks('map_rescue_off');
4841 }
4842  
4843 if (
4844 $self->rescueFollowFlag
4845 && $self->mapWin
4846 && $self->mapWin->mode eq 'update'
4847 ) {
4848 # Switch back to 'follow' mode, which was the mode in use when auto-rescue mode was
4849 # activated
4850 $self->mapWin->setMode('follow');
4851 }
4852  
4853 # Reset IVs
4854 $self->ivPoke('rescueFollowFlag', FALSE);
4855 $self->ivUndef('rescueLostRegionObj');
4856 $self->ivUndef('rescueTempRegionObj');
4857 $self->ivPoke('rescueCheckFlag', FALSE);
4858  
4859 return 1;
4860 }
4861  
4862 sub reset_tempRandom {
4863  
4864 # Called by GA::Obj::WorldModel->deleteObj, when a room matching one of the following IVs
4865 # is deleted
4866 # Also called by $self->set_trackAloneFlag
4867 # In that case, we can forget about returning to the original location
4868  
4869 my ($self, $check) = @_;
4870  
4871 # Check for improper arguments
4872 if (defined $check) {
4873  
4874 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_tempRandom', @_);
4875 }
4876  
4877 # Just reset the IVs and forget about them
4878 $self->ivUndef('tempRandomOriginRoom');
4879 $self->ivUndef('tempRandomDestRoom');
4880 $self->ivUndef('tempRandomMode');
4881  
4882 return 1;
4883 }
4884  
4885 sub set_trackAloneFlag {
4886  
4887 # Called by GA::Win::Map to make sure the value of $self->trackAloneFlag is correct when
4888 # the window opens/closes
4889  
4890 my ($self, $flag, $check) = @_;
4891  
4892 # Check for improper arguments
4893 if (! defined $flag || defined $check) {
4894  
4895 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_trackAloneFlag', @_);
4896 }
4897  
4898 # If the character previously moved through a 'temp_region' random exit into a temporary
4899 # region, we can simply delete the temporary region when the automapper window closes
4900 if ($self->tempRandomOriginRoom) {
4901  
4902 # Delete the temporary region. If $self->currentRoom was in that region, it's reset too
4903 $self->worldModelObj->deleteRegions(
4904 $self->session,
4905 FALSE, # Don't update automapper yet
4906 $self->worldModelObj->ivShow('modelHash', $self->tempRandomDestRoom->parent),
4907 );
4908  
4909 # Reset IVs
4910 $self->ivUndef('tempRandomOriginRoom');
4911 $self->ivUndef('tempRandomDestRoom');
4912 $self->ivUndef('tempRandomMode');
4913  
4914 # There's no longer any position to track
4915 $flag = FALSE;
4916 }
4917  
4918 if ($flag) {
4919 $self->ivPoke('trackAloneFlag', TRUE);
4920 } else {
4921 $self->ivPoke('trackAloneFlag', FALSE);
4922 }
4923  
4924 # Reset other IVs when the window opens/closes
4925 $self->reset_tempRandom();
4926 $self->reset_rescueRegion();
4927  
4928 return 1;
4929 }
4930  
4931 sub set_worldModelObj {
4932  
4933 my ($self, $worldModelObj, $check) = @_;
4934  
4935 # Check for improper arguments
4936 if (! defined $worldModelObj || defined $check) {
4937  
4938 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_worldModelObj', @_);
4939 }
4940  
4941 $self->ivPoke('worldModelObj', $worldModelObj);
4942  
4943 # Reset the current room
4944 $self->setCurrentRoom();
4945  
4946 # Inform the Automapper window, if it is open
4947 if ($self->mapWin) {
4948  
4949 $self->mapWin->set_worldModelObj($worldModelObj);
4950 }
4951  
4952 return 1;
4953 }
4954  
4955 ##################
4956 # Accessors - get
4957  
4958 sub session
4959 { $_[0]->{session} }
4960 sub worldModelObj
4961 { $_[0]->{worldModelObj} }
4962 sub mapWin
4963 { $_[0]->{mapWin} }
4964  
4965 sub currentRoom
4966 { $_[0]->{currentRoom} }
4967 sub lastKnownRoom
4968 { $_[0]->{lastKnownRoom} }
4969 sub ghostRoom
4970 { $_[0]->{ghostRoom} }
4971  
4972 sub facingDir
4973 { $_[0]->{facingDir} }
4974  
4975 sub trackAloneFlag
4976 { $_[0]->{trackAloneFlag} }
4977 sub pseudoStatementMode
4978 { $_[0]->{pseudoStatementMode} }
4979  
4980 sub tempRandomOriginRoom
4981 { $_[0]->{tempRandomOriginRoom} }
4982 sub tempRandomDestRoom
4983 { $_[0]->{tempRandomDestRoom} }
4984 sub tempRandomMode
4985 { $_[0]->{tempRandomMode} }
4986  
4987 sub currentMatchFlag
4988 { $_[0]->{currentMatchFlag} }
4989 sub currentMatchList
4990 { my $self = shift; return @{$self->{currentMatchList}}; }
4991  
4992 sub rescueFollowFlag
4993 { $_[0]->{rescueFollowFlag} }
4994 sub rescueLostRegionObj
4995 { $_[0]->{rescueLostRegionObj} }
4996 sub rescueTempRegionObj
4997 { $_[0]->{rescueTempRegionObj} }
4998 sub rescueCheckFlag
4999 { $_[0]->{rescueCheckFlag} }
5000 }
5001  
5002 # Package must return a true value
5003 1