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

filter: Statementstmt 0.0% 0 / 6792 Branchbran 0.0% 0 / 3082 Conditioncond 0.0% 0 / 3270 MC/DCmcdc 0.0% 0 / 1718 Subroutinesub 0.0% 0 / 477 Podpod 0.0% 0 / 474 totaltotal 0.0% 0 / 15813 CC 1542 SCAR 66.0
CC
1542
Cov
0%
testModel
7482.0
parseObj
5256.0
connectRegionBrokenExit
1560.0
CRAP 732.5
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::WorldModel
16 # Handles the world model
17  
18 { package Games::Axmud::Obj::WorldModel;
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 # Create a new instance of the (main) world model object
35 #
36 # Expected arguments
37 # $session - The calling GA::Session (not stored as an IV)
38 #
39 # Return values
40 # 'undef' on improper arguments or if $name is invalid
41 # Blessed reference to the newly-created object on success
42  
43 my ($class, $session, $check) = @_;
44  
45 # Check for improper arguments
46 if (! defined $class || ! defined $session || defined $check) {
47  
48 return $axmud::CLIENT->writeImproper($class . '->new', @_);
49 }
50  
51 # Setup
52 my $self = {
53 _objName => 'world_model',
54 _objClass => $class,
55 _parentFile => 'worldmodel',
56 _parentWorld => $session->currentWorld->name,
57 _privFlag => TRUE, # All IVs are private
58  
59 # Main IVs
60 # --------
61  
62 # Four IVs to allow an author to claim ownership of their maps
63 author => undef, # Max 128 chars
64 date => undef, # Max 64 chars
65 version => undef, # Max 64 chars
66 descripList => [], # Lines Displayed in a TextView
67  
68 # Four additional IVs not set by the user
69 # The actual date on which this world model was created. This IV was added in v1.0.223,
70 # so for models created before that, the date of the original Axmud release (Thu 31
71 # July 2014) is used
72 modelCreationDate => $axmud::CLIENT->localDate(),
73 # The Axmud version when this world model was created. This IV was added in v1.0.223, so
74 # for models created before that, the value is set to 1.0.0 by
75 # GA::Obj::File->updateExtractedData
76 modelCreationVersion => $axmud::VERSION,
77 # Flag set to TRUE if the world model has been converted from another client, set to
78 # FALSE otherwise. (This IV is not currently used, but might be, in the future, so
79 # that early attemps to convert files can be corrected by later versions)
80 modelConvertedFlag => FALSE,
81 # The other client's version, set if known ('undef' otherwise)
82 modelConvertedVersion => undef,
83 # Large world models can cause 'out of memory' errors on low-spec machines. The
84 # problem is not that the world model takes up too much memory, but that the Perl
85 # Storable module struggles to load very large files into memory
86 # Since v1.1.529, the world model is saved either as a monolithic file (as previously),
87 # or as multiple files, all of which are handled by a single file object
88 # The number of files used to store this world model, the last time it was saved. If 0,
89 # a single monolithic file was used
90 modelSaveFileCount => 0,
91  
92 # IVs for the world model
93 # -----------------------
94  
95 # Axmud creates a 'model' of the world. Each object in the model has a unique number.
96 # The first object created is #1. When objects are deleted from the model, the number
97 # is available for re-use
98 # Types of model objects are: 'region' (an area of a world), 'room' (a location in the
99 # world), 'weapon' (all weapon objects), 'armour' (all protective objects), 'garments'
100 # (all wearable non-protective objects), 'char' (for player characters), 'minion' (for
101 # non-player characters/NPCs controlled by the user), 'sentient' (for NPCs capable of
102 # speech, at least in theory), 'creature' (for NPCS not capable of speech, at least in
103 # theory) 'portable' (for all non-living things that can, in theory, be picked up),
104 # 'decoration' (for all non-living things that can not, in theory, be picked up),
105 # 'custom' (any other kind of object)
106 #
107 # Model objects have a core set of properties set by GA::Generic::ModelObj
108 # Some groups of objects have their own set of shared properties also set by
109 # GA::Generic::ModelObj
110 # Alongside the world model is an exit model, which contains all exits used by rooms in
111 # the model. Every exit has a unique number in the exit model. The first exit created
112 # is #1
113 # World model commands use the following switches:
114 # -n region, -r room, -w weapon, -a armour, -g garment, -c char, -m minion,
115 # -s sentient, -k creature, -p portable, -d decoration, -u custom, -x exit
116 #
117 # Model objects are all given a ->name (max length 32 chars). For room model objects,
118 # the name is the brief description (if available), or a shortened version of the
119 # verbose description (if not). Names do not have to be unique (except for regions and
120 # characters; e.g. there can only be one GA::ModelObj::Char whose ->name is 'Gandalf')
121 #
122 # Model objects can have a parent model object and any number of child model objects.
123 # In general, parent objects are used to 'contain' child objects. The rules for
124 # parents/children are:
125 # 1. Regions can have no parent, or their parent can be another region
126 # 2. Regions can have no children, or can have any model object(s) as children
127 # (including other regions)
128 # 3. Rooms must have a region parent; there are no orphan rooms
129 # 4. Rooms can have no children, or can have any model object(s) as children (except
130 # regions and rooms, which cannot be children of a room)
131 # 5. Other model objects can have no parent or children, or can have any model
132 # object(s) as parents or children
133 # 6. No model object can have itself as a parent or child
134 # Exit objects in the exit model have different rules:
135 # 1. Exit model objects always have a parent room, and never have children
136 # 2. The parent room doesn't count its exits as being one of its children
137 #
138 # The world model itself. A hash in the form
139 # $modelHash{number} = blessed_reference_to_model_object
140 modelHash => {},
141 # For convenience, registry hashes of all categories of model object. If these hashes
142 # were combined, the combined hash would be exactly the same as $self->modelHash
143 regionModelHash => {},
144 roomModelHash => {},
145 weaponModelHash => {},
146 armourModelHash => {},
147 garmentModelHash => {},
148 charModelHash => {},
149 minionModelHash => {},
150 sentientModelHash => {},
151 creatureModelHash => {},
152 portableModelHash => {},
153 decorationModelHash => {},
154 customModelHash => {},
155 #
156 # The number of objects in $self->modelHash (included deleted objects whose ->number has
157 # not been re-used)
158 modelObjCount => 0,
159 # The number of objects in $self->modelHash (doesn't include deleted objects, so this
160 # value is the actual number of objects it contains)
161 modelActualCount => 0,
162 # Deleted objects can have their numbers re-used. This list contains the numbers of all
163 # deleted objects which haven't yet been reused; when a new model object is created,
164 # it gets a number from the first element in this list. If the list is empty, the
165 # number used is $self->modelObjCount + 1
166 modelDeletedList => [],
167 # To avoid having an object being deleted and having its number almost immediately
168 # re-used - which could cause an unintentional error, if an old object is confused for
169 # a new one - $self->deleteObj stores the numbers of deleted objects here,
170 # temporarily
171 # GA::Session->spinMaintainLoop calls $self->updateModelBuffers, which copies them
172 # into $self->modelDeletedList on every spin of the loop. In this way, numbers don't
173 # become available for re-use until after an operation is complete
174 modelBufferList => [],
175 # Number of the most recently-created model object (may since have been deleted from the
176 # model; 'undef' if no object ever deleted)
177 mostRecentNum => undef,
178  
179 # The exit model
180 # Model objects have a ->name, but exit model objects use ->dir as an equivalent. The
181 # maximum length is 32 chars. Hash in the form
182 # $exitModelHash{number} = blessed_reference_to_exit_object
183 exitModelHash => {},
184 # The number of exit objects in $self->exitModelHash (includes deleted exit objects
185 # whose ->number has not been re-used)
186 exitObjCount => 0,
187 # The number of exit objects in $self->exitModelHash (doesn't include deleted exit
188 # objects, so this value is the actual number of exit objects it contains)
189 exitActualCount => 0,
190 # Deleted exit objects can have their numbers re-used. This list contains the numbers of
191 # all deleted exit objects which haven't yet been reused; when a new model object is
192 # created, it gets a number from the first element in this list. If the list is empty,
193 # the number used is $self->exitObjCount + 1
194 exitDeletedList => [],
195 # To avoid having an exit being deleted and having its number almost immediately
196 # re-used - which could cause an unintentional error, if an old exit is confused for
197 # a new one - $self->deleteExits stores the numbers of deleted exits here,
198 # temporarily
199 # GA::Session->spinMaintainLoop calls $self->updateModelBuffers, which copies them
200 # into $self->exitDeletedList on every spin of the loop. In this way, numbers don't
201 # become available for re-use until after an operation is complete
202 exitBufferList => [],
203 # Number of the most recently-created exit object (may since have been deleted from the
204 # model; 'undef' if no exit object ever deleted)
205 mostRecentExitNum => undef,
206  
207 # Hash of GA::Obj::Regionmap objects, in the form
208 # $regionmapHash{'region_name'} = blessed_reference_to_regionmap_object
209 regionmapHash => {},
210 # Flag set to TRUE, if the list of regions in the treeview should be displayed in
211 # reverse alphabetical order (set to FALSE to display them in the normal order)
212 reverseRegionListFlag => FALSE,
213 # The name of the region which should be displayed at the top of the list (even if the
214 # list is reversed). If set to 'undef', no region is automatically shown at the top of
215 # the list
216 firstRegion => undef,
217  
218 # IVs which set how the automapper window handles pre-drawing of regions
219 # Flag set to TRUE if pre-drawing should occur at all, FALSE if no pre-drawing should
220 # occur
221 preDrawAllowFlag => TRUE,
222 # When the automapper opens, check all regions; any that have this many rooms in them
223 # are added to the queue to be drawn by background processes (i.e. regular calls to
224 # GA::Win::Map->winUpdate)
225 # Must be an integer, 0 or above. If 0, all regions are added to the queue
226 # If $self->firstRegion is set and it contains the minimum number of rooms, it's added
227 # to the queue first
228 preDrawMinRooms => 500,
229 # When a new current region is set, the old current region's canvas widget and canvas
230 # objects are retained in memory, so they don't have to be redrawn again, if they
231 # contain at least this many rooms
232 # Must be an integer, 0 or above. If 0, all regions are retained in memory
233 # Otherwise, the canvas objects are destroyed and the canvas widgets are recycled for
234 # the next region which doesn't have at least this many rooms
235 preDrawRetainRooms => 500,
236 # What percentage of the available processor time should be allocated to pre-drawing
237 # operations
238 # The value is in the range 1-100. For efficiency, the value is approximate, so
239 # changing 50 to 51 will have absolutely no effect, but changing 50 to 70 will. If
240 # someone were to change the value to 0 (for some reason), some amount of pre-drawing
241 # would still occur
242 preDrawAllocation => 50,
243  
244 # An additional hash for character model objects. Contains exactly the same number
245 # of entries as $self->charModelHash, but this hash is in the form
246 # $knownCharHash{name} = blessed_reference_to_character_model_object
247 # Used to make sure that character model objects don't have duplicate names (i.e. you
248 # can't have two character objects whose ->name is 'Gandalf')
249 knownCharHash => {},
250 # A collection of 'minion strings', where several minion strings (e.g. 'hairy orc',
251 # 'hairy orcs', 'Glob the orc') may represent the same minion model object
252 # Unlike $self->minionModelHash, this hash can only contain one key-value pair for each
253 # possible minion string. Also, the value may be a model object or a non-model object;
254 # in either case, it's possible to compare the object against other model/non-model
255 # objects, to see if they match
256 # Minion strings are case-insensitive
257 # Hash in the form
258 # $minionStringHash{minion_string} = blessed_reference_to_minion_model_object
259 minionStringHash => {},
260  
261 # Light statuses
262 # Some worlds use different verbose descriptions depending on the the time of day, or
263 # how much light there is - for example, one description during the day, and another
264 # at night
265 # A light status describes how much light there is currently. There are three standard
266 # values: 'day' (the default value - corresponding to the description seen during the
267 # day), 'night' (the description seen at night, when the light is dimmer or
268 # non-existent), 'dark' (the description seen when there is no light at all, for
269 # example when underground - if it's different from that used at night)
270 # Each light status has a maximum length of 16 chars
271 # Room model objects in the world model store 1 or more descriptions. When new room
272 # model objects are created, the first description added is marked as belonging to the
273 # light status defined by this IV
274 lightStatus => 'day',
275 # List of standard light statuses (never altered)
276 constLightStatusList => [
277 'day', 'night', 'dark',
278 ],
279 # Customised list of light statuses (can be modified)
280 lightStatusList => [], # Set below
281  
282 # Room tags
283 # Rooms can be given a short name, usually displayed next to the room on the map. These
284 # are called room tags. The maximum size is 16 characters
285 # Room tags are unique - a room tag called 'tower' can either belong to no room at all,
286 # or a single room. However, room tags are case-insensitive - you can refer to a
287 # room's tag as 'tower', 'TOWER' or 'tOwEr', if you like. (Room tags are stored in
288 # lower-case letters, i.e. 'tower')
289 # Each room object also has its own ->roomTag IV, set to 'undef' if the room doesn't
290 # have a room tag
291 # This hash stores all room tags currently in use, in the form
292 # $roomTagHash{room_tag} = model_number_of_room
293 # NB GA::Obj::Route objects also use room tags. It's up to the user to ensure that world
294 # model room tags are equivalent to the tags used in their route objects; by the same
295 # token, adding or deleting a route does not change the contents of $self->roomTagHash
296 # (in fact, the world model isn't informed at all)
297 roomTagHash => {},
298  
299 # Teleport hash
300 # Using this hash, the client command ';teleport <destination>' is converted into a
301 # world command in order to teleport to a certain destination (assuming that the
302 # teleport ability might be available at many departure locations)
303 # In this hash, the keys are <destination>, and the corresponding values are the
304 # command to get there
305 # e.g. $teleportHash{tower} = 'goto /domains/town/room/start'
306 # e.g. $teleportHash{2} = 'goto /domains/town/room/start'
307 #
308 # If the destination ('tower' in the example above) exists as a room tag in the world
309 # model, or if it is the number of a world model room ('2' in the example above), the
310 # automapper/Locator task assume that this is the target destination. Otherwise, the
311 # target destination is unknown, and the automapper will get lost
312 # If the user types ';teleport tower', and the key 'tower' is not found in this hash,
313 # the highest-priority command cage's standard command 'teleport' is used instead.
314 # Assuming that the standard command is in the form 'teleport room', the word 'room'
315 # is replaced with the destination specified by the user. If it's a recognised room
316 # tag, the automapper/Locator task assume that this room is the target destination
317 # (world model room numbers can't be used in this case). Otherwise, the target
318 # destination is unknown, and the automapper will get lost
319 teleportHash => {},
320  
321 # IVs used to draw maps
322 # ---------------------
323  
324 # Should the Automapper window open automatically when Axmud starts? (TRUE for yes,
325 # FALSE for no)
326 autoOpenWinFlag => FALSE,
327 # Should the Automapper window open inside the session's 'main' window, if possible, and
328 # open as a normal 'grid' window, if not possible? (TRUE for yes, FALSE for no)
329 pseudoWinFlag => TRUE,
330 # When the Automapper window opens, which parts of it should be visible? (TRUE for
331 # visible, FALSE for not visible)
332 showMenuBarFlag => TRUE,
333 showToolbarFlag => TRUE,
334 showTreeViewFlag => TRUE,
335 showCanvasFlag => TRUE,
336 # The automapper window can show one or more toolbars, each with a set of buttons
337 # A list specifying how many toolbars should be shown, besides the (compulsory) first
338 # one. The list comprises the names of the button sets to use in each additional
339 # toolbar. (This list is updated whenever the user adds/removes button sets, so it's
340 # remembered between sessions)
341 # The list can contain 0, 1 or more of the button set names specified by
342 # GA::Win::Map->constButtonSetList, except for 'default'
343 # When the list is empty, only one toolbar is shown. If the list contains one item, two
344 # are shown (and so on)
345 buttonSetList => [],
346 # The automapper window's 'painting' toolbar can show buttons, each corresponding to a
347 # room flag, that are applied to the window's painter when turned on
348 # A list of room flags that should be shown (can be an empty list, but should not
349 # contain duplicates)
350 preferRoomFlagList => [],
351 # The automapper window's 'background' toolbar can show buttons, each corresponding to
352 # an RGB colour, that is used to colour in the map's background
353 # A list of RGB colours that should be shown, in addition to a button for the default
354 # colour, which is always shown (can be an empty list, but should not contain
355 # duplicates)
356 preferBGColourList => [],
357  
358 # Default and maximum sizes/colours.
359  
360 # Default sizes. Each gridblock contain max 1 room. All these sizes should be odd
361 # numbers
362 defaultGridWidthBlocks => 201, # Room's x co-ordinates
363 defaultGridHeightBlocks => 201, # Room's y co-ordinates
364 defaultBlockWidthPixels => 51, # At magnification 1
365 defaultBlockHeightPixels => 51,
366 defaultRoomWidthPixels => 31, # Room in centre of block
367 defaultRoomHeightPixels => 31,
368  
369 # Maximum sizes. We use a maximum size to stop the user creating a map bigger than the
370 # known universe in the world model's 'pref' window; we use the default size IVs above
371 # to enable smaller maps by default for testing purposes
372 # $self->defaultGridWidthBlocks (etc) is not checked against these maximum sizes. It's
373 # up to you, as the person editing these literal values, to make the maximum sizes the
374 # same as, or bigger, than the default sizes
375 maxGridWidthBlocks => 1001,
376 maxGridHeightBlocks => 1001,
377 maxBlockWidthPixels => 101,
378 maxBlockHeightPixels => 101,
379 maxRoomWidthPixels => 51,
380 maxRoomHeightPixels => 51,
381  
382 # Default map sizes
383 defaultMapWidthPixels => undef, # Set below
384 defaultMapHeightPixels => undef,
385  
386 # Hash of region scheme objects, specifying a set of colours to use in the automapper.
387 # The object named 'default' always exists and cannot be deleted. Other objects can
388 # have any name (i.e. they don't need to match a region name)
389 # Hash in the form
390 # $regionSchemeHash{style_name} = blessed_reference_to_scheme_object
391 regionSchemeHash => {},
392 # Shortcut to the default region scheme object
393 defaultSchemeObj => undef, # Set below
394  
395 # Default colours - used to reset region scheme colours to default values
396 # N.b. Region schemes have corresponding IVs for all of these values except for
397 # ->defaultNoBackgroundColour
398 defaultBackgroundColour => '#FFFF99', # Cream - map displayed
399 defaultNoBackgroundColour => '#FFFFFF', # White - no map
400 defaultRoomColour => '#FFFFFF', # White - room
401 defaultRoomTextColour => '#000000', # Black - text inside room
402 defaultSelectBoxColour => '#0088FF', # Blue - selection box
403 defaultBorderColour => '#000000', # Black - room border
404 defaultCurrentBorderColour => '#FF0000', # Red - current location
405 # (update mode)
406 defaultCurrentFollowBorderColour
407 => '#DD7422', # Orange - current location
408 # (follow mode)
409 defaultCurrentWaitBorderColour
410 => '#FF8CB3', # Pink - current location
411 # (wait mode)
412 defaultCurrentSelectBorderColour
413 => '#FF40E0', # Purple - current and
414 # selected room
415 defaultLostBorderColour => '#21D221', # Green - automapper is lost
416 defaultLostSelectBorderColour # Dark green - automapper is lost at room
417 => '#268626', # which is also a selected room
418 defaultGhostBorderColour => '#933A20', # Brown - ghost (presumed) room
419 defaultGhostSelectBorderColour # Pale brown - ghost (presumed) which is
420 => '#BB6E57', # also a selected room
421 defaultSelectBorderColour => '#0088FF', # Blue - selected location
422 defaultRoomAboveColour => '#FABA7E', # Less pale orange - room echo from above
423 defaultRoomBelowColour => '#FFCA99', # More pale orange - room echo from below
424 defaultRoomTagColour => '#C90640', # Dark red - room tag
425 defaultSelectRoomTagColour => '#0088FF', # Blue - selected room tag
426 defaultRoomGuildColour => '#1430D7', # Dark blue - room guild
427 defaultSelectRoomGuildColour
428 => '#0088FF', # Blue - selected room guild
429 defaultExitColour => '#000000', # Black - exit
430 defaultSelectExitColour => '#0088FF', # Blue - selected exit
431 defaultSelectExitTwinColour => '#3AE1EC', # Cyan - twin room/exit of
432 # selected region/broken
433 # exit
434 defaultSelectExitShadowColour
435 => '#DD7422', # Orange - selected exit's shadow exit
436 defaultRandomExitColour => '#FF0000', # Red - random exit (type 3 only)
437 defaultImpassableExitColour => '#FF00FF', # Magenta - impassable exit
438 defaultMysteryExitColour => '#900700', # Dark red - mystery exit
439 defaultCheckedDirColour => '#FF96AA', # Pink - checked direction
440 defaultDragExitColour => '#FF0000', # Red - draggable exit
441 defaultExitTagColour => '#000000', # Black - exit tag
442 defaultSelectExitTagColour => '#0088FF', # Blue - selected exit tag
443 defaultMapLabelColour => '#C90640', # Dark red - map label
444 defaultSelectMapLabelColour => '#0088FF', # Blue - selected label
445  
446 # Hash of map label style objects. Each object defines attributes like text colour,
447 # italics, and so on, that can be applied to multiple map labels
448 # Hash in the form
449 # $mapLabelStyleHash{style_name} = blessed_reference_to_style_object
450 mapLabelStyleHash => {}, # Set below
451 # The name of the map label style that should be used for new labels, set whenever a
452 # label is added to the automapper window
453 mapLabelStyle => undef, # Set below
454 # Flag set to TRUE if all labels should be aligned horizontally (in the middle of a
455 # grid block or at its edge), FALSE if labels can be placed with any horizontal
456 # alignment
457 mapLabelAlignXFlag => FALSE,
458 # Flag set to TRUE if all labels should be aligned vertically (in the middle of a
459 # grid block or at its edge), FALSE if labels can be placed with any vertical
460 # alignment
461 mapLabelAlignYFlag => FALSE,
462 # Flag set to FALSE if the map label dialogue window (created by
463 # GA::Win::Map->promptConfigLabel) should use a single-line entry box, TRUE if it
464 # should use a multi-line textview
465 mapLabelTextViewFlag => FALSE,
466  
467 # Room flags - a collection of flags used by room model objects, organised into groups
468 # called room filters and used mainly by the automapper window to set the colour of
469 # the room, with one colour for each room flag
470 # (NB There is no rule which says an RGB colour must be unique to a room flag, but
471 # obviously using the same colour with multiple room flags is a bad idea)
472 # The room model object (GA::ModelObj::Room) stores a hash of room flags. In each room,
473 # every room flag is either 'on' or 'off'. A room can have zero, one or multiple
474 # room flags
475 #
476 # Hash of room filters, showing which are currently applied (TRUE) and which are not
477 # applied. Room filters can't be added or removed by the user, so they keys in this
478 # hash are those specified by GA::Client->constRoomFilterList
479 roomFilterApplyHash => {}, # Set by $self->setupRoomFlags
480 # A hash of room flag objects (GA::Obj::RoomFlag), one for each room flag specified by
481 # GA::Client->constRoomFlagList. Hash in the form
482 # $roomFlagHash{room_flag_name} = blessed_reference_to_room_flag_object
483 roomFlagHash => {}, # Set by $self->setupRoomFlags
484 # A list of room flag names, sorted by its priority (highest-priority room flag object
485 # has its ->priority set to 1, the lowest-priority has its ->priority set to a value
486 # in the 100s. Used for quick lookup, so this list must be updated whenever
487 # $self->roomFlagHash or an individual room flag object is updated
488 # e.g. ( 'stash_room', 'hide_room', 'interesting', ... )
489 roomFlagOrderedList => [], # Set by $self->setupRoomFlags
490 # A single flag which, when set to TRUE, releases all filters, overriding the contents
491 # of ->roomFilterApplyHash (set to FALSE otherwise)
492 allRoomFiltersFlag => TRUE,
493 # How lists of room flags should be displayed in the automapper window (and in various
494 # 'edit' windows)
495 # 'default' - List all room flags
496 # 'essential' - Show only essential standard flags (those specified by
497 # GA::Client->constRoomHazardHash) and any custom room flags
498 # 'custom' - Show only custom room flags
499 roomFlagShowMode => 'default',
500 # MSDP can supply a 'TERRAIN' variable for each room. If so, those variables are
501 # collected initially in this hash, in the form
502 # $roomTerrainInitHash{terrain_type} = undef
503 roomTerrainInitHash => {},
504 # The user can then allocate a terrain to one of Axmud's room flags (in which case new
505 # rooms have their room flags set automatically, as if the painter was on), or choose
506 # to ignore the terrain type
507 # NB Room flags in this hash are exclusive. If a room's room flag is set using one of
508 # the room flags in ->roomTerrainHash, all other room flags which are also found in
509 # ->roomTerrainHash are unset in the room, regardless of whether the user set them
510 # manually or not
511 # Hash of allocated terrain types, in the form
512 # $roomTerrainHash{terrain_type} = room_flag
513 # $roomTerrainHash{terrain_type} = undef (to ignore the terrain type)
514 roomTerrainHash => {},
515  
516 # The following IVs work in a similar way. When the painter is on, rooms are allocated
517 # a room flag if text in the room title/description/exit/content list matches one of
518 # the patterns in the following hashes
519 # Hashes in the form
520 # $hash{pattern} = room_flag
521 #
522 # Patterns that match text in the room's title (tested against every room title in the
523 # room's ->titleList IV)
524 # NB A restriction applies to ->paintFromTitleHash, but not the other ->paintFrom...
525 # IVs
526 # When painting because of titles matching a pattern in ->paintFromTitleHash, room flags
527 # in the room are set for every matching pattern
528 # When that operation is complete, any room flags which are found in
529 # ->paintFromTitleHash, but which were not set during that operation, are then unset
530 # This restriction prevents problems at worlds like EmpireMUD 2.0, whose room titles
531 # change as you chop down trees and dig up crops
532 paintFromTitleHash => {},
533 # Patterns that match text in the room's description (tested against every description
534 # in the room's ->descripHash IV)
535 paintFromDescripHash => {},
536 # Patterns that match one of the room's exits (tested against every exit stored as a key
537 # in the room's ->exitNumHash)
538 paintFromExitHash => {},
539 # Patterns that match one of the objects in the room's temporary contents list, set for
540 # the non-model room object used by the Locator task. The objects are stored in the
541 # room's ->tempObjList. Patterns are tested against each of those objects'
542 # ->baseString IV, if it is set, or its ->noun IV otherwise
543 paintFromObjHash => {},
544 # Patterns that match one of the room's room commands (tested against every string in
545 # the room's ->roomCmdList)
546 paintFromRoomCmdHash => {},
547  
548 # How rooms are drawn
549 # Current room mode
550 # 'single' - The current/last known/ghost rooms are drawn with a coloured border, 1
551 # pixel wide
552 # 'double' - The current/last known/ghost rooms are drawn with a coloured border, 2
553 # pixels wide
554 # 'interior' - The current/last known/ghost rooms are drawn with a normal border, but
555 # the interior colour is changed (to match the border colour in modes 0/1),
556 # overriding any room flags that are set
557 currentRoomMode => 'single',
558 # Room interior mode - sets what characters/numbers are drawn in room interiors, towards
559 # the top
560 # Doesn't affect drawing U and D for up and down, towards the bottom. Also doesn't
561 # affect setting the room interior's colour
562 # 'none' - Draw nothing
563 # 'shadow_count' - Draw shadow/unallocated exit counts
564 # 'region_count' - Draw region/super-region exit counts
565 # 'checked_count' - Draw checked/checkable direction counts
566 # 'room_content' - Draw room contents
567 # 'hidden_count' - Draw hidden objects counts
568 # 'temp_count' - Draw temporary contents counts
569 # 'word_count' - Draw recognised word counts
570 # 'room_tag' - Draw the room tag (instead of drawing it externally)
571 # 'room_flag' - Draw room flag text (which matches the room's highest priority room
572 # flag)
573 # 'visit_count' - Draw # of character visits
574 # 'compare_count' - Draw # of matching rooms (but only in the current room)
575 # 'profile_count' - Draw room's exclusive profiles
576 # 'title_descrip' - Draw room titles/verbose descriptions
577 # 'exit_pattern' - Draw assisted moves/exit patterns
578 # 'source_code' - Draw source code path
579 # 'vnum' - Draw world's room vnum
580 # 'grid_posn' - Draw room's grid coordinates
581 roomInteriorMode => 'none',
582 # When ->roomInteriorMode is set to 'grid_posn', offsets to use, so that the visible
583 # grid coordinates match the game's grid coordinates
584 roomInteriorXOffset => 0,
585 roomInteriorYOffset => 0,
586  
587 # How exits are drawn
588 # 'ask_regionmap' - Let each individual regionmap decide (between no exits, simple
589 # exits and complex exits)
590 # 'no_exit' - Draw no exits (only the rooms themselves are drawn)
591 # 'simple_exit' - Draw simple exits (all exists are simple lines, with arrows for
592 # one-way exits)
593 # 'complex_exit' - Draw complex exits (there are four kinds of exits drawn -
594 # incomplete, uncertain, one-way and two-way)
595 drawExitMode => 'ask_regionmap',
596 # Flag set to TRUE if the automapper should obscure (i.e. filter out) some exits,
597 # drawing only those exits for rooms near the current room, or for selected rooms (and
598 # selected exits), and for rooms whose rooms flags match those in
599 # GA::Client->constRoomNoObscuredHash (e.g. 'main_route')
600 obscuredExitFlag => FALSE,
601 # Flag set to TRUE if the automapper should re-obscure exits as the character moves
602 # around (so that only exits around the character's location are visible), and
603 # when other conditions change
604 obscuredExitRedrawFlag => FALSE,
605 # Radius (in gridblocks) of a square area, with the current room in the middle. When
606 # obscuring exits is enabled, exits are drawn for all rooms in this area (including
607 # the current room), but not necessarily for any rooms outside the area
608 # Use 1 to draw only the current room, 2 to draw exits for rooms in a 3x3 area, 3 for a
609 # 5x5 area, and so on
610 obscuredExitRadius => 2,
611 # Max radius (the minimum is always 1). This maximum also applies to
612 # GA::Obj::Regionmap->obscuredExitRadius
613 maxObscuredExitRadius => 9,
614 # When this flag is set to TRUE, exit ornaments are drawn. If set to FALSE, ornaments
615 # aren't drawn
616 drawOrnamentsFlag => TRUE,
617 # Exit length - how long normal exits should be. When set to '1', adjacent rooms occupy
618 # adjacent gridblocks. When set to '2', adjacent rooms are 1 gridblock apart (and so
619 # on). This affects newly-created exits only; existing exits retain their length even
620 # when the value is changed
621 # The exit length for cardinal directions (i.e. between rooms on the same level)
622 horizontalExitLengthBlocks => 1,
623 # The exit length for up/down directions (i.e. between rooms not on the same level)
624 verticalExitLengthBlocks => 1,
625 # Max exit length (the minimum is always 1)
626 maxExitLengthBlocks => 16,
627 # Whether new broken exits should be drawn as 'bent' broken exits (a zig-zagging line
628 # from the parent room to a destination room; flag set to TRUE) or as normal broken
629 # exits (squares attached to the parent room, not touching the destination room; flag
630 # set to FALSE)
631 drawBentExitsFlag => TRUE,
632  
633 # The way in which the automapper decides whether the Locator's current room is the same
634 # one as the one displayed on the map
635 # Match the room title, if set to TRUE (set to FALSE otherwise)
636 matchTitleFlag => FALSE,
637 # Match the first part of the (verbose) description, if set to TRUE (set to FALSE
638 # otherwise)
639 matchDescripFlag => FALSE,
640 # How many characters to match, when matching the verbose description (0 - match the
641 # entire verbose description)
642 matchDescripCharCount => 100,
643 # Match exits, if set to TRUE (set to FALSE otherwise). Ignored if the current world
644 # profile's ->basicMappingFlag is not FALSE (meaning, don't use basic mapping)
645 matchExitFlag => TRUE,
646 # If this flag is set to TRUE, whenever $self->updateRoom is called to update the
647 # properties of a room model object, the room's verbose description is compared with
648 # the current dictionary's list of recognised words; every recognised noun and
649 # adjective is stored in the the room's >nounList and/or ->adjList (set to FALSE
650 # otherwise)
651 analyseDescripFlag => FALSE,
652 # Match the room's source code path, if set to TRUE (set to FALSE otherwise)
653 matchSourceFlag => FALSE,
654 # Match the room's remote vnum, if set to TRUE (set to FALSE otherwise)
655 matchVNumFlag => TRUE,
656  
657 # When the Automapper window is open and in 'update' mode, which of the room model
658 # object's properties are updated to match those gathered by the Locator task's
659 # current room (during the call to $self->updateRoom). Set to TRUE if a property
660 # should be updated, FALSE if not
661 updateTitleFlag => TRUE,
662 updateDescripFlag => TRUE,
663 updateExitFlag => TRUE,
664 updateSourceFlag => FALSE,
665 # If TRUE, this flag updates not just the room's remote vnum, but any other room data
666 # supplied by MSDP and MXP (i.e., transfers the contents of the room's
667 # ->protocolRoomHash and ->protocolExitHash IVs)
668 updateVNumFlag => TRUE,
669 # Flag set to TRUE if $self->updateRoom should set replace the room's roomm commands,
670 # FALSE if not
671 updateRoomCmdFlag => FALSE,
672 # Flag set to TRUE if $self->updateExit should set an exit's ornaments using its exit
673 # state (when the exit state is set); FALSE if not
674 updateOrnamentFlag => FALSE,
675  
676 # Flag set to TRUE if moves between rooms should be translated by the automapper (for
677 # example, if the user types 'south' and there's an exit with its ->dir set to 'enter
678 # cave', and with its ->mapDir set to 'south', the command sent to the world should be
679 # 'enter cave'). Set to FALSE otherwise
680 assistedMovesFlag => TRUE,
681 # Flags set to TRUE if the automapper should try to open, close, unlock, lock or pick
682 # exits during an assisted move (set to FALSE otherwise)
683 assistedBreakFlag => FALSE,
684 assistedPickFlag => FALSE,
685 assistedUnlockFlag => TRUE,
686 assistedOpenFlag => TRUE,
687 assistedCloseFlag => FALSE,
688 assistedLockFlag => FALSE,
689 # Flag set to TRUE if protected moves mode is turned on (for example, if the user types
690 # 'south' and assisted moves are on, but the world model has no exit with its ->mapDir
691 # drawn south, the world command is not sent, and the user sees a warning message
692 # instead; set to FALSE otherwise)
693 # Ignored when $self->assistedMovesFlag is FALSE
694 protectedMovesFlag => FALSE,
695 # Flag set to TRUE if super protected moves turned on; after the first warning message,
696 # all unprocessed commands are removed, so (for example) in 'north;get torch', if
697 # the 'north' command fails, 'get torch' is never processed. Ignored if
698 # ->proctedMovesFlag is FALSE
699 superProtectedMovesFlag => FALSE,
700 # Flag to deal with worlds like Discworld, which have some kind of pseudo-wilderness
701 # areas - neighbouring rooms have no exits leading into them, but nevertheless those
702 # exits exist and can be used
703 # Flag set to TRUE if crafty moves mode is turned on - for example, when the automapper
704 # window is open and in 'update' mode, if the user tries to leave the current room in
705 # a direction for which there isn't an exit, draws a (hidden) exit in that direction
706 # if a new room statement (rather than a fail exit message) is received
707 # If set to FALSE, no new exit (hidden or otherwise) is drawn in that situation, and the
708 # character becomes lost
709 # Ignored when if ->protectedMovesFlag is TRUE (the value of ->assistedMovesFlag
710 # doesn't matter)
711 craftyMovesFlag => FALSE,
712  
713 # Flag set to TRUE when, if setting an exit ornament (from Exits > Set ornaments...),
714 # the exit's twin exit should have the same ornament set (set to FALSE otherwise)
715 setTwinOrnamentFlag => TRUE,
716  
717 # Axbasic scripts. Only non-task based scripts are suitable for these lists. Ignored if
718 # $self->allowModelScriptFlag is FALSE.
719 # List of Axbasic scripts to run, when the character arrives in a newly-created room. If
720 # ->arriveScriptList is also set, they are ignored.
721 newRoomScriptList => [],
722 # List of Axbasic scripts to run, when the character arrives in an existing room. If
723 # the room's own ->arriveScriptList is set, those scripts are run before these
724 # scripts are run.
725 arriveScriptList => [],
726  
727 # Flag set to TRUE if the automapper should count the number of character visits (set to
728 # FALSE otherwise)
729 countVisitsFlag => TRUE,
730 # Flag set to TRUE if the world model's list of Axbasic scripts should be run when we
731 # create/enter rooms (set to FALSE if not). The scripts are stored in
732 # $self->newRoomScriptList and -> arriveScriptList
733 # Does not apply to scripts belonging to individual rooms, i.e.
734 # GA::ModelObj::Room->arriveScriptList
735 allowModelScriptFlag => TRUE,
736 # Flag set to TRUE if the room model object's own list of Axbasic scripts should be run
737 # when when we enter this room (set to FALSE if not). The scripts are stored in
738 # GA::ModelObj::Room->arriveScriptList
739 # Does not apply to to scripts belonging to the model itself, i.e
740 # $self->newRoomScriptList and ->arriveScriptList
741 allowRoomScriptFlag => TRUE,
742 # Flag set for the special case of Room A with an uncertain exit that leads north to
743 # Room B. If it's also a broken or region exit, when the user moves south from Room B,
744 # should the automapper attempt to convert the exit into an uncertain exit (flag set
745 # to TRUE), or should a new room be drawn, south of Room B (flag set to FALSE)
746 intelligentExitsFlag => TRUE,
747 # Flag set to TRUE if the automapper should create a new exit object when the character
748 # moves, and the move is detected by the Locator task using a 'follow anchor' pattern.
749 # If FALSE, the automapper becomes lost, instead
750 followAnchorFlag => FALSE,
751 # Flag set to TRUE if room tags should be displayed in capitals (set to FALSE otherwise)
752 capitalisedRoomTagFlag => TRUE,
753 # Flag set to TRUE if tooltips should be visible (set to FALSE otherwise)
754 showTooltipsFlag => TRUE,
755 # Flag set to TRUE if room notes should be visible in tooltips (set to FALSE otherwise,
756 # and ignored if ->showTooltipsFlag is FALSE)
757 showNotesFlag => TRUE,
758 # Flag set to TRUE when a message should be displayed, whenever the call to
759 # $self->compareRooms from GA::Obj::Map->useExistingRoom returns a false value,
760 # meaning that the automapper is now lost (set to FALSE otherwise)
761 explainGetLostFlag => TRUE,
762 # Flag set to TRUE if update mode should be disabled (so that only wait/follow modes are
763 # available); set to FALSE otherwise
764 disableUpdateModeFlag => FALSE,
765 # Flag set to TRUE if, when an exit becomes a region exit, its ->exitTag should be
766 # automatically set
767 updateExitTagFlag => TRUE,
768 # Flag set to TRUE if room echos should be drawn (rooms just above or below the
769 # current regionmap's current level)
770 drawRoomEchoFlag => TRUE,
771 # Flag set to TRUE if the Automapper window should activate the automapper object's
772 # ->trackAloneFlag (where possible), when the window closes (set to FALSE otherwise)
773 allowTrackAloneFlag => TRUE,
774 # Flag set to TRUE if all primary directions (inc. northnortheast, etc) should be shown
775 # in 'dialogue' windows; set to FALSE if only the usual eight compass directions (inc.
776 # north and northeast) plus up/down should be shown in 'dialogue' windows
777 showAllPrimaryFlag => FALSE,
778 # Flag set to TRUE if CTRL+C should initiate a 'move rooms to click' operation, FALSE if
779 # CTRL+C should be ignored
780 allowCtrlCopyFlag => TRUE,
781  
782 # Auto-compare mode: when the automapper window is open and in 'update' mode, Axmud
783 # can automatically compare the current room against other rooms. If one or more
784 # matches are found, IVs in GA::Obj::Map are set to enable merge operations between
785 # the current room and the matching room(s)
786 # The current setting for auto-compare mode:
787 # 'default' - Don't auto-compare the current room
788 # 'new' - Auto-compare the current room when it's a new room
789 # 'current' - Auto-compare the current room whenever the current room is set
790 autoCompareMode => 'default',
791 # Flag set to TRUE if Axmud should auto-compare all rooms in the world model; FALSE if
792 # it should only auto-compare rooms in the same region (ignored if
793 # $self->autoCompareMode is 'default')
794 autoCompareAllFlag => FALSE,
795 # The maximum number of room comparisons to perform in auto-compare mode. If 0, there is
796 # no maximum
797 autoCompareMax => 0,
798 # Auto-slide mode: what to do when, in the automapper window's 'update' mode, the
799 # character moves from an original room to a destination room, but the destination
800 # room doesn't match the Locator task's room
801 # - 'default' - Mark the character as lost
802 # - 'orig_pull' - Move the original room backwards (i.e. in the opposite direction)
803 # into the first available gridblock in which there's room for
804 # both the original room and a new destination room
805 # - 'orig_push' - Move the original room forwards (i.e. in the direction of
806 # movement) into the first available gridblock, so there's room
807 # to create a new destination room
808 # - 'other_pull' - Move the non-matching destination room backwards (i.e. in the
809 # opposite direction) into the first available gridblock, so
810 # there's room to create a new destination room
811 # - 'other_push' - Move the non-matching destination room forwards (i.e. in the
812 # direction of movement) into the first available gridblock, so
813 # there's room to create a new destination room
814 # - 'dest_pull' - Place the new destination room in the first available gridblock in
815 # the backwards direction
816 # - 'dest_push' - Place the new destination room in the first available gridblock in
817 # the forwards direction
818 autoSlideMode => 'default',
819 # When performing an auto-slide, the maximum distance to travel, looking for empty
820 # gridblocks, before giving up. Must be a positive integer
821 autoSlideMax => 10,
822 # Auto-rescue mode: when GA::Obj::Map->setCurrentRoom is called to make the character as
823 # lost, it can instead activate auto-rescue mode, which creates a temporary region
824 # where new rooms can be drawn. The current location is compared against rooms in the
825 # previous region, so that all rooms in the temporary region can be merged back into
826 # the previous region, when required
827 # Note that auto-rescue mode can't be activated all all in certain situations (for
828 # example, in wilderness rooms, after certain Axmud internal errors, in 'Connect
829 # offline' mode, when the Locator task is reset manually)
830 # Flag set to TRUE if, instead of marking the character as lost, auto-rescue mode should
831 # be activated instead (when it's possible to do so); FALSE otherwise
832 autoRescueFlag => FALSE,
833 # Flag set to TRUE if Axmud should automatically merge rooms in the temporary region
834 # back into the previous region, as soon as a new room is drawn matching a single
835 # room in the previous region (the first room drawn in the temporary region doesn't
836 # count; ignored if ->autoRescueFlag is FALSE and if the Locator task is expecting
837 # more room statements)
838 autoRescueFirstFlag => FALSE,
839 # Flag set to TRUE if Axmud should prompt the user, before automatically merging rooms
840 # back into the previous region (ignored if ->autoRescueFlag or ->autoRescueFirstFlag
841 # are FALSE)
842 autoRescuePromptFlag => FALSE,
843 # Flag set to TRUE if matching rooms should be merged, but non-matching moves should not
844 # be moved (FALSE if non-matching rooms should be moved)
845 autoRescueNoMoveFlag => FALSE,
846 # Flag set to TRUE if only character visits should be updated when merging rooms (FALSE
847 # if all of the rooms' IVs should be updated when merging a pair of rooms)
848 autoRescueVisitsFlag => FALSE,
849 # Flag set to TRUE if the automapper window's mode should be temporarily switched to
850 # 'update' mode if it's in 'follow' mode, and then restored to 'follow' mode when the
851 # merge operation is performed (FALSE if auto-rescue mode is only available when the
852 # automapper window is in 'update' mode)
853 autoRescueForceFlag => FALSE,
854  
855 # The last filepath entered - so that, for source code files stored in the same
856 # directory, the user doesn't have to type the entire path again ('undef' if none
857 # ever entered)
858 lastFilePath => undef,
859 # The last virtual area path entered ('undef' if none ever entered)
860 lastVirtualAreaPath => undef,
861 # Flag set to TRUE if the automapper should track the current room and auto-scroll the
862 # map's scrollbars, so that it is always visible after a move (set to FALSE otherwise)
863 trackPosnFlag => TRUE,
864 # How close the current room has to be to the edge of the visible map, in order to get
865 # the scrollbars moved
866 # A value from 0-1. 0 means 'always centre the map on the current room', 1 means 'centre
867 # the map only when the current room is outside the visible window'.
868 # 0.5 means that the room must be halfway between the centre of the visible map, before
869 # the map is centred. 0.66 means the room must be two-thirds of the distance away from
870 # the centre, and 0.9 means that the room must be 90% of the distance away from the
871 # centre
872 # The automapper menu currently sets it to one of four values
873 # (0, 0.33, 0.66, 1)
874 trackingSensitivity => 0.66,
875 # Flag set to TRUE if pathfinding functions (and any similar code) should avoid using
876 # rooms that are hazardous, by default - specifically, any rooms which have any of the
877 # room flags specified by GA::Client->constRoomHazardHash (currently 'blocked_room',
878 # 'avoid_room', 'danger' or 'mortal_danger') (set to FALSE otherwise)
879 avoidHazardsFlag => TRUE,
880 # Flag set to TRUE if, after finding a shortest route using the pathfinding algorithms,
881 # post-processing should be applied to smooth jagged paths (set to FALSE otherwise)
882 postProcessingFlag => TRUE,
883 # Flag set to TRUE if double-clicking over a room should be the equivalent of 'Go to
884 # room' (set to FALSE otherwise)
885 quickPathFindFlag => TRUE,
886 # Flag set to TRUE if uncertain exits should automatically be converted into 2-way exits
887 # (set to FALSE if not)
888 # NB If basic mapping mode (GA::Profile::World->basicMappingFlag) is on, travelling from
889 # one room to a new room normally creates a one-way exit. When the user prefers to
890 # create two-way exits instead, they can set this flag to TRUE
891 # NB When moving between normal and wilderness border rooms, a one-way exit is normally
892 # created. When they user prefers to create two-way exits instead, they can set this
893 # flag to TRUE
894 autocompleteExitsFlag => FALSE,
895 # When the character attempts to move in a direction but we get a failed exit message
896 # in response, and if there is no exit in the direction, we can store that direciton
897 # as a checked direction (an entry in the room object's ->checkedDirHash)
898 # Flag set to TRUE if checked directions should be collected, FALSE if not
899 # If TRUE, checked directions are collected even if the automapper window (when open) is
900 # in 'follow' mode
901 collectCheckedDirsFlag => FALSE,
902 # Flag set to TRUE if checked directions should be drawn in the automapper window, FALSE
903 # if not
904 drawCheckedDirsFlag => TRUE,
905 # Checkable direction mode - when the room's interior text is showing the number of
906 # checked directions (and checkable primary directions), this mode determines how many
907 # directions are counted when working out the checkable directions
908 # (A checkable direction is a primary direction for which there is is no exit object
909 # and no checked direction)
910 # 'simple' - north, south, west, east
911 # 'diku' - the above, plus up/down
912 # 'lp' - the above, plus northwest/northeast/southwest/southeast
913 # 'complex' - all primary directions (including eastnortheast, etc)
914 checkableDirMode => 'diku',
915  
916 # There are three pathfinding algorithms, enacted by calls to $self->findPath (to find
917 # a path using rooms in a single region), $self->findUniversalPath (to find a path
918 # using rooms in any region) and $self->findRoutePath (which doesn't consult the
919 # world model at all, using route objects, GA::Obj::Route, instead)
920 # ->findUniversalPath uses pre-calculated routes across a region, but only uses region
921 # exits that have been marked as super-region exits (so that we don't have to
922 # calculate thousands of paths across each region)
923 # An alternative is to set these IVs, so that ->findPath can use rooms in adjacent
924 # regions, as if they were in the same region
925 # Adjacent region mode - 'default' if $self->findPath should can only use rooms in a
926 # single region, 'near' if $self->findPath can use rooms in regions adjacent to
927 # the start room, and 'all' if $self->findPath ignores regions altogether, treating
928 # all rooms as if they were in the same region
929 adjacentMode => 'near',
930 # When $self->adjacentMode is 'adjacent', the number of adjacent regions to use (e.g.
931 # 1 means 'use rooms in any adjacent region', 2 means 'use rooms in any adjacent
932 # region, and any of their adjacent regions', 0 means 'don't use adjacent regions'
933 # Must be an integer, 0 or above. Ignored if $self->adjacentRegionModeis is not
934 # 'adjacent'
935 adjacentCount => 1,
936 # Boundary updates. When an existing region exit is modified in any way, or deleted, or
937 # an exit becomes a region exit, it is added to this hash, so that the parent
938 # regionmap's list of super-region exits can be updated. Hash in the form
939 # $updateBoundaryHash{exit_num} = parent_region_name
940 updateBoundaryHash => {},
941 # Parallel hash, containing only region exits which have been deleted
942 deleteBoundaryHash => {},
943 # Region path updates. When an existing exit is modified in any way, or deleted, it is
944 # added to this hash, so that the parent regionmap's region paths can be checked; if
945 # any of them contain this exit, they can then be recalculated. Hash in the form
946 # $updatePathHash{exit_num} = region_name
947 updatePathHash => {},
948 # $self->connectRegionBrokenExit opens a 'dialogue' window; while we wait for a user
949 # response, the timer loop will spin. While we're waiting, this IV is set to TRUE,
950 # and $self->updateRegionPaths won't do anything; once the 'dialogue' window has been
951 # closed, this IV is set back to FALSE
952 updateDelayFlag => FALSE,
953 # IVs checked when $self->updateRegionLevels is called, once per timer loop
954 # When room model objects and/or map labels are added to or deleted from a regionmap, we
955 # need to re-calculate the regionmap's highest and lowest occupied levels. This hash
956 # contains all the regionmaps that need to be checked. Hash in the form
957 # $checkLevelsHash{regionmap_name} = undef
958 checkLevelsHash => {},
959  
960 # Other IVs
961 # ---------
962  
963 # If the world's source code is available on the user's computer, the directory in which
964 # it can be found. (Individual model objects store the path to the matching world
965 # file, relative to this directory)
966 # Normally set to the mudlib directory, e.g. /home/myname/ds/lib/
967 mudlibPath => undef,
968 # The normal file extension used for mudlib objects. If defined, the value of this IV
969 # is added to the value of a model object's ->sourceCodePath (e.g. '.c' for LPMuds).
970 # No need to define it, if the ->sourceCodePath already contains the file extension
971 mudlibExtension => '.c',
972  
973 # The painter is a non-model GA::ModelObj::Room object whose IVs are used to 'paint'
974 # new rooms as they are created (or update existing rooms as the character moves
975 # through them). Details about the painter are stored here, but each Automapper window
976 # has its own ->painterFlag which can be set to TRUE or FALSE
977 # The non-model GA::ModelObj::Room object which is the painter object
978 painterObj => undef, # Set below
979 # A list of IVs in the painter object that are actually used to paint rooms (the others
980 # are ignored).
981 # Scalar and list IVs in the current room are replaced by their equivalents in the
982 # painter - but hash IVs are merged. (If the same key exists in both objects, the
983 # painter's key-value pair is used)
984 constPainterIVList => [
985 'wildMode',
986 'titleList',
987 'descripHash',
988 'exclusiveFlag',
989 'exclusiveHash',
990 'roomFlagHash',
991 'roomGuild',
992 'searchHash',
993 ],
994 # Flag set to TRUE, when only new rooms should be painted. Otherwise, set to FALSE, so
995 # that in 'update' mode, every time the current room changes, it is painted
996 paintAllRoomsFlag => FALSE,
997 # Flag relating to the automapper window's quick painting toolbar. Set to FALSE if
998 # quick painting should apply to one room (before resetting itself), TRUE if it should
999 # apply to multiple rooms (the user must manually reset it)
1000 quickPaintMultiFlag => FALSE,
1001  
1002 # Limits to world model searches (used by GA::PrefWin::Search). If either value is 0,
1003 # then searches use $self->modelObjCount as a limit
1004 # Maximum number of matches during a search
1005 searchMaxMatches => 1000,
1006 # Maximum number of objects searched
1007 searchMaxObjects => 10000,
1008 # A flag which, when set to TRUE, causes any matching rooms to be selected in the map
1009 # window (set to FALSE otherwise)
1010 searchSelectRoomsFlag => TRUE,
1011 # Limits to locate room operations. If the value is 0, then the whole model is searched
1012 # when trying to locate a room
1013 locateMaxObjects => 5000,
1014 # What to do, when the character uses an exit whose ->randomType is 'same_region'
1015 # (locate room in the current region). Set to TRUE if Axmud should try to locate the
1016 # new location (but only if there are less than ->locateMaxObjects to search), or
1017 # FALSE if the character should just be marked as 'lost'
1018 locateRandomInRegionFlag => FALSE,
1019 # What to do, when the character uses an exit whose ->randomType is 'any_region' (locate
1020 # room anywhere in the map). Set to TRUE if Axmud should try to locate the new
1021 # location (but only if there are less than ->locateMaxObjects to search), or FALSE if
1022 # the character should just be marked as 'lost'
1023 locateRandomAnywhereFlag => FALSE,
1024  
1025 # When the user double-clicks on a room to go there (using the shortest path), give them
1026 # an opportunity to change their minds for very long paths. IV set to the number of
1027 # steps (separate world commands) used to move from the current room to the specified
1028 # one; if the actual number of steps exceeds this value,
1029 # GA::Win::Map->processPathCallback shows a yes-no 'dialogue' window, first. If the
1030 # IV is set to 0, there is no limit
1031 pathFindStepLimit => 200,
1032  
1033 # When GA::Win::Map->doDraw is called, the drawing process can take a long time, if
1034 # there are thousands of objects to draw. The value of this IV is the number of
1035 # objects (not including exits) above which ->doDraw will create a popup window, so
1036 # that the user knows why Axmud has frozen (minimum value 100)
1037 drawPauseNum => 500,
1038 # When GA::Win::Map->recalculatePathsCallback is called, the recalculation process
1039 # can tak a long time, if there are hundreds of region paths to recalculate. The
1040 # value of this IV is the number of paths above which ->recalculatePathsCallback
1041 # will create a popup window, so that the user knows why Axmud has frozen (minimum
1042 # value 10)
1043 recalculatePauseNum => 50,
1044  
1045 # The font and font size to use for text drawn in the Automapper window (expressed as a
1046 # ratio, with 1 being the font size used for room tags at the map's current
1047 # magnification)
1048 mapFont => 'Sans',
1049 roomTagRatio => 1,
1050 roomGuildRatio => 0.7,
1051 exitTagRatio => 0.7,
1052 labelRatio => 0.8,
1053 roomTextRatio => 0.7,
1054  
1055 # $self->deleteRegions, ->deleteRooms, ->deleteExits and ->deleteLabels all make a call
1056 # to GA::Win::Map->setSelectedObj to make sure there are no selected objects in the
1057 # automapper window(s)
1058 # A single call to ->deleteRegions could cause thousands of calls to ->deleteExits,
1059 # each of them calling GA::Win::Map->setSelectedObj in turn
1060 # In that case, we only need a single call to GA::Win::Map->setSelectedObj. This flag is
1061 # set to TRUE when ->deleteRegions is called, and reset back to FALSE when that
1062 # function is finished. When the flag is TRUE, no time-wasting calls to
1063 # GA::Win::Map->setSelectedObj are made
1064 blockUnselectFlag => FALSE,
1065 };
1066  
1067 # Bless the object into existence
1068 bless $self, $class;
1069  
1070 # Set the light status list
1071 $self->{lightStatusList} = $self->{constLightStatusList};
1072  
1073 # Set map size (based on the values immediately above)
1074 $self->{defaultMapWidthPixels}
1075 = $self->{defaultGridWidthBlocks} * $self->{defaultBlockWidthPixels};
1076 $self->{defaultMapHeightPixels}
1077 = $self->{defaultGridHeightBlocks} * $self->{defaultBlockHeightPixels};
1078  
1079 # Create a default region scheme object
1080 $self->ivPoke(
1081 'defaultSchemeObj',
1082 Games::Axmud::Obj::RegionScheme->new($session, $self, 'default'),
1083 );
1084 $self->ivAdd('regionSchemeHash', 'default', $self->defaultSchemeObj);
1085  
1086 # Create some map label styles
1087 $self->addLabelStyle($session, 'Style 1', $self->{defaultMapLabelColour});
1088 $self->addLabelStyle($session, 'Style 2', '#FF40E0');
1089 $self->addLabelStyle($session, 'Style 3', '#000000', undef, 2);
1090 $self->addLabelStyle($session, 'Style 4', '#000000', undef, 4);
1091 $self->{mapLabelStyle} = 'Style 1';
1092  
1093 # Set room filters and room flags
1094 $self->setupRoomFlags($session);
1095  
1096 # Create a painter object - a non-model GA::ModelObj::Room used to 'paint' other rooms
1097 # by copying its IVs into theirs
1098 $self->resetPainter($session);
1099  
1100 return $self;
1101 }
1102  
1103 ##################
1104 # Methods
1105  
1106 # Methods called by GA::Session->spinMaintainLoop, etc
1107  
1108 sub updateRegionPaths {
1109  
1110 # Called by GA::Session->spinMaintainLoop, $self->findUniversalPath and
1111 # GA::EditWin::Regionmap->boundaries1Tab_addButtons
1112 # Uses the exit numbers stored in $self->updateBoundaryHash, ->updatePathHash and
1113 # ->deleteBoundaryHash (if any) to create, modify or delete region paths for the exits'
1114 # parent regions
1115 #
1116 # Expected arguments
1117 # $session - The calling function's GA::Session
1118 #
1119 # Return values
1120 # 'undef' on improper arguments
1121 # 1 otherwise
1122  
1123 my ($self, $session, $check) = @_;
1124  
1125 # Local variables
1126 my (
1127 @exitList, @newModList,
1128 %boundaryHash, %deleteHash, %regionmapHash, %regionNameHash, %otherHash,
1129 %otherRegionmapHash,
1130 );
1131  
1132 # Check for improper arguments
1133 if (! defined $session || defined $check) {
1134  
1135 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRegionPaths', @_);
1136 }
1137  
1138 # $self->connectRegionBrokenExit can open 'dialogue' windows; while the window is open, the
1139 # GA::Session's timer loop can still call this function. Ignore any such calls until the
1140 # dialogue connect operation has completed
1141 if ($self->updateDelayFlag) {
1142  
1143 return undef;
1144 }
1145  
1146 # Import the hashes (for quick lookup)
1147 %boundaryHash = $self->updateBoundaryHash;
1148 %otherHash = $self->updatePathHash;
1149 %deleteHash = $self->deleteBoundaryHash;
1150  
1151 # First deal with all region exits which have been created, modified or deleted since the
1152 # last spin of the timer loop (if any)
1153 if (%boundaryHash) {
1154  
1155 # Get a sorted list of exit numbers, because when two region exits in the same region
1156 # lead to the same other region, the one with the lowest exit model number (usually
1157 # the first one created) is used as the super-region exit, by default
1158 @exitList = sort {$a <=> $b} (keys %boundaryHash);
1159  
1160 OUTER: foreach my $exitNum (@exitList) {
1161  
1162 my ($regionName, $regionmapObj, $exitObj, $roomObj, $newRegionObj);
1163  
1164 $regionName = $boundaryHash{$exitNum};
1165 $regionmapObj = $self->ivShow('regionmapHash', $regionName);
1166 if (! $regionmapObj) {
1167  
1168 # If the region is being deleted, don't need to bother with its super-region
1169 # exits
1170 next OUTER;
1171 }
1172  
1173 # (As we go, create a hash of affected regionmaps, so that later on we can
1174 # check super-region exits)
1175 $regionmapHash{$regionmapObj->number} = $regionmapObj;
1176  
1177 # We deal with deleted region exits in a moment
1178 if (! exists $deleteHash{$exitNum}) {
1179  
1180 $exitObj = $self->ivShow('exitModelHash', $exitNum);
1181  
1182 # Check whether the exit has moved to a new region, or not
1183 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
1184 if ($roomObj->parent != $regionmapObj->number) {
1185  
1186 $newRegionObj = $self->ivShow('modelHash', $roomObj->parent);
1187 }
1188  
1189 # Check that the existing exit is still a region exit in its original region
1190 if (! $exitObj->regionFlag || $newRegionObj) {
1191  
1192 # An existing exit is no longer a region exit in its original region. Update
1193 # the regionmap's list of region objects
1194 $regionmapObj->removeRegionExit($exitObj);
1195  
1196 # Remove any region paths (stored in ->regionPathHash and
1197 # ->safeRegionPathHash) which were using this exit
1198 INNER: foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
1199  
1200 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
1201  
1202 if ($pathObj->startExit == $exitNum || $pathObj->stopExit == $exitNum) {
1203  
1204 # (Update both ->regionPathHash and ->safeRegionPathHash)
1205 $regionmapObj->removePaths($exitString);
1206 }
1207 }
1208  
1209 } else {
1210  
1211 # Deal with new/modified region exits in a moment
1212 push (@newModList, $exitObj, $roomObj, $regionmapObj, $newRegionObj);
1213 }
1214 }
1215 }
1216  
1217 # Deal with deleted region exits. Compile a hash of affected region names
1218 OUTER: foreach my $exitNum (keys %deleteHash) {
1219  
1220 my $regionName = $deleteHash{$exitNum};
1221  
1222 $regionNameHash{$regionName} = undef;
1223 }
1224  
1225 OUTER: foreach my $regionName (keys %regionNameHash) {
1226  
1227 my $regionmapObj = $self->ivShow('regionmapHash', $regionName);
1228 if ($regionmapObj) {
1229  
1230 INNER: foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
1231  
1232 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
1233  
1234 if (
1235 exists $deleteHash{$pathObj->startExit}
1236 || exists $deleteHash{$pathObj->stopExit}
1237 ) {
1238 # (Update both ->regionPathHash and ->safeRegionPathHash)
1239 $regionmapObj->removePaths($exitString);
1240 }
1241 }
1242 }
1243 }
1244  
1245 # Deal with new/modified region exits
1246 if (@newModList) {
1247  
1248 do {
1249  
1250 my (
1251 $exitObj, $roomObj, $regionmapObj, $newRegionObj, $destRoomObj, $matchFlag,
1252 $twinExitObj, $twinRoomObj, $twinRegionObj, $twinRegionmapObj,
1253 );
1254  
1255 $exitObj = shift @newModList;
1256 $roomObj = shift @newModList;
1257 $regionmapObj = shift @newModList;
1258 $newRegionObj = shift @newModList;
1259  
1260 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
1261 # For an exit which has moved to a new region, use the regionmap of the new
1262 # region
1263 if ($newRegionObj) {
1264  
1265 $regionmapObj = $self->ivShow('regionmapHash', $newRegionObj->name);
1266 }
1267  
1268 # Check if the regionmap already knows about this exit
1269 if (! $regionmapObj->ivExists('regionExitHash', $exitObj->number)) {
1270  
1271 # It's a new region exit, or a region exit which has moved to a new region.
1272 # If there are no super-region exits between this exit's region and the
1273 # destination region, then this exit should be marked as a super-region
1274 # exit (but not if the user has specifically marked it as a normal region
1275 # exit, in which case $exitObj->notSuperFlag will be set)
1276 INNER: foreach my $otherExitNum ($regionmapObj->ivKeys('regionExitHash')) {
1277  
1278 my ($otherExitObj, $otherDestRoomObj);
1279  
1280 $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
1281 $otherDestRoomObj = $self->ivShow('modelHash', $otherExitObj->destRoom);
1282  
1283 if (
1284 $otherExitObj->superFlag
1285 && $destRoomObj->parent == $otherDestRoomObj->parent
1286 ) {
1287 $matchFlag = TRUE;
1288 last INNER;
1289 }
1290 }
1291  
1292 if (! $matchFlag && ! $exitObj->notSuperFlag) {
1293  
1294 # This exit is a super-region exit
1295 $exitObj->ivPoke('superFlag', TRUE);
1296  
1297 # Create region paths between this super-region exit and every other
1298 # super-region exit in the region
1299 $self->connectRegionExits(
1300 $session,
1301 $regionmapObj,
1302 $roomObj,
1303 $exitObj,
1304 );
1305  
1306 # If the exit has a twin, that exit should also be a super-region exit
1307 # (unless the user has marked the twin as definitely NOT being a
1308 # super-region exit)
1309 if ($exitObj->twinExit) {
1310  
1311 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
1312 if (
1313 $twinExitObj->regionFlag
1314 && ! $twinExitObj->superFlag
1315 && ! $twinExitObj->notSuperFlag
1316 ) {
1317 $twinExitObj->ivPoke('superFlag', TRUE);
1318 $twinRoomObj = $self->ivShow('modelHash', $twinExitObj->parent);
1319 $twinRegionObj
1320 = $self->ivShow('modelHash', $twinRoomObj->parent);
1321 $twinRegionmapObj
1322 = $self->ivShow('regionmapHash', $twinRegionObj->name);
1323  
1324 # Create region paths from the twin exit, too
1325 $self->connectRegionExits(
1326 $session,
1327 $twinRegionmapObj,
1328 $twinRoomObj,
1329 $twinExitObj,
1330 );
1331 }
1332 }
1333 }
1334  
1335 # Update the regionmap's list of region objects
1336 $regionmapObj->storeRegionExit($session, $exitObj);
1337 if ($twinRegionmapObj) {
1338  
1339 $twinRegionmapObj->storeRegionExit($session, $twinExitObj);
1340 }
1341  
1342 } else {
1343  
1344 # It's an existing region exit that has been modified (but not changed
1345 # region). Check all region paths starting or ending at this exit, to make
1346 # sure they're still valid and, if not, mark them for removal
1347 INNER: foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
1348  
1349 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
1350  
1351 if (
1352 (
1353 $pathObj->startExit == $exitObj->number
1354 || $pathObj->stopExit == $exitObj->number
1355 ) && ! $self->checkRegionPath($pathObj, $regionmapObj, FALSE)
1356 ) {
1357 $regionmapObj->removePaths($exitString, 'regionPathHash');
1358 }
1359 }
1360  
1361 INNER: foreach my $exitString (
1362 $regionmapObj->ivKeys('safeRegionPathHash')
1363 ) {
1364 my $pathObj = $regionmapObj->ivShow('safeRegionPathHash', $exitString);
1365  
1366 if (
1367 (
1368 $pathObj->startExit == $exitObj->number
1369 || $pathObj->stopExit == $exitObj->number
1370 ) && ! $self->checkRegionPath($pathObj, $regionmapObj, TRUE)
1371 ) {
1372 $regionmapObj->removePaths($exitString, 'safeRegionPathHash');
1373 }
1374 }
1375 }
1376  
1377 } until (! @newModList);
1378 }
1379 }
1380  
1381 # Next, deal with all non-region exits which have been created, modified or deleted since
1382 # the last spin of the timer loop (if any)
1383 if (%otherHash) {
1384  
1385 # Remove any region exits (which have already been processed)
1386 foreach my $otherExitNum (keys %otherHash) {
1387  
1388 my $regionmapObj;
1389  
1390 if (exists $boundaryHash{$otherExitNum}) {
1391  
1392 delete $otherHash{$otherExitNum};
1393  
1394 } else {
1395  
1396 # (As we go, create a hash of affected regionmaps, so that later on we can
1397 # check super-region exits)
1398 $regionmapObj = $self->ivShow('regionmapHash', $otherHash{$otherExitNum});
1399 if ($regionmapObj) {
1400  
1401 # (If a whole region is being deleted, $regionmapObj will be 'undef')
1402 $otherRegionmapHash{$regionmapObj->number} = $regionmapObj;
1403 }
1404 }
1405 }
1406  
1407 # Now, for each regionmap in %otherRegionmapHash, check each region path in turn. If any
1408 # of them use any of the exits still in %otherHash, the path must be recalculated
1409 OUTER: foreach my $regionmapObj (values %otherRegionmapHash) {
1410  
1411 # (Add to our hash of affected regionmaps)
1412 $regionmapHash{$regionmapObj->number} = $regionmapObj;
1413  
1414 CENTRE: foreach my $pathObj ($regionmapObj->ivValues('regionPathHash')) {
1415  
1416 INNER: foreach my $exitNum (
1417 $pathObj->startExit,
1418 $pathObj->exitList,
1419 $pathObj->stopExit,
1420 ) {
1421 if (exists $otherHash{$exitNum}) {
1422  
1423 # Replace the path
1424 $self->replaceRegionPath($session, $pathObj, $regionmapObj, FALSE);
1425  
1426 last INNER;
1427 }
1428 }
1429 }
1430  
1431 CENTRE: foreach my $pathObj ($regionmapObj->ivValues('safeRegionPathHash')) {
1432  
1433 INNER: foreach my $exitNum (
1434 $pathObj->startExit,
1435 $pathObj->exitList,
1436 $pathObj->stopExit,
1437 ) {
1438 if (exists $otherHash{$exitNum}) {
1439  
1440 # Replace the path
1441 $self->replaceRegionPath($session, $pathObj, $regionmapObj, TRUE);
1442  
1443 last INNER;
1444 }
1445 }
1446 }
1447 }
1448 }
1449  
1450 # Each affected region has been stored in %regionmapHash. Now check each of those
1451 # regionmaps in turn and add new super-region exits and paths, as necessary
1452 foreach my $regionmapObj (values %regionmapHash) {
1453  
1454 my (%mainHash, %superHash);
1455  
1456 # Check each region exit. If there are one or more region exits leading to the same
1457 # destination region, and none of them are super-region exits, mark one as a
1458 # super-region exit
1459  
1460 # Compile a hash in the form
1461 # $mainHash{destination_region_number} = [reference_to_list_of_region_exit_numbers]
1462 # For each super-region exit found, compile a parallel hash in the form
1463 # $superHash{destination_region_number} = undef
1464  
1465 foreach my $exitNum ($regionmapObj->ivKeys('regionExitHash')) {
1466  
1467 my ($exitObj, $destRegionNum, $listRef);
1468  
1469 $destRegionNum = $regionmapObj->ivShow('regionExitHash', $exitNum);
1470 $exitObj = $self->ivShow('exitModelHash', $exitNum);
1471  
1472 if (! exists $mainHash{$destRegionNum}) {
1473  
1474 $mainHash{$destRegionNum} = [$exitNum];
1475  
1476 } else {
1477  
1478 $listRef = $mainHash{$destRegionNum};
1479 push (@$listRef, $exitNum);
1480 }
1481  
1482 if ($exitObj->superFlag) {
1483  
1484 $superHash{$destRegionNum} = undef;
1485 }
1486 }
1487  
1488 # Check each destination region in turn. If none of the region exits leading to it are
1489 # super-region exits, mark one as a super-region exit, and then create region paths
1490 # between it and every other super-region exit in $regionmapObj
1491 OUTER: foreach my $destRegionNum (keys %mainHash) {
1492  
1493 my (
1494 $listRef, $superExitObj, $superRoomObj,
1495 @thisList,
1496 );
1497  
1498 $listRef = $mainHash{$destRegionNum};
1499  
1500 if (! exists $superHash{$destRegionNum}) {
1501  
1502 # By default, the preferred super-region exit is the one with the lowest exit
1503 # number (which was probably created first). We can't use exits which have
1504 # been marked by the user as normal super-region exits
1505 @thisList = sort {$a <=> $b} (@$listRef);
1506 INNER: foreach my $otherExitNum (@thisList) {
1507  
1508 my $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
1509 if (! $otherExitObj->notSuperFlag) {
1510  
1511 # We can use this exit
1512 $superExitObj = $otherExitObj;
1513 last INNER;
1514 }
1515 }
1516  
1517 if ($superExitObj) {
1518  
1519 $superRoomObj = $self->ivShow('modelHash', $superExitObj->parent);
1520 $superExitObj->ivPoke('superFlag', TRUE);
1521  
1522 # Create region paths between this super-region exit and every other
1523 # super-region exit in the region
1524 $self->connectRegionExits(
1525 $session,
1526 $regionmapObj,
1527 $superRoomObj,
1528 $superExitObj,
1529 );
1530 }
1531 }
1532 }
1533 }
1534  
1535 # Reset IVs
1536 $self->ivEmpty('updateBoundaryHash');
1537 $self->ivEmpty('updatePathHash');
1538 $self->ivEmpty('deleteBoundaryHash');
1539  
1540 return 1;
1541 }
1542  
1543 sub connectRegionExits {
1544  
1545 # Called by $self->updateRegionPaths, ->recalculateRegionPaths, ->recalculateSpecificPaths
1546 # and ->setSuperRegionExit
1547 # Given a region exit (which will normally be a super-region exit, but doesn't have to be),
1548 # create paths between the region exit and all other super-region exits in the same
1549 # region
1550 #
1551 # Expected arguments
1552 # $session - The calling function's GA::Session
1553 # $regionmapObj - The GA::Obj::Regionmap which contains the room
1554 # $roomObj - A GA::ModelObj::Room contained in the region
1555 # $exitObj - One of the room's GA::Obj::Exit objects (a region exit)
1556 #
1557 # Return values
1558 # 'undef' on improper arguments
1559 # 1 otherwise
1560  
1561 my ($self, $session, $regionmapObj, $roomObj, $exitObj, $check) = @_;
1562  
1563 # Check for improper arguments
1564 if (
1565 ! defined $session || ! defined $regionmapObj || ! defined $roomObj
1566 || ! defined $exitObj || defined $check
1567 ) {
1568 return $axmud::CLIENT->writeImproper($self->_objClass . '->connectRegionExits', @_);
1569 }
1570  
1571 OUTER: foreach my $otherExitNum ($regionmapObj->ivKeys('regionExitHash')) {
1572  
1573 my (
1574 $otherExitObj, $otherRoomObj, $pathRoomListRef, $pathExitListRef, $pathObj,
1575 $reverseRoomListRef, $reverseExitListRef, $safePathRoomListRef,
1576 $safePathExitListRef, $safeReverseRoomListRef, $safeReverseExitListRef,
1577 );
1578  
1579 # Get the other boundary exit and its parent room
1580 $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
1581 $otherRoomObj = $self->ivShow('modelHash', $otherExitObj->parent);
1582  
1583 # Don't try to draw a path between $exitObj and itself, and don't use non-super region
1584 # exits
1585 if ($otherExitNum == $exitObj->number || ! $otherExitObj->superFlag) {
1586  
1587 next OUTER;
1588 }
1589  
1590 # Find the shortest path between the two boundary rooms
1591 ($pathRoomListRef, $pathExitListRef) = $self->findPath(
1592 $roomObj,
1593 $otherRoomObj,
1594 FALSE, # Don't avoid hazards
1595 undef,
1596 TRUE, # Don't use adjacent regions
1597 );
1598  
1599 # If there is actually a path between the two rooms...
1600 if (@$pathRoomListRef) {
1601  
1602 # Save it
1603 $pathObj = Games::Axmud::Obj::RegionPath->new(
1604 $session,
1605 $exitObj->number,
1606 $otherExitObj->number,
1607 $pathRoomListRef,
1608 $pathExitListRef,
1609 );
1610  
1611 if ($pathObj) {
1612  
1613 # Store the path, replacing any previously-existing path between the same two
1614 # exits
1615 $regionmapObj->storePath('regionPathHash', $exitObj, $otherExitObj, $pathObj);
1616 }
1617 }
1618  
1619 # Also find the reverse path
1620 ($reverseRoomListRef, $reverseExitListRef) = $self->findPath(
1621 $otherRoomObj,
1622 $roomObj,
1623 FALSE, # Don't avoid hazards
1624 undef,
1625 TRUE, # Don't use adjacent regions
1626 );
1627  
1628 # Save it, if found
1629 if (@$reverseRoomListRef) {
1630  
1631 # Save it
1632 $pathObj = Games::Axmud::Obj::RegionPath->new(
1633 $session,
1634 $otherExitObj->number,
1635 $exitObj->number,
1636 $reverseRoomListRef,
1637 $reverseExitListRef,
1638 );
1639  
1640 if ($pathObj) {
1641  
1642 # Store the path, replacing any previously-existing path between the same two
1643 # exits
1644 $regionmapObj->storePath('regionPathHash', $otherExitObj, $exitObj, $pathObj);
1645 }
1646 }
1647  
1648 # Now we repeat this process using only paths that avoid rooms with hazardous room
1649 # flags
1650  
1651 # Find the shortest path between the new boundary room, $roomObj, and the parent
1652 # room of the other exit
1653 ($safePathRoomListRef, $safePathExitListRef) = $self->findPath(
1654 $roomObj,
1655 $otherRoomObj,
1656 TRUE, # Avoid hazards
1657 undef,
1658 TRUE, # Don't use adjacent regions
1659 );
1660  
1661 # If there is actually a safe path between the two rooms...
1662 if (@$safePathRoomListRef) {
1663  
1664 # Save it
1665 $pathObj = Games::Axmud::Obj::RegionPath->new(
1666 $session,
1667 $exitObj->number,
1668 $otherExitObj->number,
1669 $safePathRoomListRef,
1670 $safePathExitListRef,
1671 );
1672  
1673 if ($pathObj) {
1674  
1675 # Store the path, replacing any previously-existing path between the same two
1676 # exits
1677 $regionmapObj->storePath(
1678 'safeRegionPathHash',
1679 $exitObj,
1680 $otherExitObj,
1681 $pathObj,
1682 );
1683 }
1684 }
1685  
1686 # Also find the reverse path
1687 ($safeReverseRoomListRef, $safeReverseExitListRef) = $self->findPath(
1688 $otherRoomObj,
1689 $roomObj,
1690 TRUE, # Avoid hazards
1691 undef,
1692 TRUE, # Don't use adjacent regions
1693 );
1694  
1695 # If there is actually a safe path between the two rooms...
1696 if (@$safeReverseRoomListRef) {
1697  
1698 # Save it
1699 $pathObj = Games::Axmud::Obj::RegionPath->new(
1700 $session,
1701 $otherExitObj->number,
1702 $exitObj->number,
1703 $safeReverseRoomListRef,
1704 $safeReverseExitListRef,
1705 );
1706  
1707 if ($pathObj) {
1708  
1709 # Store the path, replacing any previously-existing path between the same two
1710 # exits
1711 $regionmapObj->storePath(
1712 'safeRegionPathHash',
1713 $otherExitObj,
1714 $exitObj,
1715 $pathObj,
1716 );
1717 }
1718 }
1719 }
1720  
1721 # Operation complete
1722 return 1;
1723 }
1724  
1725 sub checkRegionPath {
1726  
1727 # Called by $self->updateRegionPaths
1728 # Checks the path stored in a GA::Obj::RegionPath object, to make sure it is still usable
1729 #
1730 # Expected arguments
1731 # $pathObj - The region path object to check
1732 # $regionmapObj - The GA::Obj::Regionmap corresponding to the region path
1733 # $safeFlag - Set to TRUE if the path should avoid rooms with hazardous room flags,
1734 # FALSE if the path can use rooms with hazardous room flags
1735 #
1736 # Return values
1737 # 'undef' on improper arguments or if the path is no longer usable
1738 # 1 if the path is still usable
1739  
1740 my ($self, $pathObj, $regionmapObj, $safeFlag, $check) = @_;
1741  
1742 # Local variables
1743 my (
1744 @roomList, @exitList,
1745 %hazardHash,
1746 );
1747  
1748 # Check for improper arguments
1749 if (
1750 ! defined $pathObj || ! defined $regionmapObj || ! defined $safeFlag || defined $check
1751 ) {
1752 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRegionPath', @_);
1753 }
1754  
1755 # Import the path object's list of rooms and exits
1756 @roomList = $pathObj->roomList;
1757 @exitList = $pathObj->exitList;
1758 # For speed, import the hash of hazardous room flags
1759 %hazardHash = $axmud::CLIENT->constRoomHazardHash;
1760  
1761 # If the room list is empty then, of course, the path is not usable
1762 if (! @roomList) {
1763  
1764 return undef;
1765 }
1766  
1767 do {
1768  
1769 my ($roomNum, $roomObj, $exitNum, $exitObj, $nextRoomObj);
1770  
1771 $roomNum = shift @roomList;
1772 $exitNum = shift @exitList;
1773  
1774 # Check that the room still exists
1775 $roomObj = $self->ivShow('modelHash', $roomNum);
1776 if (! $roomObj) {
1777  
1778 return undef;
1779 }
1780  
1781 # Check that the room is still in the right region
1782 if ($roomObj->parent ne $regionmapObj->number) {
1783  
1784 return undef;
1785 }
1786  
1787 # Check that the room does not contain hazardous room flags (if $safeFlag is set)
1788 if ($safeFlag && $roomObj->roomFlagHash) {
1789  
1790 foreach my $roomFlag ($roomObj->ivKeys('roomFlagHash')) {
1791  
1792 if (exists $hazardHash{$roomFlag}) {
1793  
1794 return undef;
1795 }
1796 }
1797 }
1798  
1799 if (! defined $exitNum) {
1800  
1801 # We've reached the end of the path, which is therefore usable
1802 return 1;
1803 }
1804  
1805 # Check that the exit still exists
1806 $exitObj = $self->ivShow('exitModelHash', $exitNum);
1807 if (! $exitObj) {
1808  
1809 return undef;
1810 }
1811  
1812 # Check that the exit leads to the correct destination room (i.e., the next room in
1813 # @roomList)
1814 $nextRoomObj = $self->ivShow('modelHash', $roomList[0]);
1815 if (! $exitObj->destRoom || $exitObj->destRoom ne $nextRoomObj->number) {
1816  
1817 return undef;
1818 }
1819  
1820 # Check that the exit is passable
1821 if ($exitObj->exitOrnament eq 'impass' || $exitObj->exitOrnament eq 'mystery') {
1822  
1823 return undef;
1824 }
1825  
1826 } until (! @roomList);
1827  
1828 # Emergency default - the path is not usable
1829 return undef;
1830 }
1831  
1832 sub replaceRegionPath {
1833  
1834 # Called by $self->updateRegionPaths
1835 # Replaces a region path with a new GA::Obj::RegionPath object
1836 #
1837 # Expected arguments
1838 # $session - The calling function's GA::Session
1839 # $pathObj - The region path object to check
1840 # $regionmapObj - The GA::Obj::Regionmap corresponding to the region path
1841 # $safeFlag - Set to TRUE if the path should avoid rooms with hazardous room flags,
1842 # FALSE if the path can use rooms with hazardous room flags
1843 #
1844 # Return values
1845 # 'undef' on improper arguments or if the path is no longer usable
1846 # 1 if the path is still usable
1847  
1848 my ($self, $session, $pathObj, $regionmapObj, $safeFlag, $check) = @_;
1849  
1850 # Local variables
1851 my (
1852 $startExitObj, $stopExitObj, $startRoomObj, $stopRoomObj, $pathRoomListRef,
1853 $pathExitListRef, $newPathObj, $exitString,
1854 );
1855  
1856 # Check for improper arguments
1857 if (
1858 ! defined $session || ! defined $pathObj || ! defined $regionmapObj
1859 || ! defined $safeFlag || defined $check
1860 ) {
1861 return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceRegionPath', @_);
1862 }
1863  
1864 # Get the boundary exits from the existing region path
1865 $startExitObj = $self->ivShow('exitModelHash', $pathObj->startExit);
1866 $stopExitObj = $self->ivShow('exitModelHash', $pathObj->stopExit);
1867 # Get their parent rooms
1868 $startRoomObj = $self->ivShow('modelHash', $startExitObj->parent);
1869 $stopRoomObj = $self->ivShow('modelHash', $stopExitObj->parent);
1870  
1871 # Find the shortest path between the two boundary rooms
1872 ($pathRoomListRef, $pathExitListRef) = $self->findPath(
1873 $startRoomObj,
1874 $stopRoomObj,
1875 $safeFlag, # Avoid hazards, or not
1876 undef,
1877 TRUE, # Don't use adjacent regions
1878 );
1879  
1880 # If there is actually a path between the two rooms...
1881 if (@$pathRoomListRef) {
1882  
1883 # Save it
1884 $newPathObj = Games::Axmud::Obj::RegionPath->new(
1885 $session,
1886 $startExitObj->number,
1887 $stopExitObj->number,
1888 $pathRoomListRef,
1889 $pathExitListRef,
1890 );
1891  
1892 if ($newPathObj) {
1893  
1894 # Store the path, replacing any previously-existing path between the same two
1895 # exits
1896 if (! $safeFlag) {
1897  
1898 $regionmapObj->storePath(
1899 'regionPathHash',
1900 $startExitObj,
1901 $stopExitObj,
1902 $newPathObj,
1903 );
1904  
1905 } else {
1906  
1907 $regionmapObj->storePath(
1908 'safeRegionPathHash',
1909 $startExitObj,
1910 $stopExitObj,
1911 $newPathObj,
1912 );
1913 }
1914 }
1915  
1916 } else {
1917  
1918 # Even though a new path could not be found, the existing path is invalid, and must be
1919 # removed
1920 $exitString = $pathObj->startExit . '_' . $pathObj->stopExit;
1921  
1922 if (! $safeFlag) {
1923 $regionmapObj->removePaths($exitString, 'regionPathHash');
1924 } else {
1925 $regionmapObj->removePaths($exitString, 'safeRegionPathHash');
1926 }
1927 }
1928  
1929 return 1;
1930 }
1931  
1932 sub updateModelBuffers {
1933  
1934 # Called by GA::Session->spinMaintainLoop
1935 # When a model object or exit object is deleted, the number is temporarily stored in
1936 # $self->modelBufferList or $self->exitBufferList
1937 # If either IV contains any numbers, copy them into ->modelDeletedList or ->exitDeletedList
1938 # so that they're available for re-use
1939 #
1940 # Expected arguments
1941 # (none besides $self)
1942 #
1943 # Return values
1944 # 'undef' on improper arguments
1945 # 1 otherwise
1946  
1947 my ($self, $check) = @_;
1948  
1949 # Check for improper arguments
1950 if (defined $check) {
1951  
1952 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateModelBuffers', @_);
1953 }
1954  
1955 if ($self->modelBufferList) {
1956  
1957 $self->ivPush('modelDeletedList', sort {$a <=> $b} ($self->modelBufferList));
1958 $self->ivEmpty('modelBufferList');
1959 }
1960  
1961 if ($self->exitBufferList) {
1962  
1963 $self->ivPush('exitDeletedList', sort {$a <=> $b} ($self->exitBufferList));
1964 $self->ivEmpty('exitBufferList');
1965 }
1966  
1967 return 1
1968 }
1969  
1970 sub updateRegionLevels {
1971  
1972 # Called by GA::Session->spinMaintainLoop
1973 # When a room model object or map label is added, moved or deleted, the parent regionmap's
1974 # name is temporarily stored in $self->checkLevelsHash
1975 # Ask each regionmap to re-calculate its highest and lowest occupied levels
1976 #
1977 # Expected arguments
1978 # (none besides $self)
1979 #
1980 # Return values
1981 # 'undef' on improper arguments
1982 # 1 otherwise
1983  
1984 my ($self, $check) = @_;
1985  
1986 # Local variables
1987 my @mapWinList;
1988  
1989 # Check for improper arguments
1990 if (defined $check) {
1991  
1992 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRegionLevels', @_);
1993 }
1994  
1995 # Collect a list of automapper windows used by this world model now (so we only have to do
1996 # it once)
1997 @mapWinList = $self->collectMapWins();
1998  
1999 OUTER: foreach my $regionName ($self->ivKeys('checkLevelsHash')) {
2000  
2001 my ($regionmapObj, $high, $low);
2002  
2003 $regionmapObj = $self->ivShow('regionmapHash', $regionName);
2004 if (! $regionmapObj) {
2005  
2006 # Region has just been deleted, so move on to the next one
2007 next OUTER;
2008 }
2009  
2010 # Check every room in the map, finding the highest and lowest occupied level
2011 foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) {
2012  
2013 my $roomObj = $self->ivShow('modelHash', $roomNum);
2014 if ($roomObj) {
2015  
2016 if (! defined $high || $high < $roomObj->zPosBlocks) {
2017  
2018 $high = $roomObj->zPosBlocks;
2019 }
2020  
2021 if (! $low || $low > $roomObj->zPosBlocks) {
2022  
2023 $low = $roomObj->zPosBlocks;
2024 }
2025 }
2026 }
2027  
2028 # Likewise check every label
2029 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
2030  
2031 if (! defined $high || $high < $labelObj->level) {
2032  
2033 $high = $labelObj->level;
2034 }
2035  
2036 if (! $low || $low > $labelObj->level) {
2037  
2038 $low = $labelObj->level;
2039 }
2040 }
2041  
2042 # If there are no rooms/labels in the regionmap, $high and $low will be 'undef' which
2043 # is, in that situation, also the correct value for the IVs
2044 $regionmapObj->ivPoke('highestLevel', $high);
2045 $regionmapObj->ivPoke('lowestLevel', $low);
2046  
2047 # All parchment objects can now be updated to remove canvas widgets for the unoccupied
2048 # levels (in this case, treat the window's visible level as the highest or lowest
2049 # level)
2050 foreach my $mapWin (@mapWinList) {
2051  
2052 my ($thisHigh, $thisLow, $parchmentObj);
2053  
2054 if (! defined $regionmapObj->highestLevel) {
2055  
2056 $thisHigh = 0;
2057 $thisLow = 0;
2058  
2059 } else {
2060  
2061 $thisHigh = $regionmapObj->highestLevel;
2062 $thisLow = $regionmapObj->lowestLevel;
2063 }
2064  
2065 if ($mapWin->currentRegionmap) {
2066  
2067 if ($mapWin->currentRegionmap->currentLevel > $thisHigh) {
2068 $thisHigh = $mapWin->currentRegionmap->currentLevel;
2069 } elsif ($mapWin->currentRegionmap->currentLevel < $thisLow) {
2070 $thisLow = $mapWin->currentRegionmap->currentLevel;
2071 }
2072 }
2073  
2074 # Furthermore, increase the highest/lowest occupied level by 1 so that room
2075 # echos can be drawn
2076 $thisHigh++;
2077 $thisLow--;
2078  
2079 # Remove any redundant canvas widgets
2080 $parchmentObj = $mapWin->ivShow('parchmentHash', $regionmapObj->name);
2081 if ($parchmentObj) {
2082  
2083 foreach my $level ($parchmentObj->ivKeys('canvasWidgetHash')) {
2084  
2085 if ($level > $thisHigh || $level < $thisLow) {
2086  
2087 $parchmentObj->ivDelete('canvasWidgetHash', $level);
2088 $parchmentObj->ivDelete('bgCanvasObjHash', $level);
2089 $parchmentObj->ivDelete('levelHash', $level);
2090 }
2091 }
2092 }
2093 }
2094 }
2095  
2096 # Update any GA::Win::Map objects using this world model
2097 foreach my $mapWin (@mapWinList) {
2098  
2099 # If the automapper is showing the same region...
2100 if (
2101 $mapWin->currentRegionmap
2102 && $self->ivExists('checkLevelsHash', $mapWin->currentRegionmap->name)
2103 ) {
2104 # ...redraw its title bar to show up/down arrows
2105 $mapWin->setWinTitle();
2106 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions (as
2107 # a response to this calculation)
2108 $mapWin->restrictWidgets();
2109 }
2110 }
2111  
2112 # Reset the IV
2113 $self->ivEmpty('checkLevelsHash');
2114  
2115 return 1
2116 }
2117  
2118 # Model test methods
2119  
2120 sub testModel {
2121  
2122 # Called by GA::Cmd::TestModel->do, GA::Cmd::MergeModel->do (or by any other function)
2123 # Tests the integrity of the world model and (optionally) fixes as many errors as possible
2124 #
2125 # Expected arguments
2126 # $session - The calling function's GA::Session
2127 #
2128 # Optional values
2129 # $fixFlag - If TRUE, fixes any errors that can be fixed. If FALSE or 'undef', does
2130 # not attempt to fix any errors
2131 # $diagnoseFlag - If TRUE, returns a list of values. If FALSE or 'undef', returns a
2132 # simple pass or fail value
2133 #
2134 # Return values
2135 # If $diagnoseFlag is TRUE:
2136 # Returns an empty list on improper arguments
2137 # Otherwise, returns a list in the form
2138 # (error_count, fix_count, message, message, message...)
2139 # ...where 'message' are any number (including zero) of error messages
2140 # If $diagnoseFlag is FALSE or 'undef':
2141 # Returns 'undef' on improper arguments or if there are any errors
2142 # Returns 1 if there are no errors
2143  
2144 my ($self, $session, $fixFlag, $diagnoseFlag, $check) = @_;
2145  
2146 # Local variables
2147 my (
2148 $errorCount, $fixCount, $count,
2149 @emptyList, @outputList, @categoryList,
2150 %modelHash, %exitModelHash, %regionModelHash, %regionmapHash, %charModelHash,
2151 %knownCharHash, %roomModelHash, %roomTagHash, %abandonExitHash,
2152 );
2153  
2154 # Check for improper arguments
2155 if (! defined $session || defined $check) {
2156  
2157 $axmud::CLIENT->writeImproper($self->_objClass . '->testModel', @_);
2158  
2159 if ($diagnoseFlag) {
2160 return @emptyList;
2161 } else {
2162 return undef;
2163 }
2164 }
2165  
2166 # So that the calls to $self->testModelRoom and $self->testModelExit can do better improper
2167 # arguments checks, give the optional flags defined values
2168 if (! $fixFlag) {
2169 $fixFlag = FALSE;
2170 } else {
2171 $fixFlag = TRUE;
2172 }
2173  
2174 if (! $diagnoseFlag) {
2175 $diagnoseFlag = FALSE;
2176 } else {
2177 $diagnoseFlag = TRUE;
2178 }
2179  
2180 # Initialise counts
2181 $errorCount = 0;
2182 $fixCount = 0;
2183  
2184 # Check that ->modelActualCount and ->exitActualCount are correct
2185 %modelHash = $self->modelHash;
2186 $count = scalar (keys %modelHash);
2187 if ($count != $self->modelActualCount) {
2188  
2189 push (@outputList,
2190 ' ->modelActualCount should be ' . $self->modelActualCount . ', but is '
2191 . $count,
2192 );
2193  
2194 $errorCount++;
2195 if ($fixFlag) {
2196  
2197 # When -f is used, fix errors
2198 $self->ivPoke('modelActualCount', scalar (keys %modelHash));
2199 $fixCount++;
2200 }
2201 }
2202  
2203 %exitModelHash = $self->exitModelHash;
2204 $count = scalar (keys %exitModelHash);
2205 if ($count != $self->exitActualCount) {
2206  
2207 push (@outputList,
2208 ' ->exitActualCount should be ' . $self->exitActualCount . ', but is '
2209 . $count,
2210 );
2211  
2212 $errorCount++;
2213 if ($fixFlag) {
2214  
2215 $self->ivPoke('exitActualCount', scalar (keys %exitModelHash));
2216 $fixCount++;
2217 }
2218 }
2219  
2220 # Check that ->modelDeletedList and ->exitDeletedList are not still in the model
2221 %modelHash = $self->modelHash;
2222 foreach my $num ($self->modelDeletedList) {
2223  
2224 if (exists $modelHash{$num}) {
2225  
2226 push (@outputList,
2227 ' Deleted model object #' . $num . ' still exists in the model',
2228 );
2229  
2230 $errorCount++;
2231 if ($fixFlag) {
2232  
2233 $self->ivDelete('modelHash', $num);
2234 $fixCount++;
2235 }
2236 }
2237 }
2238  
2239 %exitModelHash = $self->exitModelHash;
2240 foreach my $num ($self->exitDeletedList) {
2241  
2242 if (exists $exitModelHash{$num}) {
2243  
2244 push (@outputList,
2245 ' Deleted exit model object #' . $num . ' still exists in the exit model',
2246 );
2247  
2248 $errorCount++;
2249 if ($fixFlag) {
2250  
2251 $self->ivDelete('exitModelHash', $num);
2252 $fixCount++;
2253 }
2254 }
2255 }
2256  
2257 # Check that ->modelBufferList and ->exitBufferList are not still in the model
2258 %modelHash = $self->modelHash;
2259 foreach my $num ($self->modelBufferList) {
2260  
2261 if (exists $modelHash{$num}) {
2262  
2263 push (@outputList,
2264 ' Buffered model object #' . $num . ' still exists in the model',
2265 );
2266  
2267 $errorCount++;
2268 if ($fixFlag) {
2269  
2270 $self->ivDelete('modelHash', $num);
2271 $fixCount++;
2272 }
2273 }
2274 }
2275  
2276 %exitModelHash = $self->exitModelHash;
2277 foreach my $num ($self->exitBufferList) {
2278  
2279 if (exists $exitModelHash{$num}) {
2280  
2281 push (@outputList,
2282 ' Buffered exit model object #' . $num . ' still exists in the exit model',
2283 );
2284  
2285 $errorCount++;
2286 if ($fixFlag) {
2287  
2288 $self->ivDelete('exitModelHash', $num);
2289 $fixCount++;
2290 }
2291 }
2292 }
2293  
2294 # Check that everything in ->regionModelHash, etc, is the right category, exists in
2295 # ->modelHash and points to the same object
2296 @categoryList = (
2297 'region', 'room', 'weapon', 'armour', 'garment', 'char', 'minion', 'sentient',
2298 'creature', 'portable', 'decoration', 'custom',
2299 );
2300  
2301 %modelHash = $self->modelHash;
2302 OUTER: foreach my $category (@categoryList) {
2303  
2304 my (
2305 $iv,
2306 %thisHash,
2307 );
2308  
2309 $iv = $category . 'ModelHash'; # e.g. ->regionModelHash
2310 %thisHash = $self->$iv;
2311  
2312 INNER: foreach my $num (keys %thisHash) {
2313  
2314 my ($obj, $realObj);
2315  
2316 $obj = $thisHash{$num};
2317  
2318 if (! exists $modelHash{$num}) {
2319  
2320 push (@outputList,
2321 ' \'' . $category . '\' object exists in ->' . $iv . ', but not in'
2322 . '->modelHash',
2323 );
2324  
2325 $errorCount++;
2326 if ($fixFlag) {
2327  
2328 $self->ivDelete($iv, $num);
2329 $fixCount++;
2330 }
2331  
2332 next INNER;
2333 }
2334  
2335 if ($obj->category ne $category) {
2336  
2337 push (@outputList,
2338 ' \'' . $category . '\' object exists in ->' . $iv . ', but is not a \''
2339 . $category . '\' object',
2340 );
2341  
2342 $errorCount++;
2343 if ($fixFlag) {
2344  
2345 $self->ivDelete($iv, $num);
2346 $fixCount++;
2347 }
2348  
2349 next INNER;
2350 }
2351  
2352 $realObj = $modelHash{$num};
2353 if ($realObj ne $obj) {
2354  
2355 push (@outputList,
2356 ' \'' . $category . '\' object exists in ->' . $iv . ', but is not the'
2357 . ' same object that exists in ->modelHash',
2358 );
2359  
2360 $errorCount++;
2361 if ($fixFlag) {
2362  
2363 $self->ivDelete($iv, $num);
2364 $fixCount++;
2365 }
2366  
2367 next INNER;
2368 }
2369 }
2370 }
2371  
2372 # Check that every exit has a parent room
2373 %modelHash = $self->modelHash;
2374 %exitModelHash = $self->exitModelHash;
2375 OUTER: foreach my $exitObj (values %exitModelHash) {
2376  
2377 my $roomObj = $modelHash{$exitObj->parent};
2378 if (! $roomObj) {
2379  
2380 push (@outputList,
2381 ' Exit #' . $exitObj->number . ' does not have a parent room',
2382 );
2383  
2384 $errorCount++;
2385 if ($fixFlag) {
2386  
2387 # Cannot call GA::Obj::WorldModel->deleteExit, as that function assumes the exit
2388 # has a parent room and that the room has a parent region; instead, use a
2389 # function written especially for ;testmodel
2390 $self->emergencyDeleteExit($exitObj);
2391 $fixCount++;
2392 }
2393  
2394 } elsif ($roomObj->category ne 'room') {
2395  
2396 push (@outputList,
2397 ' Exit #' . $exitObj->number . ' has a parent room #' . $roomObj->number
2398 . ' which is actually a \'' . $roomObj->category . '\' object',
2399 );
2400  
2401 $errorCount++;
2402 if ($fixFlag) {
2403  
2404 $self->emergencyDeleteExit($exitObj);
2405 $fixCount++;
2406 }
2407 }
2408 }
2409  
2410 # Check that every exit has a defined ->mapDir (except for unallocatable exits, whose
2411 # ->drawMode is 'temp_unalloc'; in that case, ->mapDir must be 'undef')
2412 %exitModelHash = $self->exitModelHash;
2413 OUTER: foreach my $exitObj (values %exitModelHash) {
2414  
2415 if ($exitObj->drawMode eq 'temp_unalloc' && defined $exitObj->mapDir) {
2416  
2417 push (@outputList,
2418 ' Unallocatable exit #' . $exitObj->number . ' has a defined map'
2419 . ' direction \'' . $exitObj->mapDir,
2420 );
2421  
2422 $errorCount++;
2423 if ($fixFlag) {
2424  
2425 $self->emergencyDeleteExit($exitObj);
2426 $fixCount++;
2427 }
2428  
2429 } elsif ($exitObj->drawMode ne 'temp_unalloc' && ! defined $exitObj->mapDir) {
2430  
2431 push (@outputList,
2432 ' Exit #' . $exitObj->number . ' has an undefined map direction (and is not'
2433 . ' unallocatable)',
2434 );
2435  
2436 $errorCount++;
2437 if ($fixFlag) {
2438  
2439 $self->emergencyDeleteExit($exitObj);
2440 $fixCount++;
2441 }
2442 }
2443 }
2444  
2445 # Check that the regionmap list matches the region list
2446 %regionModelHash = $self->regionModelHash;
2447 %regionmapHash = $self->regionmapHash;
2448 OUTER: foreach my $regionName (keys %regionmapHash) {
2449  
2450 my $regionmapObj = $regionmapHash{$regionName};
2451  
2452 if (! exists $regionModelHash{$regionmapObj->number}) {
2453  
2454 push (@outputList,
2455 ' Regionmap \'' . $regionName . '\' does not have a corresponding region'
2456 . ' object in ->regionModelHash (not auto-fixable)',
2457 );
2458  
2459 $errorCount++;
2460  
2461 next OUTER;
2462  
2463 } else {
2464  
2465 delete $regionModelHash{$regionmapObj->number};
2466 }
2467 }
2468  
2469 if (%regionModelHash) {
2470  
2471 foreach my $regionObj (values %regionModelHash) {
2472  
2473 push (@outputList,
2474 ' Region \'' . $regionObj->name . '\' does not have a corresponding'
2475 . ' regionmap in ->regionmapHash (not auto-fixable)',
2476 );
2477  
2478 $errorCount++;
2479 }
2480 }
2481  
2482 # Check that the known character hash matches ->charModelHash
2483 %charModelHash = $self->charModelHash;
2484 %knownCharHash = $self->knownCharHash;
2485 OUTER: foreach my $charName (keys %knownCharHash) {
2486  
2487 my $charObj = $knownCharHash{$charName};
2488  
2489 if (! exists $charModelHash{$charObj->number}) {
2490  
2491 push (@outputList,
2492 ' ->knownCharHash \'' . $charName . '\' does not have a corresponding model'
2493 . ' object in ->charModelHash (not auto-fixable)',
2494 );
2495  
2496 $errorCount++;
2497  
2498 next OUTER;
2499  
2500 } else {
2501  
2502 delete $charModelHash{$charObj->number};
2503 }
2504 }
2505  
2506 if (%charModelHash) {
2507  
2508 foreach my $charObj (values %charModelHash) {
2509  
2510 push (@outputList,
2511 ' Character \'' . $charObj->name . '\' does not have a corresponding'
2512 . ' entry in ->knownCharHash (not auto-fixable)',
2513 );
2514  
2515 $errorCount++;
2516 }
2517 }
2518  
2519 # Check that ->roomTagHash is right
2520 %roomModelHash = $self->roomModelHash;
2521 %roomTagHash = $self->roomTagHash;
2522 OUTER: foreach my $tag (keys %roomTagHash) {
2523  
2524 my ($roomNum, $roomObj);
2525  
2526 $roomNum = $roomTagHash{$tag};
2527  
2528 if (! exists $roomModelHash{$roomNum}) {
2529  
2530 push (@outputList,
2531 ' ->roomTagHash tag \'' . $tag . '\' points to room #' . $roomNum
2532 . ' which is not in ->roomModelHash (not auto-fixable)',
2533 );
2534  
2535 $errorCount++;
2536  
2537 next OUTER;
2538 }
2539  
2540 $roomObj = $roomModelHash{$roomNum};
2541 if (! $roomObj->roomTag) {
2542  
2543 push (@outputList,
2544 ' ->roomTagHash tag \'' . $tag . '\' points to room #' . $roomNum
2545 . ' which does not have a room tag (not auto-fixable)',
2546 );
2547  
2548 $errorCount++;
2549  
2550 next OUTER;
2551  
2552 } elsif ($roomObj->roomTag ne $tag) {
2553  
2554 push (@outputList,
2555 ' ->roomTagHash tag \'' . $tag . '\' points to room #' . $roomNum
2556 . ' which has a different room tag, \'' . $roomObj->roomTag . '\' (not'
2557 . ' auto-fixable)',
2558 );
2559  
2560 $errorCount++;
2561  
2562 next OUTER;
2563  
2564 } else {
2565  
2566 delete $roomModelHash{$roomNum};
2567 }
2568 }
2569  
2570 foreach my $roomObj (values %roomModelHash) {
2571  
2572 if ($roomObj->roomTag) {
2573  
2574 push (@outputList,
2575 ' ->roomModelHash room \'' . $roomObj->number . '\' has a room tag \''
2576 . $roomObj->roomTag . '\' which has no corresponding entry in ->roomTagHash'
2577 . ' (not auto-fixable)',
2578 );
2579  
2580 $errorCount++;
2581  
2582 next OUTER;
2583 }
2584 }
2585  
2586 # Check that every room's exits exist in the exit model
2587 %roomModelHash = $self->roomModelHash;
2588 %exitModelHash = $self->exitModelHash;
2589 OUTER: foreach my $roomObj (values %roomModelHash) {
2590  
2591 my (
2592 @sortedExitList,
2593 %exitNumHash,
2594 );
2595  
2596 @sortedExitList = $roomObj->sortedExitList;
2597 %exitNumHash = $roomObj->exitNumHash;
2598  
2599 INNER: foreach my $exitDir (keys %exitNumHash) {
2600  
2601 my $exitNum = $exitNumHash{$exitDir};
2602  
2603 if (! exists $exitModelHash{$exitNum}) {
2604  
2605 push (@outputList,
2606 ' Room #' . $roomObj->number . ' exit #' . $exitNum . ' does not exist in'
2607 . ' ->exitModelHash',
2608 );
2609  
2610 $errorCount++;
2611 if ($fixFlag) {
2612  
2613 my @newList;
2614  
2615 $roomObj->ivDelete('exitNumHash', $exitDir);
2616 # Remove the corresponding entry in ->sortedExitList
2617 foreach my $item (@sortedExitList) {
2618  
2619 if ($item ne $exitDir) {
2620  
2621 push (@newList, $item);
2622 }
2623 }
2624  
2625 $roomObj->ivPoke('sortedExitList', @newList);
2626 $fixCount++;
2627 }
2628 }
2629  
2630 next INNER;
2631 }
2632 }
2633  
2634 # Check that every room's exit has corresponding entries in ->sortedExitList and
2635 # ->exitNumHash
2636 %roomModelHash = $self->roomModelHash;
2637 OUTER: foreach my $roomObj (values %roomModelHash) {
2638  
2639 my (
2640 @sortedExitList,
2641 %exitNumHash,
2642 );
2643  
2644 @sortedExitList = $roomObj->sortedExitList;
2645 %exitNumHash = $roomObj->exitNumHash;
2646  
2647 foreach my $dir (@sortedExitList) {
2648  
2649 if (! exists $exitNumHash{$dir}) {
2650  
2651 push (@outputList,
2652 ' Room #' . $roomObj->number . ' exit in direction \'' . $dir . '\' does'
2653 . ' not have a corresponding entry in ->exitNumHash (not auto-fixable)',
2654 );
2655  
2656 $errorCount++;
2657  
2658 } else {
2659  
2660 delete $exitNumHash{$dir};
2661 }
2662 }
2663  
2664 if (%exitNumHash) {
2665  
2666 foreach my $dir (keys %exitNumHash) {
2667  
2668 push (@outputList,
2669 ' Room #' . $roomObj->number . ' exit #' . $dir . '\' does not have a'
2670 . ' corresponding entry in ->sortedExitList (not auto-fixable)',
2671 );
2672  
2673 $errorCount++;
2674 }
2675 }
2676 }
2677  
2678 # Check that every twinned exit's twin still exists, and knows about its twin
2679 %exitModelHash = $self->exitModelHash;
2680 OUTER: foreach my $exitObj (values %exitModelHash) {
2681  
2682 my $twinExitObj;
2683  
2684 if ($exitObj->twinExit) {
2685  
2686 if (! exists $exitModelHash{$exitObj->twinExit}) {
2687  
2688 push (@outputList,
2689 ' Exit #' . $exitObj->number . ' has a twin exit #' . $exitObj->twinExit
2690 . ' which no longer exists',
2691 );
2692  
2693 $errorCount++;
2694 # We'll get all the mismatched twin exits to abandon each other all in one go,
2695 # in a moment
2696 $abandonExitHash{$exitObj->number} = $exitObj;
2697  
2698 } else {
2699  
2700 $twinExitObj = $exitModelHash{$exitObj->twinExit};
2701 if (! $twinExitObj->twinExit) {
2702  
2703 push (@outputList,
2704 ' Exit #' . $exitObj->number . ' has a twin exit #'
2705 . $exitObj->twinExit . ' which is not itself twinned to anything',
2706 );
2707  
2708 $errorCount++;
2709 $abandonExitHash{$exitObj->number} = $exitObj;
2710  
2711 } elsif ($twinExitObj->twinExit != $exitObj->number) {
2712  
2713 push (@outputList,
2714 ' Exit #' . $exitObj->number . ' has a twin exit #'
2715 . $exitObj->twinExit . ' which is twinned to some other exit (#'
2716 . $twinExitObj->twinExit . ')',
2717 );
2718  
2719 $errorCount++;
2720 $abandonExitHash{$exitObj->number} = $exitObj;
2721 }
2722 }
2723 }
2724 }
2725  
2726 if ($fixFlag) {
2727  
2728 # Abandon any rogue twin exits in %abandonExitHash
2729 foreach my $exitObj (values %abandonExitHash) {
2730  
2731 $self->abandonTwinExit(
2732 FALSE, # Don't update Automapper windows yet
2733 $exitObj,
2734 );
2735  
2736 $fixCount++;
2737 }
2738 }
2739  
2740 # Check that every incoming uncertain, one way and random exit still exists, and actually
2741 # points to its room
2742 %exitModelHash = $self->exitModelHash;
2743 %roomModelHash = $self->roomModelHash;
2744 OUTER: foreach my $roomObj (values %roomModelHash) {
2745  
2746 my (%uncertainExitHash, %oneWayExitHash, %randomExitHash);
2747  
2748 %uncertainExitHash = $roomObj->uncertainExitHash;
2749 %oneWayExitHash = $roomObj->oneWayExitHash;
2750 %randomExitHash = $roomObj->randomExitHash;
2751  
2752 INNER: foreach my $exitNum (keys %uncertainExitHash) {
2753  
2754 my $exitObj;
2755  
2756 if (! exists $exitModelHash{$exitNum}) {
2757  
2758 push (@outputList,
2759 ' Room #' . $roomObj->number . ' incoming uncertain exit #' . $exitNum
2760 . ' does not exist in ->exitModelHash (not auto-fixable)',
2761 );
2762  
2763 $errorCount++;
2764 next INNER;
2765 }
2766  
2767 $exitObj = $exitModelHash{$exitNum};
2768 if (! $exitObj->destRoom || $exitObj->destRoom != $roomObj->number) {
2769  
2770 push (@outputList,
2771 ' Room #' . $roomObj->number . ' incoming uncertain exit #' . $exitNum
2772 . ' does not lead to the room (not auto-fixable)',
2773 );
2774  
2775 $errorCount++;
2776 next INNER;
2777 }
2778 }
2779  
2780 INNER: foreach my $exitNum (keys %oneWayExitHash) {
2781  
2782 my $exitObj;
2783  
2784 if (! exists $exitModelHash{$exitNum}) {
2785  
2786 push (@outputList,
2787 ' Room #' . $roomObj->number . ' incoming one-way exit #' . $exitNum
2788 . ' does not exist in ->exitModelHash (not auto-fixable)',
2789 );
2790  
2791 $errorCount++;
2792 next INNER;
2793 }
2794  
2795 $exitObj = $exitModelHash{$exitNum};
2796 if (! $exitObj->destRoom || $exitObj->destRoom != $roomObj->number) {
2797  
2798 push (@outputList,
2799 ' Room #' . $roomObj->number . ' incoming one-way exit #' . $exitNum
2800 . ' does not lead to the room (not auto-fixable)',
2801 );
2802  
2803 $errorCount++;
2804 next INNER;
2805 }
2806 }
2807  
2808 INNER: foreach my $exitNum (keys %randomExitHash) {
2809  
2810 my ($exitObj, $matchFlag);
2811  
2812 if (! exists $exitModelHash{$exitNum}) {
2813  
2814 push (@outputList,
2815 ' Room #' . $roomObj->number . ' incoming random exit #' . $exitNum
2816 . ' does not exist in ->exitModelHash (not auto-fixable)',
2817 );
2818  
2819 $errorCount++;
2820 next INNER;
2821 }
2822  
2823 $exitObj = $exitModelHash{$exitNum};
2824 if ($exitObj->randomType eq 'none') {
2825  
2826 push (@outputList,
2827 ' Room #' . $roomObj->number . ' incoming random exit #' . $exitNum
2828 . ' is not marked as a random exit (not auto-fixable)',
2829 );
2830  
2831 $errorCount++;
2832 next INNER;
2833  
2834 } elsif ($exitObj->randomType ne 'room_list') {
2835  
2836 push (@outputList,
2837 ' Room #' . $roomObj->number . ' incoming random exit #' . $exitNum
2838 . ' is marked as a random exit of the wrong type (not auto-fixable)',
2839 );
2840  
2841 $errorCount++;
2842 next INNER;
2843 }
2844  
2845 DEEPER: foreach my $destRoomNum ($exitObj->randomDestList) {
2846  
2847 if ($destRoomNum == $roomObj->number) {
2848  
2849 $matchFlag = TRUE;
2850 last DEEPER;
2851 }
2852 }
2853  
2854 if (! $matchFlag) {
2855  
2856 push (@outputList,
2857 ' Room #' . $roomObj->number . ' incoming random exit #' . $exitNum
2858 . ' does not know that it leads to the room (not auto-fixable)',
2859 );
2860  
2861 $errorCount++;
2862 }
2863 }
2864 }
2865  
2866 # Check that only one-way exits have their ->oneWayDir set
2867 %exitModelHash = $self->exitModelHash;
2868 OUTER: foreach my $exitObj (values %exitModelHash) {
2869  
2870 if (! $exitObj->oneWayFlag && defined $exitObj->oneWayDir) {
2871  
2872 push (@outputList,
2873 ' Exit #' . $exitObj->number . ' is not a one-way exit, but has a one-way'
2874 . ' direction set',
2875 );
2876  
2877 $errorCount++;
2878 if ($fixFlag) {
2879  
2880 $exitObj->ivUndef('oneWayDir');
2881 $fixCount++;
2882 }
2883 }
2884 }
2885  
2886 # Check every random exit
2887 %exitModelHash = $self->exitModelHash;
2888 %roomModelHash = $self->roomModelHash;
2889 OUTER: foreach my $exitObj (values %exitModelHash) {
2890  
2891 if ($exitObj->randomType ne 'room_list' && $exitObj->randomDestList) {
2892  
2893 push (@outputList,
2894 ' Random exit #' . $exitObj->number . ' has a list of destination rooms,'
2895 . ' but its ->randomType is not set to \'room_list\' (not auto-fixable)',
2896 );
2897  
2898 $errorCount++;
2899 next OUTER;
2900  
2901 } elsif ($exitObj->randomType eq 'room_list') {
2902  
2903 INNER: foreach my $roomNum ($exitObj->randomDestList) {
2904  
2905 my $roomObj;
2906  
2907 if (! exists $roomModelHash{$roomNum}) {
2908  
2909 push (@outputList,
2910 ' Random exit #' . $exitObj->number . ' destination room #' . $roomNum
2911 . ' does not exist (not auto-fixable)',
2912 );
2913  
2914 $errorCount++;
2915  
2916 } else {
2917  
2918 $roomObj = $roomModelHash{$roomNum};
2919 if (! $roomObj->ivExists('randomExitHash', $exitObj->number)) {
2920  
2921 push (@outputList,
2922 ' Random exit #' . $exitObj->number . ' destination room #'
2923 . $roomNum . ' does not know about the incoming random exit (not'
2924 . ' auto-fixable)',
2925 );
2926  
2927 $errorCount++;
2928 }
2929 }
2930 }
2931 }
2932 }
2933  
2934 # Check every region exit
2935 %modelHash = $self->modelHash;
2936 %exitModelHash = $self->exitModelHash;
2937 OUTER: foreach my $exitObj (values %exitModelHash) {
2938  
2939 my ($roomObj, $destRoomObj, $regionObj);
2940  
2941 if ($exitObj->destRoom) {
2942  
2943 $roomObj = $modelHash{$exitObj->parent};
2944 $destRoomObj = $modelHash{$exitObj->destRoom};
2945 if (! $roomObj->parent || ! $destRoomObj->parent) {
2946  
2947 # This kind of error will have been detected (or created by) the code above
2948 next OUTER;
2949  
2950 } elsif ($exitObj->regionFlag && $roomObj->parent == $destRoomObj->parent) {
2951  
2952 push (@outputList,
2953 ' Region exit #' . $exitObj->number . ' destination room #'
2954 . $roomObj->parent . ' is actually in the same region',
2955 );
2956  
2957 $errorCount++;
2958 if ($fixFlag) {
2959  
2960 # Delete the original exit, and replace it with an incomplete exit in the
2961 # same direction
2962 $self->deleteExits(
2963 $session,
2964 FALSE, # Don't update Automapper window
2965 $exitObj,
2966 );
2967  
2968 $self->addExit(
2969 $session,
2970 FALSE, # Don't update Automapper window
2971 $roomObj,
2972 $exitObj->dir,
2973 $exitObj->mapDir,
2974 );
2975  
2976 $fixCount++;
2977 }
2978  
2979 } elsif (! $exitObj->regionFlag && $roomObj->parent != $destRoomObj->parent) {
2980  
2981 push (@outputList,
2982 ' Non-region exit #' . $exitObj->number . ' destination room #'
2983 . $roomObj->parent . ' is not in the same region',
2984 );
2985  
2986 $errorCount++;
2987 if ($fixFlag) {
2988  
2989 # Delete the original exit, and replace it with an incomplete exit in the
2990 # same direction
2991 $self->deleteExits(
2992 $session,
2993 FALSE, # Don't update Automapper window
2994 $exitObj,
2995 );
2996  
2997 $self->addExit(
2998 $session,
2999 FALSE, # Don't update Automapper window
3000 $roomObj,
3001 $exitObj->dir,
3002 $exitObj->mapDir,
3003 );
3004  
3005 $fixCount++;
3006 }
3007  
3008 } elsif (
3009 ! $exitObj->regionFlag
3010 && ($exitObj->superFlag || $exitObj->notSuperFlag)
3011 ) {
3012 push (@outputList,
3013 ' Non-region exit #' . $exitObj->number . ' is marked as a super-region'
3014 . ' exit (or as definitely not a super-region exit',
3015 );
3016  
3017 $errorCount++;
3018 if ($fixFlag) {
3019  
3020 # Just update the IVs
3021 $exitObj->ivPoke('superFlag', FALSE);
3022 $exitObj->ivPoke('notSuperFlag', FALSE);
3023  
3024 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
3025  
3026 # Any region paths using the exits will have to be updated
3027 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
3028 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
3029  
3030 $fixCount++;
3031 }
3032 }
3033 }
3034 }
3035  
3036 # Check the integrity of every regionmap
3037 %modelHash = $self->modelHash;
3038 %exitModelHash = $self->exitModelHash;
3039 %regionmapHash = $self->regionmapHash;
3040 OUTER: foreach my $regionmapObj (values %regionmapHash) {
3041  
3042 my (
3043 %gridRoomHash, %gridRoomTagHash, %gridRoomGuildHash, %gridExitHash,
3044 %gridExitTagHash, %regionExitHash, %regionPathHash,
3045 );
3046  
3047 # Check ->gridRoomHash
3048 %gridRoomHash = $regionmapObj->gridRoomHash;
3049 INNER: foreach my $posn (keys %gridRoomHash) {
3050  
3051 my (
3052 $roomNum, $roomObj, $eCount, $fCount,
3053 @opList,
3054 );
3055  
3056 $roomNum = $gridRoomHash{$posn};
3057 $roomObj = $modelHash{$roomNum};
3058 # Check the room actually exists, and so on
3059 ($eCount, $fCount, @opList) = $self->testModelRoom(
3060 $session,
3061 $fixFlag,
3062 $regionmapObj,
3063 $posn,
3064 $roomNum,
3065 $roomObj,
3066 'gridRoomHash',
3067 \%modelHash,
3068 );
3069  
3070 $errorCount += $eCount;
3071 $fixCount += $fCount;
3072 push (@outputList, @opList);
3073 }
3074  
3075 # Check ->gridRoomTagHash
3076 %gridRoomTagHash = $regionmapObj->gridRoomTagHash;
3077 INNER: foreach my $posn (keys %gridRoomTagHash) {
3078  
3079 my (
3080 $roomNum, $roomObj, $eCount, $fCount,
3081 @opList,
3082 );
3083  
3084 $roomNum = $gridRoomTagHash{$posn};
3085 $roomObj = $modelHash{$roomNum};
3086 # Check the room actually exists, and so on
3087 ($eCount, $fCount, @opList) = $self->testModelRoom(
3088 $session,
3089 $fixFlag,
3090 $regionmapObj,
3091 $posn,
3092 $roomNum,
3093 $roomObj,
3094 'gridRoomTagHash',
3095 \%modelHash,
3096 );
3097  
3098 $errorCount += $eCount;
3099 $fixCount += $fCount;
3100 push (@outputList, @opList);
3101  
3102 if (! $eCount && ! $fCount && ! $roomObj->roomTag) {
3103  
3104 push (@outputList,
3105 ' Regionmap \'' . $regionmapObj->name . '\' references the room #'
3106 . $roomNum . ' in ->gridRoomTagHash which doesn\'t have a room tag',
3107 );
3108  
3109 $errorCount++;
3110 if ($fixFlag) {
3111  
3112 $regionmapObj->ivDelete('gridRoomTagHash', $posn);
3113 $fixCount++;
3114 }
3115 }
3116 }
3117  
3118 # Check ->gridRoomGuildHash
3119 %gridRoomGuildHash = $regionmapObj->gridRoomGuildHash;
3120 INNER: foreach my $posn (keys %gridRoomGuildHash) {
3121  
3122 my (
3123 $roomNum, $roomObj, $eCount, $fCount,
3124 @opList,
3125 );
3126  
3127 $roomNum = $gridRoomGuildHash{$posn};
3128 $roomObj = $modelHash{$roomNum};
3129 # Check the room actually exists, and so on
3130 ($eCount, $fCount, @opList) = $self->testModelRoom(
3131 $session,
3132 $fixFlag,
3133 $regionmapObj,
3134 $posn,
3135 $roomNum,
3136 $roomObj,
3137 'gridRoomGuildHash',
3138 \%modelHash,
3139 );
3140  
3141 $errorCount += $eCount;
3142 $fixCount += $fCount;
3143 push (@outputList, @opList);
3144  
3145 if (! $eCount && ! $fCount && ! $roomObj->roomGuild) {
3146  
3147 push (@outputList,
3148 ' Regionmap \'' . $regionmapObj->name . '\' references a room #'
3149 . $roomNum . ' in ->gridRoomGuildHash which doesn\'t have a room guild',
3150 );
3151  
3152 $errorCount++;
3153 if ($fixFlag) {
3154  
3155 $regionmapObj->ivDelete('gridRoomGuildHash', $posn);
3156 $fixCount++;
3157 }
3158 }
3159 }
3160  
3161 # Check ->gridExitHash
3162 %gridExitHash = $regionmapObj->gridExitHash;
3163 INNER: foreach my $exitNum (keys %gridExitHash) {
3164  
3165 my (
3166 $exitObj, $roomObj, $eCount, $fCount,
3167 @opList,
3168 );
3169  
3170 $exitObj = $exitModelHash{$exitNum};
3171 # Check the exit actually exists, and so on
3172 ($eCount, $fCount, @opList) = $self->testModelExit(
3173 $session,
3174 $fixFlag,
3175 $regionmapObj,
3176 $exitNum,
3177 $exitObj,
3178 'gridExitHash',
3179 \%modelHash,
3180 \%exitModelHash,
3181 );
3182  
3183 $errorCount += $eCount;
3184 $fixCount += $fCount;
3185 push (@outputList, @opList);
3186 }
3187  
3188 # Check ->gridExitTagHash
3189 %gridExitTagHash = $regionmapObj->gridExitTagHash;
3190 INNER: foreach my $exitNum (keys %gridExitTagHash) {
3191  
3192 my (
3193 $exitObj, $roomObj, $eCount, $fCount,
3194 @opList,
3195 );
3196  
3197 $exitObj = $exitModelHash{$exitNum};
3198 # Check the exit actually exists, and so on
3199 ($eCount, $fCount, @opList) = $self->testModelExit(
3200 $session,
3201 $fixFlag,
3202 $regionmapObj,
3203 $exitNum,
3204 $exitObj,
3205 'gridExitTagHash',
3206 \%modelHash,
3207 \%exitModelHash,
3208 );
3209  
3210 $errorCount += $eCount;
3211 $fixCount += $fCount;
3212 push (@outputList, @opList);
3213  
3214 if (! $eCount && ! $fCount && ! $exitObj->exitTag) {
3215  
3216 push (@outputList,
3217 ' Regionmap \'' . $regionmapObj->name . '\' references an exit #'
3218 . $exitNum . ' in ->gridExitTagHash which doesn\'t have an exit tag',
3219 );
3220  
3221 $errorCount++;
3222 if ($fixFlag) {
3223  
3224 $regionmapObj->ivDelete('gridExitTagHash', $exitNum);
3225 $fixCount++;
3226 }
3227 }
3228 }
3229  
3230 # Check ->regionExitHash
3231 %regionExitHash = $regionmapObj->regionExitHash;
3232 INNER: foreach my $exitNum (keys %regionExitHash) {
3233  
3234 my (
3235 $exitObj, $roomObj, $eCount, $fCount,
3236 @opList,
3237 );
3238  
3239 $exitObj = $exitModelHash{$exitNum};
3240 # Check the exit actually exists, and so on
3241 ($eCount, $fCount, @opList) = $self->testModelExit(
3242 $session,
3243 $fixFlag,
3244 $regionmapObj,
3245 $exitNum,
3246 $exitObj,
3247 'regionExitHash',
3248 \%modelHash,
3249 \%exitModelHash,
3250 );
3251  
3252 $errorCount += $eCount;
3253 $fixCount += $fCount;
3254 push (@outputList, @opList);
3255  
3256 if (! $eCount && ! $fCount) {
3257  
3258 if (! $exitObj->regionFlag) {
3259  
3260 push (@outputList,
3261 ' Regionmap \'' . $regionmapObj->name . '\' references an exit #'
3262 . $exitNum . ' in ->regionExitHash which isn\'t a region exit',
3263 );
3264  
3265 $errorCount++;
3266 if ($fixFlag) {
3267  
3268 $regionmapObj->ivDelete('regionExitHash', $exitNum);
3269 $fixCount++;
3270 }
3271  
3272 } elsif (! $self->ivExists('regionModelHash', $regionExitHash{$exitNum})) {
3273  
3274 push (@outputList,
3275 ' Regionmap \'' . $regionmapObj->name . '\' references an exit #'
3276 . $exitNum . ' in ->regionExitHash which leads to a model object #'
3277 . $regionExitHash{$exitNum} . ' which isn\'t a region',
3278 );
3279  
3280 $errorCount++;
3281 if ($fixFlag) {
3282  
3283 $regionmapObj->ivDelete('regionExitHash', $exitNum);
3284 $fixCount++;
3285 }
3286 }
3287 }
3288 }
3289  
3290 # Check ->regionPathHash
3291 %regionPathHash = $regionmapObj->regionPathHash;
3292 INNER: foreach my $posn (keys %regionPathHash) {
3293  
3294 my @posnList = split('_', $posn);
3295 if (
3296 scalar @posnList != 2
3297 || ! exists $exitModelHash{$posnList[0]}
3298 || ! exists $exitModelHash{$posnList[1]}
3299 ) {
3300 push (@outputList,
3301 ' Regionmap \'' . $regionmapObj->name . '\' references a region path at'
3302 . ' an invalid position \'' . $posn . '\' (not auto-fixable)',
3303 );
3304 }
3305 }
3306 }
3307  
3308 # Operation complete. Return value(s)
3309 if ($diagnoseFlag) {
3310 return ($errorCount, $fixCount, @outputList);
3311 } elsif ($errorCount) {
3312 return undef;
3313 } else {
3314 return 1;
3315 }
3316 }
3317  
3318 sub testModelRoom {
3319  
3320 # Called by $self->testModel to check one of the hashes in a regionmap object
3321 # (GA::Obj::Regionmap)
3322 # Checks that each room in the hash actually exists, and so on
3323 #
3324 # Expected arguments
3325 # $session - The calling function's GA::Session
3326 # $fixFlag - If TRUE, fixes any errors that can be fixed. If FALSE, does not
3327 # attempt to fix any errors
3328 # $regionmapObj - The regionmap object to check
3329 # $posn - A key in one of the regionmap's hashes
3330 # $roomNum - $posn's corresponding value
3331 # $roomObj - $roomNum's corresponding room object
3332 # $iv - The hash being checked, e.g. 'gridRoomHash'
3333 # $modelHashRef - Reference to a hash containing the contents of ->modelHash
3334 #
3335 # Return values
3336 # An empty list on improper arguments
3337 # Otherwise returns a list in the form
3338 # (error_count, fix_count, message, message, message...)
3339 # ...where 'message' are any number (including zero) of error messages
3340  
3341 my (
3342 $self, $session, $fixFlag, $regionmapObj, $posn, $roomNum, $roomObj, $iv, $modelHashRef,
3343 $check,
3344 ) = @_;
3345  
3346 # Local variables
3347 my (
3348 $errorCount, $fixCount,
3349 @emptyList, @outputList, @posnList,
3350 );
3351  
3352 # Check for improper arguments
3353 if (
3354 ! defined $session || ! defined $fixFlag || ! defined $regionmapObj || ! defined $posn
3355 || ! defined $roomNum || ! defined $roomObj || ! defined $iv || ! defined $modelHashRef
3356 || defined $check
3357 ) {
3358 $axmud::CLIENT->writeImproper($self->_objClass . '->testModelRoom', @_);
3359 return @emptyList;
3360 }
3361  
3362 $errorCount = 0;
3363 $fixCount = 0;
3364  
3365 if (! exists $$modelHashRef{$roomNum}) {
3366  
3367 push (@outputList,
3368 ' Regionmap \'' . $regionmapObj->name . '\' references a room #'
3369 . $roomNum . ' in ->' . $iv . ' which is not in ->modelHash',
3370 );
3371  
3372 $errorCount++;
3373 if ($fixFlag) {
3374  
3375 $regionmapObj->ivDelete($iv, $posn);
3376 $fixCount++;
3377 }
3378 }
3379  
3380 if (! $errorCount) {
3381  
3382 if ($roomObj->category ne 'room') {
3383  
3384 push (@outputList,
3385 ' Regionmap \'' . $regionmapObj->name . '\' references a room #'
3386 . $roomNum . ' in ->' . $iv . ' which is not actually a room object',
3387 );
3388  
3389 $errorCount++;
3390 if ($fixFlag) {
3391  
3392 $regionmapObj->ivDelete($iv, $posn);
3393 $fixCount++;
3394 }
3395 }
3396 }
3397  
3398 if (! $errorCount) {
3399  
3400 if ($roomObj->parent ne $regionmapObj->number) {
3401  
3402 push (@outputList,
3403 ' Regionmap \'' . $regionmapObj->name . '\' references a room #'
3404 . $roomNum . ' in ->' . $iv . ' which is actually in a different region',
3405 );
3406  
3407 $errorCount++;
3408 if ($fixFlag) {
3409  
3410 $regionmapObj->ivDelete($iv, $posn);
3411 $fixCount++;
3412 }
3413 }
3414 }
3415  
3416 if (! $errorCount) {
3417  
3418 @posnList = split('_', $posn);
3419 if (
3420 scalar @posnList != 3
3421 || $posnList[0] != $roomObj->xPosBlocks
3422 || $posnList[1] != $roomObj->yPosBlocks
3423 || $posnList[2] != $roomObj->zPosBlocks
3424 ) {
3425 push (@outputList,
3426 ' Regionmap \'' . $regionmapObj->name . '\' references a room #'
3427 . $roomNum . ' in ->' . $iv . ' whose position \'' . $posn . '\' is incorrect'
3428 . ' (not auto-fixable)',
3429 );
3430  
3431 $errorCount++;
3432 }
3433 }
3434  
3435 return ($errorCount, $fixCount, @outputList);
3436 }
3437  
3438 sub testModelExit {
3439  
3440 # Called by $self->testModel to check one of the hashes in a regionmap object
3441 # (GA::Obj::Regionmap)
3442 # Checks that each exit in the hash actually exists, and so on
3443 #
3444 # Expected arguments
3445 # $session - The calling function's GA::Session
3446 # $fixFlag - If TRUE, fixes any errors that can be fixed. If FALSE, does not
3447 # attempt to fix any errors
3448 # $regionmapObj - The regionmap object to check
3449 # $exitNum - A key in one of the regionmap's hashes
3450 # $exitObj - $exitNum's corresponding room object ('undef' value allowed)
3451 # $iv - The hash being checked, e.g. 'gridRoomHash'
3452 # $modelHashRef - Reference to a hash containing the contents of ->modelHash
3453 # $exitModelHashRef
3454 # - Reference to a hash containing the contents of ->exitModelHash
3455 #
3456 # Return values
3457 # An empty list on improper arguments
3458 # Otherwise returns a list in the form
3459 # (error_count, fix_count, message, message, message...)
3460 # ...where 'message' are any number (including zero) of error messages
3461  
3462 my (
3463 $self, $session, $fixFlag, $regionmapObj, $exitNum, $exitObj, $iv, $modelHashRef,
3464 $exitModelHashRef, $check,
3465 ) = @_;
3466  
3467 # Local variables
3468 my (
3469 $errorCount, $fixCount, $roomObj,
3470 @emptyList, @outputList,
3471 );
3472  
3473 # Check for improper arguments
3474 if (
3475 ! defined $session || ! defined $fixFlag || ! defined $regionmapObj
3476 || ! defined $exitNum || ! defined $iv || ! defined $modelHashRef
3477 || ! defined $exitModelHashRef || defined $check
3478 ) {
3479 $axmud::CLIENT->writeImproper($self->_objClass . '->testModelExit', @_);
3480 return @emptyList;
3481 }
3482  
3483 $errorCount = 0;
3484 $fixCount = 0;
3485  
3486 if (! exists $$exitModelHashRef{$exitNum}) {
3487  
3488 push (@outputList,
3489 ' Regionmap \'' . $regionmapObj->name . '\' references an exit #'
3490 . $exitNum . ' in ->' . $iv . ' which is not in ->exitModelHash',
3491 );
3492  
3493 $errorCount++;
3494 if ($fixFlag) {
3495  
3496 $regionmapObj->ivDelete($iv, $exitNum);
3497 $fixCount++;
3498 }
3499 }
3500  
3501 if (! $errorCount) {
3502  
3503 $roomObj = $$modelHashRef{$exitObj->parent};
3504 if (
3505 # (Must check $roomObj exists and has a parent region, because some earlier checks
3506 # produce errors that might not be fixed)
3507 $roomObj
3508 && $roomObj->parent
3509 && $roomObj->parent != $regionmapObj->number
3510 ) {
3511 push (@outputList,
3512 ' Regionmap \'' . $regionmapObj->name . '\' references an exit #'
3513 . $exitNum . ' in ->' . $iv . ' which is actually in a different region',
3514 );
3515  
3516 $errorCount++;
3517 if ($fixFlag) {
3518  
3519 $regionmapObj->ivDelete($iv, $exitNum);
3520 $fixCount++;
3521 }
3522 }
3523 }
3524  
3525 return ($errorCount, $fixCount, @outputList);
3526 }
3527  
3528 sub mergeModel {
3529  
3530 # Called by GA::Cmd::MergeModel->do (only)
3531 # Merges two world models into one. The calling function has imported a world model file
3532 # (created by ;exportfiles -m <world_name>). This function merges data from that model
3533 # into this one
3534 # Not everything is merged; for example, regions, rooms and exits are merged, but the
3535 # value of ->currentRoomMode is not modified at all
3536 #
3537 # Expected arguments
3538 # $session - The calling GA::Session
3539 # $mergeModelObj - The imported world model (a GA::Obj::WorldModel object, just like this
3540 # one)
3541 #
3542 # Return values
3543 # 'undef' on improper arguments
3544 # 1 otherwise
3545  
3546 my ($self, $session, $mergeModelObj, $check) = @_;
3547  
3548 # Local variables
3549 my (
3550 @deleteList,
3551 %convertObjHash, %convertExitHash, %convertRegionHash,
3552 );
3553  
3554 # Check for improper arguments
3555 if (! defined $session || ! defined $mergeModelObj || defined $check) {
3556  
3557 return $axmud::CLIENT->writeImproper($self->_objClass . '->mergeModel', @_);
3558 }
3559  
3560 # Compile a hash converting numbers of imported model objects (regions, rooms, sentients
3561 # etc) etc to unused numbers in this model
3562 # ->modelObjCount specifies how many numbers have actually been used (i.e. if 1000 objects
3563 # ever created, but 50 of them have since been deleted and not reallocated to a new
3564 # object, ->modelObjCount is still 1000)
3565 for (my $count = 1; $count <= $mergeModelObj->modelObjCount; $count++) {
3566  
3567 my ($importObj, $newNum);
3568  
3569 $importObj = $mergeModelObj->ivShow('modelHash', $count);
3570  
3571 # If this object hasn't been deleted...
3572 if (defined $importObj) {
3573  
3574 # ...find a new number for it
3575 $newNum = $self->allocateModelNumber();
3576 $convertObjHash{$importObj->number} = $newNum;
3577 }
3578 }
3579  
3580 # Do the same for exits
3581 for (my $count = 1; $count <= $mergeModelObj->exitObjCount; $count++) {
3582  
3583 my ($importObj, $newNum);
3584  
3585 $importObj = $mergeModelObj->ivShow('exitModelHash', $count);
3586  
3587 # If this object hasn't been deleted...
3588 if (defined $importObj) {
3589  
3590 # ...find a new number for it
3591 $newNum = $self->allocateExitModelNumber();
3592 $convertExitHash{$importObj->number} = $newNum;
3593 }
3594 }
3595  
3596 # Region names. Any imported regions whose names clash with existing regions must be
3597 # renamed
3598 foreach my $importObj ($mergeModelObj->ivValues('regionmapHash')) {
3599  
3600 my ($count, $newName, $exitFlag);
3601  
3602 if ($self->ivExists('regionmapHash', $importObj->name)) {
3603  
3604 # Set the new name for the imported region
3605 $count = 1;
3606 do {
3607  
3608 $count++;
3609 $newName = $importObj->name . '_' . $count;
3610 if (! $self->ivExists('regionmapHash', $newName)) {
3611  
3612 $exitFlag = TRUE;
3613 }
3614  
3615 } until ($exitFlag);
3616  
3617 $convertRegionHash{$importObj->name} = $newName;
3618 }
3619 }
3620  
3621 # Start actually importing things
3622  
3623 # Import model objects
3624 foreach my $importObj ($mergeModelObj->ivValues('modelHash')) {
3625  
3626 my (
3627 $oldName,
3628 %childHash,
3629 );
3630  
3631 # Update the object's IVs
3632  
3633 # Group 1 IVs
3634 if ($importObj->category eq 'region') {
3635  
3636 $oldName = $importObj->name;
3637  
3638 if (exists $convertRegionHash{$importObj->name}) {
3639  
3640 $importObj->ivPoke('name', $convertRegionHash{$importObj->name});
3641 $importObj->{_objName} = $importObj->name;
3642 }
3643 }
3644  
3645 $importObj->ivPoke('number', $convertObjHash{$importObj->number});
3646  
3647 if (defined $importObj->parent) {
3648  
3649 $importObj->ivPoke('parent', $convertObjHash{$importObj->parent});
3650 }
3651  
3652 foreach my $key ($importObj->ivKeys('childHash')) {
3653  
3654 $childHash{$convertObjHash{$key}} = undef;
3655 }
3656  
3657 $importObj->ivPoke('childHash', %childHash);
3658  
3659 # ->privateHash must be emptied, because it might contain arbitrary model object numbers
3660 $importObj->ivEmpty('privateHash');
3661  
3662 # Group 2 IVs
3663 if (defined $importObj->container) {
3664  
3665 $importObj->ivPoke('container', $convertObjHash{$importObj->container});
3666 }
3667  
3668 # Group 3 IVs
3669 if (defined $importObj->targetRoomNum) {
3670  
3671 $importObj->ivPoke('targetRoomNum', $convertObjHash{$importObj->targetRoomNum});
3672 }
3673  
3674 # (No group 4 IVs to update)
3675  
3676 # Group 5 IVs
3677 if ($importObj->category eq 'region') {
3678  
3679 $importObj->ivPoke(
3680 'regionmapObj',
3681 $mergeModelObj->ivShow('regionmapHash', $oldName),
3682 );
3683  
3684 } elsif ($importObj->category eq 'room') {
3685  
3686 my (
3687 %uncertainExitHash, %oneWayExitHash, %randomExitHash, %exitNumHash,
3688 %hiddenObjHash,
3689 );
3690  
3691 foreach my $key ($importObj->ivKeys('uncertainExitHash')) {
3692  
3693 my $value = $importObj->ivShow('uncertainExitHash', $key);
3694  
3695 $uncertainExitHash{$convertExitHash{$key}} = $convertExitHash{$value};
3696 }
3697  
3698 $importObj->ivPoke('uncertainExitHash', %uncertainExitHash);
3699  
3700 foreach my $key ($importObj->ivKeys('oneWayExitHash')) {
3701  
3702 $oneWayExitHash{$convertExitHash{$key}} = undef
3703 }
3704  
3705 $importObj->ivPoke('oneWayExitHash', %oneWayExitHash);
3706  
3707 foreach my $key ($importObj->ivKeys('randomExitHash')) {
3708  
3709 $randomExitHash{$convertExitHash{$key}} = undef
3710 }
3711  
3712 $importObj->ivPoke('randomExitHash', %randomExitHash);
3713  
3714 foreach my $key ($importObj->ivKeys('exitNumHash')) {
3715  
3716 my $value = $importObj->ivShow('exitNumHash', $key);
3717  
3718 $exitNumHash{$key} = $convertExitHash{$value};
3719 }
3720  
3721 $importObj->ivPoke('exitNumHash', %exitNumHash);
3722  
3723 foreach my $key ($importObj->ivKeys('hiddenObjHash')) {
3724  
3725 my $value = $importObj->ivShow('hiddenObjHash', $key);
3726  
3727 $hiddenObjHash{$convertObjHash{$key}} = $value;
3728 }
3729  
3730 $importObj->ivPoke('hiddenObjHash', %hiddenObjHash);
3731 }
3732  
3733 # Add the imported object to this world model
3734 $self->ivAdd('modelHash', $importObj->number, $importObj);
3735 $self->ivAdd($importObj->category . 'ModelHash', $importObj->number, $importObj);
3736 $self->ivIncrement('modelActualCount');
3737 $self->ivPoke('mostRecentNum', $importObj->number);
3738 }
3739  
3740 # Import exits
3741 foreach my $importObj ($mergeModelObj->ivValues('exitModelHash')) {
3742  
3743 my @randomDestList;
3744  
3745 # Update the object's IVs
3746  
3747 $importObj->ivPoke('number', $convertExitHash{$importObj->number});
3748 $importObj->ivPoke('parent', $convertObjHash{$importObj->parent});
3749  
3750 # ->privateHash must be emptied, because it might contain arbitrary model object numbers
3751 $importObj->ivEmpty('privateHash');
3752  
3753 foreach my $num ($importObj->randomDestList) {
3754  
3755 push (@randomDestList, $convertObjHash{$num});
3756 }
3757  
3758 $importObj->ivPoke('randomDestList', @randomDestList);
3759  
3760 if (defined $importObj->destRoom) {
3761  
3762 $importObj->ivPoke('destRoom', $convertObjHash{$importObj->destRoom});
3763 }
3764  
3765 if (defined $importObj->twinExit) {
3766  
3767 $importObj->ivPoke('twinExit', $convertExitHash{$importObj->twinExit});
3768 }
3769  
3770 if (defined $importObj->shadowExit) {
3771  
3772 $importObj->ivPoke('shadowExit', $convertExitHash{$importObj->shadowExit});
3773 }
3774  
3775 # Add the imported object to this world model
3776 $self->ivAdd('exitModelHash', $importObj->number, $importObj);
3777 $self->ivIncrement('exitActualCount');
3778 $self->ivPoke('mostRecentExitNum', $importObj->number);
3779 }
3780  
3781 # Import regionmaps
3782 foreach my $importObj ($mergeModelObj->ivValues('regionmapHash')) {
3783  
3784 my (
3785 %gridRoomHash, %gridRoomTagHash, %gridRoomGuildHash, %gridExitHash,
3786 %gridExitTagHash, %regionExitHash, %regionPathHash, %safeRegionPathHash,
3787 );
3788  
3789 if (exists $convertRegionHash{$importObj->name}) {
3790  
3791 $importObj->ivPoke('name', $convertRegionHash{$importObj->name});
3792 $importObj->{_objName} = $importObj->name;
3793 }
3794  
3795 $importObj->ivPoke('number', $convertObjHash{$importObj->number});
3796  
3797 foreach my $key ($importObj->ivKeys('gridRoomHash')) {
3798  
3799 my $value = $importObj->ivShow('gridRoomHash', $key);
3800  
3801 $gridRoomHash{$key} = $convertObjHash{$value};
3802 }
3803  
3804 $importObj->ivPoke('gridRoomHash', %gridRoomHash);
3805  
3806 foreach my $key ($importObj->ivKeys('gridRoomTagHash')) {
3807  
3808 my $value = $importObj->ivShow('gridRoomTagHash', $key);
3809  
3810 $gridRoomTagHash{$key} = $convertObjHash{$value};
3811 }
3812  
3813 $importObj->ivPoke('gridRoomTagHash', %gridRoomTagHash);
3814  
3815 foreach my $key ($importObj->ivKeys('gridRoomGuildHash')) {
3816  
3817 my $value = $importObj->ivShow('gridRoomGuildHash', $key);
3818  
3819 $gridRoomGuildHash{$key} = $convertObjHash{$value};
3820 }
3821  
3822 $importObj->ivPoke('gridRoomGuildHash', %gridRoomGuildHash);
3823  
3824 foreach my $key ($importObj->ivKeys('gridExitHash')) {
3825  
3826 $gridExitHash{$convertExitHash{$key}} = undef;
3827 }
3828  
3829 $importObj->ivPoke('gridExitHash', %gridExitHash);
3830  
3831 foreach my $key ($importObj->ivKeys('gridExitTagHash')) {
3832  
3833 $gridExitTagHash{$convertExitHash{$key}} = undef;
3834 }
3835  
3836 $importObj->ivPoke('gridExitTagHash', %gridExitTagHash);
3837  
3838 foreach my $key ($importObj->ivKeys('regionExitHash')) {
3839  
3840 my $value = $importObj->ivShow('regionExitHash', $key);
3841  
3842 $regionExitHash{$convertExitHash{$key}} = $convertObjHash{$value};
3843 }
3844  
3845 $importObj->ivPoke('regionExitHash', %regionExitHash);
3846  
3847 foreach my $labelObj ($importObj->ivValues('gridLabelHash')) {
3848  
3849 if (exists $convertRegionHash{$importObj->name}) {
3850  
3851 $labelObj->ivPoke('region', $convertRegionHash{$labelObj->region});
3852 }
3853 }
3854  
3855 foreach my $key ($importObj->ivKeys('regionPathHash')) {
3856  
3857 my (
3858 $regionPathObj, $newKey,
3859 @list, @roomList, @exitList,
3860 );
3861  
3862 $regionPathObj = $importObj->ivShow('regionPathHash', $key);
3863  
3864 # $key is in the form 'a_b', where are both are exit model numbers
3865 @list = split(/\_/, $key);
3866 $newKey = $convertExitHash{$list[0]} . '_' . $convertExitHash{$list[1]};
3867  
3868 # Update the region path object (GA::Obj::RegionPath) itself
3869 $regionPathObj->ivPoke('startExit', $convertExitHash{$regionPathObj->startExit});
3870 $regionPathObj->ivPoke('stopExit', $convertExitHash{$regionPathObj->stopExit});
3871  
3872 foreach my $item ($regionPathObj->roomList) {
3873  
3874 push (@roomList, $convertObjHash{$item});
3875 }
3876  
3877 $regionPathObj->ivPoke('roomList', @roomList);
3878  
3879 foreach my $item ($regionPathObj->exitList) {
3880  
3881 push (@exitList, $convertExitHash{$item});
3882 }
3883  
3884 $regionPathObj->ivPoke('exitList', @exitList);
3885  
3886 # Mark the region path object to be put back into the regionmap
3887 $regionPathHash{$newKey} = $regionPathObj;
3888 if ($importObj->ivExists('safeRegionPathHash', $key)) {
3889  
3890 $safeRegionPathHash{$newKey} = $regionPathObj;
3891 }
3892 }
3893  
3894 $importObj->ivPoke('regionPathHash', %regionPathHash);
3895 $importObj->ivPoke('safeRegionPathHash', %safeRegionPathHash);
3896  
3897 # Add the imported object to this world model
3898 $self->ivAdd('regionmapHash', $importObj->name, $importObj);
3899 }
3900  
3901 # Update $self->knownCharHash and ->minionStringHash. Duplicate character names and
3902 # duplicate minion strings are not allowed, so if there's a clash, remove the imported
3903 # model object
3904 foreach my $name ($mergeModelObj->ivKeys('knownCharHash')) {
3905  
3906 my $importObj = $mergeModelObj->ivShow('knownCharHash', $name);
3907  
3908 if ($self->ivExists('knownCharHash', $name)) {
3909  
3910 push (@deleteList, $importObj);
3911  
3912 } else {
3913  
3914 $self->ivAdd('knownCharHash', $name, $importObj);
3915 }
3916 }
3917  
3918 foreach my $string ($mergeModelObj->ivKeys('minionStringHash')) {
3919  
3920 my $importObj = $mergeModelObj->ivShow('minionStringHash', $string);
3921  
3922 if ($self->ivExists('minionStringHash', $string)) {
3923  
3924 # $importObj can be a model or a non-model object. If the former, it must be
3925 # deleted via a call to $self->deleteObj; if the latter, we can just ignore it
3926 if ($importObj->number) {
3927  
3928 push (@deleteList, $importObj);
3929 }
3930  
3931 } else {
3932  
3933 $self->ivAdd('minionStringHash', $string, $importObj);
3934 }
3935 }
3936  
3937 foreach my $importObj (@deleteList) {
3938  
3939 $self->deleteObj(
3940 $session,
3941 FALSE, # Don't update automapper windows now
3942 $importObj,
3943 );
3944 }
3945  
3946 # Merge any new light status values into our list of light status values (but don't create
3947 # duplicates)
3948 foreach my $string ($mergeModelObj->lightStatusList) {
3949  
3950 if (! defined $self->ivFind('lightStatusList', $string)) {
3951  
3952 $self->ivPush('lightStatusList', $string);
3953 }
3954 }
3955  
3956 # Update this model's hash of room tags. If an imported room has a tag that's already in
3957 # use, remove it
3958 foreach my $importObj ($mergeModelObj->ivValues('roomModelHash')) {
3959  
3960 my ($roomTag, $regionmapObj);
3961  
3962 $roomTag = $importObj->roomTag;
3963  
3964 if ($roomTag) {
3965  
3966 if ($self->ivExists('roomTagHash', $roomTag)) {
3967  
3968 $importObj->ivUndef('roomTag');
3969 # (Need to remove it from ->teleportHash, too)
3970 $mergeModelObj->ivDelete('teleportHash', $roomTag);
3971  
3972 # (And remove the entry in the regionmap)
3973 $regionmapObj = $self->findRegionmap($importObj->parent);
3974 $regionmapObj->removeRoomTag($importObj);
3975  
3976 } else {
3977  
3978 $self->ivAdd('roomTagHash', $roomTag, $importObj->number);
3979 }
3980 }
3981 }
3982  
3983 # Update this model's hash of teleport rooms
3984 foreach my $key ($mergeModelObj->ivKeys('teleportHash')) {
3985  
3986 my $value = $mergeModelObj->ivShow('teleportHash', $key);
3987  
3988 if (exists $convertObjHash{$key}) {
3989  
3990 # The key is a room number
3991 $self->ivAdd('teleportHash', $convertObjHash{$key}, $value);
3992  
3993 } else {
3994  
3995 # The key is a room tag. Any duplicate room tags have already been removed from
3996 # ->teleportHash
3997 $self->ivAdd('teleportHash', $key, $value);
3998 }
3999 }
4000  
4001 # Import any map label styles, but don't import any styles that have the same name as an
4002 # existing style
4003 foreach my $importObj ($mergeModelObj->ivValues('mapLabelStyleHash')) {
4004  
4005 if (! $self->ivExists('mapLabelStyleHash', $importObj->name)) {
4006  
4007 $self->ivAdd('mapLabelStyleHash', $importObj->name, $importObj);
4008 }
4009 }
4010  
4011 # Import any custom room flags, but don't import any room flags that have the same name as
4012 # an existing room flag
4013 foreach my $importObj ($mergeModelObj->ivValues('roomFlagHash')) {
4014  
4015 if ($importObj->customFlag && ! $self->ivExists('roomFlagHash', $importObj->name)) {
4016  
4017 # Don't import the room flag object (GA::Obj::RoomFlag); just create a new one with
4018 # the same attributes
4019 $self->addRoomFlag(
4020 $session,
4021 $importObj->name,
4022 $importObj->shortName,
4023 $importObj->descrip,
4024 $importObj->colour,
4025 );
4026 }
4027 }
4028  
4029 # Operation complete. Any automapper windows using this world model should be updated
4030 foreach my $mapWin ($self->collectMapWins()) {
4031  
4032 $mapWin->redrawWidgets('menu_bar', 'toolbar', 'treeview');
4033 $mapWin->drawRegion();
4034 }
4035  
4036 return 1;
4037 }
4038  
4039 # Region path methods
4040  
4041 sub recalculateRegionPaths {
4042  
4043 # Called by GA::Win::Map->recalculatePathsCallback
4044 # Recalculates the region paths for a specified regionmap, replacing all previously
4045 # calculated region paths
4046 #
4047 # Expected arguments
4048 # $session - The calling function's GA::Session
4049 # $regionmapObj - The GA::Obj::RegionPath whose region paths should be recalculated
4050 #
4051 # Return values
4052 # 'undef' on improper arguments
4053 # Otherwise, returns the number of region paths created (may be 0)
4054  
4055 my ($self, $session, $regionmapObj, $check) = @_;
4056  
4057 # Local variables
4058 my (
4059 $count,
4060 @exitNumList,
4061 );
4062  
4063 # Check for improper arguments
4064 if (! defined $session || ! defined $regionmapObj || defined $check) {
4065  
4066 return $axmud::CLIENT->writeImproper($self->_objClass . '->recalculateRegionPaths', @_);
4067 }
4068  
4069 # Empty the existing hashes of region paths in this region
4070 $regionmapObj->resetPaths();
4071  
4072 # Recalculate paths from each super-region exit in turn
4073 foreach my $exitNum ($regionmapObj->ivKeys('regionExitHash')) {
4074  
4075 my ($roomObj, $exitObj);
4076  
4077 $exitObj = $self->ivShow('exitModelHash', $exitNum);
4078  
4079 if ($exitObj->superFlag) {
4080  
4081 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
4082  
4083 # Recalculate the region paths between this super-region exit and all other
4084 # super-region exits in the same region
4085 $self->connectRegionExits($session, $regionmapObj, $roomObj, $exitObj);
4086 }
4087 }
4088  
4089 # Work out how many region paths have been created
4090 $count = $regionmapObj->ivPairs('regionPathHash');
4091  
4092 # Operation complete
4093 return $count;
4094 }
4095  
4096 sub recalculateSafePaths {
4097  
4098 # Called by $self->toggleRoomFlags
4099 # When the user adds or removes a room flag from a room, and when that flag is one of the
4100 # hazardous rooms flags, the parent region's safe region paths (which connect all the
4101 # super-region exits in the region, using the shortest path that avoids rooms with
4102 # hazardous flags) must be updated
4103 #
4104 # Expected arguments
4105 # $session - The calling function's GA::Session
4106 # $regionmapObj - The GA::Obj::Regionmap for which to recalculate safe region paths
4107 # @roomList - A list of GA::ModelObj::Room objects in this region, each of which
4108 # has had a hazardous room flag added or removed
4109 #
4110 # Return values
4111 # 'undef' on improper arguments
4112 # 1 otherwise
4113  
4114 my ($self, $session, $regionmapObj, @roomList) = @_;
4115  
4116 # Local variables
4117 my %roomHash;
4118  
4119 # Check for improper arguments
4120 if (! defined $session || ! defined $regionmapObj || ! @roomList) {
4121  
4122 return $axmud::CLIENT->writeImproper($self->_objClass . '->recalculateSafePaths', @_);
4123 }
4124  
4125 # Convert @roomList into a hash for easy lookup
4126 foreach my $roomObj (@roomList) {
4127  
4128 $roomHash{$roomObj->number} = $roomObj;
4129 }
4130  
4131 # Check every safe region path in the regionmap. Any of them which uses one of the rooms
4132 # in %roomHash must be replaced
4133 OUTER: foreach my $exitString ($regionmapObj->ivKeys('safeRegionPathHash')) {
4134  
4135 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
4136  
4137 INNER: foreach my $roomNum ($pathObj->roomList) {
4138  
4139 if (exists $roomHash{$roomNum}) {
4140  
4141 # Replace the path
4142 $self->replaceRegionPath($session, $pathObj, $regionmapObj, TRUE);
4143  
4144 next OUTER;
4145 }
4146 }
4147 }
4148  
4149 # Operation complete
4150 return 1;
4151 }
4152  
4153 sub recalculateSpecificPaths {
4154  
4155 # Called by GA::Win::Map->recalculatePathsCallback
4156 # Recalculates the region paths to and from a specified super-region exit, replacing any
4157 # existing region paths to/from that exit
4158 #
4159 # Expected arguments
4160 # $session - The calling function's GA::Session
4161 # $regionmapObj - The GA::Obj::Regionmap for which to recalculate region paths
4162 # $exitObj - A super-region exit somewhere in the region
4163 #
4164 # Return values
4165 # 'undef' on improper arguments, if the specified exit isn't a super-region exit or if
4166 # it's not in the specified region
4167 # Otherwise returns the number of new region paths to/from the specified exit (may be 0)
4168  
4169 my ($self, $session, $regionmapObj, $exitObj, $check) = @_;
4170  
4171 # Local variables
4172 my ($roomObj, $count);
4173  
4174 # Check for improper arguments
4175 if (! defined $session || ! defined $regionmapObj || ! defined $exitObj || defined $count) {
4176  
4177 return $axmud::CLIENT->writeImproper(
4178 $self->_objClass . '->recalculateSpecificPaths',
4179 @_,
4180 );
4181 }
4182  
4183 # Get the exit's parent room
4184 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
4185  
4186 # Check that $exitObj is a super-region exit in the right region
4187 if (! $exitObj->superFlag || $roomObj->parent != $regionmapObj->number) {
4188  
4189 return undef;
4190 }
4191  
4192 # Check every region path in the regionmap, and remove any that start or stop at the
4193 # specified exit
4194 foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
4195  
4196 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
4197  
4198 if ($pathObj->startExit == $exitObj->number || $pathObj->stopExit == $exitObj->number) {
4199  
4200 # Remove the path
4201 $regionmapObj->removePaths($exitString);
4202 }
4203 }
4204  
4205 # Now calculate new region paths to/from the specified exit
4206 $self->connectRegionExits(
4207 $session,
4208 $regionmapObj,
4209 $roomObj,
4210 $exitObj,
4211 );
4212  
4213 # Finally, count the number of region paths now leading to/from this exit
4214 $count = 0;
4215  
4216 foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
4217  
4218 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
4219  
4220 if ($pathObj->startExit == $exitObj->number || $pathObj->stopExit == $exitObj->number) {
4221  
4222 $count++;
4223 }
4224 }
4225  
4226 return $count;
4227 }
4228  
4229 # Add non-model objects
4230  
4231 sub addRegionScheme {
4232  
4233 # Called by $self->new and GA::Cmd::AddRegionScheme->do
4234 # Adds a new region scheme object (GA::Obj::RegionScheme)
4235 #
4236 # Expected arguments
4237 # $session - The calling function's GA::Session
4238 # $name - A name for the region scheme (any characters, max length 16)
4239 #
4240 # Return values
4241 # 'undef' on improper arguments or if the region scheme object can't be created
4242 # Otherwise returns the region scheme object created
4243  
4244 my ($self, $session, $name, $check) = @_;
4245  
4246 # Local variables
4247 my $schemeObj;
4248  
4249 # Check for improper arguments
4250 if (! defined $session || ! defined $name || defined $check) {
4251  
4252 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRegionScheme', @_);
4253 }
4254  
4255 # Check specified values are valid
4256 if (length ($name) > 16) {
4257  
4258 return undef;
4259 }
4260  
4261 # Create the region scheme object
4262 $schemeObj = Games::Axmud::Obj::RegionScheme->new($session, $self, $name);
4263 if (! $schemeObj) {
4264  
4265 return undef;
4266  
4267 } else {
4268  
4269 $self->ivAdd('regionSchemeHash', $name, $schemeObj);
4270  
4271 return $schemeObj;
4272 }
4273 }
4274  
4275 sub deleteRegionScheme {
4276  
4277 # Called by anything
4278 # Deletes the specified region scheme
4279 #
4280 # Expected arguments
4281 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4282 # should be updated now, FALSE if not (in which case, they can be
4283 # updated later by the calling function, when it is ready)
4284 # $name - The name of the region scheme to delete
4285 #
4286 # Return values
4287 # 'undef' on improper arguments, if the region scheme doesn't exist or if the default
4288 # region scheme (which can't be deleted) is specified
4289 # 1 otherwise
4290  
4291 my ($self, $updateFlag, $name, $check) = @_;
4292  
4293 # Check for improper arguments
4294 if (! defined $updateFlag || ! defined $name || defined $check) {
4295  
4296 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRegionScheme', @_);
4297 }
4298  
4299 if (! $self->ivExists('regionSchemeHash', $name) || $name eq 'default') {
4300  
4301 return undef;
4302 }
4303  
4304 $self->ivDelete('regionSchemeHash', $name);
4305  
4306 # Any regionmap using that region scheme should be redrawn (if the flag is specified)
4307 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
4308  
4309 if (defined $regionmapObj->regionScheme && $regionmapObj->regionScheme eq $name) {
4310  
4311 $regionmapObj->ivUndef('regionScheme');
4312 if ($updateFlag) {
4313  
4314 # Redraw the region in any automapper window in which it's already drawn
4315 $self->updateRegion($regionmapObj->name);
4316 }
4317 }
4318 }
4319  
4320 return 1;
4321 }
4322  
4323 sub renameRegionScheme {
4324  
4325 # Called by GA::Win::Map->doRegionSchemeCallback and GA::Cmd::RenameRegionScheme->do
4326 # Renames the specified region scheme
4327 #
4328 # Expected arguments
4329 # $session - The calling function's GA::Session
4330 # $oldName - The name of an existing region scheme
4331 # $newName - The new name for that region scheme
4332 #
4333 # Return values
4334 # 'undef' on improper arguments, or if $oldName or $newName are invalid, or if the default
4335 # region scheme (which can't be renamed) is specified
4336 # 1 otherwise
4337  
4338 my ($self, $session, $oldName, $newName, $check) = @_;
4339  
4340 # Local variables
4341 my $schemeObj;
4342  
4343 # Check for improper arguments
4344 if (! defined $session || ! defined $oldName || ! defined $newName || defined $check) {
4345  
4346 return $axmud::CLIENT->writeImproper($self->_objClass . '->renameRegionScheme', @_);
4347 }
4348  
4349 # Check specified values are valid
4350 if (
4351 length ($newName) > 16
4352 || ! $self->ivExists('regionSchemeHash', $oldName)
4353 || $self->ivExists('regionSchemeHash', $newName)
4354 || $oldName eq 'default'
4355 ) {
4356 return undef;
4357 }
4358  
4359 # Get the region scheme object, and rename it
4360 $schemeObj = $self->ivShow('regionSchemeHash', $oldName);
4361 $schemeObj->ivPoke('name', $newName);
4362  
4363 # Update our IVs
4364 $self->ivDelete('regionSchemeHash', $oldName);
4365 $self->ivAdd('regionSchemeHash', $newName, $schemeObj);
4366  
4367 return 1;
4368 }
4369  
4370 sub attachRegionScheme {
4371  
4372 # Called by anything
4373 # Attaches a region scheme to a regionmap
4374 #
4375 # Expected arguments
4376 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4377 # should be updated now, FALSE if not (in which case, they can be
4378 # updated later by the calling function, when it is ready)
4379 # $schemeName - The name of the region scheme to apply
4380 # $regionName - The name of the regionmap to which the scheme should be applied
4381 #
4382 # Return values
4383 # 'undef' on improper arguments, if the scheme/region names are invalid, if the region
4384 # scheme object can't be applied or if it has already been applied
4385 # 1 otherwise
4386  
4387 my ($self, $updateFlag, $schemeName, $regionName, $check) = @_;
4388  
4389 # Local variables
4390 my ($schemeObj, $regionmapObj);
4391  
4392 # Check for improper arguments
4393 if (
4394 ! defined $updateFlag || ! defined $schemeName || ! defined $regionName
4395 || defined $check
4396 ) {
4397  
4398 return $axmud::CLIENT->writeImproper($self->_objClass . '->attachRegionScheme', @_);
4399 }
4400  
4401 # Retrieve the specified objects
4402 $schemeObj = $self->ivShow('regionSchemeHash', $schemeName);
4403 $regionmapObj = $self->ivShow('regionmapHash', $regionName);
4404 if (! $schemeObj || ! $regionmapObj) {
4405  
4406 return undef;
4407 }
4408  
4409 # If the scheme has already been applied to this regionmap, do nothing (i.e. don't redraw
4410 # the regionmap)
4411 if (
4412 (
4413 ! defined $regionmapObj->regionScheme
4414 && $schemeObj eq $self->defaultSchemeObj
4415 ) || (
4416 defined $regionmapObj->regionScheme
4417 && $regionmapObj->regionScheme eq $schemeObj->name
4418 )
4419 ) {
4420 return undef;
4421 }
4422  
4423 # Apply the region scheme. Apply the default region scheme by setting the value to 'undef'
4424 if ($schemeObj eq $self->defaultSchemeObj) {
4425 $regionmapObj->ivUndef('regionScheme');
4426 } else {
4427 $regionmapObj->ivPoke('regionScheme', $schemeObj->name);
4428 }
4429  
4430 if ($updateFlag) {
4431  
4432 # Redraw the region in any automapper window in which it's already drawn
4433 $self->updateRegion($regionName);
4434 }
4435  
4436 return 1;
4437 }
4438  
4439 sub detachRegionScheme {
4440  
4441 # Called by anything
4442 # Detaches the region scheme from a regionmap (the 'default' region scheme then applies to
4443 # it)
4444 #
4445 # Expected arguments
4446 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4447 # should be updated now, FALSE if not (in which case, they can be
4448 # updated later by the calling function, when it is ready)
4449 # $regionName - The name of the regionmap to which the scheme should be applied
4450 #
4451 # Return values
4452 # 'undef' on improper arguments, if the region name is invalid or if the region has no
4453 # region scheme attached to it
4454 # 1 otherwise
4455  
4456 my ($self, $updateFlag, $regionName, $check) = @_;
4457  
4458 # Local variables
4459 my $regionmapObj;
4460  
4461 # Check for improper arguments
4462 if (! defined $updateFlag || ! defined $regionName || defined $check) {
4463  
4464 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRegionScheme', @_);
4465 }
4466  
4467 # Retrieve the specified regionmap
4468 $regionmapObj = $self->ivShow('regionmapHash', $regionName);
4469 if (! $regionmapObj || ! defined $regionmapObj->regionScheme) {
4470  
4471 return undef;
4472  
4473 } else {
4474  
4475 $regionmapObj->ivUndef('regionScheme');
4476 if ($updateFlag) {
4477  
4478 # Redraw the region in any automapper window in which it's already drawn
4479 $self->updateRegion($regionName);
4480 }
4481 }
4482  
4483 return 1;
4484 }
4485  
4486 sub addLabelStyle {
4487  
4488 # Called by $self->new and GA::Cmd::AddLabelStyle->do
4489 # Adds a new map label style object (GA::Obj::MapLabelStyle)
4490 #
4491 # Expected arguments
4492 # $session - The calling function's GA::Session
4493 # $name - A name for the label style (any characters, max length 16)
4494 #
4495 # Optional arguments
4496 # $text - The text colour, an RGB colour tag (case-insensitive). If 'undef', no
4497 # text colour is set by this function
4498 # $underlay - The underlay colour, a normal RGB colour tag like '#ABCDEF', not an
4499 # Axmud underlay RGB tag like 'u#ABCDEF. If 'undef', no underlay
4500 # colour is set by this function
4501 # $relSize - The relative size. If specified, a value in the range 0.5-10
4502 #
4503 # Return values
4504 # 'undef' on improper arguments, if an invalid value for $text, $underlay and/or $relSize
4505 # is specified, or if the map label style object can't be created
4506 # Otherwise returns the map label style object created
4507  
4508 my ($self, $session, $name, $text, $underlay, $relSize, $check) = @_;
4509  
4510 # Local variables
4511 my ($type, $underlayFlag, $styleObj);
4512  
4513 # Check for improper arguments
4514 if (! defined $session || ! defined $name || defined $check) {
4515  
4516 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabelStyle', @_);
4517 }
4518  
4519 # Check specified values are valid
4520 if (length ($name) > 16) {
4521  
4522 return undef;
4523 }
4524  
4525 if (defined $text) {
4526  
4527 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($text);
4528 if (! defined $type || $type ne 'rgb' || $underlayFlag) {
4529  
4530 return undef;
4531 }
4532 }
4533  
4534 if (defined $underlay) {
4535  
4536 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($underlay);
4537 if (! defined $type || $type ne 'rgb' || $underlayFlag) {
4538  
4539 return undef;
4540 }
4541 }
4542  
4543 if (defined $relSize && ! $axmud::CLIENT->floatCheck($relSize, 0.5, 10)) {
4544  
4545 return undef;
4546 }
4547  
4548 # Create the map label style object
4549 $styleObj = Games::Axmud::Obj::MapLabelStyle->new(
4550 $session,
4551 $name,
4552 $text,
4553 $underlay,
4554 $relSize,
4555 );
4556  
4557 if (! $styleObj) {
4558  
4559 return undef;
4560  
4561 } else {
4562  
4563 $self->ivAdd('mapLabelStyleHash', $name, $styleObj);
4564  
4565 return $styleObj;
4566 }
4567 }
4568  
4569 sub deleteLabelStyle {
4570  
4571 # Called by anything
4572 # Deletes the specified map label style
4573 #
4574 # Expected arguments
4575 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4576 # should be updated now, FALSE if not (in which case, they can be
4577 # updated later by the calling function, when it is ready)
4578 # $name - The name of the map label style to delete
4579 #
4580 # Return values
4581 # 'undef' on improper arguments or if the map label style doesn't exist
4582 # 1 otherwise
4583  
4584 my ($self, $updateFlag, $name, $check) = @_;
4585  
4586 # Check for improper arguments
4587 if (! defined $updateFlag || ! defined $name || defined $check) {
4588  
4589 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteLabelStyle', @_);
4590 }
4591  
4592 if (! $self->ivExists('mapLabelStyleHash', $name)) {
4593  
4594 return undef;
4595 }
4596  
4597 $self->ivDelete('mapLabelStyleHash', $name);
4598  
4599 # Any label using that style should be set to use custom IVs
4600 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
4601  
4602 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
4603  
4604 if (defined $labelObj->style && $labelObj->style eq $name) {
4605  
4606 $labelObj->reset_style();
4607 }
4608 }
4609 }
4610  
4611 # Update automapper windows, if required
4612 if ($updateFlag) {
4613  
4614 $self->updateMapLabels();
4615 }
4616  
4617 return 1;
4618 }
4619  
4620 sub renameLabelStyle {
4621  
4622 # Called by GA::Win::Map->renameStyleCallback and GA::Cmd::RenameLabelStyle->do
4623 # Renames the specified label style (in case the user wants to swap the default name for
4624 # a different one, without modifying a large number of labels)
4625 #
4626 # Expected arguments
4627 # $session - The calling function's GA::Session
4628 # $oldName - The name of an existing map label style
4629 # $newName - The new name for that style
4630 #
4631 # Return values
4632 # 'undef' on improper arguments, or if $oldName or $newName are invalid
4633 # 1 otherwise
4634  
4635 my ($self, $session, $oldName, $newName, $check) = @_;
4636  
4637 # Local variables
4638 my $obj;
4639  
4640 # Check for improper arguments
4641 if (! defined $session || ! defined $oldName || ! defined $newName || defined $check) {
4642  
4643 return $axmud::CLIENT->writeImproper($self->_objClass . '->renameLabelStyle', @_);
4644 }
4645  
4646 # Check specified values are valid
4647 if (
4648 length ($newName) > 16
4649 || ! $self->ivExists('mapLabelStyleHash', $oldName)
4650 || $self->ivExists('mapLabelStyleHash', $newName)
4651 ) {
4652 return undef;
4653 }
4654  
4655 # Get the style object, and rename it
4656 $obj = $self->ivShow('mapLabelStyleHash', $oldName);
4657 $obj->ivPoke('name', $newName);
4658  
4659 # Update our IVs
4660 $self->ivDelete('mapLabelStyleHash', $oldName);
4661 $self->ivAdd('mapLabelStyleHash', $newName, $obj);
4662 if (defined $self->mapLabelStyle && $self->mapLabelStyle eq $oldName) {
4663  
4664 $self->ivPoke('mapLabelStyle', $newName);
4665 }
4666  
4667 # Any label that uses this style must be updated
4668 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
4669  
4670 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
4671  
4672 if (defined $labelObj->style && $labelObj->style eq $oldName) {
4673  
4674 $labelObj->set_style($session, $newName);
4675 }
4676 }
4677 }
4678  
4679 return 1;
4680 }
4681  
4682 sub toggleLabelAlignment {
4683  
4684 # Called by GA::Win::Map->toggleLabelAlignment or any other function
4685 # Toggles alignment of map labels in horizontal or vertical directions (using the edge of
4686 # a gridblock and the middle of it)
4687 # When turning on alignment, the position of all existing labels is changed to either the
4688 # middle of the gridblock or the edge of it; new labels are placed in the same way
4689 # When turning off alignment, all existing labels remain in their current positions, but
4690 # new labels are placed in the exact position on the map that the user clicks
4691 #
4692 # Expected arguments
4693 # $session - The calling function's GA::Session
4694 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
4695 # be updated now, FALSE if not (in which case, they can be updated later
4696 # by the calling function, when it is ready). Ignored when turning off
4697 # alignment as no label positions change
4698 # $type - Which type of alignment to toggle - 'horizontal' or 'vertical'
4699 #
4700 # Return values
4701 # 'undef' on improper arguments, if a region with the specified name already exists, if
4702 # an invalid parent region is specified or if either the region object or the
4703 # regionmap object can't be created
4704 # Otherwise returns the region object created
4705  
4706 my ($self, $session, $updateFlag, $type, $check) = @_;
4707  
4708 # Check for improper arguments
4709 if (
4710 ! defined $session
4711 || ! defined $updateFlag
4712 || ! defined $type
4713 || ($type ne 'horizontal' && $type ne 'vertical')
4714 || defined $check
4715 ) {
4716 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleLabelAlignment', @_);
4717 }
4718  
4719 if ($type eq 'horizontal') {
4720  
4721 if ($self->mapLabelAlignXFlag) {
4722  
4723 # Turn off horizontal alignment
4724 $self->ivPoke('mapLabelAlignXFlag', FALSE);
4725  
4726 } else {
4727  
4728 # Turn on horizontal alignment
4729 $self->ivPoke('mapLabelAlignXFlag', TRUE);
4730  
4731 # Update the position of every label
4732 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
4733  
4734 # Half a block width is usually fractional, e.g. width 51, half is 25.5
4735 my $halfWidth = $regionmapObj->blockWidthPixels / 2;
4736  
4737 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
4738  
4739 # Round the label's position to the nearest half gridblock
4740 # my $xPos = $halfWidth * sprintf(
4741 # '%.0f',
4742 # ($labelObj->xPosPixels / $halfWidth),
4743 # );
4744 my $xPos = $halfWidth * Math::Round::nearest(
4745 1,
4746 ($labelObj->xPosPixels / $halfWidth),
4747 );
4748  
4749 $labelObj->ivPoke('xPosPixels', int($xPos));
4750 }
4751 }
4752 }
4753  
4754 } else {
4755  
4756 if ($self->mapLabelAlignYFlag) {
4757  
4758 # Turn off vertical alignment
4759 $self->ivPoke('mapLabelAlignYFlag', FALSE);
4760  
4761 } else {
4762  
4763 # Turn on vertical alignment
4764 $self->ivPoke('mapLabelAlignYFlag', TRUE);
4765  
4766 # Update the position of every label
4767 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
4768  
4769 # Half a block height is usually fractional, e.g. height 51, half is 25.5
4770 my $halfHeight = $regionmapObj->blockHeightPixels / 2;
4771  
4772 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
4773  
4774 # Round the label's position to the nearest half gridblock
4775 # my $yPos = $halfHeight * sprintf(
4776 # '%.0f',
4777 # ($labelObj->yPosPixels / $halfHeight),
4778 # );
4779 my $yPos = $halfHeight * Math::Round::nearest(
4780 1,
4781 ($labelObj->yPosPixels / $halfHeight),
4782 );
4783  
4784 $labelObj->ivPoke('yPosPixels', int($yPos));
4785 }
4786 }
4787 }
4788 }
4789  
4790 # Update automapper windows, if required
4791 if ($updateFlag) {
4792  
4793 $self->updateMapLabels();
4794 }
4795  
4796 return 1;
4797 }
4798  
4799 # Add model objects
4800  
4801 sub addRegion {
4802  
4803 # Called by GA::Win::Map->newRegionCallback or by any other function
4804 # Creates a new GA::ModelObj::Region object and adds it to the world model. Also creates a
4805 # corresponding GA::Obj::Regionmap, adds it to the world model, and updates any
4806 # Automapper windows using this model
4807 #
4808 # Expected arguments
4809 # $session - The calling function's GA::Session
4810 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4811 # should be updated now, FALSE if not (in which case, they can be
4812 # updated later by the calling function, when it is ready)
4813 #
4814 # Optional arguments
4815 # $name - A name for the new region. If more than 32 characters, it is
4816 # shortened. If not specified, a name is generated for it (in the
4817 # form 'unnamed_x' or 'temporary_x')
4818 # $parentNum - The model number of the parent region object ('undef' if no parent
4819 # region)
4820 # $tempFlag - If set to TRUE, the new region is a temporary region (that should be
4821 # deleted, the next time the world model is loaded from file). If set
4822 # to FALSE (or 'undef'), the new region is not temporary
4823 #
4824 # Return values
4825 # 'undef' on improper arguments, if a region with the specified name already exists, if
4826 # an invalid parent region is specified or if either the region object or the
4827 # regionmap object can't be created
4828 # Otherwise returns the region object created
4829  
4830 my ($self, $session, $updateFlag, $name, $parentNum, $tempFlag, $check) = @_;
4831  
4832 # Local variables
4833 my ($count, $partName, $regionObj, $regionmapObj);
4834  
4835 # Check for improper arguments
4836 if (! defined $session || ! defined $updateFlag || defined $check) {
4837  
4838 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRegion', @_);
4839 }
4840  
4841 # If $name is not specified, generate a name
4842 if (! defined $name || $name eq '') {
4843  
4844 # Generate a name in the form 'unnamed_x', or 'temporary_x' for temporary regions
4845 if ($tempFlag) {
4846 $partName = 'temporary_';
4847 } else {
4848 $partName = 'unnamed_';
4849 }
4850  
4851 $count = 0;
4852 do {
4853  
4854 $count++;
4855 $name = $partName . $count;
4856  
4857 } until (
4858 ! $self->ivExists('regionmapHash', $name)
4859 || $count > 9999
4860 );
4861  
4862 if ($count > 9999) {
4863  
4864 # To avoid infinite loops, give up at this point
4865 return undef;
4866 }
4867 }
4868  
4869 # Check the region doesn't already exist
4870 foreach my $regionObj ($self->ivValues('regionModelHash')) {
4871  
4872 if ($regionObj->name eq $name) {
4873  
4874 # Region called $name already exists
4875 return undef;
4876 }
4877 }
4878  
4879 # If parent was specified, check it's a valid region object
4880 if (defined $parentNum && ! $self->ivExists('regionModelHash', $parentNum)) {
4881  
4882 return undef;
4883 }
4884  
4885 # Create the new region object
4886 $regionObj = Games::Axmud::ModelObj::Region->new($session, $name, TRUE, $parentNum);
4887 if ($regionObj) {
4888  
4889 # Also create a new regionmap object
4890 $regionmapObj = Games::Axmud::Obj::Regionmap->new($session, $name);
4891 }
4892  
4893 if (! $regionObj || ! $regionmapObj) {
4894  
4895 # Error creating one or both objects; we can't continue
4896 return undef;
4897 }
4898  
4899 # Add the region object to the model
4900 if (! $self->addToModel($regionObj)) {
4901  
4902 # Object could not be added
4903 return undef;
4904 }
4905  
4906 # Also add the corresponding regionmap
4907 $self->ivAdd('regionmapHash', $name, $regionmapObj);
4908 $regionmapObj->ivPoke('number', $regionObj->number);
4909  
4910 # If it's a temporary region, mark it as so
4911 if ($tempFlag) {
4912  
4913 $regionObj->ivPoke('tempRegionFlag', TRUE);
4914 }
4915  
4916 # Update any GA::Win::Map objects using this world model (if allowed)
4917 if ($updateFlag) {
4918  
4919 foreach my $mapWin ($self->collectMapWins()) {
4920  
4921 $mapWin->resetTreeView();
4922 }
4923 }
4924  
4925 # Operation complete
4926 return $regionObj;
4927 }
4928  
4929 sub addRoom {
4930  
4931 # Called by GA::Obj::Map->createNewRoom or by any other function
4932 # Creates a new GA::ModelObj::Room object, adds it to the world model, and updates any
4933 # Automapper windows using this model
4934 #
4935 # Expected arguments
4936 # $session - The calling function's GA::Session
4937 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
4938 # should be updated now, FALSE if not (in which case, they can be
4939 # updated later by the calling function, when it is ready)
4940 # $region - The name of the room's parent region
4941 # $xPosBlocks, $yPosBlocks, $zPosBlocks
4942 # - The coordinates of the new room on the regionmap's grid
4943 #
4944 # Optional arguments
4945 # $name - The value stored as the object's ->name: the room's title, if that's
4946 # available; if not, a shortened version of the verbose description.
4947 # If 'undef', a name is assigned to the room
4948 #
4949 # Return values
4950 # 'undef' on improper arguments or if the room can't be added
4951 # Otherwise returns the new GA::Model::Room object
4952  
4953 my (
4954 $self, $session, $updateFlag, $region, $xPosBlocks, $yPosBlocks, $zPosBlocks, $name,
4955 $check,
4956 ) = @_;
4957  
4958 # Local variables
4959 my ($regionmapObj, $roomObj);
4960  
4961 # Check for improper arguments
4962 if (
4963 ! defined $session || ! defined $updateFlag || ! defined $region
4964 || ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $zPosBlocks
4965 || defined $check
4966 ) {
4967 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRoom', @_);
4968 }
4969  
4970 # Find the regionmap
4971 $regionmapObj = $self->ivShow('regionmapHash', $region);
4972 if (! $regionmapObj) {
4973  
4974 return undef;
4975 }
4976  
4977 # Check that the grid coordinates are valid and not already occupied by another room
4978 if ($regionmapObj->fetchRoom($xPosBlocks, $yPosBlocks, $zPosBlocks)) {
4979  
4980 return undef;
4981 }
4982  
4983 # If $name wasn't specified, use a temporary name
4984 if (! $name) {
4985  
4986 $name = '<unnamed room>';
4987 }
4988  
4989 # Create the new room object
4990 $roomObj = Games::Axmud::ModelObj::Room->new(
4991 $session,
4992 $name,
4993 'model',
4994 $regionmapObj->number,
4995 );
4996  
4997 if (! $roomObj) {
4998  
4999 return undef;
5000 }
5001  
5002 # Add the room object to the model
5003 if (! $self->addToModel($roomObj)) {
5004  
5005 # Object could not be added
5006 return undef;
5007 }
5008  
5009 # Set the room's position
5010 $roomObj->ivPoke('xPosBlocks', $xPosBlocks);
5011 $roomObj->ivPoke('yPosBlocks', $yPosBlocks);
5012 $roomObj->ivPoke('zPosBlocks', $zPosBlocks);
5013  
5014 # Add the room to its regionmap
5015 $regionmapObj->storeRoom($roomObj);
5016  
5017 # Update any GA::Win::Map objects using this world model (if allowed)
5018 if ($updateFlag) {
5019  
5020 foreach my $mapWin ($self->collectMapWins()) {
5021  
5022 # Redraw the room
5023 $mapWin->markObjs('room', $roomObj);
5024 $mapWin->doDraw();
5025  
5026 # The regionmap's highest/lowest occupied levels need to be recalculated
5027 $self->ivAdd('checkLevelsHash', $regionmapObj->name, undef);
5028 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions (as
5029 # a response to this calculation)
5030 $mapWin->restrictWidgets();
5031 }
5032 }
5033  
5034 # Operation complete
5035 return $roomObj;
5036 }
5037  
5038 sub updateRoom {
5039  
5040 # Called by GA::Obj::Map->updateRoom, when the Automapper window is in 'update' mode, to
5041 # adjust the properties of a room object in the world model to match those of
5042 # the Locator task's non-model current room
5043 # The properties adjusted depend on various flags
5044 #
5045 # Expected arguments
5046 # $session
5047 # - The calling function's GA::Session
5048 # $updateFlag
5049 # - Flag set to TRUE if all Automapper windows using this world model should be
5050 # updated now, FALSE if not (in which case, they can be updated later by the
5051 # calling function, when it is ready)
5052 # $modelRoomObj
5053 # - A GA::ModelObj::Room in the world model
5054 #
5055 # Optional arguments
5056 # $connectRoomObj, $connectExitObj, $standardDir
5057 # - When the calling function was in turn called by GA::Obj::Map->createNewRoom, the
5058 # room from which the character arrived and the exit obj/standard direction used
5059 # (if known). Used when temporarily allocating primary directions to unallocated
5060 # exits
5061 #
5062 # Return values
5063 # 'undef' on improper arguments, if the Locator task doesn't exist, if it doesn't know the
5064 # current location or if we're not in 'update' mode
5065 # 1 otherwise
5066  
5067 my (
5068 $self, $session, $updateFlag, $modelRoomObj, $connectRoomObj, $connectExitObj,
5069 $standardDir, $check,
5070 ) = @_;
5071  
5072 # Local variables
5073 my (
5074 $taskObj, $taskRoomObj, $name, $terrain, $roomFlag,
5075 @titleList, @drawList,
5076 );
5077  
5078 # Check for improper arguments
5079 if (! defined $session || ! defined $modelRoomObj || defined $check) {
5080  
5081 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRoom', @_);
5082 }
5083  
5084 # Import the Locator task and its current room
5085 $taskObj = $session->locatorTask;
5086 if ($taskObj) {
5087  
5088 $taskRoomObj = $taskObj->roomObj;
5089 }
5090  
5091 # If the Locator task doesn't exist, or if it doesn't know the current location, we can't
5092 # use the location's properties
5093 if (! $taskRoomObj) {
5094  
5095 return undef;
5096 }
5097  
5098 # Update the room title(s) (if the Locator task knows any, and if we're allowed)
5099 if ($self->updateTitleFlag && $taskRoomObj->titleList) {
5100  
5101 # Each description in the Locator room's title list should be added to the model room's
5102 # title list, but don't add duplicates
5103 @titleList = $modelRoomObj->titleList;
5104 if (! @titleList) {
5105  
5106 # The model room's title list is empty, so simply copy the Locator room's title list
5107 # across (even if it, too, is empty)
5108 $modelRoomObj->ivPoke('titleList', $taskRoomObj->titleList);
5109  
5110 } else {
5111  
5112 OUTER: foreach my $taskTitle ($taskRoomObj->titleList) {
5113  
5114 foreach my $modelTitle (@titleList) {
5115  
5116 if ($taskTitle eq $modelTitle) {
5117  
5118 # The model room already has this room title
5119 next OUTER;
5120 }
5121 }
5122  
5123 # The model room doesn't already have this room title
5124 push (@titleList, $taskTitle);
5125 }
5126  
5127 # Store the combined list of brief descriptions
5128 $modelRoomObj->ivPoke('titleList', @titleList);
5129 }
5130 }
5131  
5132 # Update the (verbose) description(s), if the Locator task knows any, and if we're allowed
5133 if ($self->updateDescripFlag && $taskRoomObj->descripHash) {
5134  
5135 # A room's verbose description hash is in the form
5136 # ->descripHash{light_status} = description_string
5137 # e.g. $hash{'day'} = daytime_description_string
5138 # e.g. $hash{'dark'} = darkness_description_string
5139 # Any key-value pairs in the Locator room's hash are copied to the map's hash,
5140 # replacing any key-value pairs that are already there
5141 foreach my $key ($taskRoomObj->ivKeys('descripHash')) {
5142  
5143 my $value = $taskRoomObj->ivShow('descripHash', $key);
5144  
5145 $modelRoomObj->ivAdd('descripHash', $key, $value);
5146 }
5147 }
5148  
5149 # Update the room's ->name. If there's a room title, use it; if there's a verbose
5150 # description, use it; otherwise use a generic name
5151 if ($taskRoomObj->titleList) {
5152  
5153 # Use the first 32 characters of the first room title found
5154 $name = substr($taskRoomObj->ivFirst('titleList'), 0, 32);
5155  
5156 } elsif ($taskRoomObj->ivExists('descripHash', $self->lightStatus)) {
5157  
5158 # Use the first 32 characters of the verbose description matching the current light
5159 # status
5160 $name = substr($taskRoomObj->ivShow('descripHash', $self->lightStatus), 0, 32);
5161  
5162 } else {
5163  
5164 # Use a generic name
5165 $name = 'room_' . $modelRoomObj->number;
5166 }
5167  
5168 # Update the ->name IV
5169 $modelRoomObj->ivPoke('name', $name);
5170  
5171 # Analyse the verbose description to find recognised words, if we're allowed (and if the
5172 # room's verbose description is known)
5173 if ($self->analyseDescripFlag && $modelRoomObj->descripHash) {
5174  
5175 $self->analyseVerboseDescrip($session, $modelRoomObj);
5176 }
5177  
5178 # Update exits (if we're allowed)
5179 # For wilderness rooms, we don't check any exits that have been added to the map (since we
5180 # assume the world has sent a room statement with no exit list)
5181 if ($self->updateExitFlag && $modelRoomObj->wildMode eq 'normal') {
5182  
5183 # An exit's nominal direction is the one we'd expect to find in a room statement
5184 # (e.g. 'Obvious exits are: east, south, north') and are stored in the exit object's
5185 # ->dir
5186 # Room objects save their exits in two IVs: a hash in the form...
5187 # ->exitNumHash{nominal_direction} = number_in_exit_model
5188 # ...and a list, with the nominal directions sorted in a standard order
5189 # Any nominal directions in the Locator room's hash which don't exist in the map's
5190 # hash are added to the world model as new exits. Any that already exist are updated
5191 # Ignore transient exits (those which appear from time to time in various locations, for
5192 # example the entrance to a moving wagon)
5193 OUTER: foreach my $exitObj ($taskRoomObj->ivValues('exitNumHash')) {
5194  
5195 my (
5196 $slot, $convertDir,
5197 @patternList,
5198 );
5199  
5200 # Deal with transient exits
5201 @patternList = $session->currentWorld->transientExitPatternList;
5202 if (@patternList) {
5203  
5204 do {
5205  
5206 my $pattern = shift @patternList;
5207 my $destRoom = shift @patternList;
5208  
5209 if ($exitObj->dir =~ m/$pattern/) {
5210  
5211 # A transient exit; don't add it to the model room
5212 next OUTER;
5213 }
5214  
5215 } until (! @patternList);
5216 }
5217  
5218 # Deal with relative directions
5219 $slot = $session->currentDict->convertRelativeDir($exitObj->dir);
5220 if (defined $slot) {
5221  
5222 # $slot is in the range 0-7. Convert it into a standard primary direction like
5223 # 'north', depending on which way the character is currently facing
5224 $convertDir = $session->currentDict->rotateRelativeDir(
5225 $slot,
5226 $session->mapObj->facingDir,
5227 );
5228 }
5229  
5230 $self->updateExit(
5231 $session,
5232 FALSE, # Don't update Automapper windows now
5233 $modelRoomObj,
5234 $taskRoomObj,
5235 $exitObj,
5236 $convertDir,
5237 );
5238 }
5239  
5240 # Now, check the model room's list of exit objects, looking for those which don't yet
5241 # have a map direction (->mapDir) set (which will be the case for any new exits we've
5242 # just created in non-primary directions)
5243 # Allocate them one of the sixteen cardinal directions that are not already in use. If
5244 # all sixteen cardinal directions are in use, the exit object's ->mapDir remains set
5245 # to 'undef' (and isn't explicity drawn in the map)
5246 # (When this function is called by GA::Obj::Map->updateRoom which was, in turn, called
5247 # by GA::Obj::Map->createNewRoom when moving from an existing departure room to a new
5248 # arrival room, we pass information about the departure room to the function so that,
5249 # if we moved using an allocated exit, any unallocated exits in the arrival room can
5250 # be drawn in the opposite direction)
5251 foreach my $number ($modelRoomObj->ivValues('exitNumHash')) {
5252  
5253 my $exitObj = $self->ivShow('exitModelHash', $number);
5254 if ($exitObj && ! $exitObj->mapDir) {
5255  
5256 $self->allocateCardinalDir(
5257 $session,
5258 $modelRoomObj,
5259 $exitObj,
5260 $connectRoomObj,
5261 $connectExitObj,
5262 $standardDir,
5263 );
5264 }
5265 }
5266 }
5267  
5268 # Update the room source code path (if the Locator task knows it, and if we're allowed)
5269 if ($self->updateSourceFlag && $taskRoomObj->sourceCodePath) {
5270  
5271 $modelRoomObj->ivPoke('sourceCodePath', $taskRoomObj->sourceCodePath);
5272 }
5273  
5274 # Update the world's room vnum, etc (if the world has specified it, and if we're allowed)
5275 if ($self->updateVNumFlag && $taskRoomObj->ivExists('protocolRoomHash', 'vnum')) {
5276  
5277 foreach my $key ($taskRoomObj->ivKeys('protocolRoomHash')) {
5278  
5279 $modelRoomObj->ivAdd(
5280 'protocolRoomHash',
5281 $key,
5282 $taskRoomObj->ivShow('protocolRoomHash', $key),
5283 );
5284 }
5285  
5286 foreach my $key ($taskRoomObj->ivKeys('protocolExitHash')) {
5287  
5288 $modelRoomObj->ivAdd(
5289 'protocolExitHash',
5290 $key,
5291 $taskRoomObj->ivShow('protocolExitHash', $key),
5292 );
5293 }
5294  
5295 # Deal with MSDP terrain types
5296 $terrain = $taskRoomObj->ivShow('protocolRoomHash', 'terrain');
5297 if (defined $terrain) {
5298  
5299 if (! $self->ivExists('roomTerrainHash', $terrain)) {
5300  
5301 # This terrain type not allocated to a room flag yet
5302 $self->ivAdd('roomTerrainInitHash', $terrain, undef);
5303  
5304 } else {
5305  
5306 # If the terrain type should be ignored, $roomFlag will be set to 'undef'
5307 $roomFlag = $self->ivShow('roomTerrainHash', $terrain);
5308 if ($roomFlag) {
5309  
5310 # Add the corresponding room flag to the room, and remove any room flags
5311 # which belong to a differen terrain
5312 $modelRoomObj->ivAdd('roomFlagHash', $roomFlag, undef);
5313  
5314 foreach my $otherTerrain ($self->ivKeys('roomTerrainHash')) {
5315  
5316 my $otherFlag = $self->ivShow('roomTerrainHash', $otherTerrain);
5317  
5318 if ($otherFlag ne $roomFlag) {
5319  
5320 $modelRoomObj->ivDelete('roomFlagHash', $otherFlag);
5321 }
5322 }
5323 }
5324 }
5325 }
5326 }
5327  
5328 # Update room commands
5329 if ($self->updateRoomCmdFlag) {
5330  
5331 $modelRoomObj->ivPoke('roomCmdList', $taskRoomObj->roomCmdList);
5332 }
5333  
5334 # Update any GA::Win::Map objects using this world model (if allowed)
5335 if ($updateFlag) {
5336  
5337 # Compile a list of rooms to be marked for drawing
5338 @drawList = ('room', $modelRoomObj);
5339 if ($connectRoomObj) {
5340  
5341 push (@drawList, 'room', $connectRoomObj);
5342 }
5343  
5344 foreach my $mapWin ($self->collectMapWins()) {
5345  
5346 # Redraw the rooms
5347 $mapWin->markObjs(@drawList);
5348 $mapWin->doDraw();
5349 }
5350 }
5351  
5352 # Adjustment complete
5353 return 1;
5354 }
5355  
5356 sub addRoomChildren {
5357  
5358 # Called by GA::Win::Map->addContentsCallback
5359 # Adds one or more non-model objects to the world model as children of an existing model
5360 # room
5361 #
5362 # Expected arguments
5363 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
5364 # be updated now, FALSE if not (in which case, they can be updated later
5365 # by the calling function, when it is ready)
5366 # $hiddenFlag - Flag set to TRUE if the child objects should be marked as hidden, set to
5367 # FALSE otherwise
5368 # $roomObj - The world model room object to which children should be added
5369 #
5370 # Optional arguments
5371 # $obtainCmd - For hidden objects, the command used to obtain it. Set to 'undef' when
5372 # $hiddenFlag is FALSE
5373 # @objList - A list of non-model objects. If empty, the world model isn't modified
5374 #
5375 # Return values
5376 # 'undef' on improper arguments or if @objList is empty
5377 # 1 otherwise
5378  
5379 my ($self, $updateFlag, $hiddenFlag, $roomObj, $obtainCmd, @objList) = @_;
5380  
5381 # Check for improper arguments
5382 if (! defined $updateFlag || ! defined $hiddenFlag || ! defined $roomObj) {
5383  
5384 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRoomChildren', @_);
5385 }
5386  
5387 # Do nothing if the object list is empty
5388 if (! @objList) {
5389  
5390 return undef;
5391 }
5392  
5393 # Add each object in turn
5394 foreach my $obj (@objList) {
5395  
5396 # First set the parent ($self->addToModel will inform the parent it has acquired a
5397 # child)
5398 $obj->ivPoke('parent', $roomObj->number);
5399  
5400 # Add the object to the model
5401 $self->addToModel($obj);
5402  
5403 if ($hiddenFlag) {
5404  
5405 # Add the object to the hidden objects list
5406 $roomObj->ivAdd('hiddenObjHash', $obj->number, $obtainCmd);
5407 }
5408 }
5409  
5410 # Update any GA::Win::Map objects using this world model (if allowed)
5411 if ($updateFlag) {
5412  
5413 foreach my $mapWin ($self->collectMapWins()) {
5414  
5415 # Redraw the room
5416 $mapWin->markObjs('room', $roomObj);
5417 $mapWin->doDraw();
5418 }
5419 }
5420  
5421 return 1;
5422 }
5423  
5424 sub addExit {
5425  
5426 # Called by $self->updateExit and GA::Win::Map->addExitCallback
5427 # Adds a new exit object to the exit model
5428 #
5429 # Expected arguments
5430 # $session - The calling function's GA::Session
5431 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
5432 # be updated now, FALSE if not (in which case, they can be updated later
5433 # by the calling function, when it is ready)
5434 # $roomObj - The world model room object to which an exit should be added
5435 # $dir - The exit's nominal direction (stored in GA::Obj::Exit->dir)
5436 #
5437 # Optional arguments
5438 # $mapDir - The primary direction in which the exit is drawn (stored in
5439 # GA::Obj::Exit->mapDir). Set when called by ->addExitCallback; set to
5440 # 'undef' when called by ->updateExit (which decides for itself, which
5441 # primary direction to use) or when the exit is unallocatable (in which
5442 # case, GA::Obj::Exit->mapDir is 'undef')
5443 #
5444 # Return values
5445 # 'undef' on improper arguments or if the exit can't be added
5446 # Otherwise returns the new GA::Obj::Exit object
5447  
5448 my ($self, $session, $updateFlag, $roomObj, $dir, $mapDir, $check) = @_;
5449  
5450 # Local variables
5451 my (
5452 $dictObj, $exitObj, $oldExitObj, $standardDir, $reallocateExitObj, $regionFlag,
5453 $regionObj,
5454 @dirList, @sortedList,
5455 );
5456  
5457 # Check for improper arguments
5458 if (! defined $session || ! defined $roomObj || ! defined $dir || defined $check) {
5459  
5460 return $axmud::CLIENT->writeImproper($self->_objClass . '->addExit', @_);
5461 }
5462  
5463 # Import the current dictionary
5464 $dictObj = $session->currentDict;
5465  
5466 # Create the new exit object
5467 $exitObj = Games::Axmud::Obj::Exit->new(
5468 $session,
5469 $dir,
5470 'model',
5471 );
5472  
5473 if (! $exitObj) {
5474  
5475 return undef;
5476 }
5477  
5478 # Add the exit object to the exit model
5479 if (! $self->addToExitModel($exitObj)) {
5480  
5481 # Object could not be added
5482 return undef;
5483 }
5484  
5485 # If this room already has an exit using the same direction, that exit must be deleted from
5486 # the exit model
5487 if ($roomObj->ivExists('exitNumHash', $dir)) {
5488  
5489 $oldExitObj = $self->ivShow('exitModelHash', $roomObj->ivShow('exitNumHash', $dir));
5490 if ($oldExitObj) {
5491  
5492 $self->deleteExits(
5493 $session,
5494 TRUE, # Update Automapper windows now
5495 $oldExitObj,
5496 );
5497 }
5498  
5499 } else {
5500  
5501 # If this room already has an exit using the same map direction (the standard primary
5502 # direction used to draw the exit on the map), and if the new exit's nominal direction
5503 # $dir is a primary direction, then the new exit supplants the old one
5504 if ($mapDir) {
5505  
5506 # Use the specified map direction
5507 $exitObj->ivPoke('mapDir', $mapDir);
5508 $standardDir = $mapDir;
5509  
5510 } else {
5511  
5512 # Check whether the new exit's nominal direction is a (custom) primary direction by
5513 # getting the corresponding standard primary direction
5514 $standardDir = $dictObj->convertStandardDir($dir);
5515 }
5516  
5517 if ($standardDir) {
5518  
5519 # Check whether any of the room's existing exits are using the same custom primary
5520 # direction
5521 OUTER: foreach my $number ($roomObj->ivValues('exitNumHash')) {
5522  
5523 my $otherExitObj = $self->ivShow('exitModelHash', $number);
5524  
5525 if (
5526 $otherExitObj
5527 && $otherExitObj->mapDir
5528 && $otherExitObj->mapDir eq $standardDir
5529 ) {
5530 # The room's existing exit is using the map direction we need
5531 $reallocateExitObj = $otherExitObj;
5532 last OUTER;
5533 }
5534 }
5535 }
5536 }
5537  
5538 # Add the new exit object to the room
5539 $roomObj->ivAdd('exitNumHash', $dir, $exitObj->number);
5540 $exitObj->ivPoke('parent', $roomObj->number);
5541  
5542 @dirList = $roomObj->ivKeys('exitNumHash');
5543 @sortedList = $dictObj->sortExits(@dirList);
5544 $roomObj->ivPoke('sortedExitList', @sortedList);
5545  
5546 # If an existing exit has been supplanted, allocate it a different map direction
5547 if ($reallocateExitObj) {
5548  
5549 $regionFlag = $reallocateExitObj->regionFlag;
5550 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
5551  
5552 $reallocateExitObj->ivUndef('mapDir');
5553 $reallocateExitObj->ivPoke('drawMode', 'primary');
5554  
5555 $self->allocateCardinalDir($session, $roomObj, $reallocateExitObj);
5556  
5557 # Any region paths using the reallocated exit will have to be updated
5558 $self->ivAdd('updatePathHash', $reallocateExitObj->number, $regionObj->name);
5559 if ($regionFlag || $reallocateExitObj->regionFlag) {
5560  
5561 $self->ivAdd('updateBoundaryHash', $reallocateExitObj->number, $regionObj->name);
5562 }
5563 }
5564  
5565 # If a checked direction in this (primary or secondary) direction existed, remove its entry
5566 $roomObj->ivDelete('checkedDirHash', $exitObj->dir);
5567  
5568 # Set the exit type (e.g. 'primaryDir', 'primaryAbbrev', etc)
5569 $exitObj->ivPoke(
5570 'exitType',
5571 $session->currentDict->ivShow('combDirHash', $exitObj->dir),
5572 );
5573  
5574 # Update any GA::Win::Map objects using this world model (if allowed)
5575 if ($updateFlag) {
5576  
5577 foreach my $mapWin ($self->collectMapWins()) {
5578  
5579 # Redraw the exit
5580 $mapWin->markObjs('exit', $exitObj);
5581 $mapWin->doDraw();
5582 }
5583 }
5584  
5585 return $exitObj;
5586 }
5587  
5588 sub updateExit {
5589  
5590 # Called by GA::Win::Map->updateRoom
5591 # The current Locator task has a non-model room with non-model exits. Given one of those
5592 # exits, create a new exit object and add it to the world model via a call to
5593 # $self->addExit
5594 # However, if the world model room object already has an exit in the same direction, don't
5595 # replace it - just update its IVs
5596 #
5597 # Expected arguments
5598 # $session - The calling function's GA::Session
5599 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
5600 # should be updated now, FALSE if not (in which case, they can be
5601 # updated later by the calling function, when it is ready)
5602 # $modelRoomObj - The room object in the world model to which the new exit will belong
5603 # $taskRoomObj - The current Locator task's non-model room object
5604 # $taskExitObj - The non-model exit object belonging to $taskRoomObj which we need to
5605 # copy
5606 #
5607 # Optional arguments
5608 # $convertDir - If $taskExitObj's nominal direction is a relative direction, the
5609 # calling function has converted it into a standard primary direction
5610 # like 'north', depending on which direction the character is facing.
5611 # 'undef' for non-relative directions
5612 #
5613 # Return values
5614 # 'undef' on improper arguments or if the function tries and fails to create a new exit
5615 # Otherwise, returns the model number of the newly-added exit object
5616  
5617 my (
5618 $self, $session, $updateFlag, $modelRoomObj, $taskRoomObj, $taskExitObj, $convertDir,
5619 $check,
5620 ) = @_;
5621  
5622 # Local variables
5623 my ($useDir, $modelExitNum, $modelExitObj, $standardDir, $regionObj);
5624  
5625 # Check for improper arguments
5626 if (
5627 ! defined $session || ! defined $updateFlag || ! defined $modelRoomObj
5628 || ! defined $taskRoomObj || ! defined $taskExitObj || defined $check
5629 ) {
5630 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateExit', @_);
5631 }
5632  
5633 # Any relative direction has been converted into a standard primary direction like 'north'
5634 # During this function, if $convertDir was specified, use the corresponding custom
5635 # direction, otherwise use the exit's true nominal direction
5636 if (defined $convertDir) {
5637 $useDir = $session->currentDict->ivShow('primaryDirHash', $convertDir);
5638 } else {
5639 $useDir = $taskExitObj->dir;
5640 }
5641  
5642 # Does the world model room object already have an exit in this direction?
5643 if (! $modelRoomObj->ivExists('exitNumHash', $useDir)) {
5644  
5645 # It doesn't, so add a new one
5646 $modelExitObj = $self->addExit(
5647 $session,
5648 FALSE, # Don't update Automapper windows now
5649 $modelRoomObj,
5650 $useDir,
5651 );
5652  
5653 if (! $modelExitObj) {
5654  
5655 # Nothing more we can do
5656 return undef;
5657 }
5658  
5659 # Decide how to draw the exit on the map. Is its direction a recognised custom primary
5660 # direction?
5661 if (defined $convertDir) {
5662 $standardDir = $convertDir;
5663 } else {
5664 $standardDir = $session->currentDict->convertStandardDir($modelExitObj->dir);
5665 }
5666  
5667 if ($standardDir) {
5668  
5669 # The exit's nominal direction is a custom primary direction; store the
5670 # corresponding standard primary direction in ->mapDir (this is the direction in
5671 # which the exit is drawn on the map)
5672 # Otherwise, the calling function allocates a temporary value for ->mapDir, once it
5673 # has finished calling this function (so it knows which directions are available)
5674 $modelExitObj->ivPoke('mapDir', $standardDir);
5675 }
5676  
5677 } else {
5678  
5679 # Update the existing exit
5680 $modelExitNum = $modelRoomObj->ivShow('exitNumHash', $useDir);
5681 $modelExitObj = $self->ivShow('exitModelHash', $modelExitNum);
5682  
5683 # Any region paths using the existing exit will have to be updated
5684 $regionObj = $self->ivShow('modelHash', $modelRoomObj->parent);
5685 $self->ivAdd('updatePathHash', $modelExitObj->number, $regionObj->name);
5686 if ($modelExitObj->regionFlag) {
5687  
5688 $self->ivAdd('updateBoundaryHash', $modelExitObj->number, $regionObj->name);
5689 }
5690 }
5691  
5692 # Update the model exit's ornament, but don't remove an ornament from $modelExitObj if
5693 # there is no ornament on $taskExitObj
5694 if ($taskExitObj->exitOrnament ne 'none') {
5695  
5696 $modelExitObj->ivPoke('exitOrnament', $taskExitObj->exitOrnament);
5697 }
5698  
5699 # If the non-model exit has its ->exitState set, we can also use that to update the model
5700 # exit's ornament (if this behaviour is allowed by the setting of
5701 # $self->updateOrnamentFlag, but don't overrule the existing ornament, if set)
5702 if (
5703 ! $modelExitObj->exitOrnament ne 'none'
5704 && $self->updateOrnamentFlag
5705 && $taskExitObj->exitState
5706 ) {
5707 if ($taskExitObj->exitState eq 'impass') {
5708  
5709 $modelExitObj->ivPoke('exitOrnament', 'impass');
5710  
5711 } elsif (
5712 $taskExitObj->exitState eq 'locked'
5713 || $taskExitObj->exitState eq 'secret_locked'
5714 ) {
5715 $modelExitObj->ivPoke('exitOrnament', 'lock');
5716  
5717 } elsif (
5718 $taskExitObj->exitState eq 'open'
5719 || $taskExitObj->exitState eq 'closed'
5720 || $taskExitObj->exitState eq 'secret_open'
5721 || $taskExitObj->exitState eq 'secret_closed'
5722 ) {
5723 $modelExitObj->ivPoke('exitOrnament', 'open');
5724 }
5725 }
5726  
5727 # GA::Profile::World->exitStateTagHash can specify custom strings instead of exit states,
5728 # which are added to the non-model object as assisted moves, so use them
5729 foreach my $key ($taskExitObj->assistedHash) {
5730  
5731 my $value = $taskExitObj->ivShow('assistedHash', $key);
5732  
5733 $modelExitObj->ivAdd('assistedHash', $key, $value);
5734 }
5735  
5736 # Also set the exit info, if it was collected
5737 if ($taskExitObj->exitInfo) {
5738  
5739 $modelExitObj->ivPoke('exitInfo', $taskExitObj->exitInfo);
5740 }
5741  
5742 # If the Locator task found a duplicate exit, it may have converted it using the pattern
5743 # specified by GA::Profile::World->duplicateReplaceString (e.g. it might have converted a
5744 # duplicate 'east' exit into a 'swim east' exit)
5745 # Any such duplicate exits are marked hidden. If the non-model exit object is marked hidden
5746 # then so must the model exit object
5747 if ($taskExitObj->hiddenFlag) {
5748  
5749 $modelExitObj->ivPoke('hiddenFlag', TRUE);
5750 }
5751  
5752 # Update any GA::Win::Map objects using this world model (if allowed)
5753 if ($updateFlag) {
5754  
5755 foreach my $mapWin ($self->collectMapWins()) {
5756  
5757 # Redraw the exit
5758 $mapWin->markObjs('exit', $modelExitObj);
5759 $mapWin->doDraw();
5760 }
5761 }
5762  
5763 # Update complete
5764 return 1;
5765 }
5766  
5767 sub addLabel {
5768  
5769 # Called by GA::Win::Map->canvasEventHandler, ->addLabelAtBlockCallback or by any other
5770 # function
5771 # Creates a new GA::Obj::MapLabel object, adds it to the specified regionmap object and
5772 # updates any Automapper windows using this model
5773 #
5774 # Expected arguments
5775 # $session - The calling function's GA::Session
5776 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
5777 # should be updated now, FALSE if not (in which case, they can be
5778 # updated later by the calling function, when it is ready)
5779 # $regionmapObj - The GA::Obj::Regionmap to which the label should be added
5780 # $xPosPixels, $yPosPixels
5781 # - The map coordinates of the top-left pixel of the label
5782 # $level - The regionmap level on which the label is drawn
5783 # $labelText - The label text
5784 #
5785 # Optional arguments
5786 # $style - The name of the map label style to use (a GA::Obj::MapLabelStyle). If
5787 # defined, that style is applied to the label's text. If not defined,
5788 # the style depends on IVs in this object
5789 #
5790 # Return values
5791 # 'undef' on improper arguments, if the map coordinates are invalid or if the label can't
5792 # be created
5793 # Otherwise returns the new GA::Obj::MapLabel created
5794  
5795 my (
5796 $self, $session, $updateFlag, $regionmapObj, $xPosPixels, $yPosPixels, $level,
5797 $labelText, $style, $check,
5798 ) = @_;
5799  
5800 # Local variables
5801 my ($halfWidth, $halfHeight, $labelObj);
5802  
5803 # Check for improper arguments
5804 if (
5805 ! defined $session || ! defined $updateFlag || ! defined $regionmapObj
5806 || ! defined $xPosPixels || ! defined $yPosPixels || ! defined $level
5807 || ! defined $labelText || defined $check
5808 ) {
5809 return $axmud::CLIENT->writeImproper($self->_objClass . '->addLabel', @_);
5810 }
5811  
5812 # Check that the map coordinates are valid
5813 if (
5814 $xPosPixels < 0
5815 || $yPosPixels < 0
5816 || $xPosPixels > $regionmapObj->mapWidthPixels
5817 || $yPosPixels > $regionmapObj->mapHeightPixels
5818 ) {
5819 return undef;
5820 }
5821  
5822 # If label alignment is turned on, adjust the label's horizontal and or vertical position
5823 if ($self->mapLabelAlignXFlag) {
5824  
5825 # Half a block width is usually fractional, e.g. width 51, half is 25.5
5826 $halfWidth = $regionmapObj->blockWidthPixels / 2;
5827 # Round the label's position to the nearest half gridblock
5828 # $xPosPixels = $halfWidth * sprintf('%.0f', ($xPosPixels / $halfWidth));
5829 $xPosPixels = $halfWidth * Math::Round::nearest(1, ($xPosPixels / $halfWidth));
5830 }
5831  
5832 if ($self->mapLabelAlignYFlag) {
5833  
5834 # Half a block height is usually fractional, e.g. height 51, half is 25.5
5835 $halfHeight = $regionmapObj->blockHeightPixels / 2;
5836 # Round the label's position to the nearest half gridblock
5837 # $yPosPixels = $halfHeight * sprintf('%.0f', ($yPosPixels / $halfHeight));
5838 $yPosPixels = $halfHeight * Math::Round::nearest(1, ($yPosPixels / $halfHeight));
5839 }
5840  
5841 # Create the new map label object
5842 $labelObj = Games::Axmud::Obj::MapLabel->new(
5843 $session,
5844 $labelText,
5845 $regionmapObj->name,
5846 $xPosPixels,
5847 $yPosPixels,
5848 $level,
5849 $style,
5850 );
5851  
5852 if (! $labelObj) {
5853  
5854 return undef;
5855 }
5856  
5857 # Add the label to the regionmap
5858 $regionmapObj->storeLabel($labelObj);
5859  
5860 # Update any GA::Win::Map objects using this world model (if allowed)
5861 if ($updateFlag) {
5862  
5863 foreach my $mapWin ($self->collectMapWins()) {
5864  
5865 # Redraw the label
5866 $mapWin->markObjs('label', $labelObj);
5867 $mapWin->doDraw();
5868  
5869 # The regionmap's highest/lowest occupied levels need to be recalculated
5870 $self->ivAdd('checkLevelsHash', $regionmapObj->name, undef);
5871 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions (as
5872 # a response to this calculation)
5873 $mapWin->restrictWidgets();
5874 }
5875 }
5876  
5877 # Operation complete
5878 return $labelObj;
5879 }
5880  
5881 sub addChar {
5882  
5883 # Called by GA::Cmd::AddModelObject->do or by any other function
5884 # Adds a character model object to the world model. Characters are the only kind of model
5885 # object that must have a unique name (not already used by other character objects)
5886 #
5887 # Expected arguments
5888 # $session - The calling function's GA::Session
5889 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
5890 # should be updated now, FALSE if not (in which case, they can be
5891 # updated later by the calling function, when it is ready)
5892 # $name - A name for the new character model object
5893 #
5894 # Optional arguments
5895 # $parentNum - If specified, the world model number of the parent object. Otherwise
5896 # set to 'undef'
5897 #
5898 # Return values
5899 # 'undef' on improper arguments or if the character can't be added
5900 # Otherwise returns the new model object
5901  
5902 my ($self, $session, $updateFlag, $name, $parentNum, $check) = @_;
5903  
5904 # Local variables
5905 my ($obj, $parentObj, $profObj);
5906  
5907 # Check for improper arguments
5908 if (! defined $session || ! defined $updateFlag || ! defined $name || defined $check) {
5909  
5910 return $axmud::CLIENT->writeImproper($self->_objClass . '->addChar', @_);
5911 }
5912  
5913 # If the parent is specified, check it exists
5914 if ($parentNum) {
5915  
5916 if (! $self->ivExists('modelHash', $parentNum)) {
5917  
5918 return undef;
5919  
5920 } else {
5921  
5922 $parentObj = $self->ivShow('modelHash', $parentNum);
5923 }
5924 }
5925  
5926 # Check that there isn't already a known character with this name
5927 if ($self->ivExists('knownCharHash', $name)) {
5928  
5929 return undef;
5930 }
5931  
5932 # Create the new character model object
5933 $obj = Games::Axmud::ModelObj::Char->new($session, $name, TRUE, $parentNum);
5934 if (! $obj) {
5935  
5936 return undef;
5937 }
5938  
5939 # Add the new object to the model
5940 if (! $self->addToModel($obj)) {
5941  
5942 # Object could not be added
5943 return undef;
5944 }
5945  
5946 # Update the character model object IVs
5947 $self->ivAdd('knownCharHash', $name, $obj);
5948  
5949 # Update any GA::Win::Map objects using this world model (if allowed)
5950 if ($updateFlag && $parentObj && $parentObj->category eq 'room') {
5951  
5952 foreach my $mapWin ($self->collectMapWins()) {
5953  
5954 # Redraw the (parent) room
5955 $mapWin->markObjs('room', $parentObj);
5956 $mapWin->doDraw();
5957 }
5958 }
5959  
5960 # Operation complete
5961 return $obj;
5962 }
5963  
5964 sub addOther {
5965  
5966 # Called by GA::Cmd::AddModelObject->do or by any other function
5967 # Adds a model object which is not a region, room, character (or exit) to the world model
5968 #
5969 # Expected arguments
5970 # $session - The calling function's GA::Session
5971 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
5972 # should be updated now, FALSE if not (in which case, they can be
5973 # updated later by the calling function, when it is ready)
5974 # $category - The category of model object - one of 'weapon', 'armour', 'garment',
5975 # 'char', 'minion', 'sentient', 'creature', 'portable', 'decoration'
5976 # or 'custom'
5977 # $name - A name for the new model object
5978 #
5979 # Optional arguments
5980 # $parentNum - If specified, the world model number of the parent object. Otherwise
5981 # set to 'undef'
5982 #
5983 # Return values
5984 # 'undef' on improper arguments or model object can't be added
5985 # Otherwise returns the new model object
5986  
5987 my ($self, $session, $updateFlag, $category, $name, $parentNum, $check) = @_;
5988  
5989 # Local variables
5990 my ($obj, $parentObj, $package);
5991  
5992 # Check for improper arguments
5993 if (
5994 ! defined $session || ! defined $updateFlag || ! defined $category || ! defined $name
5995 || defined $check
5996 ) {
5997 return $axmud::CLIENT->writeImproper($self->_objClass . '->addOther', @_);
5998 }
5999  
6000 # Check that the $category is one that can be handled by this function
6001 if (
6002 $category ne 'weapon' && $category ne 'armour' && $category ne 'garment'
6003 && $category ne 'minion' && $category ne 'sentient' && $category ne 'creature'
6004 && $category ne 'portable' && $category ne 'decoration' && $category ne 'custom'
6005 ) {
6006 return undef;
6007 }
6008  
6009 # If the parent is specified, check it exists
6010 if ($parentNum) {
6011  
6012 if (! $self->ivExists('modelHash', $parentNum)) {
6013  
6014 return undef;
6015  
6016 } else {
6017  
6018 $parentObj = $self->ivShow('modelHash', $parentNum);
6019 }
6020 }
6021  
6022 # Create the new model object
6023 $package = 'Games::Axmud::ModelObj::' . ucfirst($category);
6024 $obj = $package->new($session, $name, TRUE, $parentNum);
6025 if (! $obj) {
6026  
6027 return undef;
6028 }
6029  
6030 # Add the new object to the model
6031 if (! $self->addToModel($obj)) {
6032  
6033 # Object could not be added
6034 return undef;
6035 }
6036  
6037 # Update any GA::Win::Map objects using this world model (if allowed)
6038 if ($updateFlag && $parentObj && $parentObj->category eq 'room') {
6039  
6040 foreach my $mapWin ($self->collectMapWins()) {
6041  
6042 # Redraw the (parent) room
6043 $mapWin->markObjs('room', $parentObj);
6044 $mapWin->doDraw();
6045 }
6046 }
6047  
6048 # Operation complete
6049 return $obj;
6050 }
6051  
6052 sub importOther {
6053  
6054 # Called by GA::Cmd::AddMinionString->do or by any other function
6055 # Imports an existing non-model object which is not a region, room, character (or exit) to
6056 # into world model
6057 #
6058 # Expected arguments
6059 # $session - The calling function's GA::Session
6060 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
6061 # should be updated now, FALSE if not (in which case, they can be
6062 # updated later by the calling function, when it is ready)
6063 # $obj - The non-model object to import
6064 #
6065 # Optional arguments
6066 # $parentNum - If specified, the world model number of the parent object. Otherwise
6067 # set to 'undef'
6068 #
6069 # Return values
6070 # 'undef' on improper arguments or if the model object can't be imported
6071 # Otherwise returns the new model object
6072  
6073 my ($self, $session, $updateFlag, $obj, $parentNum, $check) = @_;
6074  
6075 # Local variables
6076 my $parentObj;
6077  
6078 # Check for improper arguments
6079 if (! defined $session || ! defined $updateFlag || ! defined $obj || defined $check) {
6080  
6081 return $axmud::CLIENT->writeImproper($self->_objClass . '->importOther', @_);
6082 }
6083  
6084 # Check that the $category is one that can be handled by this function
6085 if (
6086 $obj->category ne 'weapon' && $obj->category ne 'armour' && $obj->category ne 'garment'
6087 && $obj->category ne 'minion' && $obj->category ne 'sentient'
6088 && $obj->category ne 'creature' && $obj->category ne 'portable'
6089 && $obj->category ne 'decoration' && $obj->category ne 'custom'
6090 ) {
6091 return undef;
6092 }
6093  
6094 # If the parent is specified, check it exists
6095 if ($parentNum) {
6096  
6097 if (! $self->ivExists('modelHash', $parentNum)) {
6098  
6099 return undef;
6100  
6101 } else {
6102  
6103 $parentObj = $self->ivShow('modelHash', $parentNum);
6104 }
6105 }
6106  
6107 # Add the existing object to the model
6108 if (! $self->addToModel($obj)) {
6109  
6110 # Object could not be added
6111 return undef;
6112 }
6113  
6114 # Update any GA::Win::Map objects using this world model (if allowed)
6115 if ($updateFlag && $parentObj && $parentObj->category eq 'room') {
6116  
6117 foreach my $mapWin ($self->collectMapWins()) {
6118  
6119 # Redraw the (parent) room
6120 $mapWin->markObjs('room', $parentObj);
6121 $mapWin->doDraw();
6122 }
6123 }
6124  
6125 # Operation complete
6126 return $obj;
6127 }
6128  
6129 # Add to model/delete from model support funcs
6130  
6131 sub addToModel {
6132  
6133 # Called by $self->addRegion, ->addRoom, ->addRoomChildren, ->addChar, ->addOther,
6134 # ->importOther and ->convertCategory (should not be called from outside this
6135 # GA::Obj::WorldModel object - call ->addRoom, ->addOther, etc, instead)
6136 # Adds a new model object or an existing non-model object - such as the Locator task's
6137 # current room and its contents - to the world model
6138 #
6139 # Expected arguments
6140 # $obj - The object to add (any object which inherits from GA::Generic::ModelObj)
6141 #
6142 # Return values
6143 # 'undef' on improper arguments or if the object can't be added to the model
6144 # Otherwise, returns the model number of the newly-added object
6145  
6146 my ($self, $obj, $check) = @_;
6147  
6148 # Local variables
6149 my ($number, $parentObj);
6150  
6151 # Check for improper arguments
6152 if (! defined $obj || defined $check) {
6153  
6154 return $axmud::CLIENT->writeImproper($self->_objClass . '->addToModel', @_);
6155 }
6156  
6157 # Allocate the object a world model number
6158 $number = $self->allocateModelNumber();
6159 if (! defined $number) {
6160  
6161 return undef;
6162 }
6163  
6164 # Update the object's IVs
6165 $obj->ivPoke('number', $number);
6166 $obj->ivPoke('modelFlag', TRUE);
6167  
6168 # Add the object to the model
6169 $self->ivAdd('modelHash', $obj->number, $obj);
6170 # (e.g. add to $self->regionModelHash)
6171 $self->ivAdd($obj->category . 'ModelHash', $obj->number, $obj);
6172  
6173 # Update model IVs. NB $self->modelObjCount is incremented by the call to
6174 # $self->allocateModelNumber
6175 $self->ivIncrement('modelActualCount');
6176 $self->ivPoke('mostRecentNum', $obj->number);
6177  
6178 # If there's a parent, inform it that it's acquired a child
6179 if ($obj->parent) {
6180  
6181 $parentObj = $self->ivShow('modelHash', $obj->parent);
6182 if ($parentObj) {
6183  
6184 $parentObj->ivAdd('childHash', $obj->number, undef);
6185 }
6186 }
6187  
6188 return $number;
6189 }
6190  
6191 sub allocateModelNumber {
6192  
6193 # Called by $self->addToModel to allocate a number to a new model object (should not be
6194 # called from outside this GA::Obj::WorldModel object)
6195 #
6196 # Expected arguments
6197 # (none besides $self)
6198 #
6199 # Return values
6200 # 'undef' on improper arguments
6201 # Otherwise, returns the model number allocated to the new model object
6202  
6203 my ($self, $check) = @_;
6204  
6205 # Local variables
6206 my (
6207 $match,
6208 @newList,
6209 );
6210  
6211 # Check for improper arguments
6212 if (defined $check) {
6213  
6214 return $axmud::CLIENT->writeImproper($self->_objClass . '->allocateModelNumber', @_);
6215 }
6216  
6217 # Allocate a number
6218 if ($self->modelDeletedList) {
6219  
6220 # Re-use the smallest previously-allocated number. Checking every value in
6221 # ->modelDeletedList now is probably more efficient than sorting ->modelDeletedList
6222 # every time a new value is added to it (especially for very big world models)
6223 foreach my $num ($self->modelDeletedList) {
6224  
6225 if (! defined $match) {
6226  
6227 $match = $num;
6228  
6229 } elsif ($match > $num) {
6230  
6231 push (@newList, $match);
6232 $match = $num;
6233  
6234 } else {
6235  
6236 push (@newList, $num);
6237 }
6238 }
6239  
6240 # Update the IV
6241 $self->ivPoke('modelDeletedList', @newList);
6242  
6243 return $match;
6244  
6245 } else {
6246  
6247 # The count of model object numbers ever allocated increases by 1, but only when
6248 # we're not re-using a number of a deleted model object
6249 return $self->ivIncrement('modelObjCount');
6250 }
6251 }
6252  
6253 sub addToExitModel {
6254  
6255 # Called by $self->addExit (should not be called from outside this GA::Obj::WorldModel
6256 # object)
6257 # Adds a new exit object to the exit model
6258 #
6259 # Expected arguments
6260 # $obj - The GA::Obj::Exit to add
6261 #
6262 # Return values
6263 # 'undef' on improper arguments or if the exit object can't be added to the exit model
6264 # Otherwise, returns the exit model number of the newly-added object
6265  
6266 my ($self, $exitObj, $check) = @_;
6267  
6268 # Local variables
6269 my ($number, $parentObj);
6270  
6271 # Check for improper arguments
6272 if (! defined $exitObj || defined $check) {
6273  
6274 return $axmud::CLIENT->writeImproper($self->_objClass . '->addToExitModel', @_);
6275 }
6276  
6277 # Allocate the object a world model number
6278 $number = $self->allocateExitModelNumber();
6279 if (! defined $number) {
6280  
6281 return undef;
6282 }
6283  
6284 # Update the object's IVs
6285 $exitObj->ivPoke('number', $number);
6286 $exitObj->ivPoke('modelFlag', TRUE);
6287  
6288 # Add the object to the exit model
6289 $self->ivAdd('exitModelHash', $exitObj->number, $exitObj);
6290  
6291 # Update exit model IVs. NB $self->exitObjCount is incremented by the call to
6292 # $self->allocateExitModelNumber
6293 $self->ivIncrement('exitActualCount');
6294 $self->ivPoke('mostRecentExitNum', $exitObj->number);
6295  
6296 return $number;
6297 }
6298  
6299 sub allocateExitModelNumber {
6300  
6301 # Called by $self->addToExitModel (should not be called from outside this
6302 # GA::Obj::WorldModel object)
6303 # Allocates a number to a new exit model object
6304 #
6305 # Expected arguments
6306 # (none besides $self)
6307 #
6308 # Return values
6309 # 'undef' on improper arguments
6310 # Otherwise, returns the exit model number allocated to the new exit model object
6311  
6312 my ($self, $check) = @_;
6313  
6314 # Local variables
6315 my (
6316 $match,
6317 @newList,
6318 );
6319  
6320 # Check for improper arguments
6321 if (defined $check) {
6322  
6323 return $axmud::CLIENT->writeImproper(
6324 $self->_objClass . '->allocateExitModelNumber',
6325 @_,
6326 );
6327 }
6328  
6329 # Allocate a number
6330 if ($self->exitDeletedList) {
6331  
6332 # Re-use the smallest previously-allocated number. Checking every value in
6333 # ->exitDeletedList now is probably more efficient than sorting ->exitDeletedList
6334 # every time a new value is added to it (especially for very big world models)
6335 foreach my $num ($self->exitDeletedList) {
6336  
6337 if (! defined $match) {
6338  
6339 $match = $num;
6340  
6341 } elsif ($match > $num) {
6342  
6343 push (@newList, $match);
6344 $match = $num;
6345  
6346 } else {
6347  
6348 push (@newList, $num);
6349 }
6350 }
6351  
6352 # Update the IV
6353 $self->ivPoke('exitDeletedList', @newList);
6354  
6355 return $match;
6356  
6357 } else {
6358  
6359 # The count of exit model object numbers ever allocated increases by 1, but only when
6360 # we're not re-using a number of a deleted exit model object
6361 return $self->ivIncrement('exitObjCount');
6362 }
6363 }
6364  
6365 sub collectMapWins {
6366  
6367 # Checks every session, and compiles a list of GA::Win::Map objects which are using this
6368 # world model
6369 #
6370 # Expected arguments
6371 # (none besides $self)
6372 #
6373 # Return values
6374 # An empty list on improper arguments
6375 # Otherwise, returns the list of matching GA::Win::Map objects (may be an empty list)
6376  
6377 my ($self, $check) = @_;
6378  
6379 # Local variables
6380 my (@emptyList, @returnArray);
6381  
6382 # Check for improper arguments
6383 if (defined $check) {
6384  
6385 $axmud::CLIENT->writeImproper($self->_objClass . '->collectMapWins', @_);
6386 return @emptyList;
6387 }
6388  
6389 foreach my $session ($axmud::CLIENT->listSessions()) {
6390  
6391 if (
6392 $session->currentWorld->name eq $self->_parentWorld
6393 && $session->mapWin
6394 ) {
6395 push (@returnArray, $session->mapWin);
6396 }
6397 }
6398  
6399 return @returnArray;
6400 }
6401  
6402 # Delete model objects
6403  
6404 sub deleteObj {
6405  
6406 # Deletes an object (and its child objects, including exits if the object is a room) from
6407 # the world model
6408 # For regions, called by $self->deleteRegions. For rooms, called by $self->deleteRooms. For
6409 # other kinds of world model object, can be called by anything (including by this function
6410 # recursively)
6411 #
6412 # Expected arguments
6413 # $session - The calling function's GA::Session
6414 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
6415 # should be updated now, FALSE if not (in which case, they can be
6416 # updated later by the calling function, when it is ready)
6417 # $obj - The model object to delete
6418 #
6419 # Optional arguments
6420 # $recursionFlag - Set to TRUE if this function has been called by itself (recursively)
6421 # (set to 'undef' otherwise)
6422 #
6423 # Return values
6424 # 'undef' on improper arguments
6425 # 1 otherwise
6426  
6427 my ($self, $session, $updateFlag, $obj, $recursionFlag, $check) = @_;
6428  
6429 # Local variables
6430 my (
6431 $parentObj, $count,
6432 @childList, @exitNumList,
6433 );
6434  
6435 # Check for improper arguments
6436 if (! defined $session || ! defined $obj || defined $check) {
6437  
6438 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteObj', @_);
6439 }
6440  
6441 # For room objects, delete its exits
6442 if ($obj->category eq 'room') {
6443  
6444 # If there are any uncertain exits which lead to this soon-to-be-deleted room, convert
6445 # them to incomplete exits (and redraw them, if allowed)
6446 foreach my $uncertainExitNum ($obj->ivKeys('uncertainExitHash')) {
6447  
6448 my $uncertainExitObj = $self->ivShow('exitModelHash', $uncertainExitNum);
6449  
6450 if (
6451 $uncertainExitObj
6452 && $uncertainExitObj->destRoom
6453 && $uncertainExitObj->destRoom == $obj->number
6454 ) {
6455 # (The call to $self->abandonUncertainExit updates $self->updateBoundaryHash and
6456 # ->updatePathHash)
6457 $self->abandonUncertainExit(
6458 $updateFlag,
6459 $uncertainExitObj,
6460 );
6461 }
6462 }
6463  
6464 # Do the same for one-way exits which lead to this soon-to-be-deleted room
6465 foreach my $oneWayExitNum ($obj->ivKeys('oneWayExitHash')) {
6466  
6467 my $oneWayExitObj = $self->ivShow('exitModelHash', $oneWayExitNum);
6468  
6469 if (
6470 $oneWayExitObj
6471 && $oneWayExitObj->destRoom
6472 && $oneWayExitObj->destRoom == $obj->number
6473 ) {
6474 # (The call to $self->abandonOneWayExit updates $self->updateBoundaryHash and
6475 # ->updatePathHash)
6476 $self->abandonOneWayExit(
6477 $updateFlag,
6478 $oneWayExitObj,
6479 );
6480 }
6481 }
6482  
6483 # Do the same for involuntary/repulse exit patterns whose corresponding destination room
6484 # is this room
6485 foreach my $value (
6486 $obj->ivValues('involuntaryExitPatternHash'),
6487 $obj->ivValues('repulseExitPatternHash'),
6488 ) {
6489 # The values in both hashes can be 'undef' if the destination room is unknown
6490 if (defined $value) {
6491  
6492 # Otherwise, $value is probably a room model number or a direction
6493 my $destRoomObj = $self->ivShow('modelHash', $value);
6494 if ($destRoomObj) {
6495  
6496 $self->updateInvoluntaryExit(
6497 $destRoomObj,
6498 $obj,
6499 );
6500 }
6501 }
6502 }
6503  
6504 # Do the same for random exits which lead to this soon-to-be-deleted room
6505 foreach my $randomExitNum ($obj->ivKeys('randomExitHash')) {
6506  
6507 my $randomExitObj = $self->ivShow('exitModelHash', $randomExitNum);
6508  
6509 if (
6510 $randomExitObj
6511 && $randomExitObj->destRoom
6512 && $randomExitObj->destRoom == $obj->number
6513 ) {
6514 # (No need to update $self->updateBoundaryHash and ->updatePathHash, since a
6515 # random exit is allowed to have an empty ->randomDestList)
6516 $self->updateRandomExit(
6517 $randomExitObj,
6518 $obj,
6519 );
6520 }
6521 }
6522  
6523 # These hashes would be consulted in the call to ->deleteExits, so we have to empty
6524 # them now
6525 $obj->ivEmpty('uncertainExitHash');
6526 $obj->ivEmpty('oneWayExitHash');
6527 $obj->ivEmpty('randomExitHash');
6528  
6529 # Delete the room's exit objects
6530 @exitNumList = $obj->ivValues('exitNumHash');
6531 foreach my $exitNum (@exitNumList) {
6532  
6533 $self->deleteExits(
6534 $session,
6535 $updateFlag,
6536 $self->ivShow('exitModelHash', $exitNum),
6537 );
6538 }
6539  
6540 # If the character previously moved through a 'temp_region' random exit into a temporary
6541 # region, and either the original or destination room is being deleted, we can simply
6542 # tell the automapper object to forget about returning to the original room
6543 foreach my $thisSession ($axmud::CLIENT->ivValues('sessionHash')) {
6544  
6545 if (
6546 $thisSession->worldModelObj eq $self
6547 && defined $thisSession->mapObj->tempRandomOriginRoom
6548 && (
6549 $thisSession->mapObj->tempRandomOriginRoom eq $obj
6550 || $thisSession->mapObj->tempRandomDestRoom eq $obj
6551 )
6552 ) {
6553 $thisSession->mapObj->reset_tempRandom();
6554 }
6555 }
6556  
6557 # If the room has a room tag, update the hash of room tags
6558 if ($obj->roomTag) {
6559  
6560 $self->ivDelete('roomTagHash', $obj->roomTag);
6561 }
6562  
6563 # Player character objects have additional IVs that must be updated
6564 } elsif ($obj->category eq 'char') {
6565  
6566 if ($self->ivExists('knownCharHash', $obj->name)) {
6567  
6568 $self->ivDelete('knownCharHash', $obj->name);
6569 }
6570 }
6571  
6572 # If this object is at the top of the deletion tree, and it has a parent, we need to inform
6573 # the parent that it has lost one of its children
6574 if (! $recursionFlag && $obj->parent) {
6575  
6576 $parentObj = $self->ivShow('modelHash', $obj->parent);
6577 if ($parentObj && $parentObj->ivExists('childHash', $obj->number)) {
6578  
6579 $parentObj->ivDelete('childHash', $obj->number);
6580 }
6581 }
6582  
6583 # Delete this object's children, if any
6584 $count = 0;
6585 if ($obj->childHash) {
6586  
6587 @childList = $obj->ivKeys('childHash');
6588 foreach my $childNum (@childList) {
6589  
6590 my $childObj = $self->ivShow('modelHash', $childNum);
6591  
6592 # Delete the child object (recursively)
6593 if ($self->deleteObj($session, $updateFlag, $childObj, TRUE)) {
6594  
6595 $count++;
6596 }
6597 }
6598 }
6599  
6600 # Delete the object from the model
6601 $self->ivDelete('modelHash', $obj->number);
6602 $self->ivDelete($obj->category . 'ModelHash', $obj->number);
6603 # Mark the number of this object as having been deleted, so it can be reused
6604 $self->ivPush('modelBufferList', $obj->number);
6605 # Adjust the model object count
6606 $self->ivDecrement('modelActualCount');
6607  
6608 # Return the total number of objects deleted (add one for this object)
6609 return ($count + 1);
6610 }
6611  
6612 sub deleteRegions {
6613  
6614 # Called by GA::Win::Map->deleteRegionCallback and $self->deleteTempRegions
6615 # Deletes one of more GA::ModelObj::Region objects, together with any child objects
6616 # (mostly the rooms it contains).
6617 # Also deletes the corresponding regionmap (GA::Obj::Regionmap) and parchment objects
6618 # (GA::Obj::Parchment)
6619 #
6620 # Expected arguments
6621 # $session - The calling function's GA::Session
6622 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
6623 # should be updated now, FALSE if not (in which case, they can be
6624 # updated later by the calling function, when it is ready)
6625 #
6626 # Optional arguments
6627 # @regionList - A list of GA::ModelObj::Region objects to delete. If the list is
6628 # empty, no regions are deleted
6629 #
6630 # Return values
6631 # 'undef' on improper arguments
6632 # 1 otherwise
6633  
6634 my ($self, $session, $updateFlag, @regionList) = @_;
6635  
6636 # Local variables
6637 my @graffitiList;
6638  
6639 # Check for improper arguments
6640 if (! defined $session || ! defined $updateFlag) {
6641  
6642 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRegions', @_);
6643 }
6644  
6645 # If @regionList is empty, do nothing
6646 if (! @regionList) {
6647  
6648 return undef;
6649 }
6650  
6651 # Before any deletion operation, all selected canvas objects must be un-selected
6652 foreach my $mapWin ($self->collectMapWins()) {
6653  
6654 $mapWin->setSelectedObj();
6655 }
6656  
6657 # This functions causes calls to self->deleteRooms and ->deleteExits. Everything in the
6658 # automapper window is already unselected, so those functions don't need to make further
6659 # calls to GA::Win::Map->setSelectedObj
6660 $self->ivPoke('blockUnselectFlag', TRUE);
6661  
6662 foreach my $regionObj (@regionList) {
6663  
6664 my @childList;
6665  
6666 # Check the region's children; any of them which are themselves regions should not be
6667 # deleted
6668 @childList = $regionObj->ivKeys('childHash');
6669 foreach my $childNum (@childList) {
6670  
6671 my $childObj = $self->ivShow('modelHash', $childNum);
6672  
6673 # Prevent deletion of the child region by resetting its parent
6674 if ($childObj->category eq 'region') {
6675  
6676 $self->setParent(
6677 FALSE, # Don't update Automapper windows yet
6678 $childNum,
6679 );
6680  
6681 # Make sure the automapper's current room is reset, if it's to be deleted
6682 } elsif (
6683 $childObj->category eq 'room'
6684 && $session->mapObj->currentRoom
6685 && $session->mapObj->currentRoom eq $childObj
6686 ) {
6687 $session->mapObj->setCurrentRoom();
6688 push (@graffitiList, $childObj);
6689 }
6690 }
6691  
6692 # Delete the region object and its child objects (if any)
6693 $self->deleteObj(
6694 $session,
6695 FALSE, # Don't update Automapper windows yet
6696 $regionObj,
6697 );
6698  
6699 # Delete the corresponding regionmap
6700 $self->ivDelete('regionmapHash', $regionObj->name);
6701  
6702 # If the character was moved to a temporary region rather than being marked lost (in
6703 # auto-rescue mode), and either the temporary or the previous region is being
6704 # deleted, we can simply forget about merging/moving rooms from one region to another
6705 foreach my $thisSession ($axmud::CLIENT->ivValues('sessionHash')) {
6706  
6707 if (
6708 $thisSession->worldModelObj eq $self
6709 && defined $thisSession->mapObj->rescueLostRegionObj
6710 && (
6711 $thisSession->mapObj->rescueLostRegionObj eq $regionObj
6712 || $thisSession->mapObj->rescueTempRegionObj eq $regionObj
6713 )
6714 ) {
6715 $thisSession->mapObj->reset_rescueRegion();
6716 }
6717 }
6718 }
6719  
6720 # Regardless of whether $updateFlag is set, or not, the automapper windows' list of
6721 # recent regions must be updated, and the deleted rooms should no longer be graffitied
6722 foreach my $mapWin ($self->collectMapWins()) {
6723  
6724 $mapWin->reset_recentRegion(@regionList);
6725 $mapWin->del_graffiti(@graffitiList);
6726 }
6727  
6728 # Update any GA::Win::Map objects using this world model (if allowed)
6729 if ($updateFlag) {
6730  
6731 foreach my $mapWin ($self->collectMapWins()) {
6732  
6733 foreach my $regionObj (@regionList) {
6734  
6735 if (
6736 $mapWin->currentRegionmap
6737 && $mapWin->currentRegionmap->number eq $regionObj->number
6738 ) {
6739 # Show the empty map
6740 $mapWin->setCurrentRegion();
6741 }
6742  
6743 $mapWin->del_parchment($regionObj->name);
6744 }
6745  
6746 # Update the window's treeview (containing the list of regions)
6747 $mapWin->resetTreeView();
6748 }
6749 }
6750  
6751 # (Allow future calls to $self->deleteRooms and ->deleteExits to check that everything in
6752 # the automapper window is unselected)
6753 $self->ivPoke('blockUnselectFlag', FALSE);
6754  
6755 return 1;
6756 }
6757  
6758 sub deleteTempRegions {
6759  
6760 # Called by GA::Win::Map->deleteTempRegionsCallback, GA::Cmd::DeleteTemporaryRegion->do
6761 # or by any other function
6762 # Deletes every temporary region in the world model (every GA::ModelObj::Region whose
6763 # ->tempRegionFlag is set). Also deletes the corresponding GA::Obj::Regionmaps
6764 #
6765 # Expected arguments
6766 # $session - The calling function's GA::Session
6767 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
6768 # should be updated now, FALSE if not (in which case, they can be
6769 # updated later by the calling function, when it is ready)
6770 #
6771 # Return values
6772 # 'undef' on improper arguments or if there are no temporary regions to delete
6773 # 1 otherwise
6774  
6775 my ($self, $session, $updateFlag, $check) = @_;
6776  
6777 # Local variables
6778 my @regionList;
6779  
6780 # Check for improper arguments
6781 if (! defined $session || ! defined $updateFlag || defined $check) {
6782  
6783 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteTempRegions', @_);
6784 }
6785  
6786 # Get a list of temporary regions
6787 foreach my $regionObj ($self->ivValues('regionModelHash')) {
6788  
6789 if ($regionObj->tempRegionFlag) {
6790  
6791 push (@regionList, $regionObj);
6792 }
6793 }
6794  
6795 if (! @regionList) {
6796  
6797 # No temporary regions to delete
6798 return undef;
6799 }
6800  
6801 # Delete each temporary region in turn
6802 $self->deleteRegions(
6803 $session,
6804 FALSE, # Don't update Automapper windows yet
6805 @regionList,
6806 );
6807  
6808 # Regardless of whether $updateFlag is set, or not, the automapper windows' list of
6809 # recent regions must be updated
6810 foreach my $mapWin ($self->collectMapWins()) {
6811  
6812 $mapWin->reset_recentRegion(@regionList);
6813 }
6814  
6815 # Update any GA::Win::Map objects using this world model (if allowed)
6816 if ($updateFlag) {
6817  
6818 foreach my $mapWin ($self->collectMapWins()) {
6819  
6820 foreach my $regionObj (@regionList) {
6821  
6822 if (
6823 $mapWin->currentRegionmap
6824 && $mapWin->currentRegionmap->number eq $regionObj->number
6825 ) {
6826 # Show no current region, which deletes all canvas objects
6827 $mapWin->setCurrentRegion();
6828 }
6829  
6830 $mapWin->del_parchment($regionObj->name);
6831 }
6832  
6833 # After any deletion operation, all selected canvas objects must be un-selected
6834 $mapWin->setSelectedObj();
6835  
6836 # Update the window's treeview (containing the list of regions)
6837 $mapWin->resetTreeView();
6838 }
6839 }
6840  
6841 return 1;
6842 }
6843  
6844 sub deleteRooms {
6845  
6846 # Called by GA::Win::Map->enableRoomsColumn, GA::Cmd::DeleteRoom->do and
6847 # $self->emptyRegion
6848 # Deletes one of more GA::ModelObj::Room objects, together with any child objects and exit
6849 # objects belonging to the room
6850 #
6851 # Expected arguments
6852 # $session - The calling function's GA::Session
6853 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
6854 # should be updated now, FALSE if not (in which case, they can be
6855 # updated later by the calling function, when it is ready)
6856 #
6857 # Optional arguments
6858 # @roomList - A list of GA::ModelObj::Room objects to delete. If the list is empty,
6859 # no rooms are deleted
6860 #
6861 # Return values
6862 # 'undef' on improper arguments
6863 # 1 otherwise
6864  
6865 my ($self, $session, $updateFlag, @roomList) = @_;
6866  
6867 # Local variables
6868 my (
6869 @mapWinList,
6870 %regionHash,
6871 );
6872  
6873 # Check for improper arguments
6874 if (! defined $session || ! defined $updateFlag) {
6875  
6876 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRooms', @_);
6877 }
6878  
6879 # If @roomList is empty, do nothing
6880 if (! @roomList) {
6881  
6882 return undef;
6883 }
6884  
6885 # Before any deletion operation, all selected canvas objects must be un-selected (but don't
6886 # need to to do that if there has been an earlier call to $self->deleteRegions)
6887 if (! $self->blockUnselectFlag) {
6888  
6889 foreach my $mapWin ($self->collectMapWins()) {
6890  
6891 $mapWin->setSelectedObj();
6892 }
6893 }
6894  
6895 foreach my $roomObj (@roomList) {
6896  
6897 my $regionmapObj;
6898  
6899 # If this room is the automapper's current room, any Automapper windows which are not
6900 # in 'wait' mode should switch to 'wait' mode at the end of this function (do it even
6901 # if $updateFlag is not set)
6902 if ($session->mapObj->currentRoom && $session->mapObj->currentRoom eq $roomObj) {
6903  
6904 $session->mapObj->setCurrentRoom();
6905  
6906 foreach my $mapWin ($self->collectMapWins()) {
6907  
6908 if ($mapWin->mode ne 'wait') {
6909  
6910 push (@mapWinList, $mapWin);
6911 }
6912 }
6913 }
6914  
6915 # Update the regionmap's hashes of rooms, room tags and room guilds
6916 $regionmapObj = $self->findRegionmap($roomObj->parent);
6917 $regionmapObj->removeRoom($roomObj);
6918 # (We can save a bit of time in the code below by storing each room's regionmap
6919 # temporarily)
6920 $regionHash{$roomObj} = $regionmapObj;
6921  
6922 # Delete the room object and its child objects and exit objects (if any)
6923 $self->deleteObj(
6924 $session,
6925 # TRUE, # Update Automapper windows now - is applied to the room's exits
6926 $updateFlag,
6927 $roomObj,
6928 );
6929  
6930 # The regionmap's highest/lowest occupied levels need to be recalculated
6931 $self->ivAdd('checkLevelsHash', $regionmapObj->name, undef);
6932  
6933 # The regionmap's hashes of living/non-living objects must be updated
6934 $regionmapObj->removeLivingCount($roomObj->number),
6935 $regionmapObj->removeNonLivingCount($roomObj->number),
6936 }
6937  
6938 # Update any GA::Win::Map objects using this world model (if allowed)
6939 if ($updateFlag) {
6940  
6941 foreach my $mapWin ($self->collectMapWins()) {
6942  
6943 # Any deleted rooms should no longer be graffitied
6944 $mapWin->del_graffiti(@roomList);
6945  
6946 foreach my $roomObj (@roomList) {
6947  
6948 my ($regionmapObj, $parchmentObj);
6949  
6950 $regionmapObj = $regionHash{$roomObj};
6951 $parchmentObj = $mapWin->ivShow('parchmentHash', $regionmapObj->name);
6952  
6953 # Delete the room's canvas objects (if they exist; its exits will have been
6954 # deleted in the call to ->deleteObj just above)
6955 $mapWin->deleteCanvasObj('room', $roomObj, $regionmapObj, $parchmentObj, TRUE);
6956 if ($roomObj->roomTag) {
6957  
6958 $mapWin->deleteCanvasObj(
6959 'room_tag',
6960 $roomObj,
6961 $regionmapObj,
6962 $parchmentObj,
6963 TRUE,
6964 );
6965 }
6966  
6967 if ($roomObj->roomGuild) {
6968  
6969 $mapWin->deleteCanvasObj(
6970 'room_guild',
6971 $roomObj,
6972 $regionmapObj,
6973 $parchmentObj,
6974 TRUE,
6975 );
6976 }
6977  
6978 # Some other function may have placed the room on the automapper's list of
6979 # objects to draw; if so, remove it
6980 if ($parchmentObj) {
6981  
6982 $parchmentObj->ivDelete('markedRoomHash', $roomObj->number);
6983 $parchmentObj->ivDelete('markedRoomTagHash', $roomObj->number);
6984 $parchmentObj->ivDelete('markedRoomGuildHash', $roomObj->number);
6985  
6986 $parchmentObj->ivDelete('queueRoomEchoHash', $roomObj->number);
6987 $parchmentObj->ivDelete('queueRoomBoxHash', $roomObj->number);
6988 $parchmentObj->ivDelete('queueRoomTextHash', $roomObj->number);
6989 $parchmentObj->ivDelete('queueRoomExitHash', $roomObj->number);
6990 $parchmentObj->ivDelete('queueRoomInfoHash', $roomObj->number);
6991 }
6992 }
6993 }
6994 }
6995  
6996 foreach my $mapWin (@mapWinList) {
6997  
6998 # This Automapper window's current room was deleted, so we need to switch to 'wait' mode
6999 $mapWin->setMode('wait');
7000 }
7001  
7002 # Check every Locator task; if its current room is one of those just be deleted, it needs to
7003 # be informed
7004 OUTER: foreach my $mapWin ($self->collectMapWins()) {
7005  
7006 my $taskObj = $mapWin->session->locatorTask;
7007  
7008 if ($taskObj && $taskObj->modelNumber) {
7009  
7010 INNER: foreach my $roomObj (@roomList) {
7011  
7012 if ($taskObj->modelNumber eq $roomObj->number) {
7013  
7014 $taskObj->resetModelRoom();
7015 next OUTER;
7016 }
7017 }
7018 }
7019 }
7020  
7021 return 1;
7022 }
7023  
7024 sub deleteExits {
7025  
7026 # Called by GA::Win::Map->deleteExitCallback, GA::Cmd::DeleteExit->do and $self->deleteObj
7027 # Deletes one or more GA::Obj::Exit objects
7028 #
7029 # Expected arguments
7030 # $session - The calling function's GA::Session
7031 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
7032 # should be updated now, FALSE if not (in which case, they can be
7033 # updated later by the calling function, when it is ready)
7034 #
7035 # Optional arguments
7036 # @exitList - A list of GA::Obj::Exit objects to delete. If the list is empty, no
7037 # exits are deleted
7038 #
7039 # Return values
7040 # 'undef' on improper arguments or if @exitList is empty
7041 # 1 otherwise
7042  
7043 my ($self, $session, $updateFlag, @exitList) = @_;
7044  
7045 # Local variables
7046 my (
7047 @redrawList, @mapWinList,
7048 %roomHash, %regionHash,
7049 );
7050  
7051 # Check for improper arguments
7052 if (! defined $session || ! defined $updateFlag) {
7053  
7054 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteExits', @_);
7055 }
7056  
7057 # If @exitList is empty, do nothing
7058 if (! @exitList) {
7059  
7060 return undef;
7061 }
7062  
7063 # Before any deletion operation, all selected canvas objects must be un-selected (but don't
7064 # need to to do that if there has been an earlier call to $self->deleteRegions)
7065 if (! $self->blockUnselectFlag) {
7066  
7067 foreach my $mapWin ($self->collectMapWins()) {
7068  
7069 $mapWin->setSelectedObj();
7070 }
7071 }
7072  
7073 foreach my $exitObj (@exitList) {
7074  
7075 my (
7076 $roomObj, $regionObj, $twinExitObj, $twinRoomObj, $destRoomObj, $regionmapObj,
7077 $twinRegionObj, $twinRegionmapObj,
7078 @dirList, @sortedDirList,
7079 );
7080  
7081 # Get the exit's parent room and region
7082 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
7083 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
7084  
7085 # Any region paths using the soon-to-be-deleted exit will have to be updated
7086 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
7087 if ($exitObj->regionFlag) {
7088  
7089 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
7090 # $self->deleteBoundaryHash contains all the exits in ->updateBoundaryHash that
7091 # have been deleted
7092 $self->ivAdd('deleteBoundaryHash', $exitObj->number, $regionObj->name);
7093 }
7094  
7095 if ($updateFlag) {
7096  
7097 # We need to keep track of the parent rooms, which must also be redrawn (in case
7098 # the exit is a shadow exit, in which case the newly-unallocated exit won't be
7099 # drawn unless we redraw the room)
7100 $roomHash{$roomObj->number} = $roomObj;
7101  
7102 # When $exitObj is an incomplete exit and the possible twin of an incoming uncertain
7103 # exit, we need to redraw any rooms which have uncertain exits leading to
7104 # $exitObj's parent room - otherwise, those uncertain exits won't get redrawn as
7105 # one-way exits. The same applies to incoming one-way exits
7106 if (! $exitObj->destRoom && $exitObj->randomType eq 'none') {
7107  
7108 # This is an incomplete exit. Redraw the parent rooms of incoming uncertain
7109 # exits...
7110 foreach my $uncertainNum ($roomObj->ivKeys('uncertainExitHash')) {
7111  
7112 my $uncertainExitObj = $self->ivShow('exitModelHash', $uncertainNum);
7113  
7114 $roomHash{$uncertainExitObj->parent}
7115 = $self->ivShow('modelHash', $uncertainExitObj->parent);
7116 }
7117  
7118 # ...and incoming one-way exits
7119 foreach my $oneWayNum ($roomObj->ivKeys('oneWayExitHash')) {
7120  
7121 my $oneWayExitObj = $self->ivShow('exitModelHash', $oneWayNum);
7122  
7123 $roomHash{$oneWayExitObj->parent}
7124 = $self->ivShow('modelHash', $oneWayExitObj->parent);
7125 }
7126 }
7127 }
7128  
7129 # If this exit has a twin exit, inform the twin exit that it is being abandoned
7130 if ($exitObj->twinExit) {
7131  
7132 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
7133 $twinRoomObj = $self->ivShow('modelHash', $twinExitObj->parent);
7134 if ($updateFlag) {
7135  
7136 $roomHash{$twinExitObj->parent} = $twinRoomObj;
7137 }
7138  
7139 # (The call to ->abandonTwinExit sets $self->updateBoundaryHash, ->updatePathHash)
7140 $self->abandonTwinExit(
7141 FALSE, # Don't update Automapper window yet
7142 $exitObj,
7143 $twinExitObj,
7144 );
7145  
7146 } elsif ($exitObj->destRoom) {
7147  
7148 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
7149  
7150 # If this exit is an uncertain exit (has a destination room, but no twin exit and
7151 # it's not a marked one way exit) then the destination room's hash of incoming
7152 # uncertain exits needs to be updated
7153 if (! $exitObj->oneWayFlag) {
7154  
7155 if ($destRoomObj->ivExists('uncertainExitHash', $exitObj->number)) {
7156  
7157 # Remove this exit from that hash
7158 $destRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
7159 }
7160  
7161 # If this exit is a one-way exit (has a destination room and it's a marked one way
7162 # exit) then the destination room's hash of incoming one-way exits needs to be
7163 # updated
7164 } else {
7165  
7166 # If the hash contains this exit object as an incoming one-way exit...
7167 if ($destRoomObj->ivExists('oneWayExitHash', $exitObj->number)) {
7168  
7169 # ...remove this ExitObj from that hash
7170 $destRoomObj->ivDelete('oneWayExitHash', $exitObj->number);
7171 }
7172 }
7173 }
7174  
7175 # Mark the number of this object as having been deleted, so it can be reused
7176 $self->ivPush('exitBufferList', $exitObj->number);
7177 # Remove the exit from the model
7178 $self->ivDelete('exitModelHash', $exitObj->number);
7179 $self->ivDecrement('exitActualCount');
7180  
7181 if ($roomObj) {
7182  
7183 # If this exit is a shadow exit for one of the other exits in the room, the other
7184 # exit must be reset
7185 foreach my $otherExitNum ($roomObj->ivValues('exitNumHash')) {
7186  
7187 my $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
7188  
7189 if (
7190 $otherExitObj # (May have been deleted from the model by this function)
7191 && $otherExitObj->shadowExit
7192 && $otherExitObj->shadowExit eq $exitObj->number
7193 ) {
7194 # The other exit retains its map direction, ->mapDir, which matches the
7195 # ->mapDir of $exitObj
7196 $otherExitObj->ivUndef('shadowExit');
7197 # The other exit is once again marked as 'unallocated'. The map direction is
7198 # definitely available, so ->drawMode is set to 'temp_alloc', not
7199 # 'temp_unalloc'
7200 $otherExitObj->ivPoke('drawMode', 'temp_alloc');
7201  
7202 # Any region paths using the other exit will have to be updated
7203 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
7204 if ($otherExitObj->regionFlag) {
7205  
7206 $self->ivAdd(
7207 'updateBoundaryHash',
7208 $otherExitObj->number,
7209 $regionObj->name,
7210 );
7211 }
7212 }
7213 }
7214  
7215 # Check this room's hash of incoming uncertain objects
7216 foreach my $uncertainNum ($roomObj->ivKeys('uncertainExitHash')) {
7217  
7218 my ($twinNumber, $uncertainExitObj);
7219  
7220 $twinNumber = $roomObj->ivShow('uncertainExitHash', $uncertainNum);
7221 if ($twinNumber && $twinNumber == $exitObj->number) {
7222  
7223 # Convert the uncertain exit to a one-way exit
7224 $uncertainExitObj = $self->ivShow('exitModelHash', $uncertainNum);
7225 $self->convertUncertainExit(
7226 FALSE, # Don't update Automapper windows yet
7227 $uncertainExitObj,
7228 $self->ivShow('modelHash', $uncertainExitObj->parent),
7229 );
7230 }
7231 }
7232  
7233 # Remove the exit from the room's list of exit names (each corresponding to a
7234 # direction)
7235 foreach my $dir ($roomObj->sortedExitList) {
7236  
7237 if ($dir ne $exitObj->dir) {
7238  
7239 push (@dirList, $dir);
7240 }
7241 }
7242  
7243 $roomObj->ivPoke('sortedExitList', @dirList);
7244  
7245 # Remove the exit from the room's hash of numbered exits
7246 $roomObj->ivDelete('exitNumHash', $exitObj->dir);
7247  
7248 # Update the parent room's regionmap
7249 $regionmapObj = $self->ivShow('regionmapHash', $regionObj->name);
7250 $regionmapObj->removeExit($exitObj);
7251 # (We can save a bit of time in the code below by storing each exit's regionmap
7252 # temporarily)
7253 $regionHash{$exitObj} = $regionmapObj;
7254  
7255 # Also update the twin exit's regionmap (if there is one)
7256 if ($twinRoomObj && $twinExitObj) {
7257  
7258 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
7259 $twinRegionmapObj = $self->ivShow('regionmapHash', $twinRegionObj->name);
7260 $twinRegionmapObj->resetExit($twinExitObj);
7261  
7262 $regionHash{$twinExitObj} = $twinRegionmapObj;
7263 }
7264 }
7265 }
7266  
7267 # Update any GA::Win::Map objects using this world model (if allowed)
7268 if ($updateFlag) {
7269  
7270 foreach my $thisRoomObj (values %roomHash) {
7271  
7272 push (@redrawList, 'room', $thisRoomObj);
7273 }
7274  
7275 foreach my $mapWin ($self->collectMapWins()) {
7276  
7277 foreach my $exitObj (@exitList) {
7278  
7279 my ($regionmapObj, $parchmentObj);
7280  
7281 $regionmapObj = $regionHash{$exitObj};
7282 $parchmentObj = $mapWin->ivShow('parchmentHash', $regionmapObj->name);
7283  
7284 # Delete the exit's canvas object (if it exists)
7285 $mapWin->deleteCanvasObj('exit', $exitObj, $regionmapObj, $parchmentObj, TRUE);
7286 # Delete the exit tag's canvas object (which might exist, even if the exit's
7287 # canvas object does not)
7288 $mapWin->deleteCanvasObj(
7289 'exit_tag',
7290 $exitObj,
7291 $regionmapObj,
7292 $parchmentObj,
7293 TRUE,
7294 );
7295  
7296 # Some other function may have placed the exit and the exit tag (if any) on the
7297 # automapper's list of objects to draw; if so, remove them
7298 if ($parchmentObj) {
7299  
7300 $parchmentObj->ivDelete('markedExitHash', $exitObj->number);
7301 $parchmentObj->ivDelete('markedExitTagHash', $exitObj->number);
7302 }
7303 }
7304  
7305 # Redraw all those rooms
7306 $mapWin->markObjs(@redrawList);
7307 $mapWin->doDraw();
7308 }
7309 }
7310  
7311 return 1;
7312 }
7313  
7314 sub emergencyDeleteExit {
7315  
7316 # Must only be called by GA::Cmd::TestModel->do for orphan exits
7317 # Deletes the exit (which should be some kind of orphan exit) from the exit model, but does
7318 # not try to update anything else
7319 #
7320 # Expected arguments
7321 # $exitObj - The exit to forcably delete
7322 #
7323 # Return values
7324 # 'undef' on improper arguments or if $exitObj isn't an orphan exit
7325 # 1 otherwise
7326  
7327 my ($self, $exitObj, $check) = @_;
7328  
7329 # Local variables
7330 my ($roomObj, $twinExitObj);
7331  
7332 # Check for improper arguments
7333 if (! defined $exitObj || defined $check) {
7334  
7335 return $axmud::CLIENT->writeImproper($self->_objClass . '->emergencyDeleteExit', @_);
7336 }
7337  
7338 # Get the exit's parent room (it shouldn't have one, or the parent should be set to some
7339 # kind of model object other than a room)
7340 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
7341 if ($roomObj && $roomObj->category eq 'room') {
7342  
7343 return undef;
7344 }
7345  
7346 # If this exit has a twin (that really exists), abandon it (using code adapted from
7347 # $self->abandonTwinExit)
7348 if ($exitObj->twinExit) {
7349  
7350 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
7351 if ($twinExitObj) {
7352  
7353 # Modify $twinExitObj
7354 $twinExitObj->ivUndef('destRoom');
7355 $twinExitObj->ivUndef('twinExit');
7356 # If this exit is marked as a broken or region exit, convert it into an incomplete
7357 # exit
7358 $twinExitObj->ivPoke('brokenFlag', FALSE);
7359 $twinExitObj->ivPoke('regionFlag', FALSE);
7360 $twinExitObj->ivPoke('superFlag', FALSE);
7361 $twinExitObj->ivPoke('notSuperFlag', FALSE);
7362  
7363 # Set ->randomType too, just to be safe
7364 $twinExitObj->ivPoke('randomType', 'none');
7365 }
7366 }
7367  
7368 # Mark the number of this object as having been deleted, so it can be reused
7369 $self->ivPush('exitBufferList', $exitObj->number);
7370 # Remove the exit from the model
7371 $self->ivDelete('exitModelHash', $exitObj->number);
7372 $self->ivDecrement('exitActualCount');
7373  
7374 # Make sure the deleted exit is not marked to be re-drawn
7375 foreach my $mapWin ($self->collectMapWins()) {
7376  
7377 # Unfortunately this means checking every parchment. We don't know the parent region of
7378 # an orphaned exit
7379 foreach my $parchmentObj ($mapWin->ivValues('parchmentHash')) {
7380  
7381 $parchmentObj->ivDelete('markedExitHash', $exitObj->number);
7382 $parchmentObj->ivDelete('markedExitTagHash', $exitObj->number);
7383 }
7384 }
7385  
7386 return 1;
7387 }
7388  
7389 sub deleteLabels {
7390  
7391 # Called by GA::Win::Map->deleteLabelCallback
7392 # Deletes one of more GA::Obj::MapLabel objects
7393 #
7394 # Expected arguments
7395 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
7396 # should be updated now, FALSE if not (in which case, they can be
7397 # updated later by the calling function, when it is ready)
7398 #
7399 # Optional arguments
7400 # @labelList - A list of GA::Obj::MapLabel objects to delete. If the list is empty,
7401 # no labels are deleted
7402 #
7403 # Return values
7404 # 'undef' on improper arguments
7405 # 1 otherwise
7406  
7407 my ($self, $updateFlag, @labelList) = @_;
7408  
7409 # Check for improper arguments
7410 if (! defined $updateFlag) {
7411  
7412 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteLabels', @_);
7413 }
7414  
7415 # If @labelList is empty, do nothing
7416 if (! @labelList) {
7417  
7418 return undef;
7419 }
7420  
7421 # Before any deletion operation, all selected canvas objects must be un-selected (but don't
7422 # need to to do that if there has been an earlier call to $self->deleteRegions)
7423 if (! $self->blockUnselectFlag) {
7424  
7425 foreach my $mapWin ($self->collectMapWins()) {
7426  
7427 $mapWin->setSelectedObj();
7428 }
7429 }
7430  
7431 foreach my $labelObj (@labelList) {
7432  
7433 # Get the label's parent regionmap
7434 my $regionmapObj = $self->ivShow('regionmapHash', $labelObj->region);
7435  
7436 # Remove the label from the regionmap
7437 $regionmapObj->removeLabel($labelObj);
7438  
7439 # The regionmap's highest/lowest occupied levels need to be recalculated
7440 $self->ivAdd('checkLevelsHash', $regionmapObj->name, undef);
7441  
7442 # Update any GA::Win::Map objects using this world model (if allowed)
7443 if ($updateFlag) {
7444  
7445 foreach my $mapWin ($self->collectMapWins()) {
7446  
7447 my $parchmentObj = $mapWin->ivShow('parchmentHash', $regionmapObj->name);
7448  
7449 # Delete the label's canvas object (if it exists)
7450 $mapWin->deleteCanvasObj(
7451 'label',
7452 $labelObj,
7453 $regionmapObj,
7454 $parchmentObj,
7455 TRUE,
7456 );
7457  
7458 # Some other function may have placed the label on the automapper's list of
7459 # objects to draw; if so, remove them
7460 if ($parchmentObj) {
7461  
7462 $parchmentObj->ivDelete('markedLabelHash', $labelObj->number);
7463 $parchmentObj->ivDelete('queueLabelHash', $labelObj->number);
7464 }
7465 }
7466 }
7467 }
7468  
7469 return 1;
7470 }
7471  
7472 # Move model objects
7473  
7474 sub moveRoomsLabels {
7475  
7476 # Called by GA::Win::Map->moveSelectedObjs
7477 # Moves one or more selected rooms and labels to a new position, possibly in a new region
7478 # NB It's up to the calling function to check that rooms are not being moved into
7479 # occupied gridblocks
7480 #
7481 # Expected arguments
7482 # $session - The calling function's GA::Session
7483 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
7484 # should be updated now, FALSE if not (in which case, they can be
7485 # updated later by the calling function, when it is ready)
7486 # $oldRegionmapObj - The GA::Obj::Regionmap from which the rooms are being moved (NB
7487 # all the rooms/labels are in the same region)
7488 # $newRegionmapObj - The GA::Obj::Regionmap to which the rooms are being moved (may
7489 # be the same as $oldRegionmapObj)
7490 # $adjustXPos, $adjustYPos, $adjustZPos
7491 # - Describes a vector between the coordinates of the rooms/labels in
7492 # their old position, and and their coordinates in the new
7493 # position
7494 # $roomHashRef - Reference to a hash of GA::ModelObj::Room objects to move. Hash
7495 # in the form
7496 # $roomHash{model_number} = blessed_reference_to_room_object
7497 # $labelHashRef - Reference to a hash of GA::Obj::MapLabel objects to move. Hash in
7498 # either of the following forms
7499 # $labelHash{label_id) = blessed_reference_to_map_label_object
7500 # $labelHash{label_number) = blessed_ref_to_map_label_object
7501 #
7502 # Return values
7503 # 'undef' on improper arguments
7504 # 1 otherwise
7505  
7506 my (
7507 $self, $session, $updateFlag, $oldRegionmapObj, $newRegionmapObj, $adjustXPos,
7508 $adjustYPos, $adjustZPos, $roomHashRef, $labelHashRef, $check,
7509 ) = @_;
7510  
7511 # Local variables
7512 my (
7513 $oldRegionObj, $newRegionObj,
7514 @mapWinList, @drawList,
7515 %roomHash, %labelHash, %checkExitHash, %drawHash,
7516 );
7517  
7518 # Check for improper arguments
7519 if (
7520 ! defined $session || ! defined $updateFlag || ! defined $oldRegionmapObj
7521 || ! defined $newRegionmapObj || ! defined $adjustXPos || ! defined $adjustYPos
7522 || ! defined $adjustZPos || ! defined $roomHashRef || ! defined $labelHashRef
7523 || defined $check
7524 ) {
7525 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveRoomsLabels', @_);
7526 }
7527  
7528 # De-reference the hashes
7529 # A hash of rooms, in the form
7530 # $roomHash{model_number} = blessed_reference_to_room_object
7531 %roomHash = %$roomHashRef;
7532 # A hash of labels, in the form
7533 # $labelHash{label_number) = blessed_reference_to_map_label_object
7534 %labelHash = %$labelHashRef;
7535  
7536 # Get the corresponding GA::ModelObj::Region objects
7537 $oldRegionObj = $self->ivShow('modelHash', $oldRegionmapObj->number);
7538 $newRegionObj = $self->ivShow('modelHash', $newRegionmapObj->number);
7539  
7540 # The automapper stores canvas objects for each drawn room in a hash, using a key in the
7541 # form (x_y_z). However, after the rooms are moved to their new position, the Axmud code
7542 # will have no way of knowing what the old position was, and thus they won't be able to
7543 # find the right key
7544 # Therefore, when moving rooms around in the same region, we have to delete canvas objects
7545 # in each automapper window now, even if $updateFlag is FALSE
7546 # (Don't need to delete anything if the whole region is going to be redrawn anyway)
7547  
7548 # Compile a list of automapper windows using this world model now (so we only have to do it
7549 # once)
7550 @mapWinList = $self->collectMapWins();
7551 # Any moved room, plus any room connected to it, must be redrawn. (Redrawing connected
7552 # rooms guarantees that exits are redrawn correctly)
7553 # Compile a hash of rooms to be redrawn to eliminate duplicates
7554 foreach my $roomObj (values %roomHash) {
7555  
7556 $drawHash{$roomObj->number} = $roomObj;
7557  
7558 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7559  
7560 my ($exitObj, $otherRoomObj);
7561  
7562 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7563  
7564 if ($exitObj->destRoom) {
7565  
7566 $otherRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
7567 $drawHash{$otherRoomObj->number} = $otherRoomObj;
7568 }
7569 }
7570  
7571 foreach my $exitNum (
7572 $roomObj->ivKeys('uncertainExitHash'),
7573 $roomObj->ivKeys('oneWayExitHash'),
7574 ) {
7575 my ($exitObj, $otherRoomObj);
7576  
7577 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7578 $otherRoomObj = $self->ivShow('modelHash', $exitObj->parent);
7579 $drawHash{$otherRoomObj->number} = $otherRoomObj;
7580 }
7581 }
7582  
7583 foreach my $mapWin (@mapWinList) {
7584  
7585 my $parchmentObj = $mapWin->ivShow('parchmentHash', $oldRegionmapObj->name);
7586  
7587 foreach my $roomObj (values %drawHash) {
7588  
7589 $mapWin->deleteCanvasObj('room', $roomObj, $oldRegionmapObj, $parchmentObj);
7590 # Also destroy the canvas objects for any checked directions
7591 $mapWin->deleteCanvasObj('checked_dir', $roomObj, $oldRegionmapObj, $parchmentObj);
7592 # Also destroy canvas objects for their exits
7593 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7594  
7595 $mapWin->deleteCanvasObj(
7596 'exit',
7597 $self->ivShow('exitModelHash', $exitNum),
7598 $oldRegionmapObj,
7599 $parchmentObj,
7600 );
7601 }
7602 }
7603 }
7604  
7605 # Regardless of whether $updateFlag is set, if the whole region isn't going to be redrawn,
7606 # canvas objects for each room must be deleted
7607 # Remove each room in turn from its old position in $oldRegionmapObj's grid
7608 foreach my $roomObj (values %roomHash) {
7609  
7610 # Remove the entries in the old regionmap's ->gridRoomHash, ->gridRoomTagHash and
7611 # ->gridRoomGuildHash
7612 $oldRegionmapObj->removeRoom($roomObj);
7613  
7614 # If the room is moving from one region to another...
7615 if ($oldRegionObj ne $newRegionObj) {
7616  
7617 # Tell the old region that it has lost a child, and tell the new region that it has
7618 # acquired one
7619 $oldRegionObj->ivDelete('childHash', $roomObj->number);
7620 $newRegionObj->ivAdd('childHash', $roomObj->number, undef);
7621 $roomObj->ivPoke('parent', $newRegionObj->number);
7622  
7623 # Remove the entries for each of the room's exits in the old regionmap's
7624 # ->gridExitHash (the entries wouldn't need to be replaced if the room were
7625 # staying in the same region)
7626 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7627  
7628 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
7629  
7630 # Remove the entries in the old regionmap's ->gridExitHash and ->gridExitTagHash
7631 $oldRegionmapObj->removeExit($exitObj);
7632  
7633 # Any exits which are currently region exits must be checked, once they have
7634 # been moved, to see if they are now broken exits (all exits are first checked
7635 # to see if they are region exits)
7636 if ($exitObj->regionFlag) {
7637  
7638 $checkExitHash{$exitNum} = $exitObj;
7639 }
7640 }
7641 }
7642  
7643 # The regionmaps' highest/lowest occupied levels need to be recalculated
7644 $self->ivAdd('checkLevelsHash', $oldRegionmapObj->name, undef);
7645 }
7646  
7647 # Move each room in turn to its new position in $newRegionmapObj's grid
7648 foreach my $roomObj (values %roomHash) {
7649  
7650 # Set the room's new coordinates
7651 $roomObj->ivPoke('xPosBlocks', ($roomObj->xPosBlocks + $adjustXPos));
7652 $roomObj->ivPoke('yPosBlocks', ($roomObj->yPosBlocks + $adjustYPos));
7653 $roomObj->ivPoke('zPosBlocks', ($roomObj->zPosBlocks + $adjustZPos));
7654  
7655 # Make new entries in the regionmap's ->gridRoomHash, ->gridRoomTagHash and
7656 # ->gridRoomGuildHash
7657 $newRegionmapObj->storeRoom($roomObj);
7658  
7659 # If the room is moving from one region to another...
7660 if ($oldRegionObj ne $newRegionObj) {
7661  
7662 # Make entries in new regionmap's ->gridExitHash
7663 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7664  
7665 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
7666  
7667 $newRegionmapObj->storeExit($exitObj);
7668 if ($exitObj->exitTag) {
7669  
7670 $newRegionmapObj->storeExitTag($exitObj);
7671 }
7672 }
7673  
7674 # Update ->livingCountHash and ->nonLivingCountHash in both regionmaps
7675 $newRegionmapObj->storeLivingCount(
7676 $roomObj->number,
7677 $oldRegionmapObj->removeLivingCount($roomObj->number),
7678 );
7679  
7680 $newRegionmapObj->storeNonLivingCount(
7681 $roomObj->number,
7682 $oldRegionmapObj->removeNonLivingCount($roomObj->number),
7683 );
7684  
7685 # The regionmaps' highest/lowest occupied levels need to be recalculated
7686 $self->ivAdd('checkLevelsHash', $newRegionmapObj->name, undef);
7687 }
7688 }
7689  
7690 # If the rooms have been moved to a new region, we must check each of their exits to see
7691 # whether they are now region exits
7692 if ($oldRegionObj ne $newRegionObj) {
7693  
7694 foreach my $roomObj (values %roomHash) {
7695  
7696 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7697  
7698 my ($exitObj, $twinExitObj, $destRoomObj);
7699  
7700 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7701 if ($exitObj->twinExit) {
7702  
7703 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
7704 }
7705  
7706 # If the exit leads to a room in a different region to the new region, it must
7707 # be added to the regionmap's ->regionExitHash
7708 if ($exitObj->destRoom) {
7709  
7710 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
7711 if ($destRoomObj->parent != $newRegionObj->number) {
7712  
7713 # This is a region exit
7714 $self->setRegionExit(
7715 FALSE, # Don't update Automapper windows
7716 $exitObj,
7717 $newRegionObj->number,
7718 );
7719  
7720 # The twin exit, if there is one, must also be marked as a region exit
7721 if ($twinExitObj) {
7722  
7723 $self->setRegionExit(
7724 FALSE, # Don't update Automapper windows
7725 $twinExitObj,
7726 $destRoomObj->parent,
7727 );
7728 }
7729  
7730 } else {
7731  
7732 # Definitely not a region exit - and neither is its twin (if there is
7733 # one)...
7734 if ($exitObj->regionFlag) {
7735  
7736 $self->unsetRegionExit(
7737 FALSE, # Don't update Automapper windows
7738 $exitObj,
7739 $newRegionmapObj->number,
7740 );
7741 }
7742  
7743 if ($twinExitObj && $twinExitObj->regionFlag) {
7744  
7745 $self->unsetRegionExit(
7746 FALSE, # Don't update Automapper windows
7747 $twinExitObj,
7748 $destRoomObj->parent,
7749 );
7750 }
7751  
7752 # For any exits which were formerly region exits, they are probably
7753 # now broken exits
7754 if (exists $checkExitHash{$exitObj->number}) {
7755  
7756 # If (by chance) the two rooms are aligned in the direction of
7757 # their exit, it's not a broken exit
7758 if (! $self->checkRoomAlignment($session, $exitObj)) {
7759  
7760 # The two rooms aren't aligned so $exitObj is a broken exit and
7761 # so is its twin (if there is one)
7762 # (Don't convert the exits to broken exits if they were already
7763 # broken exits - the call to ->setBrokenExit would reset
7764 # various IVs such as ->bentFlag)
7765 if (! $exitObj->brokenFlag) {
7766  
7767 $self->setBrokenExit(
7768 FALSE, # Don't update Automapper windows
7769 $exitObj,
7770 $newRegionmapObj->number,
7771 );
7772 }
7773  
7774 if ($twinExitObj && ! $twinExitObj->brokenFlag) {
7775  
7776 $self->setBrokenExit(
7777 FALSE, # Don't update Automapper windows
7778 $twinExitObj,
7779 $destRoomObj->parent,
7780 );
7781 }
7782  
7783 } else {
7784  
7785 # It's not a broken exit, and neither is its twin (if there is
7786 # one)
7787 $self->unsetBrokenExit(
7788 FALSE, # Don't update Automapper windows
7789 $exitObj,
7790 $newRegionmapObj->number,
7791 );
7792  
7793 if ($twinExitObj) {
7794  
7795 $self->unsetBrokenExit(
7796 FALSE, # Don't update Automapper windows
7797 $twinExitObj,
7798 $destRoomObj->parent,
7799 );
7800 }
7801 }
7802 }
7803 }
7804 }
7805 }
7806 }
7807  
7808 # If the rooms have been moved to a new position in the same region, we have to check each
7809 # exit to see whether it's a broken exit
7810 } else {
7811  
7812 foreach my $roomObj (values %roomHash) {
7813  
7814 foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
7815  
7816 my ($exitObj, $twinExitObj);
7817  
7818 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7819 if ($exitObj->twinExit) {
7820  
7821 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
7822 }
7823  
7824 # If the exit doesn't lead to one of the rooms that we've just moved - i.e. if
7825 # the destination room isn't in %roomHash - then we need to check whether it's
7826 # a broken exit or not. (Dont' bother if it's already marked as a region exit)
7827 if (
7828 ! $exitObj->regionFlag
7829 && $exitObj->destRoom
7830 && ! exists $roomHash{$exitObj->destRoom}
7831 ) {
7832 # This might be a broken exit
7833 if (! $self->checkRoomAlignment($session, $exitObj)) {
7834  
7835 # The two rooms aren't aligned so $exitObj is a broken exit and so is
7836 # its twin (if there is one)
7837 # (Don't convert the exits to broken exits if they were already broken
7838 # exits - the call to ->setBrokenExit would reset various IVs such as
7839 # ->bentFlag)
7840 if (! $exitObj->brokenFlag) {
7841  
7842 $self->setBrokenExit(
7843 FALSE, # Don't update Automapper windows
7844 $exitObj,
7845 $newRegionmapObj->number,
7846 );
7847 }
7848  
7849 if ($exitObj->bendOffsetList) {
7850  
7851 # The position of any bends, relative to the dragged room, must be
7852 # reset
7853 $self->updateExitBends(
7854 $adjustXPos,
7855 $adjustYPos,
7856 $adjustZPos,
7857 $newRegionmapObj,
7858 $exitObj,
7859 $twinExitObj,
7860 );
7861 }
7862  
7863 if ($twinExitObj && ! $twinExitObj->brokenFlag) {
7864  
7865 $self->setBrokenExit(
7866 FALSE, # Don't update Automapper windows
7867 $twinExitObj,
7868 undef, # Let ->setBrokenExit work out exit's region
7869 );
7870 }
7871  
7872 } elsif ($exitObj->brokenFlag) {
7873  
7874 # The exit is marked as a broken exit, but the two rooms are aligned,
7875 # so it's no longer a broken exit
7876 $self->unsetBrokenExit(
7877 FALSE, # Don't update Automapper windows
7878 $exitObj,
7879 $newRegionmapObj->number,
7880 );
7881  
7882 if ($twinExitObj) {
7883  
7884 $self->unsetBrokenExit(
7885 FALSE, # Don't update Automapper windows
7886 $twinExitObj,
7887 undef, # Let ->setBrokenExit work out exit's region
7888 );
7889 }
7890 }
7891 }
7892 }
7893 }
7894 }
7895  
7896 # Move each label in turn
7897 foreach my $labelObj (values %labelHash) {
7898  
7899 # If the label is moving from one region to another...
7900 if ($oldRegionObj ne $newRegionObj) {
7901  
7902 # Remove the label's entry in the old regionmap's ->gridRoomHash
7903 $oldRegionmapObj->removeLabel($labelObj);
7904  
7905 # Add it to the new region
7906 $newRegionmapObj->storeLabel($labelObj);
7907  
7908 # The label object's ->number has already been modified, so that it's a unique
7909 # number for the region - but we still need to update the name of the region
7910 # in which the label is stored
7911 $labelObj->ivPoke('region', $newRegionmapObj->name);
7912 }
7913  
7914 # Set the label's new position on the new regionmap
7915 $labelObj->ivPoke(
7916 'xPosPixels',
7917 ($labelObj->xPosPixels + ($adjustXPos * $newRegionmapObj->blockWidthPixels)),
7918 );
7919  
7920 $labelObj->ivPoke(
7921 'yPosPixels',
7922 ($labelObj->yPosPixels + ($adjustYPos * $newRegionmapObj->blockHeightPixels)),
7923 );
7924  
7925 $labelObj->ivPoke('level', ($labelObj->level + $adjustZPos));
7926 }
7927  
7928 # Now, if the room(s) were moved to a different region, update their incoming one-way /
7929 # uncertain exits
7930 if ($oldRegionmapObj ne $newRegionmapObj) {
7931  
7932 my (@regionExitList);
7933  
7934 # We must check each of the moved rooms. If any of them have one-way or uncertain exits
7935 # leading towards them, those exits must be marked as region exits
7936 # Two-way exits will already have been marked as region exits, so we don't need to worry
7937 # about them
7938 foreach my $roomObj (values %roomHash) {
7939  
7940 my @exitNumList = (
7941 $roomObj->ivKeys('uncertainExitHash'),
7942 $roomObj->ivKeys('oneWayExitHash'),
7943 );
7944  
7945 foreach my $exitNum (@exitNumList) {
7946  
7947 my ($exitObj, $departRoomObj);
7948  
7949 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7950 $departRoomObj = $self->ivShow('modelHash', $exitObj->parent);
7951  
7952 if ($departRoomObj->parent eq $oldRegionObj->number) {
7953  
7954 # Mark the uncertain exit as a region exit (and definitely not a broken
7955 # exit). The called function must work out the parent region of the
7956 # destination room.
7957 $self->setRegionExit(
7958 FALSE, # Don't update Automapper windows
7959 $exitObj,
7960 $departRoomObj->parent,
7961 );
7962 }
7963 }
7964 }
7965  
7966 # Otherwise, if rooms were moved in the same region, check their incoming one-way /
7967 # / uncertain exits
7968 } else {
7969  
7970 # We must check each of the moved rooms. If any of them have one-way or uncertain exits,
7971 # we have to check whether they're broken exits or not
7972 # Two-way exits will already have been marked as broken exits, so we don't need to worry
7973 # about them
7974 foreach my $roomObj (values %roomHash) {
7975  
7976 my @exitNumList = (
7977 $roomObj->ivKeys('uncertainExitHash'),
7978 $roomObj->ivKeys('oneWayExitHash'),
7979 );
7980  
7981 foreach my $exitNum (@exitNumList) {
7982  
7983 my ($exitObj, $departRoomObj);
7984  
7985 $exitObj = $self->ivShow('exitModelHash', $exitNum);
7986 $departRoomObj = $self->ivShow('modelHash', $exitObj->parent);
7987  
7988 # This might be a broken exit
7989 if (! $self->checkRoomAlignment($session, $exitObj)) {
7990  
7991 # The two rooms aren't aligned, so it's a broken exit
7992 $self->setBrokenExit(
7993 FALSE, # Don't update Automapper windows
7994 $exitObj,
7995 $departRoomObj->parent,
7996 );
7997  
7998 } else {
7999  
8000 # It's not a broken exit
8001 $self->unsetBrokenExit(
8002 FALSE, # Don't update Automapper windows
8003 $exitObj,
8004 $departRoomObj->parent,
8005 );
8006 }
8007 }
8008 }
8009 }
8010  
8011 # Update any GA::Win::Map objects using this world model (if allowed)
8012 if ($updateFlag) {
8013  
8014 # Compile a list of rooms, including all the rooms in %drawHash, and any rooms that are
8015 # connected to those rooms
8016 push (@drawList, $self->compileRedrawRooms(values %drawHash));
8017 # Add any labels to that list
8018 foreach my $labelObj (values %labelHash) {
8019  
8020 push (@drawList, 'label', $labelObj);
8021 }
8022  
8023 # Redraw all of the affected rooms/labels
8024 foreach my $mapWin (@mapWinList) {
8025  
8026 $mapWin->markObjs(@drawList);
8027 $mapWin->doDraw();
8028 }
8029 }
8030  
8031 # Operation complete
8032 return 1;
8033 }
8034  
8035 sub moveOtherObjs {
8036  
8037 # Called by GA::Win::Map->stopDrag at the end of a drag operation for a room tag, room
8038 # guild, exit tags or label (if the drag involves any rooms, $self->moveSelectedObjs is
8039 # called instead, and exits can't be dragged)
8040 # Updates the dragged object and redraws it (if allowed)
8041 #
8042 # Expected arguments
8043 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
8044 # should be updated now, FALSE if not (in which case, they can be
8045 # updated later by the calling function, when it is ready)
8046 # $type - The type of dragged canvas object - 'room_tag', 'room_guild',
8047 # 'exit_tag' or 'label'
8048 # $dragObj - The GA::ModelObj::Room, GA::Obj::Exit or GA::Obj::MapLabel which
8049 # corresponds to the dragged canvas object
8050 # $xPos, $yPos - The object's new position on the map (in pixels)
8051 #
8052 # Return values
8053 # 'undef' on improper arguments
8054 # 1 otherwise
8055  
8056 my ($self, $updateFlag, $type, $dragObj, $xPos, $yPos, $check) = @_;
8057  
8058 # Local variables
8059 my @redrawList;
8060  
8061 # Check for improper arguments
8062 if (
8063 ! defined $updateFlag || ! defined $type || ! defined $dragObj || ! defined $xPos
8064 || ! defined $yPos || defined $check
8065 ) {
8066 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveOtherObjs', @_);
8067 }
8068  
8069 # Update the corresponding room tag, room guild or label
8070 if ($type eq 'room_tag') {
8071  
8072 # Set the room tag's new position
8073 $dragObj->ivPoke('roomTagXOffset', $dragObj->roomTagXOffset + $xPos);
8074 $dragObj->ivPoke('roomTagYOffset', $dragObj->roomTagYOffset + $yPos);
8075  
8076 # Mark the room to be redrawn, which draws the room tag in its new position
8077 @redrawList = ('room', $dragObj);
8078  
8079 } elsif ($type eq 'room_guild') {
8080  
8081 # Set the room guild's new position
8082 $dragObj->ivPoke('roomGuildXOffset', $dragObj->roomGuildXOffset + $xPos);
8083 $dragObj->ivPoke('roomGuildYOffset', $dragObj->roomGuildYOffset + $yPos);
8084  
8085 # Mark the room to be redrawn, which draws the room guild in its new position
8086 @redrawList = ('room', $dragObj);
8087  
8088 } elsif ($type eq 'exit_tag') {
8089  
8090 # Set the room guild's new position
8091 $dragObj->ivPoke('exitTagXOffset', $dragObj->exitTagXOffset + $xPos);
8092 $dragObj->ivPoke('exitTagYOffset', $dragObj->exitTagYOffset + $yPos);
8093  
8094 # Mark the exit to be redrawn, which draws the exit tag in its new position
8095 @redrawList = ('exit', $dragObj);
8096  
8097 } elsif ($type eq 'label') {
8098  
8099 # Set the map label's new position
8100 $dragObj->ivPoke('xPosPixels', $dragObj->xPosPixels + $xPos);
8101 $dragObj->ivPoke('yPosPixels', $dragObj->yPosPixels + $yPos);
8102  
8103 # Mark the label to be redrawn
8104 @redrawList = ('label', $dragObj);
8105 }
8106  
8107 # Update any GA::Win::Map objects using this world model (if allowed)
8108 if ($updateFlag) {
8109  
8110 foreach my $mapWin ($self->collectMapWins()) {
8111  
8112 # Redraw the dragged object
8113 $mapWin->markObjs(@redrawList);
8114 $mapWin->doDraw();
8115 }
8116 }
8117  
8118 return 1;
8119 }
8120  
8121 sub mergeMap {
8122  
8123 # Called by GA::Win::Map->doMerge (or by any other automapper code)
8124 # Merges a room (or a group of rooms) into a different room (or group of rooms)
8125 # This is useful if the user is lost (or has been transported to some random location). This
8126 # function merges rooms in a region (or an area of a region) that the user wants to
8127 # discard into a region (or an area of a region) that user wants to keep. The room's IVs
8128 # are preserved, as far as possible (for example, the character visit counts in pairs of
8129 # merged rooms are combined)
8130 # The merge operation is fairly intelligent. The code compares rooms to work out which
8131 # pairs of rooms should be merged. This partly depends on how rooms are connected to each
8132 # other, but can also depend on the rooms' positions on the maps
8133 #
8134 # The function takes at least two arguments. $targetRoomObj and $twinRoomObj are
8135 # assumed to represent the same room in the game world; those two rooms are definitely
8136 # merged together. $targetRoomObj survives and $twinRoomObject is destroyed
8137 # @otherRoomList is optional. If specified, it should be one or more rooms which are near
8138 # $twinRoomObj, representing a region (or an area of the region) that the user wants to
8139 # discard
8140 # The function checks rooms that are connected to $targetRoomObj (the one that's going to
8141 # survive) to see if the rooms connected to it can be merged with any rooms in
8142 # @otherRoomList which are connected to @otherRoomList. If so, those pairs of rooms are
8143 # merged, too
8144 # Any rooms in @otherRoomList which can't be merged are simply moved, with their position
8145 # relative to $twinRoomObj being replaced with a new position relative to $targetRoomObj.
8146 # If it's not possible to move a room in @otherRoomList, because the relative position is
8147 # already occupied, then that room is not moved (or merged). It's up to the calling
8148 # function to decide what to do with it
8149 #
8150 # Expected arguments
8151 # $session - The calling GA::Session
8152 # $targetRoomObj - A GA::ModelObj::Room object which will survive the merge operation
8153 # $twinRoomObj - A GA::ModelObj::Room object which is assumed to represent the same
8154 # room in the game world
8155 #
8156 # Optional arguments
8157 # $otherRoomListRef
8158 # - Reference to a secondary list of rooms which are either connected to
8159 # $twinRoomObj or are (at the very least) in the same region as it,
8160 # and which should be merged or moved as well, if possible (otherwise
8161 # 'undef' or a reference to an empty list)
8162 # $labelListRef - Reference to a list of labels in the same region as $twinRoomObj which
8163 # should also be moved (otherwise 'undef' or a reference to an empty
8164 # list)
8165 #
8166 # Return values
8167 # 'undef' on improper arguments or if there's an error
8168 # 1 on success (meaning that $targetRoomObj and $twinRoomObj were merged, and that an
8169 # unspecified number of rooms in @otherRoomList might have been merged or moved, too)
8170  
8171 my (
8172 $self, $session, $targetRoomObj, $twinRoomObj, $otherRoomListRef, $labelListRef,
8173 $check,
8174 ) = @_;
8175  
8176 # Local variables
8177 my (
8178 $regionmapObj, $twinRegionmapObj, $result,
8179 @otherRoomList, @labelList, @checkRoomList, @deleteList, @selectList,
8180 %labelHash, %mergeHash, %noMergeHash, %moveHash, %reconnectHash, %reverseHash,
8181 %disconnectHash,
8182 );
8183  
8184 # Check for improper arguments
8185 if (! defined $targetRoomObj || ! defined $twinRoomObj || defined $check) {
8186  
8187 return $axmud::CLIENT->writeImproper($self->_objClass . '->mergeMap', @_);
8188 }
8189  
8190 # De-reference the list arguments, if specified
8191 if (defined $otherRoomListRef) {
8192  
8193 @otherRoomList = @$otherRoomListRef;
8194 }
8195  
8196 if (defined $labelListRef) {
8197  
8198 # Convert to a hash, ready for the call to $self->moveRoomsLabels
8199 foreach my $labelObj (@$labelListRef) {
8200  
8201 $labelHash{$labelObj->id} = $labelObj;
8202 }
8203 }
8204  
8205 # Basic checks. We'll assume that the calling function is satisfied that the target and twin
8206 # rooms are actually represent the same room in the world
8207  
8208 # The target and twin rooms must not be the same room model object
8209 if ($targetRoomObj eq $twinRoomObj) {
8210  
8211 return undef;
8212 }
8213  
8214 # Neither may appear in @otherRoomList. Any rooms in @otherRoomList must be in the same
8215 # region as $twinRoomObj
8216 foreach my $otherRoomObj (@otherRoomList) {
8217  
8218 if (
8219 $otherRoomObj eq $targetRoomObj
8220 || $otherRoomObj eq $twinRoomObj
8221 || $otherRoomObj->parent != $twinRoomObj->parent
8222 ) {
8223 return undef;
8224 }
8225 }
8226  
8227 # Get the target room's regionmap
8228 $regionmapObj = $self->findRegionmap($targetRoomObj->parent);
8229 $twinRegionmapObj = $self->findRegionmap($twinRoomObj->parent);
8230 if (! $regionmapObj) {
8231  
8232 return undef;
8233 }
8234  
8235 # Once a merge operation has started, the automapper object doesn't need to check that
8236 # the (newly-set) current room is in the temporary region any more
8237 $session->mapObj->reset_rescueCheckFlag();
8238  
8239 # Compile a list of pairs of rooms that will be merged with each other, starting with...
8240 $mergeHash{$twinRoomObj->number} = $targetRoomObj->number;
8241  
8242 # Now go through the rooms in @otherRoomList. Our goal is to check which of those rooms are
8243 # connected to $twinRoomObj via exits, and then to see if there are any matching rooms
8244 # connected to %targetRoomObj via equivalent exits; any room pairs we find can be marked
8245 # as mergeable
8246 if (@otherRoomList) {
8247  
8248 # (Keep track of which rooms haven't yet been marked as mergeable)
8249 foreach my $otherRoomObj (@otherRoomList) {
8250  
8251 $noMergeHash{$otherRoomObj->number} = $otherRoomObj;
8252 }
8253  
8254 # Start by checking the exits in $twinRoomObj itself
8255 push (@checkRoomList, $twinRoomObj);
8256  
8257 do {
8258  
8259 my ($checkRoomObj, $mergeRoomObj);
8260  
8261 # $checkRoomObj is either $twinRoomObj itself, or one of the rooms directly
8262 # connected to it
8263 $checkRoomObj = shift @checkRoomList;
8264 # Get the room with which $checkRoomObj will be merged
8265 $mergeRoomObj = $self->ivShow('modelHash', $mergeHash{$checkRoomObj->number});
8266  
8267 # Check all of $checkRoomObj's outgoing exits, one by one
8268 OUTER: foreach my $exitNum ($checkRoomObj->ivValues('exitNumHash')) {
8269  
8270 my ($exitObj, $destRoomObj, $exitNum2, $exitObj2, $destRoomObj2);
8271  
8272 $exitObj = $self->ivShow('exitModelHash', $exitNum);
8273  
8274 # If this exit's destination room is one of those which might be merged, get the
8275 # destination room object
8276 if ($exitObj->destRoom && exists $noMergeHash{$exitObj->destRoom}) {
8277  
8278 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
8279  
8280 # If the equivalent room has an exit in the same direction, get that exit's
8281 # destination room
8282 $exitNum2 = $mergeRoomObj->ivShow('exitNumHash', $exitObj->dir);
8283 if (defined $exitNum2) {
8284  
8285 $exitObj2 = $self->ivShow('exitModelHash', $exitNum2);
8286 }
8287  
8288 if ($exitObj2 && $exitObj2->destRoom) {
8289  
8290 $destRoomObj2 = $self->ivShow('modelHash', $exitObj2->destRoom);
8291 }
8292 }
8293  
8294 # Compare the two destination rooms to see if they are also matches
8295 if ($destRoomObj2) {
8296  
8297 ($result) = $self->compareRooms($session, $destRoomObj, $destRoomObj2);
8298 if ($result) {
8299  
8300 # Success! Mark these rooms as mergeable
8301 $mergeHash{$destRoomObj->number} = $destRoomObj2->number;
8302 delete $noMergeHash{$destRoomObj->number};
8303  
8304 # $destRoomObj is connected to $twinRoomObj; in a future iteration of
8305 # this loop, check $destRoomObj's exits too
8306 push (@checkRoomList, $destRoomObj);
8307 }
8308 }
8309 }
8310  
8311 # Check all of $checkRoomObj's incoming uncertain exits, one by one
8312 OUTER: foreach my $key ($checkRoomObj->ivKeys('uncertainExitHash')) {
8313  
8314 my (
8315 $exitObj, $incomingExitObj, $parentRoomObj, $exitNum2, $exitObj2,
8316 $parentRoomObj2,
8317 );
8318  
8319 # $exitObj is the exit belonging to $checkRoomObj, and $incomingExitObj is an
8320 # an uncertain exit which might be its twin exit)
8321 $exitObj = $self->ivShow(
8322 'exitModelHash',
8323 $checkRoomObj->ivShow('uncertainExitHash', $key),
8324 );
8325  
8326 $incomingExitObj = $self->ivShow('exitModelHash', $key);
8327  
8328 # If this incoming exit's parent room is one of those which might be merged, get
8329 # the parent room object
8330 if (exists $noMergeHash{$incomingExitObj->parent}) {
8331  
8332 $parentRoomObj = $self->ivShow('modelHash', $incomingExitObj->parent);
8333  
8334 # If the equivalent room has an outgoing exit in the same direction as
8335 # $exitObj, or an incoming exit in the same direction as $incomingExitObj,
8336 # get the corresponding destination/parent room
8337 $exitNum2 = $mergeRoomObj->ivShow('exitNumHash', $exitObj->dir);
8338 if (defined $exitNum2) {
8339  
8340 $exitObj2 = $self->ivShow('exitModelHash', $exitNum2);
8341 if ($exitObj2->destRoom) {
8342  
8343 $parentRoomObj2 = $self->ivShow('modelHash', $exitObj2->destRoom);
8344 }
8345  
8346 } else {
8347  
8348 INNER: foreach my $key ($mergeRoomObj->ivKeys('uncertainExitHash')) {
8349  
8350 my $incomingExitObj2 = $self->ivShow('exitModelHash', $key);
8351  
8352 if ($incomingExitObj2->dir eq $incomingExitObj->dir) {
8353  
8354 $parentRoomObj2
8355 = $self->ivShow('modelHash', $incomingExitObj2->parent);
8356  
8357 last INNER;
8358 }
8359 }
8360 }
8361 }
8362  
8363 # Compare the two parent rooms to see if they are also matches
8364 if ($parentRoomObj2) {
8365  
8366 ($result) = $self->compareRooms($session, $parentRoomObj, $parentRoomObj2);
8367 if ($result) {
8368  
8369 # Success! Mark these rooms as mergeable
8370 $mergeHash{$parentRoomObj->number} = $parentRoomObj2->number;
8371 delete $noMergeHash{$parentRoomObj->number};
8372  
8373 # $parentRoomObj is connected to $twinRoomObj; in a future iteration of
8374 # this loop, check $parentRoomObj's exits too
8375 push (@checkRoomList, $parentRoomObj);
8376 }
8377 }
8378 }
8379  
8380 # Check all of $checkRoomObj's incoming one-way exits, one by one
8381 OUTER: foreach my $key ($checkRoomObj->ivKeys('oneWayExitHash')) {
8382  
8383 my ($exitObj, $parentRoomObj, $parentRoomObj2);
8384  
8385 $exitObj = $self->ivShow('exitModelHash', $key);
8386  
8387 # If this one-way exit's parent room is one of those which might be merged, get
8388 # the parent room object
8389 if (exists $noMergeHash{$exitObj->parent}) {
8390  
8391 $parentRoomObj = $self->ivShow('modelHash', $exitObj->parent);
8392  
8393 # If the equivalent room has an incoming one-way exit in the same direction
8394 # as $oneWayExitObj get the corresponding parent room
8395 INNER: foreach my $key ($mergeRoomObj->ivKeys('oneWayExitHash')) {
8396  
8397 my $exitObj2 = $self->ivShow('exitModelHash', $key);
8398  
8399 if ($exitObj2->dir eq $exitObj->dir) {
8400  
8401 $parentRoomObj2 = $self->ivShow('modelHash', $exitObj2->parent);
8402 last INNER;
8403 }
8404 }
8405 }
8406  
8407 # Compare the two parent rooms to see if they are also matches
8408 if ($parentRoomObj2) {
8409  
8410 ($result) = $self->compareRooms($session, $parentRoomObj, $parentRoomObj2);
8411 if ($result) {
8412  
8413 # Success! Mark these rooms as mergeable
8414 $mergeHash{$parentRoomObj->number} = $parentRoomObj2->number;
8415 delete $noMergeHash{$parentRoomObj->number};
8416  
8417 # $parentRoomObj is connected to $twinRoomObj; in a future iteration of
8418 # this loop, check $parentRoomObj's exits too
8419 push (@checkRoomList, $parentRoomObj);
8420 }
8421 }
8422 }
8423  
8424 } until (! @checkRoomList);
8425 }
8426  
8427 # Any members of @otherRoomList which still survive in %noMergeHash are not merged with any
8428 # existing room, but are simply moved to a new position
8429 foreach my $otherRoomObj (values %noMergeHash) {
8430  
8431 my ($xAdjust, $yAdjust, $zAdjust, $existRoomNum);
8432  
8433 # Find this room's position relative to $twinRoomObj
8434 $xAdjust = $otherRoomObj->xPosBlocks - $twinRoomObj->xPosBlocks;
8435 $yAdjust = $otherRoomObj->yPosBlocks - $twinRoomObj->yPosBlocks;
8436 $zAdjust = $otherRoomObj->zPosBlocks - $twinRoomObj->zPosBlocks;
8437  
8438 # At the same position, relative to $targetRoomObj, does a room already exist?
8439 $existRoomNum = $regionmapObj->fetchRoom(
8440 $targetRoomObj->xPosBlocks + $xAdjust,
8441 $targetRoomObj->yPosBlocks + $yAdjust,
8442 $targetRoomObj->zPosBlocks + $zAdjust,
8443 );
8444  
8445 if ($existRoomNum) {
8446  
8447 # Compare this room with $otherRoomObj. If they match, those two rooms can also be
8448 # merged. If they don't match, $otherRoomObj is not moved or merged
8449 ($result) = $self->compareRooms($session, $targetRoomObj, $otherRoomObj);
8450 if (! $result) {
8451  
8452 # Any rooms to be moved (not merged) which have exits leading to or from this
8453 # room must be disconnected from them, before redrawing the map
8454 $disconnectHash{$otherRoomObj->number} = $otherRoomObj;
8455  
8456 } else {
8457  
8458 $mergeHash{$otherRoomObj->number} = $existRoomNum;
8459 }
8460  
8461 } else {
8462  
8463 # The gridblock is empty, so $otherRoomObj can be moved there without being merged
8464 # with other rooms
8465 $moveHash{$otherRoomObj->number} = $otherRoomObj;
8466 }
8467 }
8468  
8469 # For rooms in %moveHash, any exits which lead to a room in %mergeHash will be disconnected
8470 # when the pair of rooms are merged, after which one of the pair is destroyed
8471 # Compile a hash of such exits and their new destination rooms so they can be reconnected
8472 # after the merge operation
8473 foreach my $otherRoomObj (values %moveHash) {
8474  
8475 foreach my $exitNum ($otherRoomObj->ivValues('exitNumHash')) {
8476  
8477 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
8478  
8479 if ($exitObj->destRoom && exists $mergeHash{$exitObj->destRoom}) {
8480  
8481 # the exit number = the replacement (surviving) destination room
8482 $reconnectHash{$exitNum} = $mergeHash{$exitObj->destRoom};
8483 }
8484 }
8485 }
8486  
8487 # Now the same thing in reverse. For pairs of rooms in %mergeHash, if the room to be
8488 # destroyed has any exits leading to a room in %moveHash, that exit will be disconnected
8489 # Update %reconnectHash with the equivalent exit in the surviving room and the same
8490 # destination
8491 foreach my $key (keys %mergeHash) {
8492  
8493 my ($thisTwinObj, $thisTargetObj);
8494  
8495 $thisTwinObj = $self->ivShow('modelHash', $key);
8496 $thisTargetObj = $self->ivShow('modelHash', $mergeHash{$key});
8497  
8498 foreach my $exitNum ($thisTwinObj->ivValues('exitNumHash')) {
8499  
8500 my ($exitObj, $exitObj2);
8501  
8502 # $exitObj will be destroyed, along with its parent; $exitObj2 will survive
8503 $exitObj = $self->ivShow('exitModelHash', $exitNum);
8504 if ($thisTargetObj->ivExists('exitNumHash', $exitObj->dir)) {
8505  
8506 $exitObj2 = $self->ivShow(
8507 'exitModelHash',
8508 $thisTargetObj->ivShow('exitNumHash', $exitObj->dir),
8509 );
8510  
8511 if (
8512 $exitObj->destRoom
8513 && exists $moveHash{$exitObj->destRoom}
8514 && $exitObj2
8515 && ! $exitObj2->destRoom
8516 ) {
8517 # the exit number = the moved destination room
8518 $reconnectHash{$exitObj2->number} = $exitObj->destRoom;
8519 }
8520 }
8521 }
8522 }
8523  
8524 if (%mergeHash) {
8525  
8526 # If the automapper's current room is any of the rooms that are about to be merged,
8527 # change it
8528 if (
8529 $session->mapObj->currentRoom
8530 && exists ($mergeHash{$session->mapObj->currentRoom->number})
8531 ) {
8532 $session->mapObj->setCurrentRoom(
8533 $self->ivShow('modelHash', $mergeHash{$session->mapObj->currentRoom->number}),
8534 );
8535 }
8536  
8537 # Merge the pairs of rooms in %mergeHash
8538 %reverseHash = reverse %mergeHash;
8539 foreach my $key (keys %mergeHash) {
8540  
8541 my ($thisTwinObj, $thisTargetObj);
8542  
8543 $thisTwinObj = $self->ivShow('modelHash', $key);
8544 $thisTargetObj = $self->ivShow('modelHash', $mergeHash{$key});
8545  
8546 # Merge the two rooms. $thisTargetObj is the one that survives
8547 $self->mergeRoom($thisTwinObj, $thisTargetObj);
8548 push (@deleteList, $self->ivShow('modelHash', $key));
8549  
8550 # Check $thisTargetObj's incoming uncertain exits. If the equivalent exit in
8551 # $thisTwinObj is a two-way exit, we can make the former a two-way exit too
8552 foreach my $uncertainExitNum ($thisTargetObj->ivKeys('uncertainExitHash')) {
8553  
8554 my (
8555 $incompleteExitNum, $uncertainExitObj, $incompleteExitObj,
8556 $uncertainRoomObj, $equivRoomObj, $equivExitNum, $equivExitObj,
8557 );
8558  
8559 # Every uncertain exit has a corresponding incomplete exit, which might be
8560 # connected to it (but we're not certain yet)
8561 $incompleteExitNum
8562 = $thisTargetObj->ivShow('uncertainExitHash', $uncertainExitNum);
8563  
8564 $uncertainExitObj = $self->ivShow('exitModelHash', $uncertainExitNum);
8565 $incompleteExitObj = $self->ivShow('exitModelHash', $incompleteExitNum);
8566  
8567 $uncertainRoomObj = $self->ivShow('modelHash', $uncertainExitObj->parent);
8568  
8569 # Does $uncertainRoomObj also exist in %mergeHash (i.e. are both that room and
8570 # $thisTwinObj being merged into other rooms?)
8571 if (exists $reverseHash{$uncertainRoomObj->number}) {
8572  
8573 # Get the room that will be merged into $uncertainRoomObj
8574 $equivRoomObj
8575 = $self->ivShow('modelHash', $reverseHash{$uncertainRoomObj->number});
8576  
8577 # Is there an exit in $thisTwinObj in the same direction as
8578 # $incompleteExitObj, which is a two-way exit and whose destination room
8579 # is $equivRoomObj?
8580 $equivExitNum = $thisTwinObj->ivShow(
8581 'exitNumHash',
8582 $incompleteExitObj->dir,
8583 );
8584  
8585 if (defined $equivExitNum) {
8586  
8587 $equivExitObj = $self->ivShow('exitModelHash', $equivExitNum);
8588 if (
8589 $equivExitObj->twinExit
8590 && $equivExitObj->destRoom
8591 && $equivExitObj->destRoom == $equivRoomObj->number
8592 ) {
8593 # Convert $uncertainExitObj and $incompleteExitObj into two-way twin
8594 # exits
8595 $self->connectRooms(
8596 $session,
8597 FALSE, # Don't update windows now
8598 $thisTargetObj, # Departure room
8599 $uncertainRoomObj, # Arrival room
8600 $incompleteExitObj->dir,
8601 $incompleteExitObj->mapDir,
8602 $incompleteExitObj,
8603 $uncertainExitObj, # The opposite exit
8604 );
8605 }
8606 }
8607 }
8608 }
8609 }
8610  
8611 # After merging the pairs of rooms, delete the one we don't need any more
8612 $self->deleteRooms(
8613 $session,
8614 FALSE, # Don't update automapper windows yet
8615 @deleteList,
8616 );
8617 }
8618  
8619 if (%moveHash && ! $self->autoRescueNoMoveFlag) {
8620  
8621 # Move all rooms that haven't been merged (and for which there is space at the new
8622 # location)
8623 $self->moveRoomsLabels(
8624 $session,
8625 FALSE, # Don't update windows now
8626 $twinRegionmapObj, # Move from this region...
8627 $regionmapObj, # ...to this one...
8628 $targetRoomObj->xPosBlocks - $twinRoomObj->xPosBlocks, # ...using this vector
8629 $targetRoomObj->yPosBlocks - $twinRoomObj->yPosBlocks,
8630 $targetRoomObj->zPosBlocks - $twinRoomObj->zPosBlocks,
8631 \%moveHash,
8632 \%labelHash,
8633 );
8634  
8635 # Reconnect exits between surviving rooms in %mergeHash and the moved rooms in
8636 # %moveHash
8637 foreach my $exitNum (keys %reconnectHash) {
8638  
8639 my ($exitObj, $destRoomObj);
8640  
8641 $exitObj = $self->ivShow('exitModelHash', $exitNum);
8642 $destRoomObj = $self->ivShow('modelHash', $reconnectHash{$exitNum});
8643  
8644 $self->connectRooms(
8645 $session,
8646 FALSE, # Don't update windows now
8647 $self->ivShow('modelHash', $exitObj->parent), # Departure room
8648 $destRoomObj, # Arrival room
8649 $exitObj->dir,
8650 $exitObj->mapDir,
8651 $exitObj,
8652 );
8653 }
8654 }
8655  
8656 # Any rooms that are left behind - not merged and not moved - must be disconnected from any
8657 # rooms that were moved (not merged)
8658 if (%disconnectHash) {
8659  
8660 foreach my $otherRoomObj (values %disconnectHash) {
8661  
8662 foreach my $exitNum ($otherRoomObj->ivValues('exitNumHash')) {
8663  
8664 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
8665  
8666 if ($exitObj->destRoom && exists $moveHash{$exitObj->destRoom}) {
8667  
8668 $self->disconnectExit(
8669 FALSE, # Don't update automapper windows yet
8670 $exitObj,
8671 );
8672 }
8673 }
8674 }
8675  
8676 foreach my $moveRoomObj (values %moveHash) {
8677  
8678 foreach my $exitNum ($moveRoomObj->ivValues('exitNumHash')) {
8679  
8680 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
8681  
8682 if ($exitObj->destRoom && exists $disconnectHash{$exitObj->destRoom}) {
8683  
8684 $self->disconnectExit(
8685 FALSE, # Don't update automapper windows yet
8686 $exitObj,
8687 );
8688 }
8689 }
8690 }
8691 }
8692  
8693 # Update any GA::Win::Map objects using this world model (if allowed)
8694 foreach my $mapWin ($self->collectMapWins()) {
8695  
8696 # Mark the two affected regions to be redrawn. The TRUE argument means that only the
8697 # specified region needs to be redrawn
8698 $mapWin->redrawRegions($regionmapObj, TRUE);
8699 if ($twinRegionmapObj ne $regionmapObj) {
8700  
8701 $mapWin->redrawRegions($twinRegionmapObj, TRUE);
8702 }
8703  
8704 # For visual clarity, select any rooms that were moved or merged
8705 foreach my $roomNum (values %mergeHash, keys %moveHash) {
8706  
8707 push (@selectList, $self->ivShow('modelHash', $roomNum), 'room');
8708 }
8709  
8710 $mapWin->setSelectedObj(
8711 \@selectList,
8712 TRUE, # Select multiple objects
8713 );
8714 }
8715  
8716 return 1;
8717 }
8718  
8719 sub mergeRoom {
8720  
8721 # Called by $self->mergeMap (only; to merge a single pair of rooms, call ->mergeMap, not
8722 # this function)
8723 # Merges IVs from a pair of rooms, $targetRoomObj (which will survive the operation) and
8724 # $twinRoomObj (which will be destroyed)
8725 #
8726 # Expected arguments
8727 # $twinRoomObj, $targetRoomObj
8728 # - The GA::ModelObj::Room objects to merge
8729 #
8730 # Return values
8731 # 'undef' on improper arguments
8732 # 1 otherwise
8733  
8734 my ($self, $twinRoomObj, $targetRoomObj, $check) = @_;
8735  
8736 # Check for improper arguments
8737 if (! defined $twinRoomObj || ! defined $targetRoomObj || defined $check) {
8738  
8739 return $axmud::CLIENT->writeImproper($self->_objClass . '->mergeRoom', @_);
8740 }
8741  
8742 # If the flag is set, only character visits are merged
8743 if (! $self->autoRescueVisitsFlag) {
8744  
8745 # Transfer the twin room's child objects to the target
8746 foreach my $childNum ($twinRoomObj->ivKeys('childHash')) {
8747  
8748 $self->setParent(
8749 FALSE, # Don't update automapper windows yet
8750 $childNum,
8751 $targetRoomObj->number,
8752 );
8753 }
8754  
8755 # (Don't transfer ->privateHash - we have no idea what sort of data it contains, nor of
8756 # what conflicts that transferring it to a different room might cause)
8757  
8758 # Add any notes in the twin room to any existing notes in target room
8759 if ($twinRoomObj->notesList) {
8760  
8761 $targetRoomObj->ivPush('notesList', $twinRoomObj->notesList);
8762 }
8763  
8764 # If the twin has a room tag and the target room doesn't, apply the tag to the target
8765 # room
8766 if (defined $twinRoomObj->roomTag && ! defined $targetRoomObj->roomTag) {
8767  
8768 $self->setRoomTag(
8769 FALSE, # Don't update automapper windows yet
8770 $targetRoomObj,
8771 $twinRoomObj->roomTag,
8772 );
8773 }
8774  
8775 # Same for room guilds
8776 if (defined $twinRoomObj->roomGuild && ! defined $targetRoomObj->roomGuild) {
8777  
8778 $self->setRoomGuild(
8779 FALSE, # Don't update automapper windows yet
8780 $twinRoomObj->roomGuild,
8781 $targetRoomObj,
8782 );
8783 }
8784  
8785 # Combine lists of room titles, but don't create duplicates
8786 foreach my $string ($twinRoomObj->titleList) {
8787  
8788 if (! $targetRoomObj->ivFind('titleList', $string)) {
8789  
8790 $targetRoomObj->ivPush('titleList', $string);
8791 }
8792 }
8793  
8794 # Combine hashes of verbose descriptions, but don't replace any verbose description that
8795 # already exists in $targetRoomObj
8796 foreach my $key ($twinRoomObj->ivKeys('descripHash')) {
8797  
8798 my $value = $twinRoomObj->ivShow('descripHash', $key);
8799  
8800 if (! $targetRoomObj->ivExists('descripHash', $key)) {
8801  
8802 $targetRoomObj->ivAdd('descripHash', $key, $value);
8803 }
8804 }
8805  
8806 # Combine various pattern lists, but don't create duplicates
8807 foreach my $iv (
8808 qw(unspecifiedPatternList failExitPatternList specialDepartPatternList)
8809 ) {
8810 foreach my $string ($twinRoomObj->$iv) {
8811  
8812 if (! $targetRoomObj->ivFind($iv, $string)) {
8813  
8814 $targetRoomObj->ivPush($iv, $string);
8815 }
8816 }
8817 }
8818  
8819 foreach my $key ($twinRoomObj->ivKeys('involuntaryExitPatternHash')) {
8820  
8821 my $value = $twinRoomObj->ivShow('involuntaryExitPatternHash', $key);
8822  
8823 $self->addInvoluntaryExit($targetRoomObj, $key, $value);
8824 }
8825  
8826 foreach my $key ($twinRoomObj->ivKeys('repulseExitPatternHash')) {
8827  
8828 my $value = $twinRoomObj->ivShow('repulseExitPatternHash', $key);
8829  
8830 $self->addRepulseExit($targetRoomObj, $key, $value);
8831 }
8832 }
8833  
8834 # Combine visits, adding the sum of visits in the target and twin rooms
8835 foreach my $key ($twinRoomObj->ivKeys('visitHash')) {
8836  
8837 my $value = $twinRoomObj->ivShow('visitHash', $key);
8838  
8839 if (! $targetRoomObj->ivExists('visitHash', $key)) {
8840  
8841 $targetRoomObj->ivAdd('visitHash', $key, $value);
8842  
8843 } else {
8844  
8845 $targetRoomObj->ivAdd(
8846 'visitHash',
8847 $key,
8848 $targetRoomObj->ivShow('visitHash', $key) + $value,
8849 );
8850 }
8851 }
8852  
8853 # If the flag is set, only character visits are merged
8854 if (! $self->autoRescueVisitsFlag) {
8855  
8856 # Combine exclusivity IVs
8857 if ($twinRoomObj->exclusiveFlag) {
8858  
8859 $targetRoomObj->ivPoke('exclusiveFlag', TRUE);
8860  
8861 foreach my $key ($twinRoomObj->ivKeys('exclusiveHash')) {
8862  
8863 $targetRoomObj->ivAdd('exclusiveHash', $key, undef);
8864 }
8865 }
8866  
8867 # Combine room flag hashes
8868 foreach my $key ($twinRoomObj->ivKeys('roomFlagHash')) {
8869  
8870 $targetRoomObj->ivAdd('roomFlagHash', $key, undef);
8871 }
8872  
8873 # If the twin has a source code/virtual area path and the target room doesn't, copy them
8874 # across
8875 if (! $targetRoomObj->sourceCodePath && $twinRoomObj->sourceCodePath) {
8876  
8877 $targetRoomObj->ivPoke('sourceCodePath', $twinRoomObj->sourceCodePath);
8878 }
8879  
8880 if (! $targetRoomObj->virtualAreaPath && $twinRoomObj->virtualAreaPath) {
8881  
8882 $targetRoomObj->ivPoke('virtualAreaPath', $twinRoomObj->virtualAreaPath);
8883 }
8884  
8885 # (Don't modify MSDP and MXP data supplied to $targetRoomObj)
8886  
8887 # The keys in ->hiddenObjHash are a subset of the keys in ->childHash, so they must be
8888 # transferred, too
8889 foreach my $key ($twinRoomObj->hiddenObjHash) {
8890  
8891 $targetRoomObj->ivAdd(
8892 'hiddenObjHash',
8893 $key,
8894 $twinRoomObj->ivShow('hiddenObjHash', $key),
8895 );
8896 }
8897  
8898 # Transfer search results, but don't replace any existing search results
8899 foreach my $key ($twinRoomObj->searchHash) {
8900  
8901 if (! $targetRoomObj->ivExists('searchHash', $key)) {
8902  
8903 $targetRoomObj->ivAdd(
8904 'searchHash',
8905 $key,
8906 $twinRoomObj->ivShow('searchHash', $key),
8907 );
8908 }
8909 }
8910  
8911 # Combine noun/adjective/script lists, but don't create duplicates
8912 foreach my $iv (qw(nounList adjList arriveScriptList)) {
8913  
8914 foreach my $string ($twinRoomObj->$iv) {
8915  
8916 if (! $targetRoomObj->ivFind($iv, $string)) {
8917  
8918 $targetRoomObj->ivPush($iv, $string);
8919 }
8920 }
8921 }
8922  
8923 # Combine checked directions, adding the sum of failed attempts in the target and twin
8924 # rooms
8925 foreach my $key ($twinRoomObj->ivKeys('checkedDirHash')) {
8926  
8927 my $value = $twinRoomObj->ivShow('checkedDirHash', $key);
8928  
8929 if (! $targetRoomObj->ivExists('checkedDirHash', $key)) {
8930  
8931 $targetRoomObj->ivAdd('checkedDirHash', $key, $value);
8932  
8933 } else {
8934  
8935 $targetRoomObj->ivAdd(
8936 'checkedDirHash',
8937 $key,
8938 $targetRoomObj->ivShow('checkedDirHash', $key) + $value,
8939 );
8940 }
8941 }
8942 }
8943  
8944 # Operation complete
8945 return 1;
8946 }
8947  
8948 # Modify model objects - all objects
8949  
8950 sub setParent {
8951  
8952 # Can be called by anything
8953 # Sets the parent model object of a child object. Should not be used to add rooms to a
8954 # region (call $self->addRoom for that), or to add non-model objects to a room (call
8955 # $self->addRoomChildren for that), or to add an exit (call->addExit for that)
8956 # Checks the rules for setting parents/children, and performs the operation
8957 #
8958 # Expected arguments
8959 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
8960 # should be updated now, FALSE if not (in which case, they can be
8961 # updated later by the calling function, when it is ready)
8962 # $objNum - The world model number of the object to modify
8963 #
8964 # Optional arguments
8965 # $parentNum - The world model number of the new parent. If set to 'undef', the
8966 # object should have no parent
8967 #
8968 # Return values
8969 # 'undef' on improper arguments, if either object does not exist or if the operation fails
8970 # 1 otherwise
8971  
8972 my ($self, $updateFlag, $objNum, $parentNum, $check) = @_;
8973  
8974 # Local variables
8975 my ($obj, $parentObj, $oldParentObj);
8976  
8977 # Check for improper arguments
8978 if (! defined $updateFlag || ! defined $objNum || defined $check) {
8979  
8980 return $axmud::CLIENT->writeImproper($self->_objClass . '->setParent', @_);
8981 }
8982  
8983 # Find the corresponding model objects
8984 $obj = $self->ivShow('modelHash', $objNum);
8985 if (! $obj) {
8986  
8987 return undef;
8988 }
8989  
8990 if ($parentNum) {
8991  
8992 $parentObj = $self->ivShow('modelHash', $parentNum);
8993 if (! $parentObj) {
8994  
8995 return undef;
8996 }
8997 }
8998  
8999 # Check the rules for setting parents (see the comments in $self->new)
9000 if (
9001 # General rules
9002 ($obj->category eq 'region' && $parentObj && $parentObj->category ne 'region')
9003 # Rules for this function only
9004 || $obj->category eq 'room'
9005 # Object cannot be its own parent
9006 || $parentObj && $obj eq $parentObj
9007 ) {
9008 return undef;
9009 }
9010  
9011 if (! $parentObj) {
9012  
9013 # Object should have no parent
9014 if (! $obj->parent) {
9015  
9016 # The object already has no parent; nothing to do
9017 return 1;
9018 }
9019  
9020 # Remove the object from the parent's child list
9021 $oldParentObj = $self->ivShow('modelHash', $obj->parent);
9022 if ($oldParentObj->ivExists('childHash', $objNum)) {
9023  
9024 $oldParentObj->ivDelete('childHash', $objNum);
9025 }
9026  
9027 # Set the object to have no parent
9028 $obj->ivUndef('parent');
9029  
9030 } else {
9031  
9032 # Remove the object's current parent, if there is one
9033 if ($obj->parent) {
9034  
9035 $oldParentObj = $self->ivShow('modelHash', $obj->parent);
9036 if ($oldParentObj->ivExists('childHash', $objNum)) {
9037  
9038 $oldParentObj->ivDelete('childHash', $objNum);
9039 }
9040 }
9041  
9042 # Set the new parent
9043 $obj->ivPoke('parent', $parentNum);
9044 # Inform the parent it has acquired a child
9045 $parentObj->ivAdd('childHash', $objNum, undef);
9046 }
9047  
9048 # Update any GA::Win::Map objects using this world model (if allowed)
9049 if ($updateFlag) {
9050  
9051 foreach my $mapWin ($self->collectMapWins()) {
9052  
9053 if ($obj->category eq 'room') {
9054  
9055 # Redraw the room
9056 $mapWin->markObjs('room', $obj);
9057 $mapWin->doDraw();
9058 }
9059 }
9060 }
9061  
9062 return 1;
9063 }
9064  
9065 sub addChild {
9066  
9067 # Can be called by anything
9068 # Adds a child object to a parent model object. Should not be used to add rooms to a region
9069 # (call $self->addRoom for that), or to add non-model objects to a room (call
9070 # $self->addRoomChildren for that), or to add an exit (call->addExit for that)
9071 # Checks the rules for setting parents/children, and performs the operation
9072 #
9073 # Expected arguments
9074 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
9075 # should be updated now, FALSE if not (in which case, they can be
9076 # updated later by the calling function, when it is ready)
9077 # $objNum - The world model number of the object to modify
9078 # $childNum - The child object to add to the parent
9079 #
9080 # Return values
9081 # 'undef' on improper arguments, if either object does not exist or if the operation fails
9082 # 1 otherwise
9083  
9084 my ($self, $updateFlag, $objNum, $childNum, $check) = @_;
9085  
9086 # Local variables
9087 my ($obj, $childObj, $oldParentObj);
9088  
9089 # Check for improper arguments
9090 if (
9091 ! defined $updateFlag || ! defined $objNum || ! defined $childNum || defined $check
9092 ) {
9093 return $axmud::CLIENT->writeImproper($self->_objClass . '->addChild', @_);
9094 }
9095  
9096 # Find the corresponding model objects
9097 $obj = $self->ivShow('modelHash', $objNum);
9098 if (! $obj) {
9099  
9100 return undef;
9101 }
9102  
9103 $childObj = $self->ivShow('modelHash', $childNum);
9104 if (! $childObj) {
9105  
9106 return undef;
9107 }
9108  
9109 # Check the rules for adding children (see the comments in $self->new)
9110 if (
9111 # General rules
9112 (
9113 $obj->category eq 'room'
9114 && ($childObj->category eq 'region' || $childObj->category eq 'room')
9115 )
9116 # Rules for this function
9117 || ($obj->category eq 'region' && $childObj->category eq 'room')
9118 # Object cannot be its own child
9119 || ($obj eq $childObj)
9120 ) {
9121 return undef;
9122 }
9123  
9124 # If the child object already has a parent, remove the parent
9125 if ($childObj->parent) {
9126  
9127 $oldParentObj = $self->ivShow('modelHash', $childObj->parent);
9128 if ($oldParentObj->ivExists('childHash', $childNum)) {
9129  
9130 $oldParentObj->ivDelete('childHash', $childNum);
9131 }
9132 }
9133  
9134 # Add the child object to the new parent
9135 $childObj->ivPoke('parent', $objNum);
9136 $obj->ivAdd('childHash', $childNum, undef);
9137  
9138 # Update any GA::Win::Map objects using this world model (if allowed)
9139 if ($updateFlag) {
9140  
9141 foreach my $mapWin ($self->collectMapWins()) {
9142  
9143 if ($obj->category eq 'room') {
9144  
9145 # Redraw the room
9146 $mapWin->markObjs('room', $obj);
9147 $mapWin->doDraw();
9148 }
9149 }
9150 }
9151  
9152 return 1;
9153 }
9154  
9155 sub removeChild {
9156  
9157 # Can be called by anything
9158 # Removes a child object from a parent model object. Should not be used to remove rooms from
9159 # a region (call $self->deleteRooms for that) or to remove exits (call $self->deleteExits
9160 # for that)
9161 # Checks the rules for setting parents/children, and performs the operation
9162 #
9163 # Expected arguments
9164 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
9165 # should be updated now, FALSE if not (in which case, they can be
9166 # updated later by the calling function, when it is ready)
9167 # $objNum - The world model number of the object to modify
9168 #
9169 # Optional arguments
9170 # $childNum - The child object to remove from the parent. If 'undef', all children
9171 # are removed
9172 #
9173 # Return values
9174 # 'undef' on improper arguments or if child object can't be removed
9175 # 1 otherwise
9176  
9177 my ($self, $updateFlag, $objNum, $childNum, $check) = @_;
9178  
9179 # Local variables
9180 my (
9181 $obj, $childObj,
9182 @childList,
9183 );
9184  
9185 # Check for improper arguments
9186 if (
9187 ! defined $updateFlag || ! defined $objNum || defined $check
9188 ) {
9189 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeChild', @_);
9190 }
9191  
9192 # Find the corresponding model objects
9193 $obj = $self->ivShow('modelHash', $objNum);
9194 if (! $obj) {
9195  
9196 return undef;
9197 }
9198  
9199 if ($childNum) {
9200  
9201 # Remove a single child
9202 $childObj = $self->ivShow('modelHash', $childNum);
9203 if (! $childObj) {
9204  
9205 return undef;
9206  
9207 } else {
9208  
9209 push (@childList, $childObj);
9210 }
9211  
9212 } else {
9213  
9214 # Remove all children
9215 foreach my $number ($obj->ivKeys('childHash')) {
9216  
9217 $childObj = $self->ivShow('modelHash', $number);
9218  
9219 if ($obj->category eq 'region' && $childObj->category eq 'room') {
9220  
9221 # This function can't be used to remove rooms from a region
9222 return undef;
9223  
9224 } else {
9225  
9226 push (@childList, $childObj);
9227 }
9228 }
9229 }
9230  
9231 # Remove each child in turn
9232 foreach $childObj (@childList) {
9233  
9234 # Remove the child object from the parent
9235 $childObj->ivUndef('parent');
9236 $obj->ivDelete('childHash', $childNum);
9237 }
9238  
9239 # Update any GA::Win::Map objects using this world model (if allowed)
9240 if ($updateFlag) {
9241  
9242 # We only need to redraw rooms on the currently visible regionmap and level
9243 foreach my $mapWin ($self->collectMapWins()) {
9244  
9245 if ($obj->category eq 'room') {
9246  
9247 # Redraw the room
9248 $mapWin->markObjs('room', $obj);
9249 $mapWin->doDraw();
9250 }
9251 }
9252 }
9253  
9254 return 1;
9255 }
9256  
9257 sub convertCategory {
9258  
9259 # Called by GA::Cmd::AddMinionString->do or by any other function
9260 # Converts the category of a model object (or a non-model object); actually, it creates a
9261 # new model object (or non-model object) of the desired category, and preserves the values
9262 # stored in IVs (as far as possible)
9263 # Regions, rooms and exits can't be converted to another category (and objects can't be
9264 # converted to regions, rooms or exits)
9265 # Group 5 IVs are not converted; the new object will have default group 5 IVs
9266 #
9267 # Expected arguments
9268 # $session - The calling function's GA::Session
9269 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
9270 # should be updated now, FALSE if not (in which case, they can be
9271 # updated later by the calling function, when it is ready)
9272 # $oldObj - The existing model (or non-model) object
9273 # $newCategory - The category of the new object
9274 #
9275 # Return values
9276 # 'undef' on improper arguments
9277 # Otherwise, the blessed reference of the replacement object
9278  
9279 my ($self, $session, $updateFlag, $oldObj, $newCategory, $check) = @_;
9280  
9281 # Local variables
9282 my (
9283 $modelFlag, $package, $newObj, $parentObj,
9284 %childHash,
9285 );
9286  
9287 # Check for improper arguments
9288 if (
9289 ! defined $session || ! defined $updateFlag || ! defined $oldObj
9290 || ! defined $newCategory || defined $check
9291 ) {
9292 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertCategory', @_);
9293 }
9294  
9295 # Check that this category of object can be converted
9296 if ($oldObj->category eq 'region' || $newCategory eq 'region') {
9297  
9298 return $session->writeError(
9299 'Cannot convert to/from world model region objects',
9300 $self->_objClass . '->convertCategory',
9301 );
9302  
9303 } elsif ($oldObj->category eq 'room' || $newCategory eq 'room') {
9304  
9305 return $session->writeError(
9306 'Cannot convert to/from world model room objects',
9307 $self->_objClass . '->convertCategory',
9308 );
9309  
9310 } elsif ($oldObj->category eq 'exit' || $newCategory eq 'exit') {
9311  
9312 return $session->writeError(
9313 'Cannot convert to/from exit model objects',
9314 $self->_objClass . '->convertCategory',
9315 );
9316 }
9317  
9318 # Check that $newCategory is valid
9319 if (
9320 $newCategory ne 'weapon' && $newCategory ne 'armour' && $newCategory ne 'garment'
9321 && $newCategory ne 'char' && $newCategory ne 'minion' && $newCategory ne 'sentient'
9322 && $newCategory ne 'creature' && $newCategory ne 'portable'
9323 && $newCategory ne 'decoration' && $newCategory ne 'custom'
9324 ) {
9325 return $session->writeError(
9326 'Unrecognised world object category \'' . $newCategory . '\'',
9327 $self->_objClass . '->convertCategory',
9328 );
9329 }
9330  
9331 # To keep the code simple, mark whether the existing object is already in the world model,
9332 # or not
9333 if ($oldObj->number) {
9334 $modelFlag = TRUE;
9335 } else {
9336 $modelFlag = FALSE;
9337 }
9338  
9339 # Create the new model object
9340 $package = 'Games::Axmud::ModelObj::' . ucfirst($newCategory);
9341 $newObj = $package->new($session, $oldObj->name, $modelFlag, $oldObj->parent);
9342 if (! $newObj) {
9343  
9344 return undef;
9345 }
9346  
9347 # If the old object was in the model, remove it, and add the new object to the model (the
9348 # new object will almost certainly have a different model number)
9349 if ($modelFlag) {
9350  
9351 # Store the old object's children (if any), so they can be re-assigned to the new object
9352 %childHash = $oldObj->childHash;
9353  
9354 # Add the new object to the model
9355 if (! $self->addToModel($newObj)) {
9356  
9357 # Object could not be added
9358 return undef;
9359  
9360 } else {
9361  
9362 # Delete the old one
9363 $self->deleteObj(
9364 $session,
9365 FALSE, # Don't update Automapper windows yet
9366 $oldObj,
9367 );
9368 }
9369  
9370 # Reassign any children to the new object
9371 foreach my $childNum (keys %childHash) {
9372  
9373 $self->setParent(
9374 FALSE,
9375 $childNum,
9376 $newObj->number,
9377 );
9378 }
9379 }
9380  
9381 # For IVs that exist both in the original and new objects, transfer them
9382  
9383 # Group 1 IVs (only a few are object-specific)
9384 $newObj->ivPoke('privateHash', $oldObj->privateHash);
9385 $newObj->ivPoke('sourceCodePath', $oldObj->sourceCodePath);
9386 $newObj->ivPoke('notesList', $oldObj->notesList);
9387  
9388 # Group 2 IVs (exist in all objects convertable by this function)
9389 $newObj->ivPoke('noun', $oldObj->noun);
9390 $newObj->ivPoke('nounTag', $oldObj->nounTag);
9391 $newObj->ivPoke('otherNounList', $oldObj->otherNounList);
9392 $newObj->ivPoke('adjList', $oldObj->adjList);
9393 $newObj->ivPoke('pseudoAdjList', $oldObj->pseudoAdjList);
9394 $newObj->ivPoke('rootAdjList', $oldObj->rootAdjList);
9395 $newObj->ivPoke('unknownWordList', $oldObj->unknownWordList);
9396 $newObj->ivPoke('multiple', $oldObj->multiple);
9397 $newObj->ivPoke('baseString', $oldObj->baseString);
9398 $newObj->ivPoke('descrip', $oldObj->descrip);
9399  
9400 $newObj->ivPoke('container', $oldObj->container);
9401 $newObj->ivPoke('inventoryType', $oldObj->inventoryType);
9402  
9403 # Group 3 IVs
9404 if (
9405 (
9406 $oldObj->category eq 'char' || $oldObj->category eq 'minion'
9407 || $oldObj->category eq 'sentient' || $oldObj->category eq 'creature'
9408 ) && (
9409 $newCategory eq 'char' || $newCategory eq 'sentient' || $newCategory eq 'creature'
9410 )
9411 ) {
9412 $newObj->ivPoke('targetStatus', $oldObj->targetStatus);
9413 $newObj->ivPoke('targetType', $oldObj->targetType);
9414 $newObj->ivPoke('targetPath', $oldObj->targetPath);
9415 $newObj->ivPoke('explicitFlag', $oldObj->explicitFlag);
9416 $newObj->ivPoke('alreadyAttackedFlag', $oldObj->alreadyAttackedFlag);
9417 }
9418  
9419 # Group 4 IVs
9420 if (
9421 (
9422 $oldObj->category eq 'weapon' || $oldObj->category eq 'armour'
9423 || $oldObj->category eq 'garment' || $oldObj->category eq 'portable'
9424 || $oldObj->category eq 'decoration' || $oldObj->category eq 'custom'
9425 ) && (
9426 $newCategory eq 'weapon' || $newCategory eq 'armour' || $newCategory eq 'garment'
9427 || $newCategory eq 'portable' || $newCategory eq 'decoration'
9428 || $newCategory eq 'custom'
9429 )
9430 ) {
9431 $newObj->ivPoke('explicitFlag', $oldObj->explicitFlag);
9432 $newObj->ivPoke('weight', $oldObj->weight);
9433 $newObj->ivPoke('bonusHash', $oldObj->bonusHash);
9434 $newObj->ivPoke('condition', $oldObj->condition);
9435 $newObj->ivPoke('conditionChangeFlag', $oldObj->conditionChangeFlag);
9436 $newObj->ivPoke('fixableFlag', $oldObj->fixableFlag);
9437 $newObj->ivPoke('sellableFlag', $oldObj->sellableFlag);
9438 $newObj->ivPoke('buyValue', $oldObj->buyValue);
9439 $newObj->ivPoke('sellValue', $oldObj->sellValue);
9440 $newObj->ivPoke('exclusiveFlag', $oldObj->exclusiveFlag);
9441 $newObj->ivPoke('exclusiveHash', $oldObj->exclusiveHash);
9442 }
9443  
9444 # (Group 5 IVs are not converted)
9445  
9446 # Update any GA::Win::Map objects using this world model (if allowed)
9447 if ($newObj->parent) {
9448  
9449 $parentObj = $self->ivShow('modelHash', $newObj->parent);
9450 }
9451  
9452 if ($updateFlag && $parentObj && $parentObj->category eq 'room') {
9453  
9454 foreach my $mapWin ($self->collectMapWins()) {
9455  
9456 # Redraw the (parent) room
9457 $mapWin->markObjs('room', $parentObj);
9458 $mapWin->doDraw();
9459 }
9460 }
9461  
9462 # Operation complete
9463 return $newObj;
9464 }
9465  
9466 # Modify model objects - regions
9467  
9468 sub renameRegion {
9469  
9470 # Called by GA::Win::Map->renameRegionCallback
9471 # Renames an existing region
9472 #
9473 # Expected arguments
9474 # $regionmapObj - The GA::Obj::Regionmap corresponding to the region that must be
9475 # renamed
9476 # $newName - The new name for the region
9477 #
9478 # Return values
9479 # 'undef' on improper arguments or if a region named $newName already exists
9480 # 1 otherwise
9481  
9482 my ($self, $regionmapObj, $newName, $check) = @_;
9483  
9484 # Local variables
9485 my (
9486 $oldName, $regionObj,
9487 %redrawHash,
9488 );
9489  
9490 # Check for improper arguments
9491 if (! defined $regionmapObj || ! defined $newName || defined $check) {
9492  
9493 return $axmud::CLIENT->writeImproper($self->_objClass . '->renameRegion', @_);
9494 }
9495  
9496 # Check that a region with this name doesn't already exist
9497 if ($self->ivExists('regionmapHash', $newName)) {
9498  
9499 return undef;
9500 }
9501  
9502 # Give the regionmap object its new name (briefly storing the old one)
9503 $oldName = $regionmapObj->name;
9504 $regionmapObj->{_objName} = $newName;
9505 $regionmapObj->ivPoke('name', $newName);
9506  
9507 # Find the equivalent GA::ModelObj::Region, and give it the same new name
9508 $regionObj = $self->ivShow('modelHash', $regionmapObj->number);
9509 if ($regionObj) {
9510  
9511 $regionObj->{_objName} = $newName;
9512 $regionObj->ivPoke('name', $newName);
9513 }
9514  
9515 # Check all of this region's incoming region exits, updating their exit tags so that they
9516 # display the new region (but if the tags have been modified by the user, leave them
9517 # alone)
9518 foreach my $thisRegionmapObj ($self->ivValues('regionmapHash')) {
9519  
9520 # (Region exits can't lead to a destination room in their own region)
9521 if ($thisRegionmapObj ne $regionmapObj) {
9522  
9523 foreach my $exitNum ($thisRegionmapObj->ivKeys('regionExitHash')) {
9524  
9525 my ($exitObj, $destRegionNum, $destRegionObj, $defaultText, $roomObj);
9526  
9527 $destRegionNum = $thisRegionmapObj->ivShow('regionExitHash', $exitNum);
9528  
9529 # If the region exit leads to our newly-renamed region...
9530 if ($destRegionNum == $regionmapObj->number) {
9531  
9532 $exitObj = $self->ivShow('exitModelHash', $exitNum);
9533 $destRegionObj = $self->ivShow('modelHash', $destRegionNum);
9534  
9535 # Get the default text that would have been given to the exit's tag, before
9536 # its parent region was renamed
9537 $defaultText = $self->getExitTagText($exitObj, undef, $oldName);
9538 if ($exitObj->exitTag && $exitObj->exitTag eq $defaultText) {
9539  
9540 # The user has not modified the tag's default text, so modify it to show
9541 # the region's new name
9542 $self->applyExitTag(
9543 FALSE, # Don't update Automapper windows yet
9544 $exitObj,
9545 $thisRegionmapObj,
9546 undef,
9547 TRUE, # Override $self->updateExitTagFlag
9548 );
9549  
9550 # Mark the parent room to be redrawn (which redraws the exit). Use a
9551 # hash so that the same room isn't drawn twice
9552 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
9553 $redrawHash{$roomObj->number} = $roomObj;
9554 }
9555 }
9556 }
9557 }
9558 }
9559  
9560 # Delete the old entry in the hash of regionmaps, and replace it with a new one
9561 $self->ivDelete('regionmapHash', $oldName);
9562 $self->ivAdd('regionmapHash', $newName, $regionmapObj);
9563  
9564 # All of this regionmap's labels must be updated
9565 foreach my $labelObj ($regionmapObj->ivValues('gridLabelHash')) {
9566  
9567 $labelObj->ivPoke('region', $regionmapObj->name);
9568 }
9569  
9570 # Update each Automapper window
9571 foreach my $mapWin ($self->collectMapWins()) {
9572  
9573 my (
9574 $parchmentObj,
9575 @redrawList,
9576 );
9577  
9578 # Update the parchment object for this region, if it exists
9579 $parchmentObj = $mapWin->ivShow('parchmentHash', $oldName);
9580 if ($parchmentObj) {
9581  
9582 $mapWin->del_parchment($oldName);
9583 $parchmentObj->ivPoke('name', $newName);
9584 $mapWin->add_parchment($parchmentObj);
9585 }
9586  
9587 # Redraw the list of regions in the treeview
9588 $mapWin->resetTreeView();
9589  
9590 # Reset the Automapper window's title bar
9591 $mapWin->setWinTitle();
9592  
9593 # If there are any region exits whose exit tags have been modified, redraw them
9594 if (%redrawHash) {
9595  
9596 foreach my $thisRoomObj (values %redrawHash) {
9597  
9598 push (@redrawList, 'room', $thisRoomObj);
9599 }
9600  
9601 $mapWin->markObjs(@redrawList);
9602 $mapWin->doDraw();
9603 }
9604  
9605 # The automapper windows' list of recent regions must be updated
9606 $mapWin->set_recentRegion($oldName, $newName);
9607 }
9608  
9609 return 1;
9610 }
9611  
9612 sub resetRegionCounts {
9613  
9614 # Called by GA::Win::Map->enableRegionsColumn
9615 # Resets the living/non-living objects counts for an existing region and redraws the region
9616 #
9617 # Expected arguments
9618 # $regionmapObj - The GA::Obj::Regionmap whose counts should be reset
9619 #
9620 # Return values
9621 # 'undef' on improper arguments
9622 # 1 otherwise
9623  
9624 my ($self, $regionmapObj, $check) = @_;
9625  
9626 # Check for improper arguments
9627 if (! defined $regionmapObj || defined $check) {
9628  
9629 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRegionCounts', @_);
9630 }
9631  
9632 # Reset the regionmap's IVs
9633 $regionmapObj->resetCounts();
9634  
9635 # Update each Automapper window
9636 foreach my $mapWin ($self->collectMapWins()) {
9637  
9638 if ($mapWin->currentRegionmap eq $regionmapObj) {
9639  
9640 # Redraw (all) regions to remove the displayed counts
9641 $mapWin->redrawRegions();
9642 }
9643 }
9644  
9645 return 1;
9646 }
9647  
9648 sub emptyRegion {
9649  
9650 # Called by GA::Win::Map->emptyRegionCallback
9651 # Empties an existing region of all its child model objects. Also empties the corresponding
9652 # regionmap
9653 #
9654 # Expected arguments
9655 # $session - The calling function's GA::Session
9656 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
9657 # should be updated now, FALSE if not (in which case, they can be
9658 # updated later by the calling function, when it is ready)
9659 # $regionObj - The region object to empty
9660 #
9661 # Return values
9662 # 'undef' on improper arguments
9663 # 1 otherwise
9664  
9665 my ($self, $session, $updateFlag, $regionObj, $check) = @_;
9666  
9667 # Local variables
9668 my (
9669 $regionmapObj,
9670 @roomList, @otherList,
9671 );
9672  
9673 # Check for improper arguments
9674 if (! defined $session || ! defined $updateFlag || ! defined $regionObj || defined $check) {
9675  
9676 return $axmud::CLIENT->writeImproper($self->_objClass . '->emptyRegion', @_);
9677 }
9678  
9679 # So that we only have to call a function once, split the region's children into one list of
9680 # rooms and another list of everything else. However, child regions should not be deleted
9681 foreach my $childNum ($regionObj->ivKeys('childHash')) {
9682  
9683 my $childObj = $self->ivShow('modelHash', $childNum);
9684  
9685 if ($childObj->category eq 'room') {
9686 push (@roomList, $childObj);
9687 } elsif ($childObj->category ne 'region') {
9688 push (@otherList, $childObj);
9689 }
9690 }
9691  
9692 # Delete all rooms (which deletes all the rooms' child objects and exits)
9693 $self->deleteRooms(
9694 $session,
9695 FALSE, # Don't update Automapper windows yet
9696 @roomList,
9697 );
9698  
9699 # Delete everything else (all non-room objects which are children of the region itself)
9700 foreach my $otherObj (@otherList) {
9701  
9702 $self->deleteObj(
9703 $session,
9704 FALSE,
9705 $otherObj, # Don't update Automapper windows yet
9706 );
9707 }
9708  
9709 # Get the corresponding regionmap and empty it
9710 $regionmapObj = $self->ivShow('regionmapHash', $regionObj->name);
9711 $regionmapObj->emptyGrid();
9712  
9713 # Update any GA::Win::Map objects using this world model (if allowed)
9714 if ($updateFlag) {
9715  
9716 foreach my $mapWin ($self->collectMapWins()) {
9717  
9718 if (
9719 $mapWin->currentRegionmap
9720 && $mapWin->currentRegionmap eq $regionmapObj
9721 ) {
9722 # Redraw (all) regions. This region will be empty, and any connecting regions
9723 # will have their region exits drawn correctly
9724 $mapWin->redrawRegions();
9725 }
9726 }
9727 }
9728  
9729 return 1
9730 }
9731  
9732 sub connectRegionBrokenExit {
9733  
9734 # Called by GA::Win::Map->connectExitToRoom (but is available to other code, if necessary)
9735 # After the user chooses the 'connect to click' menu item and clicks on a room, connects the
9736 # selected exit to the clicked room, marking it as a broken or region exit if necessary
9737 # Also prompts the user to ask if they'd like to create an exit in the reverse direction
9738 #
9739 # Expected arguments
9740 # $session - The calling function's GA::Session
9741 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
9742 # be updated now, FALSE if not (in which case, they can be updated later
9743 # by the calling function, when it is ready)
9744 # $roomObj - The clicked GA::ModelObj::Room object
9745 # $exitObj - The GA::Exit::Obj object to connect to the room
9746 # $type - What type of exit to create - set to 'broken' or 'region'. If set to
9747 # 'broken', the function checks that it really is a broken exit
9748 #
9749 # Return values
9750 # 'undef' on improper arguments
9751 # 1 otherwise
9752  
9753 my ($self, $session, $updateFlag, $roomObj, $exitObj, $type, $check) = @_;
9754  
9755 # Local variables
9756 my (
9757 $twinExitObj, $parentRoomObj, $parentRegionObj, $twinDir, $twinMapDir, $oppExitNum,
9758 $oppExitObj, $useExitObj, $choice, $forceOneWayFlag, $pairedTwinExit, $pairedTwinRoom,
9759 $pairedTwinRegion, $regionFlag, $specialBrokenFlag,
9760 @redrawList, @exitList, @comboList,
9761 %comboHash,
9762 );
9763  
9764 # Check for improper arguments
9765 if (
9766 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
9767 || ! defined $type || defined $check
9768 ) {
9769 return $axmud::CLIENT->writeImproper(
9770 $self->_objClass . '->connectRegionBrokenExit',
9771 @_,
9772 );
9773 }
9774  
9775 # This function uses 'dialogue' windows. While the 'dialogue' window is open, we don't want
9776 # the GA::Session->spinMaintainLoop to call $self->updateRegionPaths, so we set this
9777 # flag to TRUE. At the end of the function, we set it back to FALSE, so that
9778 # ->updateRegionPaths can be called as normal
9779 $self->ivPoke('updateDelayFlag', TRUE);
9780  
9781 # Before doing anything, make sure the exit doesn't have a twin and/or shadow exit (both of
9782 # which will be obsolete after the connection operation)
9783 if ($exitObj->twinExit) {
9784  
9785 # (The call to ->abandonTwinExit sets $self->updateBoundaryHash, ->updatePathHash)
9786 $self->abandonTwinExit(
9787 FALSE, # Don't update Automapper windows yet
9788 $exitObj,
9789 );
9790 }
9791  
9792 if ($exitObj->shadowExit) {
9793  
9794 # (The call to ->abandonShadowExit sets $self->updateBoundaryHash, ->updatePathHash)
9795 $self->abandonShadowExit($exitObj);
9796 }
9797  
9798 # If the exit currently has a destination room, that room should be redrawn
9799 if ($exitObj->destRoom) {
9800  
9801 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->destRoom));
9802 }
9803  
9804 # Connect the exit to the specified room
9805 $self->connectRooms(
9806 $session,
9807 FALSE, # Don't update Automapper windows yet
9808 $self->ivShow('modelHash', $exitObj->parent),
9809 $roomObj,
9810 $exitObj->dir,
9811 $exitObj->mapDir, # May be 'undef'
9812 $exitObj,
9813 );
9814  
9815 # The call to ->connectRooms may have allocated a twin; if so, get the blessed reference
9816 if ($exitObj->twinExit) {
9817  
9818 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
9819 }
9820  
9821 # While we're at it, get the exit's parent room
9822 $parentRoomObj = $self->ivShow('modelHash', $exitObj->parent);
9823 $parentRegionObj = $self->ivShow('modelHash', $parentRoomObj->parent);
9824  
9825 # Mark the exit as a broken or a region exit
9826 if ($type eq 'broken') {
9827  
9828 # The rooms might - by coincidence - be aligned, so that we don't have to mark it as a
9829 # broken exit. Mark it as broken for now, and check towards the end of the function
9830 $exitObj->ivPoke('brokenFlag', TRUE);
9831 $self->checkBentExit($exitObj, $parentRoomObj);
9832  
9833 $exitObj->ivPoke('regionFlag', FALSE);
9834 $self->cancelExitTag(
9835 FALSE, # Don't update Automapper windows yet
9836 $exitObj,
9837 $self->ivShow('regionmapHash', $parentRegionObj->name),
9838 );
9839  
9840 if ($twinExitObj) {
9841  
9842 $twinExitObj->ivPoke('brokenFlag', TRUE);
9843 $self->checkBentExit($twinExitObj);
9844  
9845 $twinExitObj->ivPoke('regionFlag', FALSE);
9846 $self->cancelExitTag(
9847 FALSE, # Don't update Automapper windows yet
9848 $twinExitObj,
9849 );
9850 }
9851  
9852 } else {
9853  
9854 # Likewise, mark the exit (and its twin, if there is one) as a region exit for now
9855 $exitObj->ivPoke('regionFlag', TRUE);
9856 $self->applyExitTag(
9857 FALSE, # Don't update Automapper windows yet
9858 $exitObj,
9859 $self->ivShow('regionmapHash', $parentRegionObj->name),
9860 );
9861  
9862 $exitObj->ivPoke('brokenFlag', FALSE);
9863 $exitObj->ivPoke('bentFlag', FALSE);
9864 $exitObj->ivEmpty('bendOffsetList');
9865  
9866 if ($twinExitObj) {
9867  
9868 $twinExitObj->ivPoke('regionFlag', TRUE);
9869 $self->applyExitTag(
9870 FALSE, # Don't update Automapper windows yet
9871 $twinExitObj,
9872 undef, # Called function finds the parent regionmap
9873 undef, # No custom text
9874 # Force ->applyExitTag to replace the existing text, in case a 1-way exit has
9875 # just become a 2-way exit (etc)
9876 TRUE,
9877 );
9878  
9879 $twinExitObj->ivPoke('brokenFlag', FALSE);
9880 $twinExitObj->ivPoke('bentFlag', FALSE);
9881 $twinExitObj->ivEmpty('bendOffsetList');
9882 }
9883 }
9884  
9885 # See if the exit's nominal direction can be converted into an opposite direction. Use mode
9886 # 0 (do not abbreviate / if there is more than one opposite direction, use the first one)
9887 ($twinDir) = $self->reversePath(
9888 $session,
9889 'no_abbrev',
9890 $exitObj->dir,
9891 );
9892  
9893 # Also get the opposite of the exit's map direction (a primary direction), but not for
9894 # unallocated exits
9895 if (
9896 $exitObj->mapDir
9897 && ($exitObj->drawMode eq 'primary' || $exitObj->drawMode eq 'perm_alloc')
9898 ) {
9899 $twinMapDir = $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir);
9900 }
9901  
9902 # If the exit isn't already a twin (the call to ->connectRooms earlier in this function
9903 # might have allocated a twin) and if the destination room has an exit which might be a
9904 # twin exit, ask the user whether they should be paired
9905 if (
9906 ! $twinExitObj
9907 && (
9908 ($twinDir && $twinDir ne $exitObj->dir)
9909 || $twinMapDir
9910 )
9911 ) {
9912 # Does the clicked room already have an exit in the opposite direction, that is probably
9913 # the specified exit's twin exit? If so, is it an 'incomplete' exit that's ready to be
9914 # connected to something?
9915 if ($twinDir && $roomObj->ivExists('exitNumHash', $twinDir)) {
9916  
9917 $oppExitNum = $roomObj->ivShow('exitNumHash', $twinDir);
9918 $oppExitObj = $self->ivShow('exitModelHash', $oppExitNum);
9919  
9920 } elsif ($twinMapDir) {
9921  
9922 # Check map directions
9923 @exitList = $roomObj->ivValues('exitNumHash');
9924 OUTER: foreach my $exitNum (@exitList) {
9925  
9926 my ($thisExitObj, $dir, $string);
9927  
9928 $thisExitObj = $self->ivShow('exitModelHash', $exitNum);
9929 if ($thisExitObj->mapDir && $thisExitObj->mapDir eq $twinMapDir) {
9930  
9931 $oppExitNum = $exitNum;
9932 $oppExitObj = $thisExitObj;
9933 last OUTER;
9934 }
9935 }
9936 }
9937  
9938 if ($oppExitObj) {
9939  
9940 if (
9941 $oppExitObj->exitOrnament eq 'impass'
9942 || $oppExitObj->exitOrnament eq 'mystery'
9943 || $oppExitObj->randomType ne 'none'
9944 ) {
9945 # The opposite exit is impassable, so it can't be made a twin (or it is a random
9946 # exit, and it should remain a random exit)
9947 # Therefore, $exitObj must be made one-way
9948 $forceOneWayFlag = TRUE;
9949 }
9950  
9951 if (
9952 $session->mapWin
9953 && ! $oppExitObj->destRoom
9954 && $oppExitObj->randomType eq 'none'
9955 && ! $forceOneWayFlag
9956 ) {
9957 # Prompt the user to modify it (but only if the calling session actually has an
9958 # automapper window open)
9959 $choice = $session->mapWin->showMsgDialogue(
9960 'Set up twin exit',
9961 'question',
9962 'Would you like to modify the clicked room\'s existing \'' . $exitObj->dir
9963 . '\' exit to lead back to the original room?',
9964 'yes-no',
9965 'yes',
9966 );
9967  
9968 if ($choice eq 'yes') {
9969  
9970 # Mark this exit to be used as a twin exit (rest of the code is below)
9971 $useExitObj = $oppExitObj;
9972 }
9973 }
9974  
9975 # Does the clicked room have any exits at all?
9976 } elsif ($roomObj->exitNumHash) {
9977  
9978 @exitList = $roomObj->ivValues('exitNumHash');
9979 foreach my $exitNum (@exitList) {
9980  
9981 my ($thisExitObj, $dir, $string);
9982  
9983 $thisExitObj = $self->ivShow('exitModelHash', $exitNum);
9984  
9985 # Only add incomplete exits that don't have shadow exits
9986 if (
9987 ! $thisExitObj->destRoom
9988 && $thisExitObj->randomType eq 'none'
9989 && ! $thisExitObj->shadowExit
9990 ) {
9991 $dir = $thisExitObj->dir;
9992 $string = $dir . ' #' . $roomObj->ivShow('exitNumHash', $dir);
9993 push (@comboList, $string);
9994 $comboHash{$string} = $roomObj->ivShow('exitNumHash', $dir);
9995 }
9996 }
9997  
9998 if ($session->mapWin && @comboList) {
9999  
10000 # Prompt the user for an exit
10001 $choice = $session->mapWin->showComboDialogue(
10002 'Set up twin exit',
10003 'Choose one of the clicked room\'s existing exits to lead back to the'
10004 . ' original room (or click the \'Cancel\' button to mark this exit as'
10005 . ' one-way)',
10006 \@comboList,
10007 );
10008  
10009 if ($choice) {
10010  
10011 # Modify the existing exit (rest of the code is below)
10012 $useExitObj = $self->ivShow('exitModelHash', $comboHash{$choice});
10013  
10014 } else {
10015  
10016 # We need to mark the exit as one-way shortly
10017 $forceOneWayFlag = TRUE;
10018 }
10019 }
10020 }
10021 }
10022  
10023 if ($useExitObj) {
10024  
10025 # (A two-way exit)
10026 $twinExitObj = $useExitObj;
10027 $regionFlag = $twinExitObj->regionFlag;
10028  
10029 # Set the twin exit's IVs
10030 $twinExitObj->ivPoke('destRoom', $exitObj->parent);
10031 $twinExitObj->ivPoke('twinExit', $exitObj->number);
10032 # Make it the selected exit's twin
10033 $exitObj->ivPoke('twinExit', $twinExitObj->number);
10034 # Make sure neither room has either of these exits still marked as uncertain
10035 if ($roomObj->ivExists('uncertainExitHash', $exitObj->number)) {
10036  
10037 $roomObj->ivDelete('uncertainExitHash', $exitObj->number);
10038 }
10039  
10040 if ($parentRoomObj->ivExists('uncertainExitHash', $twinExitObj->number)) {
10041  
10042 $parentRoomObj->ivDelete('uncertainExitHash', $twinExitObj->number);
10043 }
10044  
10045 # The call to ->connectRooms may have marked one of the rooms as one-way; if so, the
10046 # exit now loses its one-way status
10047 $exitObj->ivPoke('oneWayFlag', FALSE);
10048 $exitObj->ivPoke('oneWayDir', undef);
10049 $twinExitObj->ivPoke('oneWayFlag', FALSE);
10050 $twinExitObj->ivPoke('oneWayDir', undef);
10051  
10052 # Deal with broken/region exits
10053 if ($type eq 'broken') {
10054  
10055 $twinExitObj->ivPoke('brokenFlag', TRUE);
10056  
10057 # Special case: if an exit whose ->mapDir is up or down is twinned with an exit
10058 # whose ->mapDir is not up or down, then these are definitely unbendable broken
10059 # exits (trying to draw them as normal exits or bent broken exits causes all sorts
10060 # of problems)
10061 if (
10062 $exitObj->mapDir
10063 && $twinExitObj->mapDir
10064 && (
10065 (
10066 ($exitObj->mapDir eq 'up' || $exitObj->mapDir eq 'down')
10067 && $twinExitObj->mapDir ne 'up'
10068 && $twinExitObj->mapDir ne 'down'
10069 ) || (
10070 ($twinExitObj->mapDir eq 'up' || $twinExitObj->mapDir eq 'down')
10071 && $exitObj->mapDir ne 'up'
10072 && $exitObj->mapDir ne 'down'
10073 )
10074 )
10075 ) {
10076 $specialBrokenFlag = TRUE;
10077 $exitObj->ivPoke('bentFlag', FALSE);
10078 $exitObj->ivEmpty('bendOffsetList');
10079 $twinExitObj->ivPoke('bentFlag', FALSE);
10080 $twinExitObj->ivEmpty('bendOffsetList');
10081  
10082 } else {
10083  
10084 $self->checkBentExit($twinExitObj);
10085 }
10086  
10087 $twinExitObj->ivPoke('regionFlag', FALSE);
10088 $self->cancelExitTag(
10089 FALSE, # Don't update Automapper windows yet
10090 $twinExitObj,
10091 );
10092  
10093 } else {
10094  
10095 $twinExitObj->ivPoke('brokenFlag', FALSE);
10096 $twinExitObj->ivPoke('bentFlag', FALSE);
10097 $twinExitObj->ivEmpty('bendOffsetList');
10098  
10099 $twinExitObj->ivPoke('regionFlag', TRUE);
10100 $self->applyExitTag(
10101 FALSE, # Don't update Automapper windows yet
10102 $twinExitObj,
10103 undef, # Called function finds the parent regionmap
10104 undef, # No custom text
10105 # Force ->applyExitTag to replace the existing text, in case a 1-way exit has
10106 # just become a 2-way exit (etc)
10107 TRUE,
10108 );
10109 }
10110  
10111 # Mark the twin exit (and its parent room) to be drawn a different colour (ignored for
10112 # bent broken exits)
10113 $pairedTwinExit = $twinExitObj;
10114 $pairedTwinRoom = $self->ivShow('modelHash', $twinExitObj->parent);
10115 $pairedTwinRegion = $self->ivShow('modelHash', $pairedTwinRoom->parent);
10116  
10117 # Any region paths using the exits will have to be updated
10118 $self->ivAdd('updatePathHash', $exitObj->number, $parentRegionObj->name);
10119 if ($regionFlag || $exitObj->regionFlag) {
10120  
10121 $self->ivAdd('updateBoundaryHash', $exitObj->number, $parentRegionObj->name);
10122 }
10123  
10124 $self->ivAdd('updatePathHash', $twinExitObj->number, $pairedTwinRegion->name);
10125 if ($regionFlag || $twinExitObj->regionFlag) {
10126  
10127 $self->ivAdd('updateBoundaryHash', $twinExitObj->number, $pairedTwinRegion->name);
10128 }
10129  
10130 } else {
10131  
10132 # (A one-way or uncertain exit)
10133 if ($forceOneWayFlag) {
10134  
10135 # The user declined to connect this exit to an available opposite exit. This exit
10136 # would ordinarily be marked as 'uncertain', but now it should be marked as
10137 # one-way
10138 $exitObj->ivPoke('oneWayFlag', TRUE);
10139 # The default incoming direction (where the exit touches its destination room) is
10140 # the opposite of ->mapDir
10141 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as
10142 # an emergency default value for ->mapDir
10143 if ($exitObj->mapDir) {
10144  
10145 $exitObj->ivPoke(
10146 'oneWayDir',
10147 $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir),
10148 );
10149  
10150 } else {
10151  
10152 # Emergency default
10153 $exitObj->ivPoke('oneWayDir', 'north');
10154 }
10155  
10156 if ($roomObj->ivExists('uncertainExitHash', $exitObj->number)) {
10157  
10158 $roomObj->ivDelete('uncertainExitHash', $exitObj->number);
10159 }
10160  
10161 $roomObj->ivAdd('oneWayExitHash', $exitObj->number, undef);
10162 }
10163  
10164 # Any region paths using the exit will have to be updated
10165 $self->ivAdd('updatePathHash', $exitObj->number, $parentRegionObj->name);
10166 if ($regionFlag || $exitObj->regionFlag) {
10167  
10168 $self->ivAdd('updateBoundaryHash', $exitObj->number, $parentRegionObj->name);
10169 }
10170 }
10171  
10172 # If the exit has been marked as a broken exit, check whether the exit is in fact aligned
10173 # with its destination room and, if so, remove its broken exit status
10174 if (
10175 $type eq 'broken'
10176 && ! $specialBrokenFlag
10177 && $self->checkRoomAlignment($session, $exitObj)
10178 ) {
10179 $self->unsetBrokenExit(
10180 FALSE, # Don't update Automapper windows
10181 $exitObj,
10182 undef, # $exitObj's parent region not immediately available
10183 );
10184  
10185 if ($twinExitObj) {
10186  
10187 $self->unsetBrokenExit(
10188 FALSE, # Don't update Automapper windows
10189 $twinExitObj,
10190 undef,
10191 );
10192 }
10193 }
10194  
10195 # Update any GA::Win::Map objects using this world model (if allowed)
10196 if ($updateFlag) {
10197  
10198 push (@redrawList,
10199 'room', $roomObj,
10200 'room', $parentRoomObj,
10201 );
10202  
10203 # Only draw a paired twin room (and its exit) a special colour, if the exit is a normal
10204 # (unbent) broken exit or a region exit - the special colour is only for exits not
10205 # drawn with a line
10206 if (
10207 $pairedTwinRoom
10208 && (
10209 (! $pairedTwinExit->brokenFlag && ! $pairedTwinExit->regionFlag)
10210 || ($pairedTwinExit->brokenFlag && $pairedTwinExit->bentFlag)
10211 )
10212 ) {
10213 $pairedTwinRoom = undef;
10214 }
10215  
10216 # If the paired twin room is still to be drawn a different colour, mark it to be
10217 # redrawn
10218 if ($pairedTwinRoom) {
10219  
10220 push (@redrawList, 'room', $pairedTwinRoom);
10221 }
10222  
10223 foreach my $mapWin ($self->collectMapWins()) {
10224  
10225 # Mark the paired room/exit (if set) to be drawn a different colour
10226 if ($pairedTwinRoom) {
10227  
10228 $mapWin->set_pairedTwinRoom($pairedTwinRoom);
10229 $mapWin->set_pairedTwinExit($pairedTwinExit);
10230 }
10231  
10232 # Redraw affected rooms immediately
10233 $mapWin->markObjs(@redrawList);
10234 $mapWin->doDraw();
10235 }
10236 }
10237  
10238 # Allow $self->updateRegionPaths to be called again
10239 $self->ivPoke('updateDelayFlag', FALSE);
10240  
10241 return 1;
10242 }
10243  
10244 # Modify model objects - rooms
10245  
10246 sub updateRegion {
10247  
10248 # Can be called by anything to force any Automapper windows to redraw regions (though at the
10249 # moment, only code in 'edit' windows calls this function)
10250 #
10251 # Expected arguments
10252 # (none besides $self)
10253 #
10254 # Optional arguments
10255 # $region - The name of a regionmap. If specified, only this region is redrawn in
10256 # every Automapper window (but if it's not already drawn, even partially,
10257 # it's not redrawn). If not specified, all drawn regions in each
10258 # Automapper window are redrawn
10259 #
10260 # Return values
10261 # 'undef' on improper arguments or if the specified region doesn't exist
10262 # 1 otherwise
10263  
10264 my ($self, $region, $check) = @_;
10265  
10266 # Local variables
10267 my $regionmapObj;
10268  
10269 # Check for improper arguments
10270 if (defined $check) {
10271  
10272 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRegion', @_);
10273 }
10274  
10275 if ($region) {
10276  
10277 # Find the equivalent regionmap
10278 $regionmapObj = $self->ivShow('regionmapHash', $region);
10279 if (! $regionmapObj) {
10280  
10281 # Nothing more we can do
10282 return undef;
10283 }
10284 }
10285  
10286 # Update each Automapper window in turn
10287 foreach my $mapWin ($self->collectMapWins()) {
10288  
10289 if (! $regionmapObj) {
10290  
10291 # Redraw all drawn regions
10292 $mapWin->redrawRegions();
10293  
10294 } elsif ($mapWin->ivExists('parchmentHash', $regionmapObj->name)) {
10295  
10296 # Redraw the specified region (if it's drawn in this automapper window). The TRUE
10297 # argument means 'don't redraw other regions'
10298 $mapWin->redrawRegions($regionmapObj, TRUE);
10299 }
10300 }
10301  
10302 return 1;
10303 }
10304  
10305 sub updateMaps {
10306  
10307 # Can be called by anything in the automapper object (GA::Obj::Map) and the Automapper
10308 # window (GA::Win::Map) to update every Automapper window using this world model
10309 # Usually called after other calls to this world model object, in which the $updateFlag
10310 # argument was set to FALSE - the calling function is now ready for the Automapper windows
10311 # to be updated
10312 #
10313 # Expected arguments
10314 # (none besides $self)
10315 #
10316 # Optional arguments
10317 # @list - A list to send to each Automapper window's ->markObjs, in the form
10318 # (type, object, type, object...)
10319 # - If it's an empty list, nothing is marked to be drawn; GA::Win::Map->doDraw
10320 # is still called in each automapper window, in the expectation that
10321 # something has already been marked to be drawn
10322 #
10323 # Return values
10324 # 'undef' on improper arguments
10325 # 1 otherwise
10326  
10327 my ($self, @list) = @_;
10328  
10329 # (No improper arguments to check)
10330  
10331 foreach my $mapWin ($self->collectMapWins()) {
10332  
10333 if (@list) {
10334  
10335 $mapWin->markObjs(@list);
10336 }
10337  
10338 $mapWin->doDraw();
10339 }
10340  
10341 return 1;
10342 }
10343  
10344 sub updateMapMenuToolbars {
10345  
10346 # Can be called by anything in the automapper object (GA::Obj::Map) and the Automapper
10347 # window (GA::Win::Map) to update every Automapper window using this world model
10348 # Also called by the painter's edit window, when ->saveChanges is applied
10349 # Redraws the menu bars and/or toolbars in all automapper windows using this world model
10350 #
10351 # Expected arguments
10352 # (none besides $self)
10353 #
10354 # Return values
10355 # 'undef' on improper arguments
10356 # 1 otherwise
10357  
10358 my ($self, $check) = @_;
10359  
10360 # Check for improper arguments
10361 if (defined $check) {
10362  
10363 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateMapMenuToolbars', @_);
10364 }
10365  
10366 foreach my $mapWin ($self->collectMapWins()) {
10367  
10368 $mapWin->redrawWidgets('menu_bar', 'toolbar');
10369 }
10370  
10371 return 1;
10372 }
10373  
10374 sub updateMapExit {
10375  
10376 # Called by several of this object's functions to update a single exit (and its twin) in
10377 # every Automapper window using this world model
10378 #
10379 # Expected arguments
10380 # $exitObj - The exit object to update
10381 #
10382 # Optional arguments
10383 # $twinExitObj - The exit's twin object, if known (if 'undef', this function looks up
10384 # for twin exit object)
10385 #
10386 # Return values
10387 # 'undef' on improper arguments
10388 # 1 otherwise
10389  
10390 my ($self, $exitObj, $twinExitObj, $check) = @_;
10391  
10392 # Local variables
10393 my @list;
10394  
10395 # Check for improper arguments
10396 if (! defined $exitObj || defined $check) {
10397  
10398 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateMapExit', @_);
10399 }
10400  
10401 # If the exit has a twin, that must be redrawn, too
10402 @list = ('exit', $exitObj);
10403  
10404 if (! $twinExitObj && $exitObj->twinExit) {
10405  
10406 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
10407 }
10408  
10409 if ($twinExitObj) {
10410  
10411 push (@list, 'exit', $twinExitObj);
10412 }
10413  
10414 foreach my $mapWin ($self->collectMapWins()) {
10415  
10416 # Redraw the objects
10417 $mapWin->markObjs(@list);
10418 $mapWin->doDraw();
10419 }
10420  
10421 return 1;
10422 }
10423  
10424 sub updateMapLabels {
10425  
10426 # Called by GA::EditWin::MapLabelStyle->saveChanges and $self->deleteLabelStyle to redraw
10427 # all labels in every Automapper using this world model (assuming that the map label style
10428 # has been modified)
10429 #
10430 # Expected arguments
10431 # (none besides $self)
10432 #
10433 # Return values
10434 # 'undef' on improper arguments
10435 # 1 otherwise
10436  
10437 my ($self, $check) = @_;
10438  
10439 # Local variables
10440 my @list;
10441  
10442 # Check for improper arguments
10443 if (defined $check) {
10444  
10445 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateMapLabels', @_);
10446 }
10447  
10448 foreach my $mapWin ($self->collectMapWins()) {
10449  
10450 if ($mapWin->currentRegionmap) {
10451  
10452 foreach my $labelObj ($mapWin->currentRegionmap->ivValues('gridLabelHash')) {
10453  
10454 push (@list, 'label', $labelObj);
10455 }
10456  
10457 # Redraw the objects
10458 $mapWin->markObjs(@list);
10459 $mapWin->doDraw();
10460 }
10461 }
10462  
10463 return 1;
10464 }
10465  
10466 sub connectRooms {
10467  
10468 # Called by GA::Obj::Map->autoProcessNewRoom, ->useExistingRoom,
10469 # GA::Obj::Map->createNewRoom, $self->connectRegions or any other function
10470 # Given two room objects in the world model, and the command we use to move from one to the
10471 # other, connect the rooms by modifying their exit object's IVs
10472 #
10473 # Expected arguments
10474 # $session - The calling function's GA::Session
10475 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
10476 # should be updated now, FALSE if not (in which case, they can be
10477 # updated later by the calling function, when it is ready)
10478 # $departRoomObj - The GA::ModelObj::Room from which the character left
10479 # $arriveRoomObj - The GA::ModelObj::Room to which the character arrived
10480 # $dir - The command used to move (e.g. 'north', 'cross bridge')
10481 #
10482 # Optional arguments
10483 # $mapDir - How the exit is drawn on the map - matches a standard primary
10484 # direction (e.g. 'north', 'south', 'up'). If not specified, the exit
10485 # can't be drawn on the map
10486 # $exitObj - An existing GA::Obj::Exit to use, if known; the parent room is
10487 # $departRoomObj. If no exit is specified, the destination room's
10488 # ->exitNumHash is consulted to provide it
10489 # $oppExitObj - An existing GA::Obj::Exit belonging to $arriveRoomObj. If set, those
10490 # two exits are linked; otherwise, the user is prompted for an
10491 # opposite exit, if there isn't already an obvious candidate. Ignored
10492 # if $exitObj is not also set
10493 # $forceFlag - If TRUE, the value of $self->autocompleteExitsFlag is ignored, and
10494 # this function behaves as if that IV was set to TRUE
10495 #
10496 # Return values
10497 # 'undef' on improper arguments or if the rooms can't be connected
10498 # 1 otherwise
10499  
10500 my (
10501 $self, $session, $updateFlag, $departRoomObj, $arriveRoomObj, $dir, $mapDir, $exitObj,
10502 $oppExitObj, $forceFlag,
10503 $check,
10504 ) = @_;
10505  
10506 # Local variables
10507 my (
10508 $number, $departExitObj, $standardDir, $departRegionFlag, $arriveExitObj,
10509 $arriveRegionFlag, $departRegionObj, $arriveRegionObj, $twinExitObj,
10510 @redrawList,
10511 );
10512  
10513 # Check for improper arguments
10514 if (
10515 ! defined $session || ! defined $updateFlag || ! defined $departRoomObj
10516 || ! defined $arriveRoomObj || ! defined $dir || defined $check
10517 ) {
10518 return $axmud::CLIENT->writeImproper($self->_objClass . '->connectRooms', @_);
10519 }
10520  
10521 # Connect the exit from the departure to the arrival room
10522  
10523 # If $exitObj and/or $oppExitObj were specified, check that they belong to the specified
10524 # parent rooms
10525 if (
10526 ($exitObj && $exitObj->parent ne $departRoomObj->number)
10527 || ($oppExitObj && $oppExitObj->parent ne $arriveRoomObj->number)
10528 ) {
10529 return undef;
10530 }
10531  
10532 # Get the departure room's exit object (unless already specified)
10533 if (! $exitObj) {
10534  
10535 $number = $departRoomObj->ivShow('exitNumHash', $dir);
10536 if (defined $number) {
10537  
10538 $departExitObj = $self->ivShow('exitModelHash', $number);
10539 }
10540  
10541 } else {
10542  
10543 $departExitObj = $exitObj;
10544 }
10545  
10546 if (! $departExitObj) {
10547  
10548 # The departure exit isn't known (probably because the room from which the character is
10549 # leaving hasn't yet been updated with a call to GA::Obj::Map->updateRoom and,
10550 # therefore, doesn't have any exits at all)
10551 # This can also happen when the character leaves the room via a hidden exit that the
10552 # Locator task doesn't know about, or when the departure room is dark and its exits
10553 # aren't known
10554  
10555 # We can't connect the rooms properly until the Locator task has seen the departure
10556 # room's statement, and knows which exits it has. As a compromise, create an
10557 # incomplete exit - that has no destination room - in the direction just moved; it's
10558 # up to the user to connect it to a room. (The exit will be connected to its arrival
10559 # room, in the normal way, once the Locator has seen the departure room's statement)
10560 # If we're not allowed to add exits - or if it's a retracing exit - then do nothing
10561 if ($self->updateExitFlag && $departRoomObj ne $arriveRoomObj) {
10562  
10563 # If it's not a primary direction, then the new exit is drawn as 'unallocated' (and
10564 # this function call returns 'undef')
10565 $standardDir = $session->currentDict->convertStandardDir($dir);
10566  
10567 # Add a new incomplete exit, using what information we have
10568 $exitObj = $self->addExit(
10569 $session,
10570 TRUE, # Update Automapper windows now
10571 $departRoomObj,
10572 $dir,
10573 $standardDir, # May be 'undef'
10574 );
10575  
10576 # If the room isn't dark, make it a hidden exit (but don't bother, if
10577 # unallocated)
10578 if ($exitObj && $standardDir) {
10579  
10580 $self->setHiddenExit(
10581 FALSE, # Don't update Automapper windows now
10582 $exitObj,
10583 TRUE, # Exit is hidden
10584 );
10585 }
10586 }
10587  
10588 # There's nothing more we can do
10589 return undef;
10590  
10591 } else {
10592  
10593 $departRegionFlag = $departExitObj->regionFlag;
10594 }
10595  
10596 # Set the IVs for $departExitObj, which connects the departure and arrival rooms
10597 # ($departExitObj->dir is already set to $dir)
10598 if ($mapDir) {
10599  
10600 # Don't overwrite an allocated ->mapDir with 'undef'
10601 $departExitObj->ivPoke('mapDir', $mapDir);
10602 }
10603  
10604 $departExitObj->ivPoke('destRoom', $arriveRoomObj->number);
10605  
10606 # If the departure and arrival rooms are the same, it's a retracing exit
10607 if ($departRoomObj eq $arriveRoomObj) {
10608  
10609 # The parent room of the twin exit, if any, must be added to the redraw list now
10610 if ($departExitObj->twinExit) {
10611  
10612 $twinExitObj = $self->ivShow('exitModelHash', $departExitObj->twinExit);
10613 if ($twinExitObj && $twinExitObj->parent) {
10614  
10615 push (@redrawList, 'room', $self->ivShow('modelHash', $twinExitObj->parent));
10616 }
10617 }
10618  
10619 # Now we can convert the exit (and its twin, if any)
10620 $self->setRetracingExit(
10621 FALSE, # Don't update Automapper windows now
10622 $departExitObj,
10623 );
10624  
10625 # If we're not using an existing exit object which already has an opposite exit
10626 # (stored in ->twinExit)...
10627 } elsif (! $departExitObj->twinExit) {
10628  
10629 # Check whether an exit in the opposite primary direction exists (unless one was
10630 # specified by the calling function, in which case, use that)
10631 # (NB $oppExitObj, if specified, must be ignored unles $exitObj was also specified)
10632 if ($exitObj && $oppExitObj) {
10633 $arriveExitObj = $oppExitObj;
10634 } else {
10635 $arriveExitObj = $self->checkOppPrimary($departExitObj);
10636 }
10637  
10638 # Obviously, we don't use an unallocated exit
10639 if (
10640 $arriveExitObj
10641 && (
10642 $arriveExitObj->drawMode eq 'primary'
10643 || $arriveExitObj->drawMode eq 'perm_alloc'
10644 )
10645 ) {
10646 # An opposite exit exists
10647 $arriveRegionFlag = $arriveExitObj->regionFlag;
10648 if (
10649 (
10650 ($self->autocompleteExitsFlag || $forceFlag)
10651 # (Don't connect $departExitObj to an opposite unallocated exit)
10652 && $arriveExitObj->drawMode ne 'temp_alloc'
10653 && $arriveExitObj->drawMode ne 'temp_unalloc'
10654 && (
10655 (! $arriveExitObj->destRoom && $arriveExitObj->randomType eq 'none')
10656 || (
10657 $arriveExitObj->destRoom
10658 && $arriveExitObj->destRoom == $departRoomObj->number
10659 )
10660 )
10661 ) || (
10662 $arriveExitObj->destRoom
10663 && $arriveExitObj->destRoom == $departRoomObj->number
10664 )
10665 ) {
10666 # Either this is a genuine two-way exit, or the flag insists that we treat it as
10667 # a two-way exit (although it might be an uncertain or a two-way exit)
10668 # Link the two exit objects together.
10669 $departExitObj->ivPoke('twinExit', $arriveExitObj->number);
10670 $arriveExitObj->ivPoke('twinExit', $departExitObj->number);
10671  
10672 # When ->autocompleteExitsFlag is set, the arrival room's exit won't have its
10673 # destination room set. Set it now
10674 if ($self->autocompleteExitsFlag || $forceFlag) {
10675  
10676 $arriveExitObj->ivPoke('destRoom', $departRoomObj->number);
10677 }
10678  
10679 # If either exit is marked as a broken exit, so must the other be so marked
10680 # (This can happen when we have three rooms in a row, A-B-C, and are travelling
10681 # two gridblocks at a time from A to C. C's exit towards A will already be
10682 # marked as 'broken', so A's exit towards C must also be broken)
10683 if ($arriveExitObj->brokenFlag) {
10684  
10685 $self->setBrokenExit(
10686 FALSE, # Don't update Automapper windows now
10687 $departExitObj,
10688 $departRoomObj->parent,
10689 );
10690 }
10691  
10692 if ($departExitObj->brokenFlag) {
10693  
10694 $self->setBrokenExit(
10695 FALSE, # Don't update Automapper windows now
10696 $arriveExitObj,
10697 $arriveRoomObj->parent,
10698 );
10699 }
10700  
10701 # If either room used to have an uncertain exit pointing at the other, tell the
10702 # other room that it no longer needs to keep track
10703 $arriveRoomObj->ivDelete('uncertainExitHash', $departExitObj->number);
10704 $departRoomObj->ivDelete('uncertainExitHash', $arriveExitObj->number);
10705  
10706 # Likewise update the rooms for 1-way exits
10707 $arriveRoomObj->ivDelete('oneWayExitHash', $departExitObj->number);
10708 $departRoomObj->ivDelete('oneWayExitHash', $arriveExitObj->number);
10709  
10710 # Each exit should lose its 1-way flag, if it has one
10711 $arriveExitObj->ivPoke('oneWayFlag', FALSE);
10712 $arriveExitObj->ivPoke('oneWayDir', undef);
10713 $departExitObj->ivPoke('oneWayFlag', FALSE);
10714 $departExitObj->ivPoke('oneWayDir', undef);
10715  
10716 } elsif (
10717 (
10718 $arriveExitObj->destRoom
10719 && $arriveExitObj->destRoom != $departRoomObj->number
10720 )
10721 || $arriveExitObj->randomType ne 'none'
10722 ) {
10723 # The opposite exit is already connected to some other room (or it's a random
10724 # exit), so this is a one-way exit
10725 $departExitObj->ivPoke('oneWayFlag', TRUE);
10726 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north'
10727 # as an emergency default value for ->mapDir
10728 if ($departExitObj->mapDir) {
10729  
10730 $departExitObj->ivPoke(
10731 'oneWayDir',
10732 $axmud::CLIENT->ivShow('constOppDirHash', $departExitObj->mapDir),
10733 );
10734  
10735 } else {
10736  
10737 # Emergency default
10738 $departExitObj->ivPoke('oneWayDir', 'north');
10739 }
10740  
10741 $arriveRoomObj->ivAdd('oneWayExitHash', $departExitObj->number, undef);
10742  
10743 # If $departExitObj used to be an uncertain exit, tell the arrival room that it
10744 # no longer needs to keep track of it
10745 $arriveRoomObj->ivDelete('uncertainExitHash', $departExitObj->number);
10746  
10747 } else {
10748  
10749 # This is an uncertain exit. Update the arrival room
10750 $arriveRoomObj->ivAdd(
10751 'uncertainExitHash',
10752 $departExitObj->number,
10753 $arriveExitObj->number,
10754 );
10755 }
10756  
10757 } else {
10758  
10759 # This is a one-way exit
10760 $departExitObj->ivPoke('oneWayFlag', TRUE);
10761 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as
10762 # an emergency default value for ->mapDir
10763 if ($departExitObj->mapDir) {
10764  
10765 $departExitObj->ivPoke(
10766 'oneWayDir',
10767 $axmud::CLIENT->ivShow('constOppDirHash', $departExitObj->mapDir),
10768 );
10769  
10770 } else {
10771  
10772 # Emergency default
10773 $departExitObj->ivPoke('oneWayDir', 'north');
10774 }
10775  
10776 $arriveRoomObj->ivAdd('oneWayExitHash', $departExitObj->number, undef);
10777  
10778 # If $departExitObj used to be an uncertain exit, tell the arrival room that it no
10779 # longer needs to keep track of it
10780 $arriveRoomObj->ivDelete('uncertainExitHash', $departExitObj->number);
10781  
10782 # If $arriveExitObj, an exit was found in the opposite direction to $departExitObj,
10783 # but it's unallocated. Reallocate its temporary map direction so that
10784 # $departExitObj isn't drawn over the top of $arriveExitObj
10785 # NB $arriveExitObj->drawMode could also be 'temp_unalloc', in which case it's not
10786 # drawn in a way that could be underneath $departExitObj
10787 if ($arriveExitObj && $arriveExitObj->drawMode eq 'temp_alloc') {
10788  
10789 $self->allocateCardinalDir($session, $arriveRoomObj, $arriveExitObj);
10790 }
10791 }
10792 }
10793  
10794 # Any region paths using the exits will have to be updated
10795 $departRegionObj = $self->ivShow('modelHash', $departRoomObj->parent);
10796 $self->ivAdd('updatePathHash', $departExitObj->number, $departRegionObj->name);
10797 if ($departRegionFlag || $departExitObj->regionFlag) {
10798  
10799 $self->ivAdd('updateBoundaryHash', $departExitObj->number, $departRegionObj->name);
10800 }
10801  
10802 if ($arriveExitObj) {
10803  
10804 $arriveRegionObj = $self->ivShow('modelHash', $arriveRoomObj->parent);
10805 $self->ivAdd('updatePathHash', $arriveExitObj->number, $arriveRegionObj->name);
10806 if ($arriveRegionFlag || $arriveExitObj->regionFlag) {
10807  
10808 $self->ivAdd('updateBoundaryHash', $arriveExitObj->number, $arriveRegionObj->name);
10809 }
10810 }
10811  
10812 # When an exit is connected to a room, it loses its impassable status (if set). Don't
10813 # specify the flag for the twin exit, because if the twin exit has a different kind of
10814 # exit ornament, we don't want to lose it
10815 if ($departExitObj->exitOrnament eq 'impass' || $departExitObj->exitOrnament eq 'mystery') {
10816  
10817 $self->setExitOrnament(
10818 FALSE, # Don't update Automapper windows yet
10819 $departExitObj,
10820 );
10821 }
10822  
10823 # The twin exit object (if any) also loses its impassable status
10824 if (
10825 $arriveExitObj
10826 && (
10827 $arriveExitObj->exitOrnament eq 'impass'
10828 || $arriveExitObj->exitOrnament eq 'mystery'
10829 )
10830 ) {
10831 $self->setExitOrnament(
10832 FALSE, # Don't update Automapper windows yet
10833 $arriveExitObj,
10834 );
10835 }
10836  
10837 # When a retracing exit is connected to a room, it loses its retracing status (unless it is
10838 # being connected to its own parent room - in which case it is, by profile, a retracing
10839 # exit)
10840 if (
10841 $departExitObj->retraceFlag
10842 && $departExitObj->destRoom != $departExitObj->parent
10843 ) {
10844 # (We don't call $self->restoreRetracingExit, because that would destroy the exit's
10845 # ->destRoom setting)
10846 $departExitObj->ivPoke('retraceFlag', FALSE);
10847 }
10848  
10849 # When a random exit is connected to a room, it loses its random status (and any destination
10850 # rooms stored in ->randomDestList)
10851 if ($departExitObj->randomType ne 'none') {
10852  
10853 $self->restoreRandomExit(
10854 FALSE, # Don't update Automapper windows yet
10855 $departExitObj,
10856 );
10857 }
10858  
10859 # When an exit is connected to a room, it loses any existing bends
10860 $departExitObj->ivEmpty('bendOffsetList');
10861 if ($arriveExitObj) {
10862  
10863 $arriveExitObj->ivEmpty('bendOffsetList');
10864 }
10865  
10866 # Update any GA::Win::Map objects using this world model (if allowed)
10867 if ($updateFlag) {
10868  
10869 # Compile a list of rooms to be marked for drawing (if $departRoomObj is not on the
10870 # visible region level, it won't get drawn, so there's no danger in marking it to be
10871 # drawn here)
10872 push (@redrawList, 'room', $arriveRoomObj);
10873 if ($departRoomObj && $departRoomObj ne $arriveRoomObj) {
10874  
10875 push (@redrawList, 'room', $departRoomObj);
10876 }
10877  
10878 foreach my $mapWin ($self->collectMapWins()) {
10879  
10880 # Redraw the rooms
10881 $mapWin->markObjs(@redrawList);
10882 $mapWin->doDraw();
10883 }
10884 }
10885  
10886 return 1;
10887 }
10888  
10889 sub slideRoom {
10890  
10891 # Called by GA::Obj::Map->useExistingRoom after a character move when there's no room for a
10892 # new arrival room
10893 # Depending on the value of $self->autoSlideMode, either the original departure room is
10894 # moved (slided) to a new position (in the same region, on the same level), or the room
10895 # that's occupying the gridblock where we'd like to draw a new room is moved, or this
10896 # function finds an empty gridblock where a new room can be drawn
10897 #
10898 # Expected arguments
10899 # $session - The calling function's GA::Session
10900 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
10901 # should be updated now, FALSE if not (in which case, they can be
10902 # updated later by the calling function, when it is ready)
10903 # $departRoomObj - The GA::ModelObj::Room from which the character left
10904 # $arriveRoomObj - The GA::ModelObj::Room occupying the gridblock where a new room
10905 # would be placed, if a slide operation were not necessary
10906 # $mapDir - The standard primary direction of movement
10907 #
10908 # Return values
10909 # An empty list on improper arguments or if it's possible to slide a room
10910 # Otherwise, returns a list in the form
10911 # (new_x_pos, new_y_pos, z_posn, slid_room_obj)
10912 # ...where 'new_x_pos' and 'new_y_pos' are the moved room's new coordinates in the region,
10913 # 'z_posn' is the room's (unmodified) level in the region, and 'room_obj' is the
10914 # room object that was moved, or 'undef' if the coordinates represent an empty
10915 # gridblock in which a new room can be created
10916  
10917 my ($self, $session, $updateFlag, $departRoomObj, $arriveRoomObj, $mapDir, $check) = @_;
10918  
10919 # Local variables
10920 my (
10921 $mode, $regionmapObj, $slideRoomObj, $xPos, $yPos, $zPos, $useXPos, $useYPos,
10922 @emptyList,
10923 %convertHash, %roomHash, %emptyHash,
10924 );
10925  
10926 # Check for improper arguments
10927 if (
10928 ! defined $session || ! defined $updateFlag || ! defined $departRoomObj
10929 || ! defined $arriveRoomObj || ! defined $mapDir || defined $check
10930 ) {
10931 $axmud::CLIENT->writeImproper($self->_objClass . '->slideRoom', @_);
10932 return @emptyList;
10933 }
10934  
10935 # Import IVs (for convenience)
10936 $mode = $self->autoSlideMode;
10937 $regionmapObj = $self->findRegionmap($departRoomObj->parent);
10938  
10939 if (
10940 $mode eq 'default'
10941 || $mapDir eq 'up'
10942 || $mapDir eq 'down'
10943 || $departRoomObj->parent != $arriveRoomObj->parent
10944 ) {
10945 # Cannot slide either room
10946 return @emptyList;
10947  
10948 } elsif ($mode eq 'orig_pull' || $mode eq 'orig_push') {
10949  
10950 $slideRoomObj = $departRoomObj;
10951 $xPos = $slideRoomObj->xPosBlocks;
10952 $yPos = $slideRoomObj->yPosBlocks;
10953 $zPos = $slideRoomObj->zPosBlocks;
10954  
10955 } elsif ($mode eq 'other_pull' || $mode eq 'other_push') {
10956  
10957 $slideRoomObj = $arriveRoomObj;
10958 $xPos = $slideRoomObj->xPosBlocks;
10959 $yPos = $slideRoomObj->yPosBlocks;
10960 $zPos = $slideRoomObj->zPosBlocks;
10961  
10962 } elsif ($mode eq 'dest_pull' || $mode eq 'dest_push') {
10963  
10964 # ($slideRoomObj remains 'undef', as the new room hasn't been created yet)
10965 $xPos = $arriveRoomObj->xPosBlocks;
10966 $yPos = $arriveRoomObj->yPosBlocks;
10967 $zPos = $arriveRoomObj->zPosBlocks;
10968  
10969 } else {
10970  
10971 # Invalid $mode
10972 return @emptyList;
10973 }
10974  
10975 # For 'push', use the direction of movement, $mapDir. For 'pull', use the opposite direction
10976 if ($mode =~ m/pull/) {
10977  
10978 $mapDir = $axmud::CLIENT->ivShow('constOppDirHash', $mapDir);
10979 }
10980  
10981 # Greatly simplify the code by sliding in only eight directions
10982 %convertHash = (
10983 northnortheast => 'north',
10984 eastnortheast => 'east',
10985 eastsoutheast => 'east',
10986 southsoutheast => 'south',
10987 southsouthwest => 'south',
10988 westsouthwest => 'west',
10989 westnorthwest => 'west',
10990 northnorthwest => 'north',
10991 );
10992  
10993 if (exists $convertHash{$mapDir}) {
10994  
10995 $mapDir = $convertHash{$mapDir};
10996 }
10997  
10998 # Find the nearest unoccupied gridblock. One algorithm for sliding n/s/w/e, another for
10999 # sliding nw/ne/sw/se
11000 if ($mapDir eq 'north' || $mapDir eq 'south' || $mapDir eq 'west' || $mapDir eq 'east') {
11001  
11002 # Search for gridblocks in this general order, where R is the position currently
11003 # expressed by $xPos and $yPos
11004 #
11005 # 45678 4 4
11006 # 123 51 15
11007 # R R 62R R26
11008 # 123 73 37
11009 # 45678 8 8
11010  
11011 # 'dest_push' operations look a lot nicer if we modify the starting position by one
11012 # block
11013 if ($mode eq 'dest_push') {
11014  
11015 if ($mapDir eq 'north') {
11016 $yPos++;
11017 } elsif ($mapDir eq 'south') {
11018 $yPos--;
11019 } elsif ($mapDir eq 'west') {
11020 $xPos++;
11021 } elsif ($mapDir eq 'east') {
11022 $xPos--;
11023 }
11024 }
11025  
11026 # Maximum size of the cone is 8 gridblocks
11027 OUTER: for ($a = 1; $a <= $self->autoSlideMax; $a++) {
11028  
11029 my ($thisXPos, $thisYPos);
11030  
11031 if ($mapDir eq 'north') {
11032  
11033 $yPos--;
11034 $thisXPos = $xPos - $a;
11035 $thisYPos = $yPos;
11036  
11037 } elsif ($mapDir eq 'south') {
11038  
11039 $yPos++;
11040 $thisXPos = $xPos - $a;
11041 $thisYPos = $yPos;
11042  
11043 } elsif ($mapDir eq 'west') {
11044  
11045 $xPos--;
11046 $thisXPos = $xPos;
11047 $thisYPos = $yPos - $a;
11048  
11049 } else {
11050  
11051 $xPos++;
11052 $thisXPos = $xPos;
11053 $thisYPos = $yPos - $a;
11054 }
11055  
11056 INNER: for ($b = 0; $b < (($a * 2) + 1); $b++) {
11057  
11058 if ($thisXPos) {
11059 $thisXPos += $b;
11060 } else {
11061 $thisYPos += $b;
11062 }
11063  
11064 if (
11065 # Gridblock actually exists
11066 $regionmapObj->checkGridBlock($thisXPos, $thisYPos, $zPos)
11067 # ...and is not occupied
11068 && ! $regionmapObj->fetchRoom($thisXPos, $thisYPos, $zPos)
11069 ) {
11070 # Success!
11071 $useXPos = $thisXPos;
11072 $useYPos = $thisYPos;
11073 last OUTER;
11074 }
11075 }
11076 }
11077  
11078 } else {
11079  
11080 # Search for gridblocks in this general order, where R is the position expressed by
11081 # $xPos and $yPos
11082 #
11083 # 5 5
11084 # 24 42
11085 # R13 R13 31R 31R
11086 # 24 42
11087 # 5 5
11088  
11089 # Maximum size of the cone is 8 gridblocks
11090 OUTER: for ($a = 1; $a <= 8; $a++) {
11091  
11092 my ($thisXPos, $thisYPos);
11093  
11094 if ($mapDir eq 'northeast' || $mapDir eq 'southeast') {
11095 $xPos++;
11096 } else {
11097 $xPos--;
11098 }
11099  
11100 $thisXPos = $xPos;
11101 $thisYPos = $yPos;
11102  
11103 INNER: for ($b = 0; $b < ($a + 1); $b++) {
11104  
11105 if ($mapDir eq 'northeast' || $mapDir eq 'northwest') {
11106 $thisYPos += ($b * -1);
11107 } else {
11108 $thisYPos += $b;
11109 }
11110  
11111 if (
11112 # Gridblock actually exists
11113 $regionmapObj->checkGridBlock($thisXPos, $thisYPos, $zPos)
11114 # ...and is not occupied
11115 && ! $regionmapObj->fetchRoom($thisXPos, $thisYPos, $zPos)
11116 ) {
11117 # Success!
11118 $useXPos = $thisXPos;
11119 $useYPos = $thisYPos;
11120 last OUTER;
11121 }
11122 }
11123 }
11124 }
11125  
11126 if (! defined $useXPos) {
11127  
11128 # No empty gridblock found
11129 return @emptyList;
11130 }
11131  
11132 # Empty gridblock found at $useXPos, $useYPos, $zPos
11133 #.
11134 if (! $slideRoomObj) {
11135  
11136 # For some auto-slide modes, return the location of the empty gridblock, so a new room
11137 # can be created there
11138 return ($useXPos, $useYPos, $zPos);
11139  
11140 } else {
11141  
11142 # For others, move an existing room to the empty gridblock
11143  
11144 # $self->moveRoomsLabels expects a room list, stored as a hash
11145 $roomHash{$slideRoomObj->number} = $slideRoomObj;
11146  
11147 if (
11148 ! $self->moveRoomsLabels(
11149 $session,
11150 $updateFlag,
11151 $regionmapObj,
11152 $regionmapObj,
11153 ($useXPos - $slideRoomObj->xPosBlocks),
11154 ($useYPos - $slideRoomObj->yPosBlocks),
11155 0,
11156 \%roomHash,
11157 \%emptyHash, # No labels to move
11158 )
11159 ) {
11160 return @emptyList;
11161 } else {
11162 return ($useXPos, $useYPos, $zPos, $slideRoomObj);
11163 }
11164 }
11165  
11166 return 1;
11167 }
11168  
11169 sub updateVisitCount {
11170  
11171 # Called by several functions in the automapper object (GA::Obj::Map) and the Automapper
11172 # window (GA::Win::Map)
11173 # Increments the number of character visits to a room, if allowed
11174 #
11175 # Expected arguments
11176 # $session - The calling function's GA::Session
11177 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11178 # be updated now, FALSE if not (in which case, they can be updated later
11179 # by the calling function, when it is ready)
11180 # $number - The model number of the room object to update
11181 #
11182 # Return values
11183 # 'undef' on improper arguments, if the model object doesn't exist, if it isn't a room, if
11184 # $self->countVisitsFlag is set to TRUE (meaning we don't count character visits) or
11185 # if the current session doesn't have a current character profile
11186 # 1 otherwise
11187  
11188 my ($self, $session, $updateFlag, $number, $check) = @_;
11189  
11190 # Local variables
11191 my ($roomObj, $charName);
11192  
11193 # Check for improper arguments
11194 if (! defined $session || ! defined $updateFlag || ! defined $number || defined $check) {
11195  
11196 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateVisitCount', @_);
11197 }
11198  
11199 # Check that we're allowed to count character visits and that the current session has a
11200 # current character profile
11201 if (! $self->countVisitsFlag || ! $session->currentChar) {
11202  
11203 return undef;
11204 }
11205  
11206 # Get the model object
11207 $roomObj = $self->ivShow('modelHash', $number);
11208 if (! $roomObj || $roomObj->category ne 'room') {
11209  
11210 return undef;
11211 }
11212  
11213 # Update the room
11214 $charName = $session->currentChar->name;
11215  
11216 if (! $roomObj->ivExists('visitHash', $charName)) {
11217  
11218 # First visit to this room
11219 $roomObj->ivAdd('visitHash', $charName, 1);
11220  
11221 } else {
11222  
11223 # A return visit to this room
11224 $roomObj->ivIncHash('visitHash', $charName);
11225 }
11226  
11227 # Update any GA::Win::Map objects using this world model (if allowed)
11228 if ($updateFlag) {
11229  
11230 foreach my $mapWin ($self->collectMapWins()) {
11231  
11232 # Redraw the room
11233 $mapWin->markObjs('room', $roomObj);
11234 $mapWin->doDraw();
11235 }
11236 }
11237  
11238 return 1;
11239 }
11240  
11241 sub resetVisitCount {
11242  
11243 # Called by GA::Win::Map->resetVisitsCallback
11244 # Removes the record of the number of visits in a specified room for a specified character
11245 #
11246 # Expected arguments
11247 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11248 # be updated now, FALSE if not (in which case, they can be updated
11249 # later by the calling function, when it is ready)
11250 # $roomObj - The GA::ModelObj::Room to update
11251 #
11252 # Optional arguments
11253 # $char - The name of the character whose record should be erased. If set to
11254 # 'undef', all characters' records are erased
11255 #
11256 # Return values
11257 # 'undef' on improper arguments or if no record(s) are deleted
11258 # 1 otherwise
11259  
11260 my ($self, $updateFlag, $roomObj, $char, $check) = @_;
11261  
11262 # Check for improper arguments
11263 if (! defined $updateFlag || ! defined $roomObj || ! defined $char || defined $check) {
11264  
11265 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetVisitCount', @_);
11266 }
11267  
11268 if ($char) {
11269  
11270 if (! $roomObj->ivExists('visitHash', $char)) {
11271  
11272 # Record doesn't exist
11273 return undef;
11274  
11275 } else {
11276  
11277 $roomObj->ivDelete('visitHash', $char);
11278 }
11279  
11280 } else {
11281  
11282 if (! $roomObj->visitHash) {
11283  
11284 # No records for this room
11285 return undef;
11286  
11287 } else {
11288  
11289 $roomObj->ivEmpty('visitHash');
11290 }
11291 }
11292  
11293 # Update any GA::Win::Map objects using this world model (if allowed)
11294 if ($updateFlag) {
11295  
11296 OUTER: foreach my $mapWin ($self->collectMapWins()) {
11297  
11298 # Redraw the room
11299 $mapWin->markObjs('room', $roomObj);
11300 $mapWin->doDraw();
11301 }
11302 }
11303  
11304 return 1;
11305 }
11306  
11307 sub resetRoomData {
11308  
11309 # Called by GA::Win::Map->resetRoomDataCallback
11310 # Resets data stored in one or more room model objects
11311 #
11312 # Expected arguments
11313 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11314 # be updated now, FALSE if not (in which case, they can be updated later
11315 # by the calling function, when it is ready)
11316 # $type - The type of data to reset - 'title', 'descrip', 'room_tag', 'room_guild',
11317 # 'room_flag', 'room_cmd', 'unspecified', 'exit_depart', 'checked_dir',
11318 # 'script', 'noun_adj', 'search', 'char_visit', 'exclusive', 'remote',
11319 # 'path' or 'all_data' for all of the above
11320 #
11321 # Optional arguments
11322 # @roomList - The list of room model objects to reset (can be an empty list)
11323 #
11324 # Return values
11325 # 'undef' on improper argumentsm or if no data is deleted
11326 # 1 otherwise
11327  
11328 my ($self, $updateFlag, $type, @roomList) = @_;
11329  
11330 # Local variables
11331 my @markList;
11332  
11333 # Check for improper arguments
11334 if (! defined $updateFlag || ! defined $type) {
11335  
11336 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRoomData', @_);
11337 }
11338  
11339 foreach my $roomObj (@roomList) {
11340  
11341 if ($type eq 'title' || $type eq 'all_data') {
11342  
11343 $roomObj->ivEmpty('titleList');
11344 }
11345  
11346 if ($type eq 'descrip' || $type eq 'all_data') {
11347  
11348 $roomObj->ivEmpty('descripHash');
11349 }
11350  
11351 if ($type eq 'room_tag' || $type eq 'all_data') {
11352  
11353 $roomObj->ivUndef('roomTag');
11354 $roomObj->ivPoke('roomTagXOffset', 0);
11355 $roomObj->ivPoke('roomTagYOffset', 0);
11356 }
11357  
11358 if ($type eq 'room_guild' || $type eq 'all_data') {
11359  
11360 $roomObj->ivUndef('roomGuild');
11361 $roomObj->ivPoke('roomGuildXOffset', 0);
11362 $roomObj->ivPoke('roomGuildYOffset', 0);
11363 }
11364  
11365 if ($type eq 'room_flag' || $type eq 'all_data') {
11366  
11367 $roomObj->ivEmpty('roomFlagHash');
11368 $roomObj->ivUndef('lastRoomFlag');
11369 }
11370  
11371 if ($type eq 'room_cmd' || $type eq 'all_data') {
11372  
11373 $roomObj->ivEmpty('roomCmdList');
11374 $roomObj->ivEmpty('tempRoomCmdList');
11375 }
11376  
11377 if ($type eq 'unspecified' || $type eq 'all_data') {
11378  
11379 $roomObj->ivEmpty('unspecifiedPatternList');
11380 }
11381  
11382 if ($type eq 'exit_depart' || $type eq 'all_data') {
11383  
11384 $roomObj->ivEmpty('failExitPatternList');
11385 $roomObj->ivEmpty('specialDepartPatternList');
11386 $roomObj->ivEmpty('involuntaryExitPatternHash');
11387 $roomObj->ivEmpty('repulseExitPatternHash');
11388 }
11389  
11390 if ($type eq 'checked_dir' || $type eq 'all_data') {
11391  
11392 $roomObj->ivEmpty('checkedDirHash');
11393 }
11394  
11395 if ($type eq 'noun_adj' || $type eq 'all_data') {
11396  
11397 $roomObj->ivEmpty('nounList');
11398 $roomObj->ivEmpty('adjList');
11399 }
11400  
11401 if ($type eq 'search' || $type eq 'all_data') {
11402  
11403 $roomObj->ivEmpty('searchHash');
11404 }
11405  
11406 if ($type eq 'char_visit' || $type eq 'all_data') {
11407  
11408 $roomObj->ivEmpty('visitHash');
11409 }
11410  
11411 if ($type eq 'exlusive' || $type eq 'all_data') {
11412  
11413 $roomObj->ivPoke('exclusiveFlag', FALSE);
11414 $roomObj->ivEmpty('exclusiveHash');
11415 }
11416  
11417 if ($type eq 'remote' || $type eq 'all_data') {
11418  
11419 $roomObj->ivEmpty('protocolRoomHash');
11420 $roomObj->ivEmpty('protocolExitHash');
11421 }
11422  
11423 if ($type eq 'script' || $type eq 'all_data') {
11424  
11425 $roomObj->ivEmpty('arriveScriptList');
11426 }
11427  
11428 if ($type eq 'path' || $type eq 'all_data') {
11429  
11430 $roomObj->ivUndef('sourceCodePath');
11431 $roomObj->ivUndef('virtualAreaPath');
11432 }
11433 }
11434  
11435 # Update any GA::Win::Map objects using this world model (if allowed)
11436 if ($updateFlag && @roomList) {
11437  
11438 foreach my $roomObj (@roomList) {
11439  
11440 push (@markList, 'room', $roomObj);
11441 }
11442  
11443 foreach my $mapWin ($self->collectMapWins()) {
11444  
11445 # Redraw the rooms
11446 $mapWin->markObjs(@markList);
11447 $mapWin->doDraw();
11448 }
11449 }
11450  
11451 return 1;
11452 }
11453  
11454 sub addExitPattern {
11455  
11456 # Can be called by anything
11457 # Adds a pattern to a specified room
11458 #
11459 # Expected arguments
11460 # $roomObj - The GA::ModelObj::Room to update
11461 # $type - The type of pattern to add - 'fail', 'special' or 'unspecified' (if not
11462 # one of these strings, no pattern is added)
11463 # $pattern - The pattern to add
11464 #
11465 # Return values
11466 # 'undef' on improper arguments
11467 # 1 otherwise
11468  
11469 my ($self, $roomObj, $type, $pattern, $check) = @_;
11470  
11471 # Check for improper arguments
11472 if (! defined $roomObj || ! defined $type || ! defined $pattern || defined $check) {
11473  
11474 return $axmud::CLIENT->writeImproper($self->_objClass . '->addExitPattern', @_);
11475 }
11476  
11477 if ($type eq 'fail') {
11478 $roomObj->ivPush('addFailExitPattern', $pattern);
11479 } elsif ($type eq 'special') {
11480 $roomObj->ivPush('specialDepartPatternList', $pattern);
11481 } elsif ($type eq 'unspecified') {
11482 $roomObj->ivPush('unspecifiedPatternList', $pattern);
11483 }
11484  
11485 return 1;
11486 }
11487  
11488 sub setRoomSource {
11489  
11490 # Called by GA::Win::Map->setFilePathCallback
11491 # Sets a world model room's source code file and (optionally) its virtual area file, when
11492 # it is known
11493 #
11494 # Expected arguments
11495 # $roomObj - The GA::ModelObj::Room to modify
11496 #
11497 # Optional arguments
11498 # $filePath - The path to the room's source code file, relative to
11499 # $self->mudlibPath. If 'undef' or an empty string, the room's
11500 # ->sourceCodePath is set to 'undef'
11501 # $virtualPath - The virtual area path, e.g. '/filepath/forest/24,3', relative to
11502 # $self->mudlibPath. If 'undef' or an empty string, the room's
11503 # ->sourceCodePath is set to 'undef'
11504 #
11505 # Return values
11506 # 'undef' on improper arguments
11507 # 1 otherwise
11508  
11509 my ($self, $roomObj, $filePath, $virtualPath, $check) = @_;
11510  
11511 # Check for improper arguments
11512 if (! defined $roomObj || defined $check) {
11513  
11514 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomSource', @_);
11515 }
11516  
11517 if (! $filePath) {
11518  
11519 $roomObj->ivUndef('sourceCodePath');
11520  
11521 } else {
11522  
11523 $roomObj->ivPoke('sourceCodePath', $filePath);
11524 # Save this filepath for the next new room, so that if the directories are the same, the
11525 # user doesn't have to type the whole thing again
11526 $self->ivPoke('lastFilePath', $filePath);
11527 }
11528  
11529 if (! $virtualPath) {
11530  
11531 $roomObj->ivUndef('virtualAreaPath');
11532  
11533 } else {
11534  
11535 $roomObj->ivPoke('virtualAreaPath', $virtualPath);
11536 # Likewise, save the virtual area
11537 $self->ivPoke('lastVirtualAreaPath', $filePath);
11538 }
11539  
11540 foreach my $mapWin ($self->collectMapWins()) {
11541  
11542 # If the room is on the automapper's region and level...
11543 if (
11544 $mapWin->currentRegionmap
11545 && $mapWin->currentRegionmap->number eq $roomObj->parent
11546 && $mapWin->currentRegionmap->currentLevel == $roomObj->zPosBlocks
11547 ) {
11548 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
11549 $mapWin->restrictWidgets();
11550 }
11551 }
11552  
11553 return 1;
11554 }
11555  
11556 sub addSearchTerm {
11557  
11558 # Called by GA::Win::Map->addSearchResultCallback
11559 # Adds a search term (and its result) to a specified room object
11560 #
11561 # Expected arguments
11562 # $roomObj - The GA::ModelObj::Room to modify
11563 # $term - The search term, e.g. 'fireplace'
11564 # $result - The result, e.g. 'It's an old fireplace'
11565 #
11566 # Return values
11567 # 'undef' on improper arguments
11568 # 1 otherwise
11569  
11570 my ($self, $roomObj, $term, $result, $check) = @_;
11571  
11572 # Check for improper arguments
11573 if (! defined $roomObj || ! defined $term || ! defined $result || defined $check) {
11574  
11575 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSearchTerm', @_);
11576 }
11577  
11578 $roomObj->ivAdd('searchHash', $term, $result);
11579  
11580 return 1;
11581 }
11582  
11583 sub setRoomTag {
11584  
11585 # Called by GA::Win::Map->setRoomTagCallback
11586 # Sets the specified room's room tag, updating all IVs and redrawing the room (if allowed)
11587 #
11588 # Expected arguments
11589 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11590 # be updated now, FALSE if not (in which case, they can be updated later
11591 # by the calling function, when it is ready)
11592 # $roomObj - The room object to use
11593 # $tag - The room's new tag
11594 #
11595 # Return values
11596 # 'undef' on improper arguments, if the $tag contains the string '@@@' (which is needed
11597 # for route objects) or if the $tag is longer than the maximum 16 characters
11598 # 1 otherwise
11599  
11600 my ($self, $updateFlag, $roomObj, $tag, $check) = @_;
11601  
11602 # Local variables
11603 my (
11604 $oldRoomNum, $oldRoomObj, $regionmapObj,
11605 @redrawList,
11606 );
11607  
11608 # Check for improper arguments
11609 if (! defined $updateFlag || ! defined $roomObj || ! defined $tag || defined $check) {
11610  
11611 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomTag', @_);
11612 }
11613  
11614 # Check that the $tag is valid
11615 if (length($tag) > 16 || $tag =~ m/@@@/) {
11616  
11617 # Invalid tag
11618 return undef;
11619  
11620 } else {
11621  
11622 # Room tags are stored in lower-case letters
11623 $tag = lc($tag);
11624 }
11625  
11626 # If the room already has a tag, remove it
11627 if ($roomObj->roomTag) {
11628  
11629 $self->resetRoomTag(
11630 FALSE, # Don't update the Automapper windows yet
11631 $roomObj,
11632 );
11633 }
11634  
11635 # See if the specified tag already exists
11636 $oldRoomNum = $self->checkRoomTag($tag);
11637 if ($oldRoomNum) {
11638  
11639 # Remove the other room's tag
11640 $oldRoomObj = $self->ivShow('modelHash', $oldRoomNum);
11641 $self->resetRoomTag(
11642 FALSE, # Don't update the Automapper windows yet
11643 $oldRoomObj,
11644 );
11645  
11646 # Mark the other room to be redrawn
11647 push (@redrawList, 'room', $oldRoomObj);
11648 }
11649  
11650 # Assign the tag to $roomObj
11651 $self->ivAdd('roomTagHash', $tag, $roomObj->number);
11652 $roomObj->ivPoke('roomTag', $tag);
11653  
11654 # Find the room's regionmap and update it
11655 $regionmapObj = $self->findRegionmap($roomObj->parent);
11656 $regionmapObj->storeRoomTag($roomObj);
11657  
11658 # Update any GA::Win::Map objects using this world model (if allowed)
11659 if ($updateFlag) {
11660  
11661 # $roomObj must be redrawn
11662 push (@redrawList, 'room', $roomObj);
11663  
11664 foreach my $mapWin ($self->collectMapWins()) {
11665  
11666 # Redraw the rooms
11667 $mapWin->markObjs(@redrawList);
11668 $mapWin->doDraw();
11669 }
11670 }
11671  
11672 return 1;
11673 }
11674  
11675 sub resetRoomTag {
11676  
11677 # Called by GA::Win::Map->setRoomTagCallback
11678 # Removes the specified room's room tag (if any), updating all IVs and redrawing the room
11679 # (if allowed)
11680 #
11681 # Expected arguments
11682 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11683 # be updated now, FALSE if not (in which case, they can be updated later
11684 # by the calling function, when it is ready)
11685 # $roomObj - The room object to update
11686 #
11687 # Return values
11688 # 'undef' on improper arguments or if the specified room doesn't have a room tag
11689 # 1 otherwise
11690  
11691 my ($self, $updateFlag, $roomObj, $check) = @_;
11692  
11693 # Local variables
11694 my ($regionObj, $regionmapObj, $key);
11695  
11696 # Check for improper arguments
11697 if (! defined $updateFlag || ! defined $roomObj || defined $check) {
11698  
11699 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRoomTag', @_);
11700 }
11701  
11702 # Check the room actually has a room tag
11703 if (! $roomObj->roomTag) {
11704  
11705 # Nothing to do here
11706 return undef;
11707 }
11708  
11709 # Delete the entry in the world model's list of room tags
11710 $self->ivDelete('roomTagHash', $roomObj->roomTag);
11711  
11712 # Find the room's regionmap and update it
11713 $regionmapObj = $self->findRegionmap($roomObj->parent);
11714 $regionmapObj->removeRoomTag($roomObj);
11715  
11716 # Reset the room object's own IV
11717 $roomObj->ivUndef('roomTag');
11718  
11719 # Update any GA::Win::Map objects using this world model (if allowed)
11720 if ($updateFlag) {
11721  
11722 foreach my $mapWin ($self->collectMapWins()) {
11723  
11724 # Redraw the room
11725 $mapWin->markObjs('room', $roomObj);
11726 $mapWin->doDraw();
11727 }
11728 }
11729  
11730 return 1;
11731 }
11732  
11733 sub checkRoomTag {
11734  
11735 # Called by GA::Win::Map->setRoomGuildCallback, GA::Cmd::SetRoom->do and
11736 # $self->setRoomTag
11737 # Checks whether a room tag is already in use, or not. Since room tags are supposed to be
11738 # checked in a case-insensitive way, we need to check every existing room tag
11739 # If an existing model room is using the room tag, returns the room's model number;
11740 # otherwise returns 'undef'
11741 #
11742 # Expected arguments
11743 # $tag - A room tag to check. If it is set to 'tower', this function checks whether
11744 # any room is using the tag 'tower', 'TOWER', 'tOwEr', etc
11745 #
11746 # Return values
11747 # 'undef' on improper arguments or if the room tag is available for use
11748 # Otherwise, returns the model number of the room using this tag (with or without the
11749 # same capital letters)
11750  
11751 my ($self, $tag, $check) = @_;
11752  
11753 # Check for improper arguments
11754 if (! defined $tag || defined $check) {
11755  
11756 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRoomTag', @_);
11757 }
11758  
11759 foreach my $otherTag ($self->ivKeys('roomTagHash')) {
11760  
11761 if (lc($tag) eq lc($otherTag)) {
11762  
11763 # The tag is already in use. Return the room's model number
11764 return $self->ivShow('roomTagHash', $otherTag);
11765 }
11766 }
11767  
11768 # The tag is available
11769 return undef;
11770 }
11771  
11772 sub setRoomGuild {
11773  
11774 # Called by GA::Win::Map->setRoomGuildCallback
11775 # Sets the specified room's guild, updating all IVs and redrawing the room (if allowed)
11776 #
11777 # Expected arguments
11778 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11779 # be updated now, FALSE if not (in which case, they can be updated later
11780 # by the calling function, when it is ready)
11781 #
11782 # Optional argument
11783 # $guildName - The name of the guild profile for this room. If set to 'undef', the room's
11784 # guild is reset
11785 # @roomList - A list of room GA::ModelObj::Room objects. If the list is empty, no rooms
11786 # are updated
11787 #
11788 # Return values
11789 # 'undef' on improper arguments or if @roomList is empty
11790 # 1 otherwise
11791  
11792 my ($self, $updateFlag, $guildName, @roomList) = @_;
11793  
11794 # Local variables
11795 my @redrawList;
11796  
11797 # Check for improper arguments
11798 if (! defined $updateFlag) {
11799  
11800 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomGuild', @_);
11801 }
11802  
11803 # Do nothing if @roomList is empty
11804 if (! @roomList) {
11805  
11806 return undef;
11807 }
11808  
11809 # Update each room in turn
11810 foreach my $roomObj (@roomList) {
11811  
11812 my $regionmapObj;
11813  
11814 # Set the room's guild. $guildName might be 'undef'
11815 $roomObj->ivPoke('roomGuild', $guildName);
11816  
11817 # Update the regionmap
11818 $regionmapObj = $self->findRegionmap($roomObj->parent);
11819  
11820 if ($guildName) {
11821 $regionmapObj->storeRoomGuild($roomObj);
11822 } else {
11823 $regionmapObj->removeRoomGuild($roomObj);
11824 }
11825 }
11826  
11827 # Update any GA::Win::Map objects using this world model (if allowed)
11828 if ($updateFlag) {
11829  
11830 foreach my $roomObj (@roomList) {
11831  
11832 push (@redrawList, 'room', $roomObj);
11833 }
11834  
11835 foreach my $mapWin ($self->collectMapWins()) {
11836  
11837 # Redraw the rooms
11838 $mapWin->markObjs(@redrawList);
11839 $mapWin->doDraw();
11840 }
11841 }
11842  
11843 return 1;
11844 }
11845  
11846 sub resetRoomOffsets {
11847  
11848 # Called by GA::Win::Map->resetRoomOffsetsCallback
11849 # Resets the room's room tag and room guild offsets - the distance from the default position
11850 # at which the text is drawn (allows the user to drag the text around the map)
11851 #
11852 # Expected arguments
11853 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11854 # be updated now, FALSE if not (in which case, they can be updated later
11855 # by the calling function, when it is ready)
11856 # $mode - Set to 0 to reset room tags and room guilds, 1 to reset room tags only or
11857 # 2 to reset room guilds only
11858 #
11859 # Optional argument
11860 # @roomList - A list of room GA::ModelObj::Room objects. If the list is empty, no
11861 # rooms are updated
11862 #
11863 # Return values
11864 # 'undef' on improper arguments or if @roomList is empty
11865 # 1 otherwise
11866  
11867 my ($self, $updateFlag, $mode, @roomList) = @_;
11868  
11869 # Local variables
11870 my @redrawList;
11871  
11872 # Check for improper arguments
11873 if (! defined $updateFlag || ! defined $mode) {
11874  
11875 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRoomOffsets', @_);
11876 }
11877  
11878 # Do nothing if @roomList is empty
11879 if (! @roomList) {
11880  
11881 return undef;
11882 }
11883  
11884 # Update each room in turn
11885 foreach my $roomObj (@roomList) {
11886  
11887 if ($roomObj->roomTag && $mode != 2) {
11888  
11889 $roomObj->ivPoke('roomTagXOffset', 0);
11890 $roomObj->ivPoke('roomTagYOffset', 0);
11891 }
11892  
11893 if ($roomObj->roomGuild && $mode != 1) {
11894  
11895 $roomObj->ivPoke('roomGuildXOffset', 0);
11896 $roomObj->ivPoke('roomGuildYOffset', 0);
11897 }
11898 }
11899  
11900 # Update any GA::Win::Map objects using this world model (if allowed)
11901 if ($updateFlag) {
11902  
11903 foreach my $roomObj (@roomList) {
11904  
11905 push (@redrawList, 'room', $roomObj);
11906 }
11907  
11908 foreach my $mapWin ($self->collectMapWins()) {
11909  
11910 # Redraw the rooms
11911 $mapWin->markObjs(@redrawList);
11912 $mapWin->doDraw();
11913 }
11914 }
11915  
11916 return 1;
11917 }
11918  
11919 sub toggleRoomExclusivity {
11920  
11921 # Called by GA::Win::Map->enableRoomsColumn
11922 # Toggles the ->exclusiveFlag for one or more room objects
11923 #
11924 # Expected arguments
11925 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11926 # be updated now, FALSE if not (in which case, they can be updated later
11927 # by the calling function, when it is ready)
11928 #
11929 # Optional argument
11930 # @roomList - A list of room GA::ModelObj::Room objects. If the list is empty, no rooms
11931 # are updated
11932 #
11933 # Return values
11934 # 'undef' on improper arguments or if @roomList is empty
11935 # 1 otherwise
11936  
11937 my ($self, $updateFlag, @roomList) = @_;
11938  
11939 # Local variables
11940 my @redrawList;
11941  
11942 # Check for improper arguments
11943 if (! defined $updateFlag) {
11944  
11945 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleRoomExclusivity', @_);
11946 }
11947  
11948 # Do nothing if @roomList is empty
11949 if (! @roomList) {
11950  
11951 return undef;
11952 }
11953  
11954 # Update each room in turn
11955 foreach my $roomObj (@roomList) {
11956  
11957 if ($roomObj->exclusiveFlag) {
11958 $roomObj->ivPoke('exclusiveFlag', FALSE);
11959 } else {
11960 $roomObj->ivPoke('exclusiveFlag', TRUE);
11961 }
11962 }
11963  
11964 # Update any GA::Win::Map objects using this world model (if allowed)
11965 if ($updateFlag) {
11966  
11967 foreach my $roomObj (@roomList) {
11968  
11969 push (@redrawList, 'room', $roomObj);
11970 }
11971  
11972 foreach my $mapWin ($self->collectMapWins()) {
11973  
11974 # Redraw the rooms
11975 $mapWin->markObjs(@redrawList);
11976 $mapWin->doDraw();
11977 }
11978 }
11979  
11980 return 1;
11981 }
11982  
11983 sub setRoomExclusiveProfile {
11984  
11985 # Called by GA::Win::Map->enableRoomsColumn
11986 # Toggles the ->exclusiveFlag for one or more room objects
11987 #
11988 # Expected arguments
11989 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
11990 # be updated now, FALSE if not (in which case, they can be updated later
11991 # by the calling function, when it is ready)
11992 # $roomObj - The GA::ModelObj::Room to update
11993 # $profName - The profile to be set as an exclusive profile for this room
11994 #
11995 # Return values
11996 # 'undef' on improper arguments or if @roomList is empty
11997 # 1 otherwise
11998  
11999 my ($self, $updateFlag, $roomObj, $profName, $check) = @_;
12000  
12001 # Check for improper arguments
12002 if (! defined $updateFlag) {
12003  
12004 return $axmud::CLIENT->writeImproper(
12005 $self->_objClass . '->setRoomExclusiveProfile',
12006 @_,
12007 );
12008 }
12009  
12010 # Add the profile to this room's exclusive profile hash
12011 $roomObj->ivAdd('exclusiveHash', $profName, undef);
12012  
12013 # Update any GA::Win::Map objects using this world model (if allowed)
12014 if ($updateFlag) {
12015  
12016 foreach my $mapWin ($self->collectMapWins()) {
12017  
12018 # Redraw the room
12019 $mapWin->markObjs('room', $roomObj);
12020 $mapWin->doDraw();
12021 }
12022 }
12023  
12024 return 1;
12025 }
12026  
12027 sub resetExclusiveProfiles {
12028  
12029 # Called by GA::Win::Map->enableRoomsColumn
12030 # Resets the list of exclusive profile for one or more room objects
12031 #
12032 # Expected arguments
12033 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12034 # be updated now, FALSE if not (in which case, they can be updated later
12035 # by the calling function, when it is ready)
12036 #
12037 # Optional argument
12038 # @roomList - A list of room GA::ModelObj::Room objects. If the list is empty, no rooms
12039 # are updated
12040 #
12041 # Return values
12042 # 'undef' on improper arguments or if @roomList is empty
12043 # 1 otherwise
12044  
12045 my ($self, $updateFlag, @roomList) = @_;
12046  
12047 # Local variables
12048 my @redrawList;
12049  
12050 # Check for improper arguments
12051 if (! defined $updateFlag) {
12052  
12053 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetExclusiveProfiles', @_);
12054 }
12055  
12056 # Do nothing if @roomList is empty
12057 if (! @roomList) {
12058  
12059 return undef;
12060 }
12061  
12062 # Update each room in turn
12063 foreach my $roomObj (@roomList) {
12064  
12065 $roomObj->ivEmpty('exclusiveHash');
12066 }
12067  
12068 # Update any GA::Win::Map objects using this world model (if allowed)
12069 if ($updateFlag) {
12070  
12071 foreach my $roomObj (@roomList) {
12072  
12073 push (@redrawList, 'room', $roomObj);
12074 }
12075  
12076 foreach my $mapWin ($self->collectMapWins()) {
12077  
12078 # Redraw the rooms
12079 $mapWin->markObjs(@redrawList);
12080 $mapWin->doDraw();
12081 }
12082 }
12083  
12084 return 1;
12085 }
12086  
12087 sub updateInvRepExit {
12088  
12089 # Called by $self->deleteObj
12090 # Each room model object keeps track of which rooms use it as the destination room for an
12091 # involuntary exit pattern/repulse exit pattern
12092 # When a room is deleted, this function is called to remove an entry in the destination
12093 # room's hash
12094 #
12095 # Expected arguments
12096 # $destRoomObj - The room to update
12097 # $deleteRoomObj - The room to be deleted
12098 #
12099 # Return values
12100 # 'undef' on improper arguments
12101 # 1 otherwise
12102  
12103 my ($self, $destRoomObj, $deleteRoomObj, $check) = @_;
12104  
12105 # Check for improper arguments
12106 if (! defined $destRoomObj || ! defined $deleteRoomObj || defined $check) {
12107  
12108 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateInvRepExit', @_);
12109 }
12110  
12111 # Update IVs
12112 $destRoomObj->ivDelete('invRepExitHash', $deleteRoomObj->number);
12113  
12114 return 1;
12115 }
12116  
12117 sub addInvoluntaryExit {
12118  
12119 # Called by GA::EditWin::ModelObj::Room->saveChanges,
12120 # GA::Win::Map->addInvoluntaryExitCallback or any other function
12121 # Adds an involuntary exit pattern and, optionally, a direction (or a room model number)
12122 # which identifies the destination room
12123 #
12124 # Expected arguments
12125 # $roomObj - The room model object (GA::ModelObj::Room) to update
12126 # $pattern - The involuntary exit pattern to add
12127 #
12128 # Optional arguments
12129 # $value - The direction of movement, or the number of the destination room, or
12130 # 'undef'
12131 #
12132 # Return values
12133 # 'undef' on improper arguments
12134 # 1 otherwise
12135  
12136 my ($self, $roomObj, $pattern, $value, $check) = @_;
12137  
12138 # Local variables
12139 my $destRoomObj;
12140  
12141 # Check for improper arguments
12142 if (! defined $roomObj || ! defined $pattern || defined $check) {
12143  
12144 return $axmud::CLIENT->writeImproper($self->_objClass . '->addInvoluntaryExit', @_);
12145 }
12146  
12147 # Update IVs
12148 $roomObj->ivAdd('involuntaryExitPatternHash', $pattern, $value);
12149 # If $value is a destination room, update that room, too
12150 if (defined $value) {
12151  
12152 $destRoomObj = $self->ivShow('modelHash', $value);
12153 if ($destRoomObj) {
12154  
12155 $destRoomObj->ivAdd('invRepExitHash', $roomObj->number);
12156 }
12157 }
12158  
12159 return 1;
12160 }
12161  
12162 sub removeInvoluntaryExit {
12163  
12164 # Called by GA::EditWin::ModelObj::Room->saveChanges or any other function
12165 # Removes an involuntary exit pattern. If the pattern has a corresponding destination room,
12166 # updates the destination room's IVs too
12167 #
12168 # Expected arguments
12169 # $roomObj - The room model object (GA::ModelObj::Room) to update
12170 # $pattern - The involuntary exit pattern to remove
12171 #
12172 # Return values
12173 # 'undef' on improper arguments
12174 # 1 otherwise
12175  
12176 my ($self, $roomObj, $pattern, $check) = @_;
12177  
12178 # Local variables
12179 my ($value, $destRoomObj, $matchFlag);
12180  
12181 # Check for improper arguments
12182 if (! defined $roomObj || ! defined $pattern || defined $check) {
12183  
12184 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeInvoluntaryExit', @_);
12185 }
12186  
12187 # Update IVs
12188 $value = $roomObj->ivShow('involuntaryExitPatternHash', $pattern);
12189 $roomObj->ivDelete('involuntaryExitPatternHash', $pattern);
12190  
12191 if (defined $value) {
12192  
12193 # $value can be 'undef', a direction or a destination room model object
12194 $destRoomObj = $self->ivShow('modelHash', $value);
12195 if (defined $destRoomObj) {
12196  
12197 # If $roomObj has no further involuntary or repulse exit patterns whose
12198 # corresponding destination room number is $value, we can delete the entry
12199 OUTER: foreach my $otherVal (
12200 $roomObj->ivValues('involuntaryExitPatternHash'),
12201 $roomObj->ivValues('repulseExitPatternHash'),
12202 ) {
12203 if (defined $otherVal && $otherVal eq $value) {
12204  
12205 $matchFlag = TRUE;
12206 last OUTER;
12207 }
12208 }
12209  
12210 if (! $matchFlag) {
12211  
12212 $destRoomObj->ivDelete('invRepExitHash', $roomObj->number);
12213 }
12214 }
12215 }
12216  
12217 return 1;
12218 }
12219  
12220 sub addRepulseExit {
12221  
12222 # Called by GA::EditWin::ModelObj::Room->saveChanges,
12223 # GA::Win::Map->addRepulseExitCallback or any other function
12224 # Adds a repulse exit pattern and, optionally, a direction (or a room model number) which
12225 # identifies the destination room
12226 #
12227 # Expected arguments
12228 # $roomObj - The room model object (GA::ModelObj::Room) to update
12229 # $pattern - The repulse exit pattern to add
12230 #
12231 # Optional arguments
12232 # $value - The direction of movement, or the number of the destination room, or
12233 # 'undef'
12234 #
12235 # Return values
12236 # 'undef' on improper arguments
12237 # 1 otherwise
12238  
12239 my ($self, $roomObj, $pattern, $value, $check) = @_;
12240  
12241 # Local variables
12242 my $destRoomObj;
12243  
12244 # Check for improper arguments
12245 if (! defined $roomObj || ! defined $pattern || defined $check) {
12246  
12247 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRepulseExit', @_);
12248 }
12249  
12250 # Update IVs
12251 $roomObj->ivAdd('repulseExitPatternHash', $pattern, $value);
12252 # If $value is a destination room, update that room, too
12253 if (defined $value) {
12254  
12255 $destRoomObj = $self->ivShow('modelHash', $value);
12256 if ($destRoomObj) {
12257  
12258 $destRoomObj->ivAdd('invRepExitHash', $roomObj->number);
12259 }
12260 }
12261  
12262 return 1;
12263 }
12264  
12265 sub removeRepulseExit {
12266  
12267 # Called by GA::EditWin::ModelObj::Room->saveChanges or any other function
12268 # Removes a repulse exit pattern. If the pattern has a corresponding destination room,
12269 # updates the destination room's IVs too
12270 #
12271 # Expected arguments
12272 # $roomObj - The room model object (GA::ModelObj::Room) to update
12273 # $pattern - The repulse exit pattern to remove
12274 #
12275 # Return values
12276 # 'undef' on improper arguments
12277 # 1 otherwise
12278  
12279 my ($self, $roomObj, $pattern, $check) = @_;
12280  
12281 # Local variables
12282 my ($value, $destRoomObj, $matchFlag);
12283  
12284 # Check for improper arguments
12285 if (! defined $roomObj || ! defined $pattern || defined $check) {
12286  
12287 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRepulseExit', @_);
12288 }
12289  
12290 # Update IVs
12291 $value = $roomObj->ivShow('repulseExitPatternHash', $pattern);
12292 $roomObj->ivDelete('repulseExitPatternHash', $pattern);
12293  
12294 if (defined $value) {
12295  
12296 # $value can be 'undef', a direction or a destination room model object
12297 $destRoomObj = $self->ivShow('modelHash', $value);
12298 if (defined $destRoomObj) {
12299  
12300 # If $roomObj has no further involuntary or repulse exit patterns whose
12301 # corresponding destination room number is $value, we can delete the entry
12302 OUTER: foreach my $otherVal (
12303 $roomObj->ivValues('involuntaryExitPatternHash'),
12304 $roomObj->ivValues('repulseExitPatternHash'),
12305 ) {
12306 if (defined $otherVal && $otherVal eq $value) {
12307  
12308 $matchFlag = TRUE;
12309 last OUTER;
12310 }
12311 }
12312  
12313 if (! $matchFlag) {
12314  
12315 $destRoomObj->ivDelete('invRepExitHash', $roomObj->number);
12316 }
12317 }
12318 }
12319  
12320 return 1;
12321 }
12322  
12323 sub addRandomDestination {
12324  
12325 # Called by GA::EditWin::Exit->saveChanges
12326 # Each room model object keeps track of the exits which use the room as a random destination
12327 # (but only when GA::Obj::Exit->randomType is 'room_list')
12328 # This function is called to add an exit to the room's hash
12329 #
12330 # Expected arguments
12331 # $roomObj - The room to update
12332 # $exitObj - The exit (belonging to another room) which now uses $roomObj as one of its
12333 # random destinations
12334 #
12335 # Return values
12336 # 'undef' on improper arguments
12337 # 1 otherwise
12338  
12339 my ($self, $roomObj, $exitObj, $check) = @_;
12340  
12341 # Check for improper arguments
12342 if (! defined $roomObj || ! defined $exitObj || defined $check) {
12343  
12344 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRandomDestination', @_);
12345 }
12346  
12347 $roomObj->ivAdd('randomExitHash', $exitObj->number, undef);
12348  
12349 return 1;
12350 }
12351  
12352 sub removeRandomDestination {
12353  
12354 # Called by GA::EditWin::Exit->saveChanges
12355 # Each room model object keeps track of the exits which use the room as a random destination
12356 # (but only when GA::Obj::Exit->randomType is 'room_list')
12357 # This function is called to remove an exit from the room's hash
12358 #
12359 # Expected arguments
12360 # $roomObj - The room to update
12361 # $exitObj - The exit (belonging to another room) which no longer uses $roomObj as one
12362 # of its random destinations
12363 #
12364 # Return values
12365 # 'undef' on improper arguments
12366 # 1 otherwise
12367  
12368 my ($self, $roomObj, $exitObj, $check) = @_;
12369  
12370 # Check for improper arguments
12371 if (! defined $roomObj || ! defined $exitObj || defined $check) {
12372  
12373 return $axmud::CLIENT->writeImproper(
12374 $self->_objClass . '->removeRandomDestination',
12375 @_,
12376 );
12377 }
12378  
12379 $roomObj->ivDelete('randomExitHash', $exitObj->number, undef);
12380  
12381 return 1;
12382 }
12383  
12384 sub updateRandomExit {
12385  
12386 # Called by $self->deleteObj when a room is deleted, which has an incoming random exit. This
12387 # function removes the room from the exit's list of random destination rooms
12388 #
12389 # Expected arguments
12390 # $exitObj - The exit object to update
12391 # $roomObj - The room which is being deleted
12392 #
12393 # Return values
12394 # 'undef' on improper arguments
12395 # 1 otherwise
12396  
12397 my ($self, $exitObj, $roomObj, $check) = @_;
12398  
12399 # Local variables
12400 my (@roomList, @modList);
12401  
12402 # Check for improper arguments
12403 if (! defined $exitObj || ! defined $roomObj || defined $check) {
12404  
12405 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRandomExit', @_);
12406 }
12407  
12408 # Import the IV
12409 @roomList = $exitObj->randomDestList;
12410  
12411 # Remove $roomObj from the exit's list of random destinations
12412 foreach my $roomNum (@roomList) {
12413  
12414 if ($roomNum ne $roomObj->number) {
12415  
12416 push (@modList, $roomNum);
12417 }
12418 }
12419  
12420 # Update the IV
12421 $exitObj->ivPoke('randomDestList', @modList);
12422  
12423 return 1;
12424 }
12425  
12426 sub setWildernessRoom {
12427  
12428 # Can be called by anything
12429 # Sets a room's ->wildMode, removing any existing exit objects and redrawing as required
12430 #
12431 # Expected arguments
12432 # $session - The calling function's GA::Session
12433 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12434 # be updated now, FALSE if not (in which case, they can be updated later
12435 # by the calling function, when it is ready)
12436 # $mode - The new wilderness mode, one of the strings 'normal', 'border' or 'wild'
12437 # (it doesn't matter if any specified room already has that mode)
12438 #
12439 # Optional arguments
12440 # @roomList - A list of GA::ModelObj::Room objects to update (can be an empty list)
12441 #
12442 # Return values
12443 # 'undef' on improper arguments
12444 # 1 otherwise
12445  
12446 my ($self, $session, $updateFlag, $mode, @roomList) = @_;
12447  
12448 # Local variables
12449 my (
12450 @drawList,
12451 %checkHash,
12452 );
12453  
12454 # Check for improper arguments
12455 if (
12456 ! defined $session
12457 || ! defined $updateFlag
12458 || ! defined $mode
12459 || ($mode ne 'normal' && $mode ne 'border' && $mode ne 'wild')
12460 ) {
12461 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWildernessRoom', @_);
12462 }
12463  
12464 foreach my $roomObj (@roomList) {
12465  
12466 my @exitList;
12467  
12468 # For 'wilderness' rooms, remove all existing exits
12469 if ($mode eq 'wild') {
12470  
12471 foreach my $number ($roomObj->exitNumHash) {
12472  
12473 my ($exitObj, $destRoomObj);
12474  
12475 $exitObj = $self->ivShow('exitModelHash', $number);
12476 if ($exitObj) {
12477  
12478 push (@exitList, $exitObj);
12479  
12480 if (defined $exitObj->destRoom) {
12481  
12482 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
12483 }
12484 }
12485  
12486 # Don't mark the same room to be redrawn twice
12487 if ($destRoomObj && ! exists $checkHash{$destRoomObj->number}) {
12488  
12489 push (@drawList, 'room', $destRoomObj);
12490 $checkHash{$destRoomObj->number} = undef;
12491 }
12492 }
12493  
12494 # For 'wilderness border' rooms, remove all existing exits unless they're connected to a
12495 # normal room
12496 } elsif ($mode eq 'border') {
12497  
12498 foreach my $number ($roomObj->exitNumHash) {
12499  
12500 my ($exitObj, $destRoomObj);
12501  
12502 $exitObj = $self->ivShow('exitModelHash', $number);
12503 if ($exitObj) {
12504  
12505 if (defined $exitObj->destRoom) {
12506  
12507 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
12508 }
12509  
12510 if (! $destRoomObj || $destRoomObj->wildMode ne 'normal') {
12511  
12512 push (@exitList, $exitObj);
12513 }
12514 }
12515  
12516  
12517 # Don't mark the same room to be redrawn twice
12518 if ($destRoomObj && ! exists $checkHash{$destRoomObj->number}) {
12519  
12520 push (@drawList, 'room', $destRoomObj);
12521 $checkHash{$destRoomObj->number} = undef;
12522 }
12523 }
12524 }
12525  
12526 # Delete any exits from rooms that are now 'wilderness' or 'wilderness border' rooms
12527 $self->deleteExits(
12528 $session,
12529 # Deleted exits must be redrawn immediately, regardless of $updateFlag setting
12530 TRUE,
12531 @exitList,
12532 );
12533  
12534 # Now we can actually set the IV
12535 $roomObj->ivPoke('wildMode', $mode);
12536  
12537 # Mark this room to be redrawn (unless it's already been marked to be redrawn)
12538 if (! exists $checkHash{$roomObj->number}) {
12539  
12540 push (@drawList, 'room', $roomObj);
12541 $checkHash{$roomObj->number} = undef;
12542 }
12543 }
12544  
12545 # Update any GA::Win::Map objects using this world model (if allowed)
12546 if ($updateFlag) {
12547  
12548 foreach my $mapWin ($self->collectMapWins()) {
12549  
12550 $mapWin->markObjs(@drawList);
12551 $mapWin->doDraw();
12552 }
12553 }
12554  
12555 return 1;
12556 }
12557  
12558 # Modify model objects - exits
12559  
12560 sub disconnectExit {
12561  
12562 # Can be called by anything
12563 # Disconnects the specified exit object from its destination room. If the exit has a twin
12564 # exit, that exit is disconnected, too
12565 # This function is a quick way to call the right code (e.g. $self->abandonTwinExit,
12566 # ->abandonUncertainExit etc)
12567 #
12568 # Expected arguments
12569 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12570 # be updated now, FALSE if not (in which case, they can be updated later
12571 # by the calling function, when it is ready)
12572 # $exitObj - The GA::Obj::Exit to disconnect
12573 #
12574 # Return values
12575 # 'undef' on improper arguments or if the exit isn't connected to a room
12576 # Otherwise returns the result of the call to $self->abandonTwinExit, etc)
12577  
12578 my ($self, $updateFlag, $exitObj, $check) = @_;
12579  
12580 # Check for improper arguments
12581 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
12582  
12583 return $axmud::CLIENT->writeImproper($self->_objClass . '->disconnectExit', @_);
12584 }
12585  
12586 if ($exitObj->destRoom) {
12587  
12588 if ($exitObj->twinExit) {
12589  
12590 # Two-way exit
12591 return $self->abandonTwinExit($updateFlag, $exitObj);
12592  
12593 } elsif ($exitObj->retraceFlag) {
12594  
12595 # Retracing exit
12596 return $self->restoreRetracingExit($updateFlag, $exitObj);
12597  
12598 } elsif ($exitObj->oneWayFlag) {
12599  
12600 # One-way exit
12601 return $self->abandonOneWayExit($updateFlag, $exitObj);
12602  
12603 } elsif ($exitObj->randomType ne 'none') {
12604  
12605 # Random exit
12606 return $self->restoreRandomExit($updateFlag, $exitObj);
12607  
12608 } else {
12609  
12610 # Uncertain exit
12611 return $self->abandonUncertainExit($updateFlag, $exitObj);
12612 }
12613  
12614 } elsif ($exitObj->randomType ne 'none') {
12615  
12616 # Random exit
12617 return $self->restoreRandomExit($updateFlag, $exitObj);
12618  
12619 } else {
12620  
12621 # Exit not connected
12622 return undef;
12623 }
12624  
12625 return 1;
12626 }
12627  
12628 sub setRegionExit {
12629  
12630 # Can be called by anything
12631 # Converts an exit into a region exit (cancelling its status as a broken exit, if need be)
12632 #
12633 # Expected arguments
12634 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12635 # be updated now, FALSE if not (in which case, they can be updated later
12636 # by the calling function, when it is ready)
12637 # $exitObj - The GA::Obj::Exit to convert
12638 #
12639 # Optional arguments
12640 # $regionNum - The model number of the exit's parent region (set to 'undef' if not
12641 # immediately available)
12642 #
12643 # Return values
12644 # 'undef' on improper arguments
12645 # 1 otherwise
12646  
12647 my ($self, $updateFlag, $exitObj, $regionNum, $check) = @_;
12648  
12649 # Local variables
12650 my ($roomObj, $regionObj, $destRoomObj, $destRegionObj);
12651  
12652 # Check for improper arguments
12653 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
12654  
12655 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRegionExit', @_);
12656 }
12657  
12658 # Mark the exit as a region exit
12659 $exitObj->ivPoke('regionFlag', TRUE);
12660 $exitObj->ivPoke('brokenFlag', FALSE);
12661 $exitObj->ivPoke('bentFlag', FALSE);
12662 $exitObj->ivEmpty('bendOffsetList');
12663  
12664 # Find the parent region
12665 if (! $regionNum) {
12666  
12667 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
12668 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
12669  
12670 } else {
12671  
12672 $regionObj = $self->ivShow('modelHash', $regionNum);
12673 }
12674  
12675 # Automatically set the exit tag, if allowed
12676 $self->applyExitTag(
12677 FALSE, # Don't update Automapper windows yet
12678 $exitObj,
12679 $self->ivShow('regionmapHash', $regionObj->name),
12680 );
12681  
12682 # Any region paths using the exit will have to be updated
12683 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
12684 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
12685  
12686 if ($updateFlag) {
12687  
12688 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12689 # window using this world model
12690 $self->updateMapExit($exitObj);
12691 }
12692  
12693 return 1;
12694 }
12695  
12696 sub unsetRegionExit {
12697  
12698 # Can be called by anything
12699 # Converts a region exit into a non-region exit (it's up to the calling function to check
12700 # whether it is now a broken exit, or not)
12701 #
12702 # Expected arguments
12703 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12704 # be updated now, FALSE if not (in which case, they can be updated later
12705 # by the calling function, when it is ready)
12706 # $exitObj - The GA::Obj::Exit to convert
12707 #
12708 # Optional arguments
12709 # $regionNum - The model number of the exit's parent region (set to 'undef' if not
12710 # immediately available)
12711 #
12712 # Return values
12713 # 'undef' on improper arguments
12714 # 1 otherwise
12715  
12716 my ($self, $updateFlag, $exitObj, $regionNum, $check) = @_;
12717  
12718 # Local variables
12719 my ($roomObj, $regionObj);
12720  
12721 # Check for improper arguments
12722 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
12723  
12724 return $axmud::CLIENT->writeImproper($self->_objClass . '->unsetRegionExit', @_);
12725 }
12726  
12727 # If it's not a region exit, do nothing
12728 if ($exitObj->regionFlag) {
12729  
12730 # Find the parent region
12731 if (! $regionNum) {
12732  
12733 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
12734 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
12735  
12736 } else {
12737  
12738 $regionObj = $self->ivShow('modelHash', $regionNum);
12739 }
12740  
12741 # Update IVs
12742 $exitObj->ivPoke('regionFlag', FALSE);
12743 $exitObj->ivPoke('superFlag', FALSE);
12744 $exitObj->ivPoke('notSuperFlag', FALSE);
12745 $self->cancelExitTag(
12746 FALSE, # Don't update Automapper windows yet
12747 $exitObj,
12748 $self->ivShow('regionmapHash', $regionObj->name),
12749 );
12750  
12751 # Any region paths using the exit will have to be updated
12752 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
12753 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
12754  
12755 if ($updateFlag) {
12756  
12757 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12758 # window using this world model
12759 $self->updateMapExit($exitObj);
12760 }
12761 }
12762  
12763 return 1;
12764 }
12765  
12766 sub setBrokenExit {
12767  
12768 # Can be called by anything
12769 # Converts an exit into a broken exit. Region exits can't be converted into broken exits, so
12770 # the operation will fail if a calling function tries that
12771 #
12772 # Expected arguments
12773 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12774 # be updated now, FALSE if not (in which case, they can be updated later
12775 # by the calling function, when it is ready)
12776 # $exitObj - The GA::Obj::Exit to convert
12777 #
12778 # Optional arguments
12779 # $regionNum - The model number of the exit's parent region (set to 'undef' if not
12780 # immediately available)
12781 #
12782 # Return values
12783 # 'undef' on improper arguments or if $exitObj is a region exit
12784 # 1 otherwise
12785  
12786 my ($self, $updateFlag, $exitObj, $regionNum, $check) = @_;
12787  
12788 # Local variables
12789 my ($roomObj, $regionObj, $destRoomObj);
12790  
12791 # Check for improper arguments
12792 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
12793  
12794 return $axmud::CLIENT->writeImproper($self->_objClass . '->setBrokenExit', @_);
12795 }
12796  
12797 # Region exits can't be converted into broken exits
12798 if ($exitObj->regionFlag) {
12799  
12800 return undef;
12801 }
12802  
12803 # Find the parent region and destination room (if any)
12804 if (! $regionNum) {
12805  
12806 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
12807 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
12808  
12809 } else {
12810  
12811 $regionObj = $self->ivShow('modelHash', $regionNum);
12812 }
12813  
12814 if ($exitObj->destRoom) {
12815  
12816 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
12817 }
12818  
12819 # Any region paths using the exit will have to be updated
12820 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
12821  
12822 # Mark the exit as broken
12823 $exitObj->ivPoke('brokenFlag', TRUE);
12824 $self->checkBentExit($exitObj, $roomObj, $destRoomObj);
12825  
12826 if ($updateFlag) {
12827  
12828 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12829 # window using this world model
12830 $self->updateMapExit($exitObj);
12831 }
12832  
12833 return 1;
12834 }
12835  
12836 sub unsetBrokenExit {
12837  
12838 # Can be called by anything
12839 # Converts a broken exit into a non-broken exit (it's up to the calling function to check
12840 # whether it is now a region exit, or not)
12841 #
12842 # Expected arguments
12843 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12844 # be updated now, FALSE if not (in which case, they can be updated later
12845 # by the calling function, when it is ready)
12846 # $exitObj - The GA::Obj::Exit to convert
12847 #
12848 # Optional arguments
12849 # $regionNum - The model number of the exit's parent region (set to 'undef' if not
12850 # immediately available)
12851 #
12852 # Return values
12853 # 'undef' on improper arguments
12854 # 1 otherwise
12855  
12856 my ($self, $updateFlag, $exitObj, $regionNum, $check) = @_;
12857  
12858 # Local variables
12859 my ($roomObj, $regionObj);
12860  
12861 # Check for improper arguments
12862 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
12863  
12864 return $axmud::CLIENT->writeImproper($self->_objClass . '->unsetBrokenExit', @_);
12865 }
12866  
12867 # If it's not a broken exit, do nothing
12868 if ($exitObj->brokenFlag) {
12869  
12870 # Update IVs
12871 $exitObj->ivPoke('brokenFlag', FALSE);
12872 $exitObj->ivPoke('bentFlag', FALSE);
12873 $exitObj->ivEmpty('bendOffsetList');
12874  
12875 # Find the parent region
12876 if (! $regionNum) {
12877  
12878 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
12879 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
12880  
12881 } else {
12882  
12883 $regionObj = $self->ivShow('modelHash', $regionNum);
12884 }
12885  
12886 # Any region paths using the exit will have to be updated
12887 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
12888  
12889 if ($updateFlag) {
12890  
12891 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12892 # window using this world model
12893 $self->updateMapExit($exitObj);
12894 }
12895 }
12896  
12897 return 1;
12898 }
12899  
12900 sub restoreBrokenExit {
12901  
12902 # Can be called by anything
12903 # Converts an existing broken exit into a normal (unbroken) exit, if it's possible to do so
12904 #
12905 # Expected arguments
12906 # $session - The calling function's GA::Session
12907 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
12908 # should be updated now, FALSE if not (in which case, they can be
12909 # updated later by the calling function, when it is ready)
12910 # $exitObj - The GA::Obj::Exit to convert
12911 #
12912 # Optional arguments
12913 # $noCheckFlag - Flag set to TRUE if the calling function has already checked whether
12914 # it's possible to restore the broken index (in a call to
12915 # $self->checkRoomAlignment). If set to FALSE (or 'undef'), this
12916 # function performs the check
12917 #
12918 # Return values
12919 # 'undef' on improper arguments or if the broken exit can't be restored
12920 # 1 otherwise
12921  
12922 my ($self, $session, $updateFlag, $exitObj, $noCheckFlag, $check) = @_;
12923  
12924 # Local variables
12925 my ($roomObj, $regionObj);
12926  
12927 # Check for improper arguments
12928 if (! defined $session || ! defined $updateFlag || ! defined $exitObj || defined $check) {
12929  
12930 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreBrokenExit', @_);
12931 }
12932  
12933 if (
12934 ! $exitObj->brokenFlag
12935 || (! $noCheckFlag && ! $self->checkRoomAlignment($session, $exitObj))
12936 ) {
12937 # The broken exit can't be restored
12938 return undef;
12939 }
12940  
12941 # Mark the exit as not broken
12942 $exitObj->ivPoke('brokenFlag', FALSE);
12943 $exitObj->ivPoke('bentFlag', FALSE);
12944 $exitObj->ivEmpty('bendOffsetList');
12945  
12946 # Find the parent region
12947 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
12948 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
12949  
12950 # Any region paths using the restored exit will have to be updated
12951 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
12952  
12953 if ($updateFlag) {
12954  
12955 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12956 # window using this world model
12957 $self->updateMapExit($exitObj);
12958 }
12959  
12960 return 1;
12961 }
12962  
12963 sub setHiddenExit {
12964  
12965 # Can be called by anything
12966 # Converts an exit into a hidden exit (one which isn't expected to appear in a room
12967 # statement's list of exits)
12968 #
12969 # Expected arguments
12970 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
12971 # be updated now, FALSE if not (in which case, they can be updated later
12972 # by the calling function, when it is ready)
12973 # $exitObj - The GA::Obj::Exit to modify
12974 # $hiddenFlag - The new value of the IV - TRUE of FALSE
12975 #
12976 # Return values
12977 # 'undef' on improper arguments
12978 # 1 otherwise
12979  
12980 my ($self, $updateFlag, $exitObj, $hiddenFlag, $check) = @_;
12981  
12982 # Check for improper arguments
12983 if (
12984 ! defined $updateFlag || ! defined $exitObj || ! defined $hiddenFlag || defined $check
12985 ) {
12986 return $axmud::CLIENT->writeImproper($self->_objClass . '->setHiddenExit', @_);
12987 }
12988  
12989 if ($hiddenFlag) {
12990 $exitObj->ivPoke('hiddenFlag', TRUE);
12991 } else {
12992 $exitObj->ivPoke('hiddenFlag', FALSE);
12993 }
12994  
12995 if ($updateFlag) {
12996  
12997 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
12998 # window using this world model
12999 $self->updateMapExit($exitObj);
13000 }
13001  
13002 return 1;
13003 }
13004  
13005 sub convertUncertainExit {
13006  
13007 # Can be called by anything
13008 # Converts an uncertain exit into a one-way exit, updating the (potential) destination
13009 # room's IVs as well
13010 #
13011 # Expected arguments
13012 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13013 # be updated now, FALSE if not (in which case, they can be updated later
13014 # by the calling function, when it is ready)
13015 # $exitObj - The GA::Obj::Exit to convert
13016 # $roomObj - The GA::ModelObj::Room which stores this exit as an uncertain exit
13017 #
13018 # Return values
13019 # 'undef' on improper arguments
13020 # 1 otherwise
13021  
13022 my ($self, $updateFlag, $exitObj, $roomObj, $check) = @_;
13023  
13024 # Check for improper arguments
13025 if (! defined $updateFlag || ! defined $exitObj || ! defined $roomObj || defined $check) {
13026  
13027 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertUncertainExit', @_);
13028 }
13029  
13030 # Mark the uncertain exit as a one-way exit
13031 $exitObj->ivPoke('oneWayFlag', TRUE);
13032 # The default incoming direction (where the exit touches its destination room) is the
13033 # opposite of ->mapDir
13034 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as an
13035 # emergency default value for ->mapDir
13036 if ($exitObj->mapDir) {
13037  
13038 $exitObj->ivPoke(
13039 'oneWayDir',
13040 $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir),
13041 );
13042  
13043 } else {
13044  
13045 # Emergency default
13046 $exitObj->ivPoke('oneWayDir', 'north');
13047 }
13048  
13049 # Set ->randomType too, just to be safe
13050 $exitObj->ivPoke('randomType', 'none');
13051 # Update the (potential) destination room's IVs
13052 $roomObj->ivDelete('uncertainExitHash', $exitObj->number);
13053 $roomObj->ivAdd('oneWayExitHash', $exitObj->number, undef);
13054  
13055 # Update any GA::Win::Map objects using this world model (if allowed)
13056 if ($updateFlag) {
13057  
13058 foreach my $mapWin ($self->collectMapWins()) {
13059  
13060 # Redraw both the exit and its destination room
13061 $mapWin->markObjs(
13062 'exit', $exitObj,
13063 'room', $roomObj,
13064 );
13065  
13066 $mapWin->doDraw();
13067 }
13068 }
13069  
13070 return 1;
13071 }
13072  
13073 sub convertOneWayExit {
13074  
13075 # Can be called by anything
13076 # Converts a one-way exit into an uncertain exit, updating the destination room's IVs as
13077 # well
13078 #
13079 # Expected arguments
13080 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
13081 # should be updated now, FALSE if not (in which case, they can be
13082 # updated later by the calling function, when it is ready)
13083 # $incomingExitObj - The GA::Obj::Exit to convert
13084 # $roomObj - The GA::ModelObj::Room which stores this exit as a one-way exit
13085 # $oppExitObj - The exit in $roomObj which is the opposite of the incoming exit
13086 #
13087 # Return values
13088 # 'undef' on improper arguments
13089 # 1 otherwise
13090  
13091 my ($self, $updateFlag, $incomingExitObj, $roomObj, $oppExitObj, $check) = @_;
13092  
13093 # Local variables
13094 my @redrawList;
13095  
13096 # Check for improper arguments
13097 if (
13098 ! defined $updateFlag || ! defined $incomingExitObj || ! defined $roomObj
13099 || defined $check
13100 ) {
13101 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertOneWayExit', @_);
13102 }
13103  
13104 # Mark the one-way exit as an uncertain exit
13105 $incomingExitObj->ivPoke('oneWayFlag', FALSE);
13106 $incomingExitObj->ivPoke('oneWayDir', undef);
13107 # Set ->randomType too, just to be safe
13108 $incomingExitObj->ivPoke('randomType', 'none');
13109 # Update the destination room's IVs
13110 $roomObj->ivDelete('oneWayExitHash', $incomingExitObj->number);
13111 $roomObj->ivAdd('uncertainExitHash', $incomingExitObj->number, $oppExitObj->number);
13112  
13113 # Update any GA::Win::Map objects using this world model (if allowed)
13114 if ($updateFlag) {
13115  
13116 # Redraw both rooms
13117 @redrawList = (
13118 'room', $roomObj,
13119 'room', $self->ivShow('modelHash', $incomingExitObj->parent),
13120 );
13121  
13122 foreach my $mapWin ($self->collectMapWins()) {
13123  
13124 $mapWin->markObjs(@redrawList);
13125 $mapWin->doDraw();
13126 }
13127 }
13128  
13129 return 1;
13130 }
13131  
13132 sub markOneWayExit {
13133  
13134 # Called by GA::Win::Map->markOneWayExitCallback
13135 # Converts an existing two-way or uncertain exit into a one-way exit, updating the
13136 # destination room's IVs as well
13137 #
13138 # Expected arguments
13139 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13140 # be updated now, FALSE if not (in which case, they can be updated later
13141 # by the calling function, when it is ready)
13142 # $exitObj - The GA::Obj::Exit to convert
13143 #
13144 # Return values
13145 # 'undef' on improper arguments
13146 # 1 otherwise
13147  
13148 my ($self, $updateFlag, $exitObj, $check) = @_;
13149  
13150 # Local variables
13151 my (
13152 $destRoomObj, $twinExitObj, $parentRoomObj, $parentRegionObj,
13153 @redrawList,
13154 );
13155  
13156 # Check for improper arguments
13157 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13158  
13159 return $axmud::CLIENT->writeImproper($self->_objClass . '->markOneWayExit', @_);
13160 }
13161  
13162 # Mark this exit as a one-way exit
13163 $exitObj->ivPoke('oneWayFlag', TRUE);
13164 # The default incoming direction (where the exit touches its destination room) is the
13165 # opposite of ->mapDir
13166 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as an
13167 # emergency default value for ->mapDir
13168 if ($exitObj->mapDir) {
13169  
13170 $exitObj->ivPoke(
13171 'oneWayDir',
13172 $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir),
13173 );
13174  
13175 } else {
13176  
13177 # Emergency default
13178 $exitObj->ivPoke('oneWayDir', 'north');
13179 }
13180  
13181 # Set ->randomType too, just to be safe
13182 $exitObj->ivPoke('randomType', 'none');
13183 # (The exit's ->destRoom will be reset in the call to ->abandonTwinExit, so save it so it
13184 # can be restored)
13185 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
13186  
13187 # If the exit is a two-way exit (not an uncertain exit)
13188 if ($exitObj->twinExit) {
13189  
13190 # Mark the twin exit as an incomplete exit (the call to ->abandonTwinExit updates
13191 # $self->updatePathHash and ->updateBoundaryHash)
13192 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
13193 $self->abandonTwinExit(
13194 FALSE, # Don't update Automapper windows yet
13195 $exitObj,
13196 $twinExitObj,
13197 );
13198  
13199 } else {
13200  
13201 # Remove the selected exit from the destination room's hash of incoming uncertain exits
13202 $destRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
13203  
13204 # Get the parent room and region
13205 $parentRoomObj = $self->ivShow('modelHash', $exitObj->parent);
13206 $parentRegionObj = $self->ivShow('modelHash', $parentRoomObj->parent);
13207  
13208 # Any region paths using the exit will have to be updated
13209 $self->ivAdd('updatePathHash', $exitObj->number, $parentRegionObj->name);
13210 if ($exitObj->regionFlag) {
13211  
13212 $self->ivAdd('updateBoundaryHash', $exitObj->number, $parentRegionObj->name);
13213 }
13214 }
13215  
13216 # Update the destination room's IVs
13217 $exitObj->ivPoke('destRoom', $destRoomObj->number);
13218 $destRoomObj->ivAdd('oneWayExitHash', $exitObj->number, undef);
13219  
13220 # Update any GA::Win::Map objects using this world model (if allowed)
13221 if ($updateFlag) {
13222  
13223 # Redraw both rooms
13224 @redrawList = (
13225 'room', $destRoomObj,
13226 'room', $self->ivShow('modelHash', $exitObj->parent),
13227 );
13228  
13229 foreach my $mapWin ($self->collectMapWins()) {
13230  
13231 $mapWin->markObjs(@redrawList);
13232 $mapWin->doDraw();
13233 }
13234 }
13235  
13236 return 1;
13237 }
13238  
13239 sub abandonTwinExit {
13240  
13241 # Can be called by anything
13242 # If the specified exit has a twin exit, updates both exits to remove the relationship
13243 # between them
13244 #
13245 # Expected arguments
13246 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
13247 # should be updated now, FALSE if not (in which case, they can be
13248 # updated later by the calling function, when it is ready)
13249 # $exitObj - The GA::Obj::Exit to check
13250 #
13251 # Optional arguments
13252 # $twinExitObj - $exitObj's twin exit object, if known. If not specified, this function
13253 # finds it
13254 #
13255 # Return values
13256 # 'undef' on improper arguments or if the exit object doesn't have a twin
13257 # 1 otherwise
13258  
13259 my ($self, $updateFlag, $exitObj, $twinExitObj, $check) = @_;
13260  
13261 # Local variables
13262 my (
13263 $roomObj, $regionObj, $twinRoomObj, $twinRegionObj,
13264 @list,
13265 );
13266  
13267 # Check for improper arguments
13268 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13269  
13270 return $axmud::CLIENT->writeImproper($self->_objClass . '->abandonTwinExit', @_);
13271 }
13272  
13273 # If the exit doesn't have a twin, do nothing
13274 if (! $exitObj->twinExit) {
13275  
13276 return undef;
13277  
13278 # Find the twin exit object, if not specified
13279 } elsif (! $twinExitObj) {
13280  
13281 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
13282 }
13283  
13284 # Find the parent room and region
13285 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13286 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13287  
13288 # Any region paths using the exits will have to be updated
13289 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13290 if ($exitObj->regionFlag) {
13291  
13292 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13293 }
13294  
13295 # Modify $exitObj
13296 $exitObj->ivUndef('destRoom');
13297 $exitObj->ivUndef('twinExit');
13298 # If this exit is marked as a broken or region exit, convert it into an incomplete exit
13299 $exitObj->ivPoke('brokenFlag', FALSE);
13300 $exitObj->ivPoke('bentFlag', FALSE);
13301 $exitObj->ivEmpty('bendOffsetList');
13302  
13303 $exitObj->ivPoke('regionFlag', FALSE);
13304 $exitObj->ivPoke('superFlag', FALSE);
13305 $exitObj->ivPoke('notSuperFlag', FALSE);
13306 $self->cancelExitTag(
13307 FALSE, # Don't update Automapper windows yet
13308 $exitObj,
13309 $self->ivShow('regionmapHash', $regionObj->name),
13310 );
13311  
13312 # Set ->randomType too, just to be safe
13313 $exitObj->ivPoke('randomType', 'none');
13314  
13315 # Modify the $twinExitObj, if it still exists
13316 if ($twinExitObj) {
13317  
13318 # Find the parent room and region
13319 $twinRoomObj = $self->ivShow('modelHash', $twinExitObj->parent);
13320 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
13321  
13322 # Any region paths using the exits will have to be updated
13323 $self->ivAdd('updatePathHash', $twinExitObj->number, $twinRegionObj->name);
13324 if ($twinExitObj->regionFlag) {
13325  
13326 $self->ivAdd('updateBoundaryHash', $twinExitObj->number, $twinRegionObj->name);
13327 }
13328  
13329 # Modify $twinExitObj
13330 $twinExitObj->ivUndef('destRoom');
13331 $twinExitObj->ivUndef('twinExit');
13332 # If this exit is marked as a broken or region exit, convert it into an incomplete exit
13333 $twinExitObj->ivPoke('brokenFlag', FALSE);
13334 $twinExitObj->ivPoke('bentFlag', FALSE);
13335 $twinExitObj->ivEmpty('bendOffsetList');
13336 $twinExitObj->ivPoke('regionFlag', FALSE);
13337 $twinExitObj->ivPoke('superFlag', FALSE);
13338 $twinExitObj->ivPoke('notSuperFlag', FALSE);
13339 $self->cancelExitTag(
13340 FALSE, # Don't update Automapper windows yet
13341 $twinExitObj,
13342 $self->ivShow('regionmapHash', $twinRegionObj->name),
13343 );
13344  
13345 # Set ->randomType too, just to be safe
13346 $twinExitObj->ivPoke('randomType', 'none');
13347 }
13348  
13349 # Update any GA::Win::Map objects using this world model (if allowed)
13350 if ($updateFlag) {
13351  
13352 # If the exit has a twin, that must be redrawn, too
13353 @list = ('exit', $exitObj);
13354 if ($twinExitObj) {
13355  
13356 push (@list, 'exit', $twinExitObj);
13357 }
13358  
13359 foreach my $mapWin ($self->collectMapWins()) {
13360  
13361 # Redraw the exit(s)
13362 $mapWin->markObjs(@list);
13363 $mapWin->doDraw();
13364 }
13365 }
13366  
13367 return 1;
13368 }
13369  
13370 sub abandonShadowExit {
13371  
13372 # Can be called by anything
13373 # If the specified exit has a shadow exit, resets the stored shadow exit
13374 #
13375 # Expected arguments
13376 # $exitObj - The GA::Obj::Exit to check
13377 #
13378 # Return values
13379 # 'undef' on improper arguments or if the exit object doesn't have a shadow exit
13380 # 1 otherwise
13381  
13382 my ($self, $exitObj, $check) = @_;
13383  
13384 # Local variables
13385 my ($roomObj, $regionObj);
13386  
13387 # Check for improper arguments
13388 if (! defined $exitObj || defined $check) {
13389  
13390 return $axmud::CLIENT->writeImproper($self->_objClass . '->abandonShadowExit', @_);
13391 }
13392  
13393 # If the exit doesn't have a shadow, do nothing
13394 if (! $exitObj->shadowExit) {
13395  
13396 return undef;
13397 }
13398  
13399 # Update the exit
13400 $exitObj->ivUndef('shadowExit');
13401  
13402 # Find the parent region
13403 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13404 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13405 # Any region paths using the exit will have to be updated
13406 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13407 if ($exitObj->regionFlag) {
13408  
13409 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13410 }
13411  
13412 return 1;
13413 }
13414  
13415 sub abandonUncertainExit {
13416  
13417 # Called by $self->deleteObj
13418 # Also called by $self->convertToTwinExits and GA::Win::Map->disconnectExitCallback
13419 #
13420 # If the specified uncertain exit has a destination room which is to be deleted, its
13421 # destination must be reset. This function also converts an uncertain exit to an
13422 # incomplete exit, for any code that needs it
13423 #
13424 # Expected arguments
13425 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
13426 # should be updated now, FALSE if not (in which case, they can be
13427 # updated later by the calling function, when it is ready)
13428 # $exitObj - The GA::Obj::Exit to check
13429 #
13430 # Return values
13431 # 'undef' on improper arguments or if the exit object doesn't have a twin
13432 # 1 otherwise
13433  
13434 my ($self, $updateFlag, $exitObj, $check) = @_;
13435  
13436 # Local variables
13437 my ($roomObj, $regionObj, $destRoomObj);
13438  
13439 # Check for improper arguments
13440 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13441  
13442 return $axmud::CLIENT->writeImproper($self->_objClass . '->abandonUncertainExit', @_);
13443 }
13444  
13445 # If the exit isn't an uncertain exit, do nothing
13446 if (
13447 ! $exitObj->destRoom
13448 || $exitObj->randomType ne 'none'
13449 || $exitObj->oneWayFlag
13450 || $exitObj->retraceFlag
13451 ) {
13452 return undef;
13453 }
13454  
13455 # Find the parent room and region
13456 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13457 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13458 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
13459  
13460 # Modify $exitObj
13461 $exitObj->ivUndef('destRoom');
13462 $exitObj->ivUndef('twinExit');
13463 # Set ->randomType too, just to be safe
13464 $exitObj->ivPoke('randomType', 'none');
13465 # If this exit is marked as a broken or region exit, convert it into an incomplete exit
13466 $exitObj->ivPoke('brokenFlag', FALSE);
13467 $exitObj->ivPoke('bentFlag', FALSE);
13468 $exitObj->ivEmpty('bendOffsetList');
13469  
13470 $exitObj->ivPoke('regionFlag', FALSE);
13471 $self->cancelExitTag(
13472 FALSE, # Don't update Automapper windows yet
13473 $exitObj,
13474 $self->ivShow('regionmapHash', $regionObj->name),
13475 );
13476  
13477 # Inform the destination room that it has lost an incoming uncertain exit (if the
13478 # destination room still exits)
13479 if ($destRoomObj) {
13480  
13481 $destRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
13482 }
13483  
13484 # Any region paths using the exits will have to be updated
13485 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13486 if ($exitObj->regionFlag) {
13487  
13488 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13489 }
13490  
13491 # Update any GA::Win::Map objects using this world model (if allowed)
13492 if ($updateFlag) {
13493  
13494 foreach my $mapWin ($self->collectMapWins()) {
13495  
13496 # Redraw the exit
13497 $mapWin->markObjs('exit', $exitObj);
13498 $mapWin->doDraw();
13499 }
13500 }
13501  
13502 return 1;
13503 }
13504  
13505 sub abandonOneWayExit {
13506  
13507 # Called by $self->deleteObj
13508 # Also called by $self->convertToTwinExits and GA::Win::Map->disconnectExitCallback
13509 #
13510 # If the specified one-way exit has a destination room which is to be deleted, its
13511 # destination must be reset. This function also converts a one-way exit to an incomplete
13512 # exit, for any code that needs it
13513 #
13514 # Expected arguments
13515 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
13516 # should be updated now, FALSE if not (in which case, they can be
13517 # updated later by the calling function, when it is ready)
13518 # $exitObj - The GA::Obj::Exit to check
13519 #
13520 # Return values
13521 # 'undef' on improper arguments or if the exit object doesn't have a twin
13522 # 1 otherwise
13523  
13524 my ($self, $updateFlag, $exitObj, $check) = @_;
13525  
13526 # Local variables
13527 my ($roomObj, $regionmapObj, $destRoomObj);
13528  
13529 # Check for improper arguments
13530 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13531  
13532 return $axmud::CLIENT->writeImproper($self->_objClass . '->abandonOneWayExit', @_);
13533 }
13534  
13535 # If the exit isn't a one-way exit, do nothing
13536 if (! $exitObj->oneWayFlag) {
13537  
13538 return undef;
13539 }
13540  
13541 # Find the parent room and region, and the destination room
13542 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13543 $regionmapObj = $self->findRegionmap($roomObj->parent);
13544 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
13545  
13546 # Modify $exitObj
13547 $exitObj->ivUndef('destRoom');
13548 $exitObj->ivUndef('twinExit');
13549 $exitObj->ivPoke('oneWayFlag', FALSE);
13550 $exitObj->ivPoke('oneWayDir', undef);
13551 # Set ->randomType too, just to be safe
13552 $exitObj->ivPoke('randomType', 'none');
13553 # If this exit is marked as a broken or region exit, convert it into an incomplete exit
13554 $exitObj->ivPoke('brokenFlag', FALSE);
13555 $exitObj->ivPoke('bentFlag', FALSE);
13556 $exitObj->ivEmpty('bendOffsetList');
13557 # $exitObj->ivPoke('regionFlag', FALSE);
13558  
13559 # Any region paths using the exits will have to be updated, the next time
13560 # $self->updateRegionPaths is called
13561 $self->ivAdd('updatePathHash', $exitObj->number, $regionmapObj->name);
13562 if ($exitObj->regionFlag) {
13563  
13564 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionmapObj->name);
13565 # The regionmap's ->regionExitHash can be updated immediately, though
13566 $regionmapObj->resetExit($exitObj);
13567  
13568 $exitObj->ivPoke('regionFlag', FALSE);
13569 }
13570  
13571 $self->cancelExitTag(
13572 FALSE, # Don't update Automapper windows yet
13573 $exitObj,
13574 $self->ivShow('regionmapHash', $regionmapObj->name),
13575 );
13576  
13577 # Inform the destination room that it has lost an incoming 1-way exit (if the destination
13578 # room still exits)
13579 if ($destRoomObj) {
13580  
13581 $destRoomObj->ivDelete('oneWayExitHash', $exitObj->number);
13582 }
13583  
13584 # Update any GA::Win::Map objects using this world model (if allowed)
13585 if ($updateFlag) {
13586  
13587 foreach my $mapWin ($self->collectMapWins()) {
13588  
13589 # Redraw the exit
13590 $mapWin->markObjs('exit', $exitObj);
13591 $mapWin->doDraw();
13592 }
13593 }
13594  
13595 return 1;
13596 }
13597  
13598 sub convertToTwinExits {
13599  
13600 # Called by GA::Win::Map->setExitTwinCallback
13601 # Converts a pair of exits, which are either uncertain or one-way exits (one of each, or
13602 # both the same) into twin exits
13603 # Usually called for two exits which aren't in opposite directions (e.g. north and east),
13604 # but which nonetheless lead to each other's parent rooms
13605 #
13606 # Expected arguments
13607 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13608 # be updated now, FALSE if not (in which case, they can be updated later
13609 # by the calling function, when it is ready)
13610 # @exitList - A list of two The GA::Obj::Exits to convert
13611 #
13612 # Return values
13613 # 'undef' on improper arguments or if the exit object doesn't have a twin
13614 # 1 otherwise
13615  
13616 my ($self, $updateFlag, @exitList) = @_;
13617  
13618 # Local variables
13619 my ($exitObj1, $exitObj2, $roomObj1, $roomObj2);
13620  
13621 # Check for improper arguments
13622 if (! defined $updateFlag || scalar @exitList != 2) {
13623  
13624 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertToTwinExits', @_);
13625 }
13626  
13627 # Check that the each of the two exits are either one-way or uncertain exits
13628 foreach my $exitObj (@exitList) {
13629  
13630 if (
13631 ! (
13632 $exitObj->oneWayFlag
13633 || (
13634 $exitObj->destRoom
13635 && ! $exitObj->twinExit
13636 && ! $exitObj->retraceFlag
13637 && $exitObj->randomType eq 'none'
13638 )
13639 )
13640 ) {
13641 return undef;
13642 }
13643 }
13644  
13645 # Reset both exits, removing their status as one-way or twin exits. The FALSE arguments mean
13646 # 'don't update Automapper windows yet'
13647 foreach my $exitObj (@exitList) {
13648  
13649 if ($exitObj->oneWayFlag) {
13650 $self->abandonOneWayExit(FALSE, $exitObj);
13651 } else {
13652 $self->abandonUncertainExit(FALSE, $exitObj);
13653 }
13654 }
13655  
13656 # Now mark each exit as the other's twin
13657 $exitObj1 = shift @exitList;
13658 $exitObj2 = shift @exitList;
13659  
13660 $exitObj1->ivPoke('twinExit', $exitObj2->number);
13661 $exitObj1->ivPoke('destRoom', $exitObj2->parent);
13662  
13663 $exitObj2->ivPoke('twinExit', $exitObj1->number);
13664 $exitObj2->ivPoke('destRoom', $exitObj1->parent);
13665  
13666 # If the exits' parent rooms are in the same region, mark it as a broken exit; otherwise
13667 # mark it as a region exit
13668 $roomObj1 = $self->ivShow('modelHash', $exitObj1->parent);
13669 $roomObj2 = $self->ivShow('modelHash', $exitObj2->parent);
13670  
13671 if ($roomObj1->parent == $roomObj2->parent) {
13672  
13673 $self->setBrokenExit(
13674 FALSE, # Don't update Automapper windows yet
13675 $exitObj1,
13676 $roomObj1->parent,
13677 );
13678  
13679 $self->setBrokenExit(
13680 FALSE, # Don't update Automapper windows yet
13681 $exitObj2,
13682 $roomObj2->parent,
13683 );
13684  
13685 } else {
13686  
13687 $self->setRegionExit(
13688 FALSE, # Don't update Automapper windows yet
13689 $exitObj1,
13690 $roomObj1->parent,
13691 );
13692  
13693 $self->setRegionExit(
13694 FALSE, # Don't update Automapper windows yet
13695 $exitObj2,
13696 $roomObj2->parent,
13697 );
13698 }
13699  
13700 # Update any GA::Win::Map objects using this world model (if allowed)
13701 if ($updateFlag) {
13702  
13703 foreach my $mapWin ($self->collectMapWins()) {
13704  
13705 # Redraw the rooms
13706 $mapWin->markObjs(
13707 'room', $roomObj1,
13708 'room', $roomObj2,
13709 );
13710  
13711 $mapWin->doDraw();
13712 }
13713 }
13714  
13715 return 1;
13716 }
13717  
13718 sub setRetracingExit {
13719  
13720 # Called by $self->connectRooms
13721 # Converts an exit into a retracing exit (resetting other IVs as necessary)
13722 #
13723 # Expected arguments
13724 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13725 # be updated now, FALSE if not (in which case, they can be updated later
13726 # by the calling function, when it is ready)
13727 # $exitObj - The GA::Obj::Exit to convert
13728 #
13729 # Return values
13730 # 'undef' on improper arguments
13731 # 1 otherwise
13732  
13733 my ($self, $updateFlag, $exitObj, $check) = @_;
13734  
13735 # Local variables
13736 my ($regionFlag, $destRoomNum, $twinExitNum, $roomObj, $regionObj);
13737  
13738 # Check for improper arguments
13739 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13740  
13741 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRetracingExit', @_);
13742 }
13743  
13744 $regionFlag = $exitObj->regionFlag;
13745  
13746 # The call to ->abandonTwinExit resets $exitObj->destRoom, so store it so that we can
13747 # restore the original value
13748 if ($exitObj->destRoom) {
13749  
13750 $destRoomNum = $exitObj->destRoom;
13751 }
13752  
13753 # Make sure the exit doesn't have an existing twin and/or shadow exit (both of which are now
13754 # obsolete)
13755 if ($exitObj->twinExit) {
13756  
13757 $twinExitNum = $exitObj->twinExit;
13758  
13759 $self->abandonTwinExit(
13760 FALSE, # Don't update Automapper windows now
13761 $exitObj,
13762 );
13763 }
13764  
13765 if ($exitObj->shadowExit) {
13766  
13767 $self->abandonShadowExit($exitObj);
13768 }
13769  
13770 # Set the exit's IVs
13771 $exitObj->ivPoke('brokenFlag', FALSE);
13772 $exitObj->ivPoke('bentFlag', FALSE);
13773 $exitObj->ivEmpty('bendOffsetList');
13774  
13775 $exitObj->ivPoke('regionFlag', FALSE);
13776 $self->cancelExitTag(
13777 FALSE, # Don't update Automapper windows yet
13778 $exitObj,
13779 );
13780  
13781 $exitObj->ivPoke('randomType', 'none');
13782 $exitObj->ivPoke('oneWayFlag', FALSE);
13783 $exitObj->ivPoke('oneWayDir', undef);
13784 $exitObj->ivPoke('retraceFlag', TRUE);
13785  
13786 if (defined $destRoomNum) {
13787  
13788 $exitObj->ivPoke('destRoom', $destRoomNum);
13789 }
13790  
13791 # If there is a twin exit, the call to ->abandonTwinExit has already updated
13792 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
13793 if (! $exitObj->twinExit) {
13794  
13795 # Find the parent region
13796 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13797 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13798 # Any region paths using the exit will have to be updated
13799 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13800 if ($regionFlag) {
13801  
13802 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13803 }
13804 }
13805  
13806 # Update any GA::Win::Map objects using this world model (if allowed)
13807 if ($updateFlag) {
13808  
13809 foreach my $mapWin ($self->collectMapWins()) {
13810  
13811 my (
13812 $twinExitObj,
13813 @list,
13814 );
13815  
13816 # Mark both the exit and its twin (if any) to be redrawn
13817 @list = ('exit', $exitObj);
13818 if ($twinExitNum) {
13819  
13820 $twinExitObj = $self->ivShow('exitModelHash', $twinExitNum);
13821 if ($twinExitObj) {
13822  
13823 push (@list, 'exit', $twinExitObj);
13824 }
13825 }
13826  
13827 # Redraw the objects
13828 $mapWin->markObjs(@list);
13829 $mapWin->doDraw();
13830 }
13831 }
13832  
13833 return 1;
13834 }
13835  
13836 sub restoreRetracingExit {
13837  
13838 # Called by GA::Win::Map->restoreRetracingExitCallback
13839 # Converts an existing retracing exit into an incomplete exit
13840 #
13841 # Expected arguments
13842 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13843 # be updated now, FALSE if not (in which case, they can be updated later
13844 # by the calling function, when it is ready)
13845 # $exitObj - The GA::Obj::Exit to convert
13846 #
13847 # Return values
13848 # 'undef' on improper arguments
13849 # 1 otherwise
13850  
13851 my ($self, $updateFlag, $exitObj, $check) = @_;
13852  
13853 # Local variables
13854 my $roomObj;
13855  
13856 # Check for improper arguments
13857 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13858  
13859 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreRetracingExit', @_);
13860 }
13861  
13862 # Convert the exit
13863 $exitObj->ivPoke('retraceFlag', FALSE);
13864 $exitObj->ivUndef('destRoom');
13865  
13866 # Update any GA::Win::Map objects using this world model (if allowed)
13867 if ($updateFlag) {
13868  
13869 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13870  
13871 foreach my $mapWin ($self->collectMapWins()) {
13872  
13873 # Redraw the room
13874 $mapWin->markObjs('room', $roomObj);
13875 $mapWin->doDraw();
13876 }
13877 }
13878  
13879 return 1;
13880 }
13881  
13882 sub setRandomExit {
13883  
13884 # Called by GA::Win::Map->markRandomExitCallback
13885 # Converts an exit into a random exit (resetting other IVs as necessary)
13886 #
13887 # Expected arguments
13888 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13889 # be updated now, FALSE if not (in which case, they can be updated later
13890 # by the calling function, when it is ready)
13891 # $exitObj - The GA::Obj::Exit to convert
13892 # $exitType - Set to 'same_region' if the exit leads to a random location in the current
13893 # region, 'any_region' if the exit leads to a random location in any
13894 # region, 'temp_region' if a destination should be created in a new
13895 # temporary region, or 'room_list' if the exit leads to a random location
13896 # in the exit's ->randomDestList
13897 #
13898 # Return values
13899 # 'undef' on improper arguments
13900 # 1 otherwise
13901  
13902 my ($self, $updateFlag, $exitObj, $exitType, $check) = @_;
13903  
13904 # Local variables
13905 my (
13906 $regionFlag, $currentType, $roomObj, $regionObj,
13907 @redrawList,
13908 );
13909  
13910 # Check for improper arguments
13911 if (
13912 ! defined $updateFlag || ! defined $exitObj || ! defined $exitType
13913 || (
13914 $exitType ne 'same_region' && $exitType ne 'any_region'
13915 && $exitType ne 'temp_region' && $exitType ne 'room_list'
13916 )
13917 || defined $check
13918 ) {
13919 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRandomExit', @_);
13920 }
13921  
13922 $regionFlag = $exitObj->regionFlag;
13923 $currentType = $exitObj->randomType;
13924  
13925 # If the exit already has a destination room, mark it for redrawing
13926 if ($exitObj->destRoom) {
13927  
13928 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->destRoom));
13929 }
13930  
13931 # If the exit has a twin, it must be abandoned
13932 if ($exitObj->twinExit) {
13933  
13934 $self->abandonTwinExit(
13935 FALSE, # Don't update Automapper windows yet
13936 $exitObj,
13937 );
13938 }
13939  
13940 # The same applies if the exit has a shadow exit
13941 if ($exitObj->shadowExit) {
13942  
13943 $self->abandonShadowExit($exitObj);
13944 }
13945  
13946 # Update the exit
13947 $exitObj->ivPoke('brokenFlag', FALSE);
13948 $exitObj->ivPoke('bentFlag', FALSE);
13949 $exitObj->ivEmpty('bendOffsetList');
13950  
13951 $exitObj->ivPoke('regionFlag', FALSE);
13952 $self->cancelExitTag(
13953 FALSE, # Don't update Automapper windows yet
13954 $exitObj,
13955 );
13956  
13957 $exitObj->ivPoke('randomType', $exitType);
13958 $exitObj->ivPoke('oneWayFlag', FALSE);
13959 $exitObj->ivPoke('oneWayDir', undef);
13960 $exitObj->ivPoke('retraceFlag', FALSE);
13961  
13962 # If there is a twin exit, the call to ->abandonTwinExit has already updated
13963 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
13964 if (! $exitObj->twinExit) {
13965  
13966 # Find the parent region
13967 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13968 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13969 # Any region paths using the exit will have to be updated
13970 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13971 if ($regionFlag) {
13972  
13973 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13974 }
13975 }
13976  
13977 # Mark the exit's parent room to be redawn (if allowed)
13978 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
13979  
13980 # If the exit's ->randomType was set to 'room_list' (but is not set to 'same_region' or
13981 # 'any_region'), we need to update the exit's ->randomDestList and each of the former
13982 # destination rooms
13983 if ($currentType eq 'room_list' && $exitType ne 'room_list') {
13984  
13985 foreach my $destRoomNum ($exitObj->randomDestList) {
13986  
13987 my $destRoomObj = $self->ivShow('modelHash', $destRoomNum);
13988 if ($destRoomObj && $destRoomObj->ivExists('randomExitHash', $exitObj->number)) {
13989  
13990 $destRoomObj->ivDelete($exitObj->number);
13991 }
13992 }
13993  
13994 $exitObj->ivEmpty('randomDestList');
13995 }
13996  
13997 # Update any GA::Win::Map objects using this world model (if allowed)
13998 if ($updateFlag) {
13999  
14000 foreach my $mapWin ($self->collectMapWins()) {
14001  
14002 # Redraw the objects
14003 $mapWin->markObjs(@redrawList);
14004 $mapWin->doDraw();
14005 }
14006 }
14007  
14008 return 1;
14009 }
14010  
14011 sub restoreRandomExit {
14012  
14013 # Called by GA::Win::Map->restoreRandomExitCallback
14014 # Converts an existing random exit into an incomplete exit
14015 #
14016 # Expected arguments
14017 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14018 # be updated now, FALSE if not (in which case, they can be updated later
14019 # by the calling function, when it is ready)
14020 # $exitObj - The GA::Obj::Exit to convert
14021 #
14022 # Return values
14023 # 'undef' on improper arguments
14024 # 1 otherwise
14025  
14026 my ($self, $updateFlag, $exitObj, $check) = @_;
14027  
14028 # Local variables
14029 my $roomObj;
14030  
14031 # Check for improper arguments
14032 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14033  
14034 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreRandomExit', @_);
14035 }
14036  
14037  
14038 # Remove the defined list of destination rooms (for random type 'room_list'), if set
14039 foreach my $destRoomNum ($exitObj->randomDestList) {
14040  
14041 my $destRoomObj = $self->ivShow('modelHash', $destRoomNum);
14042 if ($destRoomObj && $destRoomObj->ivExists('randomExitHash', $exitObj->number)) {
14043  
14044 $destRoomObj->ivDelete($exitObj->number);
14045 }
14046  
14047 $exitObj->ivEmpty('randomDestList');
14048 }
14049  
14050 # Convert the exit
14051 $exitObj->ivPoke('randomType', 'none');
14052  
14053 # Update any GA::Win::Map objects using this world model (if allowed)
14054 if ($updateFlag) {
14055  
14056 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14057  
14058 foreach my $mapWin ($self->collectMapWins()) {
14059  
14060 # Redraw the room
14061 $mapWin->markObjs('room', $roomObj);
14062 $mapWin->doDraw();
14063 }
14064 }
14065  
14066 return 1;
14067 }
14068  
14069 sub setSuperRegionExit {
14070  
14071 # Called by GA::Win::Map->markSuperExitCallback
14072 # Converts a region exit into a super-region exit (resetting other IVs as necessary)
14073 #
14074 # Expected arguments
14075 # $session - The calling function's GA::Session
14076 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14077 # should be updated now, FALSE if not (in which case, they can be
14078 # updated later by the calling function, when it is ready)
14079 # $exitObj - The GA::Obj::Exit to convert
14080 # $exclusiveFlag - Set to TRUE if this should be the only super-region exit leading from
14081 # its parent region to its destination region. Set to FALSE if other
14082 # super-region exits between the two regions (if any) can be left as
14083 # super-region exits
14084 #
14085 # Return values
14086 # 'undef' on improper arguments, if the specified exit is already a super-region exit or
14087 # if it is not a region exit at all
14088 # 1 otherwise
14089  
14090 my ($self, $session, $updateFlag, $exitObj, $exclusiveFlag, $check) = @_;
14091  
14092 # Local variables
14093 my (
14094 $roomObj, $regionmapObj, $destRegionNum,
14095 @redrawList,
14096 %regionExitHash,
14097 );
14098  
14099 # Check for improper arguments
14100 if (
14101 ! defined $session || ! defined $updateFlag || ! defined $exitObj
14102 || ! defined $exclusiveFlag || defined $check
14103 ) {
14104 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSuperRegionExit', @_);
14105 }
14106  
14107 # Check that the specified exit isn't already a super-region exit, and that it is a region
14108 # exit
14109 if ($exitObj->superFlag || ! $exitObj->regionFlag) {
14110  
14111 return undef;
14112 }
14113  
14114 # Get the parent regionmap
14115 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14116 $regionmapObj = $self->findRegionmap($roomObj->parent);
14117  
14118 # Import the regionmap's hash of region exits (for quick lookup)
14119 %regionExitHash = $regionmapObj->regionExitHash;
14120  
14121 # Get $exitObj's destination region (stored in the regionmap)
14122 $destRegionNum = $regionExitHash{$exitObj->number};
14123  
14124 # If $exclusiveFlag is set, any super-region exits in this regionmap leading to the same
14125 # destination region must be converted to non-super region exits
14126 if ($exclusiveFlag) {
14127  
14128 OUTER: foreach my $otherExitNum (keys %regionExitHash) {
14129  
14130 my ($otherExitObj, $otherDestRegionNum);
14131  
14132 $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
14133 $otherDestRegionNum = $regionExitHash{$otherExitNum};
14134  
14135 # Ignore the entry for $exitObj itself, all normal region exits and any exit which
14136 # has a different destination region
14137 if (
14138 $otherExitNum != $exitObj->number
14139 && $otherExitObj->superFlag
14140 && $destRegionNum == $otherDestRegionNum
14141 ) {
14142 # This super-region exit must be converted to a normal region exit
14143 $otherExitObj->ivPoke('superFlag', FALSE);
14144 # The user wasn't directly responsible for this change
14145 $otherExitObj->ivPoke('notSuperFlag', FALSE);
14146  
14147 # Remove any region paths (stored in ->regionPathHash and
14148 # ->safeRegionPathHash) which were using this exit
14149 INNER: foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
14150  
14151 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
14152  
14153 if (
14154 $pathObj->startExit == $exitObj->number
14155 || $pathObj->stopExit == $exitObj->number
14156 ) {
14157 # (Update both ->regionPathHash and ->safeRegionPathHash)
14158 $regionmapObj->removePaths($exitString);
14159 }
14160 }
14161  
14162 # Any region paths using the exit will have to be updated
14163 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionmapObj->name);
14164 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionmapObj->name);
14165  
14166 # Mark the exit's parent room to be re-drawn
14167 push (@redrawList, 'room', $self->ivShow('modelHash', $otherExitObj->parent));
14168 }
14169 }
14170 }
14171  
14172 # Now convert $exitObj to a super-region exit
14173 $exitObj->ivPoke('superFlag', TRUE);
14174 $exitObj->ivPoke('notSuperFlag', FALSE);
14175  
14176 # Create region paths between this super-region exit and every other
14177 # super-region exit in the region
14178 $self->connectRegionExits(
14179 $session,
14180 $regionmapObj,
14181 $roomObj,
14182 $exitObj,
14183 );
14184  
14185 # Mark the exit's parent room to be re-drawn (if allowed)
14186 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14187  
14188 # Update any GA::Win::Map objects using this world model (if allowed)
14189 if ($updateFlag) {
14190  
14191 foreach my $mapWin ($self->collectMapWins()) {
14192  
14193 # Redraw the objects
14194 $mapWin->markObjs(@redrawList);
14195 $mapWin->doDraw();
14196 }
14197 }
14198  
14199 return 1;
14200 }
14201  
14202 sub restoreSuperRegionExit {
14203  
14204 # Called by GA::Win::Map->restoreSuperExitCallback
14205 # Converts an existing super-region exit into a normal region exit
14206 #
14207 # Expected arguments
14208 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14209 # be updated now, FALSE if not (in which case, they can be updated later
14210 # by the calling function, when it is ready)
14211 # $exitObj - The GA::Obj::Exit to convert
14212 #
14213 # Return values
14214 # 'undef' on improper arguments or if the specified exit isn't a super-region exit
14215 # 1 otherwise
14216  
14217 my ($self, $updateFlag, $exitObj, $check) = @_;
14218  
14219 # Local variables
14220 my (
14221 $roomObj, $regionObj, $regionmapObj,
14222 @redrawList,
14223 );
14224  
14225 # Check for improper arguments
14226 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14227  
14228 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreSuperRegionExit', @_);
14229 }
14230  
14231 # Check that the specified exit is a super-region exit
14232 if (! $exitObj->superFlag) {
14233  
14234 return undef;
14235 }
14236  
14237 # Get the parent regionmap
14238 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14239 $regionmapObj = $self->findRegionmap($roomObj->parent);
14240  
14241 # Convert the exit to a normal region exit
14242 $exitObj->ivPoke('superFlag', FALSE);
14243 # The user was directly responsible for this change
14244 $exitObj->ivPoke('notSuperFlag', TRUE);
14245  
14246 # Remove any region paths (stored in ->regionPathHash and
14247 # ->safeRegionPathHash) which were using this exit
14248 foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
14249  
14250 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
14251  
14252 if (
14253 $pathObj->startExit == $exitObj->number
14254 || $pathObj->stopExit == $exitObj->number
14255 ) {
14256 # (Update both ->regionPathHash and ->safeRegionPathHash)
14257 $regionmapObj->removePaths($exitString);
14258 }
14259 }
14260  
14261 # Any region paths using the exit will have to be updated
14262 $self->ivAdd('updatePathHash', $exitObj->number, $regionmapObj->name);
14263 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionmapObj->name);
14264  
14265 # Mark the exit's parent room to be re-drawn
14266 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14267  
14268 # Update any GA::Win::Map objects using this world model (if allowed)
14269 if ($updateFlag) {
14270  
14271 foreach my $mapWin ($self->collectMapWins()) {
14272  
14273 # Redraw the objects
14274 $mapWin->markObjs(@redrawList);
14275 $mapWin->doDraw();
14276 }
14277 }
14278  
14279 return 1;
14280 }
14281  
14282 sub setImpassableExit {
14283  
14284 # Called by $self->setExitOrnament (should not be called by anything else)
14285 # Converts any kind of exit into an (incomplete) impassable or mystery exit
14286 #
14287 # Expected arguments
14288 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14289 # be updated now, FALSE if not (in which case, they can be updated later
14290 # by the calling function, when it is ready)
14291 # $exitObj - The GA::Obj::Exit to convert
14292 # $type - 'impass' or 'mystery'
14293 #
14294 # Return values
14295 # 'undef' on improper arguments
14296 # 1 otherwise
14297  
14298 my ($self, $updateFlag, $exitObj, $type, $check) = @_;
14299  
14300 # Local variables
14301 my (
14302 $destRoomObj, $regionFlag, $roomObj, $regionObj,
14303 @redrawList,
14304 );
14305  
14306 # Check for improper arguments
14307 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14308  
14309 return $axmud::CLIENT->writeImproper($self->_objClass . '->setImpassableExit', @_);
14310 }
14311  
14312 $regionFlag = $exitObj->regionFlag;
14313  
14314 # If the exit already has a destination room, mark it for redrawing
14315 if ($exitObj->destRoom) {
14316  
14317 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
14318 push (@redrawList, 'room', $destRoomObj);
14319 }
14320  
14321 # If the exit has a twin, it must be abandoned
14322 if ($exitObj->twinExit) {
14323  
14324 $self->abandonTwinExit(
14325 FALSE, # Don't update Automapper windows yet
14326 $exitObj,
14327 );
14328 }
14329  
14330 # The same applies if the exit has a shadow exit
14331 if ($exitObj->shadowExit) {
14332  
14333 $self->abandonShadowExit($exitObj);
14334 }
14335  
14336 # Update the destination room (if any)
14337 if ($destRoomObj) {
14338  
14339 if ($destRoomObj->ivExists('uncertainExitHash', $exitObj->number)) {
14340  
14341 $destRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
14342 }
14343  
14344 if ($destRoomObj->ivExists('oneWayExitHash', $exitObj->number)) {
14345  
14346 $destRoomObj->ivDelete('oneWayExitHash', $exitObj->number);
14347 }
14348 }
14349  
14350 # Update the exit. The ->exitOrnament IV is set by the calling function
14351 $exitObj->ivPoke('brokenFlag', FALSE);
14352 $exitObj->ivPoke('bentFlag', FALSE);
14353 $exitObj->ivEmpty('bendOffsetList');
14354  
14355 $exitObj->ivPoke('regionFlag', FALSE);
14356 $self->cancelExitTag(
14357 FALSE, # Don't update Automapper windows yet
14358 $exitObj,
14359 );
14360  
14361 $exitObj->ivPoke('randomType', 'none');
14362 $exitObj->ivUndef('destRoom');
14363 $exitObj->ivPoke('oneWayFlag', FALSE);
14364 $exitObj->ivPoke('oneWayDir', undef);
14365 $exitObj->ivPoke('retraceFlag', FALSE);
14366 if ($type eq 'impass') {
14367  
14368 # (There is no exit state corresponding to a mystery exit)
14369 $exitObj->ivPoke('exitState', 'impass');
14370 }
14371  
14372 # If there is a twin exit, the call to ->abandonTwinExit has already updated
14373 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
14374 if (! $exitObj->twinExit) {
14375  
14376 # Find the parent region
14377 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14378 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14379 # Any region paths using the exit will have to be updated
14380 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14381 if ($regionFlag) {
14382  
14383 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14384 }
14385 }
14386  
14387 # Mark the exit's parent room to be redawn (if allowed)
14388 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14389  
14390 # Update any GA::Win::Map objects using this world model (if allowed)
14391 if ($updateFlag) {
14392  
14393 foreach my $mapWin ($self->collectMapWins()) {
14394  
14395 # Redraw the objects
14396 $mapWin->markObjs(@redrawList);
14397 $mapWin->doDraw();
14398 }
14399 }
14400  
14401 return 1;
14402 }
14403  
14404 sub setExitOrnament {
14405  
14406 # Can be called by anything (especially by $self->setMultipleOrnaments)
14407 # Sets (or resets) the exit's ornament . Optionally sets (or resets) the ornament of the
14408 # twin exit (if there is one) to match
14409 #
14410 # Expected arguments
14411 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14412 # be updated now, FALSE if not (in which case, they can be updated later
14413 # by the calling function, when it is ready)
14414 # $exitObj - The exit object to modify
14415 #
14416 # Optional arguments
14417 # $type - The exit ornament type, one of the permitted values for
14418 # GA::Obj::Exit->exitOrnament ('none', 'break', 'pick', 'lock', 'open',
14419 # 'impass', 'mystery'). If 'undef', the value 'none' is set
14420 # $twinFlag - If set to TRUE, the twin exit's ornament (if there is a twin exit) is set
14421 # to match
14422 #
14423 # Return values
14424 # 'undef' on improper arguments
14425 # 1 otherwise
14426  
14427 my ($self, $updateFlag, $exitObj, $type, $twinFlag, $check) = @_;
14428  
14429 # Local variables
14430 my (
14431 $regionFlag, $twinExitObj, $twinRegionFlag, $roomObj, $regionObj, $twinRoomObj,
14432 $twinRegionObj,
14433 );
14434  
14435 # Check for improper arguments
14436 if (
14437 ! defined $updateFlag || ! defined $exitObj
14438 || (
14439 defined $type && $type ne 'none' && $type ne 'break' && $type ne 'pick'
14440 && $type ne 'lock' && $type ne 'open' && $type ne 'impass' && $type ne 'mystery'
14441 ) || defined $check
14442 ) {
14443 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitOrnament', @_);
14444 }
14445  
14446 $regionFlag = $exitObj->regionFlag;
14447  
14448 # Set the twin exit object now (if needed), because the call to ->setImpassableExit
14449 # abandons the twin
14450 if ($twinFlag && $exitObj->twinExit) {
14451  
14452 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
14453 $twinRegionFlag = $twinExitObj->regionFlag;
14454 }
14455  
14456 # Set (or reset) the IV
14457 if (! defined $type) {
14458 $exitObj->ivPoke('exitOrnament', 'none');
14459 } else {
14460 $exitObj->ivPoke('exitOrnament', $type);
14461 }
14462  
14463 # Update impassable/mystery exit settings
14464 if ($type && ($type eq 'impass' || $type eq 'mystery')) {
14465  
14466 # Convert this exit into an incomplete impassable exit
14467 $self->setImpassableExit(
14468 FALSE, # Don't update Automapper windows yet
14469 $exitObj,
14470 $type,
14471 );
14472  
14473 } elsif ($exitObj->exitState eq 'impass') {
14474  
14475 # The exit's state is no longer impassable
14476 $exitObj->ivPoke('exitState', 'normal'); # State not known
14477 }
14478  
14479 # The call to ->setImpassableExit updates ->updatePathHash and ->updateBoundaryHash. If it
14480 # was not called, those IVs must be updated now
14481 if (! $type || $type ne 'impass') {
14482  
14483 # Find the parent region
14484 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14485 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14486 # Update the hashes
14487 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14488 if ($exitObj->regionFlag) {
14489  
14490 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14491 }
14492 }
14493  
14494 # Reset the IVs on the twin exit, if necessary
14495 if ($twinExitObj) {
14496  
14497 $twinExitObj->ivPoke('exitOrnament', $exitObj->exitOrnament);
14498  
14499 if ($type && ($type eq 'impass' || $type eq 'mystery')) {
14500  
14501 # Convert this exit into an incomplete impassable exit
14502 $self->setImpassableExit(
14503 FALSE, # Don't update Automapper windows yet
14504 $twinExitObj,
14505 $type,
14506 );
14507  
14508 } elsif ($twinExitObj->exitState eq 'impass') {
14509  
14510 # The exit's state is no longer impassable
14511 $twinExitObj->ivPoke('exitState', 'normal'); # State not known
14512 }
14513  
14514 if (! $type || ($type ne 'impass' && $type ne 'mystery')) {
14515  
14516 # The call to ->setImpassableExit updates ->updatePathHash and ->updateBoundaryHash.
14517 # If it was not called, those IVs must be updated now
14518 # Find the parent region
14519 $twinRoomObj = $self->ivShow('modelHash', $twinExitObj->parent);
14520 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
14521 # Update the hashes
14522 $self->ivAdd('updatePathHash', $twinExitObj->number, $twinRegionObj->name);
14523 if ($twinExitObj->regionFlag) {
14524  
14525 $self->ivAdd('updateBoundaryHash', $twinExitObj->number, $twinRegionObj->name);
14526 }
14527 }
14528 }
14529  
14530 if ($updateFlag) {
14531  
14532 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
14533 # window using this world model
14534 $self->updateMapExit($exitObj, $twinExitObj);
14535 }
14536  
14537 return 1;
14538 }
14539  
14540 sub setMultipleOrnaments {
14541  
14542 # Called by GA::Win::Map->exitOrnamentCallback
14543 # Sets ornaments for one or more exits
14544 #
14545 # Expected arguments
14546 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14547 # should be updated now, FALSE if not (in which case, they can be
14548 # updated later by the calling function, when it is ready)
14549 #
14550 # Optional arguments
14551 # $type - The exit ornament type, one of the permitted values for
14552 # GA::Obj::Exit->exitOrnament ('none', 'break', 'pick', 'lock',
14553 # 'open', 'impass', 'mystery'). If 'undef', the value 'none' is set
14554 # @exitList - A list of exit objects to modify. If the list is empty, no exits are
14555 # modified
14556 #
14557 # Return values
14558 # 'undef' on improper arguments or if @exitList is empty
14559 # 1 otherwise
14560  
14561 my ($self, $updateFlag, $type, @exitList) = @_;
14562  
14563 # Local variables
14564 my (
14565 @redrawList,
14566 %roomHash,
14567 );
14568  
14569 # Check for improper arguments
14570 if (! defined $updateFlag) {
14571  
14572 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMultipleOrnaments', @_);
14573 }
14574  
14575 # An exit's twin exit can be reset during the ornament-setting process, so compile a list of
14576 # rooms to redraw first
14577 if ($updateFlag) {
14578  
14579 foreach my $exitObj (@exitList) {
14580  
14581 my $twinExitObj;
14582  
14583 # Mark this room as needing to be redrawn (if allowed), adding it to a hash to
14584 # eliminate duplicates
14585 $roomHash{$exitObj->parent} = $self->ivShow('modelHash', $exitObj->parent);
14586 # If the exit has a twin exit, its parent must also be marked to be redrawn (e.g.
14587 # when we take a two-way exit and modify one of the twins to an impassable exit,
14588 # the other one must be redrawn, two)
14589 if ($exitObj->twinExit) {
14590  
14591 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
14592 $roomHash{$twinExitObj->parent}
14593 = $self->ivShow('modelHash', $twinExitObj->parent);
14594 }
14595 }
14596 }
14597  
14598 foreach my $exitObj (@exitList) {
14599  
14600 # Reset or set the exit's ornament IVs (and reset/set the twin exit's ornament IVs to
14601 # match, if the appropriate flag is set)
14602 $self->setExitOrnament(
14603 FALSE, # Don't update Automapper windows yet
14604 $exitObj,
14605 $type, # May be 'undef'
14606 $self->setTwinOrnamentFlag,
14607 );
14608 }
14609  
14610 # Update any GA::Win::Map objects using this world model (if allowed)
14611 if ($updateFlag) {
14612  
14613 foreach my $roomObj (values %roomHash) {
14614  
14615 push (@redrawList, 'room', $roomObj);
14616 }
14617  
14618 foreach my $mapWin ($self->collectMapWins()) {
14619  
14620 # Redraw the rooms
14621 $mapWin->markObjs(@redrawList);
14622 $mapWin->doDraw();
14623 }
14624 }
14625  
14626 return 1;
14627 }
14628  
14629 sub setAssistedMove {
14630  
14631 # Called by GA::Win::Map->addExitCallback and ->setAssistedMoveCallback
14632 # Adds or removes an assisted move to/from a specified exit object
14633 #
14634 # Expected arguments
14635 # $exitObj - The GA::Obj::Exit to be modified
14636 # $profile - The name of a profile. When it's a current profile, this assisted move
14637 # is available to the automapper object code
14638 #
14639 # Optional arguments
14640 # $cmdSequence - A sequence of one or more world commands (separated by the usual
14641 # command separator) that comprise the assisted move, e.g.
14642 # 'north;open door;east'. If 'undef' or an empty string, the assisted
14643 # move for $profile is removed
14644 #
14645 # Return values
14646 # 'undef' on improper arguments
14647 # 1 otherwise
14648  
14649 my ($self, $exitObj, $profile, $cmdSequence, $check) = @_;
14650  
14651 # Check for improper arguments
14652 if (! defined $exitObj || ! defined $profile || defined $check) {
14653  
14654 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAssistedMove', @_);
14655 }
14656  
14657 # Update the exit object
14658 if (! defined $cmdSequence || $cmdSequence eq '') {
14659 $exitObj->ivDelete('assistedHash', $profile);
14660 } else {
14661 $exitObj->ivAdd('assistedHash', $profile, $cmdSequence);
14662 }
14663  
14664 return 1;
14665 }
14666  
14667 sub modifyIncomingExits {
14668  
14669 # Called by GA::Win::Map->addExitCallback
14670 # After the new exit is added, checks the parent room's list of incoming exits. Any incoming
14671 # exits whose map direction, ->mapDir, is the opposite of the new exit's map direction
14672 # must be converted to uncertain exits
14673 #
14674 # Expected arguments
14675 # $session - The calling function's GA::Session
14676 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14677 # should be updated now, FALSE if not (in which case, they can be
14678 # updated later by the calling function, when it is ready)
14679 # $roomObj - The new exit's parent room
14680 # $exitObj - The new GA::Obj::Exit object
14681 #
14682 # Return values
14683 # 'undef' on improper arguments or if no incoming exits are converted
14684 # 1 otherwise
14685  
14686 my ($self, $session, $updateFlag, $roomObj, $exitObj, $check) = @_;
14687  
14688 # Check for improper arguments
14689 if (
14690 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14691 || defined $check
14692 ) {
14693 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyIncomingExits', @_);
14694 }
14695  
14696 # Check each incoming exit in turn
14697 foreach my $incomingNum ($roomObj->ivKeys('oneWayExitHash')) {
14698  
14699 my ($incomingExitObj, $oppDir, $incomingRoomObj, $incomingRegionObj);
14700  
14701 $incomingExitObj = $self->ivShow('exitModelHash', $incomingNum);
14702  
14703 # Only check allocated exits...
14704 if (
14705 $incomingExitObj->drawMode eq 'primary'
14706 || $incomingExitObj->drawMode eq 'perm_alloc'
14707 ) {
14708 # Get the opposite direction of the incoming exit
14709 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->dir);
14710 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->dir) {
14711  
14712 # Special case: A-O-B, where O is a gap, and B has 1-way exit pointing at A; if
14713 # we put a room at location O, and connect A and O, the exit from B should
14714 # be drawn as a broken exit
14715 if (
14716 ! $incomingExitObj->regionFlag
14717 && ! $self->checkRoomAlignment($session, $incomingExitObj)
14718 ) {
14719 $self->setBrokenExit($updateFlag, $incomingExitObj);
14720 }
14721  
14722 # Convert the incoming exit into an uncertain exit
14723 $incomingExitObj->ivPoke('oneWayFlag', FALSE);
14724 $incomingExitObj->ivPoke('oneWayDir', undef);
14725 # Remove the entry from one hash, and add it the other
14726 $roomObj->ivDelete('oneWayExitHash', $incomingExitObj->number);
14727 $roomObj->ivAdd(
14728 'uncertainExitHash',
14729 $incomingExitObj->number,
14730 $exitObj->number,
14731 );
14732  
14733 # If the incoming exit had any bends, remove them
14734 $incomingExitObj->ivEmpty('bendOffsetList');
14735  
14736 # Find the incoming exit's parent region
14737 $incomingRoomObj = $self->ivShow('modelHash', $incomingExitObj->parent);
14738 $incomingRegionObj = $self->ivShow('modelHash', $incomingRoomObj->parent);
14739 # Any region paths using the exit will have to be updated
14740 $self->ivAdd(
14741 'updatePathHash',
14742 $incomingExitObj->number,
14743 $incomingRegionObj->name,
14744 );
14745  
14746 if ($incomingExitObj->regionFlag) {
14747  
14748 $self->ivAdd(
14749 'updateBoundaryHash',
14750 $incomingExitObj->number,
14751 $incomingRegionObj->name,
14752 );
14753 }
14754  
14755 if ($updateFlag) {
14756  
14757 # Mark this incoming exit to be redrawn in every Automapper window using
14758 # this world model
14759 $self->updateMapExit($incomingExitObj);
14760 }
14761  
14762 # Return 1 to show that an exit was modified
14763 return 1;
14764 }
14765 }
14766 }
14767  
14768 # No exits were modified
14769 return undef;
14770 }
14771  
14772 sub changeShadowExitDir {
14773  
14774 # Called by GA::Win::Map->changeDirCallback
14775 # When the user tries to change the direction of an exit that's been allocated a shadow
14776 # exit, the 'change direction' operation merely reassigns it as an unallocated exit
14777 #
14778 # Expected arguments
14779 # $session - The calling function's GA::Session
14780 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14781 # should be updated now, FALSE if not (in which case, they can be
14782 # updated later by the calling function, when it is ready)
14783 # $roomObj - The exit's parent room
14784 # $exitObj - The GA::Obj::Exit object to be modified
14785 #
14786 # Return values
14787 # 'undef' on improper arguments
14788 # 1 otherwise
14789  
14790 my ($self, $session, $updateFlag, $roomObj, $exitObj, $check) = @_;
14791  
14792 # Local variables
14793 my $regionObj;
14794  
14795 # Check for improper arguments
14796 if (
14797 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14798 || defined $check
14799 ) {
14800 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeShadowExitDir', @_);
14801 }
14802  
14803 # Update the exit's IVs
14804 $exitObj->ivPoke('drawMode', 'temp_alloc');
14805 $exitObj->ivUndef('shadowExit');
14806 $exitObj->ivUndef('mapDir');
14807  
14808 # Allocate a primary direction (using the sixteen cardinal directions, but not 'up' or
14809 # 'down')
14810 $self->allocateCardinalDir($session, $roomObj, $exitObj);
14811  
14812 # Find the parent region
14813 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14814 # Any region paths using the exit will have to be updated
14815 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14816 if ($exitObj->regionFlag) {
14817  
14818 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14819 }
14820  
14821 if ($updateFlag) {
14822  
14823 # Mark this incoming exit to be redrawn in every Automapper window using this world
14824 # model
14825 $self->updateMapExit($exitObj);
14826 }
14827  
14828 return 1;
14829 }
14830  
14831 sub changeExitDir {
14832  
14833 # Called by GA::Win::Map->changeDirCallback
14834 # Changes an exit's direction
14835 #
14836 # Expected arguments
14837 # $session - The calling function's GA::Session
14838 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14839 # should be updated now, FALSE if not (in which case, they can be
14840 # updated later by the calling function, when it is ready)
14841 # $roomObj - The exit's parent room
14842 # $exitObj - The GA::Obj::Exit object to be modified
14843 # $dir - The exit's new (nominal) direction, stored in ->dir
14844 #
14845 # Optional arguments
14846 # $mapDir - The exit's new map direction, stored in ->mapDir. If not specified, a
14847 # map direction is allocated (if possible)
14848 #
14849 # Return values
14850 # 'undef' on improper arguments or if the exit's direction can't be changed
14851 # 1 otherwise
14852  
14853 my ($self, $session, $updateFlag, $roomObj, $exitObj, $dir, $mapDir, $check) = @_;
14854  
14855 # Local variables
14856 my (
14857 $twinExitObj, $regionObj,
14858 @dirList, @sortedList, @redrawList,
14859 );
14860  
14861 # Check for improper arguments
14862 if (
14863 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14864 || ! defined $dir || defined $check
14865 ) {
14866 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeExitDir', @_);
14867 }
14868  
14869 # If $mapDir was specified and an existing exit already uses that map direction, we can't
14870 # modify the specified exit
14871 if ($mapDir) {
14872  
14873 foreach my $number ($roomObj->ivValues('exitNumHash')) {
14874  
14875 my $otherExitObj = $self->ivShow('exitModelHash', $number);
14876  
14877 if ($otherExitObj && $otherExitObj->mapDir && $otherExitObj->mapDir eq $mapDir) {
14878  
14879 return undef;
14880 }
14881 }
14882 }
14883  
14884 # Modify the exit object and its parent room object
14885  
14886 # Update the exit's ->dir
14887 $roomObj->ivDelete('exitNumHash', $exitObj->dir);
14888 $exitObj->ivPoke('dir', $dir);
14889 $roomObj->ivAdd('exitNumHash', $dir, $exitObj->number);
14890  
14891 # Delete the equivalent entry in the room's ->sortedExitList
14892 @dirList = $roomObj->ivKeys('exitNumHash');
14893 @sortedList = $session->currentDict->sortExits(@dirList);
14894 $roomObj->ivPoke('sortedExitList', @sortedList);
14895  
14896 # Set the exit's ->mapDir
14897 if ($mapDir) {
14898  
14899 $exitObj->ivPoke('mapDir', $mapDir);
14900  
14901 } else {
14902  
14903 # Allocate the exit an appropriate map direction
14904 $self->allocateCardinalDir($session, $roomObj, $exitObj);
14905 }
14906  
14907 # Set the exit type (e.g. 'primaryDir', 'primaryAbbrev', etc)
14908 $exitObj->ivPoke(
14909 'exitType',
14910 $session->currentDict->ivShow('combDirHash', $exitObj->dir),
14911 );
14912  
14913 # Find the parent region
14914 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14915 # Any region paths using the exit will have to be updated
14916 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14917 if ($exitObj->regionFlag) {
14918  
14919 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14920 }
14921  
14922 # Check the parent room's exits; if any were previously unallocated exits which were
14923 # allocated the shadow exit we've just modified, then we must also modify those exits
14924 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
14925  
14926 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
14927  
14928 if (
14929 $otherExitObj->shadowExit
14930 && $otherExitObj->shadowExit == $exitObj->number
14931 && $otherExitObj->mapDir
14932 && $otherExitObj->mapDir ne $mapDir
14933 ) {
14934 # Assign the exit object a new map direction, matching its shadow's new map
14935 # direction
14936 $otherExitObj->ivPoke('mapDir', $mapDir);
14937  
14938 # Find the parent room and region
14939  
14940 # Any region paths using the exit will have to be updated
14941 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
14942 if ($otherExitObj->regionFlag) {
14943  
14944 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
14945 }
14946 }
14947 }
14948  
14949 # Now, we need to check if the room has any more unallocated exits. If they've temporarily
14950 # been assigned the primary direction 'undef', we must reallocate them
14951 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
14952  
14953 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
14954  
14955 if (! defined $otherExitObj->mapDir && $otherExitObj->drawMode eq 'primary') {
14956  
14957 # Assign the exit object a new map direction (using the sixteen cardinal directions,
14958 # but not 'up' or 'down'), if any are available
14959 $self->allocateCardinalDir($session, $roomObj, $otherExitObj);
14960  
14961 # Any region paths using the exit will have to be updated
14962 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
14963 if ($otherExitObj->regionFlag) {
14964  
14965 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
14966 }
14967 }
14968 }
14969  
14970 # Mark $roomObj to be redrawn (if allowed)
14971 push (@redrawList, 'room', $roomObj);
14972  
14973 # Now, if there are any incoming 1-way exits whose ->mapDir is now the opposite of
14974 # the exit we've just modified, the incoming exit should be marked as an uncertain exit
14975 OUTER: foreach my $incomingExitNum ($roomObj->ivKeys('oneWayExitHash')) {
14976  
14977 my ($incomingExitObj, $oppDir);
14978  
14979 $incomingExitObj = $self->ivShow('exitModelHash', $incomingExitNum);
14980  
14981 # Only check allocated exits...
14982 if (
14983 $incomingExitObj->drawMode eq 'primary'
14984 || $incomingExitObj->drawMode eq 'perm_alloc'
14985 ) {
14986 # Get the opposite direction of the incoming exit
14987 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->mapDir);
14988 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->mapDir) {
14989  
14990 # Convert the incoming exit into an uncertain exit
14991 $self->convertOneWayExit(
14992 FALSE, # Don't update Automapper windows yet
14993 $incomingExitObj,
14994 $roomObj,
14995 $exitObj,
14996 );
14997  
14998 # Mark the incoming exit's parent room to be redrawn
14999 push (
15000 @redrawList,
15001 'room',
15002 $self->ivShow('modelHash', $incomingExitObj->parent),
15003 );
15004  
15005 last OUTER;
15006 }
15007 }
15008 }
15009  
15010 # Both the exit, and its twin exit (if there is one) must be checked for alignment. If
15011 # they're no longer aligned, they must be marked as broken exits. If they are now aligned,
15012 # their broken exit status must be removed
15013 # Don't bother checking if the exit is marked as a region exit
15014 if ($exitObj->destRoom && ! $exitObj->regionFlag) {
15015  
15016 # Get the twin exit object (if any)
15017 if ($exitObj->twinExit) {
15018  
15019 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
15020 # Mark the twin exit's parent room to be redrawn
15021 push (
15022 @redrawList,
15023 'room',
15024 $self->ivShow('modelHash', $twinExitObj->parent),
15025 );
15026 }
15027  
15028 if (! $self->checkRoomAlignment($session, $exitObj)) {
15029  
15030 # Mark this exit and the twin exit, if there is one, as broken exits
15031 $self->setBrokenExit(
15032 FALSE, # Don't update Automapper windows now
15033 $exitObj,
15034 );
15035  
15036 if ($twinExitObj) {
15037  
15038 $self->setBrokenExit(
15039 FALSE, # Don't update Automapper windows now
15040 $twinExitObj,
15041 );
15042 }
15043  
15044 } elsif ($exitObj->brokenFlag) {
15045  
15046 # The rooms are now aligned, so it's no longer a broken exit (don't need to call a
15047 # separate function; there's only one IV to update)
15048 $exitObj->ivPoke('brokenFlag', FALSE);
15049 if ($twinExitObj) {
15050  
15051 $twinExitObj->ivPoke('brokenFlag', FALSE);
15052 }
15053 }
15054 }
15055  
15056 # Redraw the room(s) (and their exits), if allowed
15057 if ($updateFlag) {
15058  
15059 $self->updateMaps(@redrawList);
15060 }
15061  
15062 return 1;
15063 }
15064  
15065 sub setExitIncomingDir {
15066  
15067 # Called by GA::Win::Map->setExitTwinCallback
15068 # Changes a one-way exit's incoming direction (the direction it is drawn close to its
15069 # destination room)
15070 #
15071 # Expected arguments
15072 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15073 # should be updated now, FALSE if not (in which case, they can be
15074 # updated later by the calling function, when it is ready)
15075 # $exitObj - The GA::Obj::Exit object to be modified
15076 # $dir - The new incoming direction (should be a standard primary direction)
15077 #
15078 # Return values
15079 # 'undef' on improper arguments or if the exit's direction can't be changed
15080 # 1 otherwise
15081  
15082 my ($self, $updateFlag, $exitObj, $dir, $check) = @_;
15083  
15084 # Local variables
15085 my ($roomObj, $destRoomObj);
15086  
15087 # Check for improper arguments
15088 if (! defined $updateFlag || ! defined $exitObj || ! defined $dir || defined $check) {
15089  
15090 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitIncomingDir', @_);
15091 }
15092  
15093 # Check that $exitObj is really one-way and that $dir is really a standard primary direction
15094 if (! $exitObj->oneWayFlag || ! $axmud::CLIENT->ivExists('constOppDirHash', $dir)) {
15095  
15096 return undef;
15097  
15098 } else {
15099  
15100 $exitObj->ivPoke('oneWayDir', $dir);
15101  
15102 # Redraw the exit's parent room and its destination room, if allowed
15103 if ($updateFlag) {
15104  
15105 # Get the exit's parent room and its destination room
15106 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15107 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15108  
15109 $self->updateMaps(
15110 'room', $roomObj,
15111 'room', $destRoomObj,
15112 );
15113 }
15114  
15115 return 1;
15116 }
15117 }
15118  
15119 sub setExitMapDir {
15120  
15121 # Called by GA::Win::Map->allocateMapDirCallback
15122 # Sets an exit's map direction, ->mapDir, using a value specified by the user
15123 #
15124 # Expected arguments
15125 # $session - The calling function's GA::Session
15126 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15127 # should be updated now, FALSE if not (in which case, they can be
15128 # updated later by the calling function, when it is ready)
15129 # $roomObj - The exit's parent room
15130 # $exitObj - The GA::Obj::Exit object to be modified
15131 # $mapDir - The exit's new map direction (a standard primary direction)
15132 #
15133 # Return values
15134 # 'undef' on improper arguments or if the exit's direction can't be changed
15135 # 1 otherwise
15136  
15137 my ($self, $session, $updateFlag, $roomObj, $exitObj, $mapDir, $check) = @_;
15138  
15139 # Local variables
15140 my (
15141 $customDir, $regionObj,
15142 @redrawList,
15143 );
15144  
15145 # Check for improper arguments
15146 if (
15147 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
15148 || ! defined $mapDir || defined $check
15149 ) {
15150 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitMapDir', @_);
15151 }
15152  
15153 # Update the selected exit and mark it as 'allocated'
15154 $exitObj->ivPoke('mapDir', $mapDir);
15155 # Mark the exit as 'allocated'
15156 $exitObj->ivPoke('drawMode', 'perm_alloc');
15157 # Any checked directions in the corresponding custom primary direction are destroyed
15158 $customDir = $session->currentDict->ivShow('primaryDirHash', $mapDir);
15159 if (defined $customDir) {
15160  
15161 $roomObj->ivDelete('checkedDirHash', $customDir);
15162 }
15163  
15164 # Find the parent region
15165 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15166 # Any region paths using the exit will have to be updated
15167 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15168 if ($exitObj->regionFlag) {
15169  
15170 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15171 }
15172  
15173 # Check the parent room to see if it has any more unallocated exits. If they've temporarily
15174 # been assigned the same map direction as the map direction specified by the user,
15175 # $mapDir, we must reallocate them
15176 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
15177  
15178 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
15179  
15180 if (
15181 $otherExitObj->mapDir
15182 && $otherExitObj->mapDir eq $mapDir
15183 && (
15184 $otherExitObj->drawMode eq 'temp_alloc'
15185 || $otherExitObj->drawMode eq 'temp_unalloc'
15186 )
15187 ) {
15188 # Assign the exit object a new map direction (using the sixteen cardinal directions,
15189 # but not 'up' or 'down'), if any are available
15190 $otherExitObj->ivUndef('mapDir');
15191 $self->allocateCardinalDir($session, $roomObj, $otherExitObj);
15192  
15193 # Any region paths using the exit will have to be updated
15194 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
15195 if ($exitObj->regionFlag) {
15196  
15197 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
15198 }
15199  
15200 # (Having found one matching exit, we don't need to check the others)
15201 last OUTER;
15202 }
15203 }
15204  
15205 # Mark $roomObj to be redrawn (if allowed)
15206 push (@redrawList, 'room', $roomObj);
15207  
15208 # Now, if there are any incoming 1-way exits whose ->mapDir is now the opposite of
15209 # the exit we've just allocated, the incoming exit should be marked as an uncertain exit
15210 OUTER: foreach my $incomingExitNum ($roomObj->ivKeys('oneWayExitHash')) {
15211  
15212 my ($incomingExitObj, $oppDir);
15213  
15214 $incomingExitObj = $self->ivShow('exitModelHash', $incomingExitNum);
15215  
15216 # Only check allocated exits...
15217 if (
15218 $incomingExitObj->drawMode eq 'primary'
15219 || $incomingExitObj->drawMode eq 'perm_alloc'
15220 ) {
15221 # Get the opposite direction of the incoming exit
15222 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->mapDir);
15223 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->mapDir) {
15224  
15225 # Convert the incoming exit into an uncertain exit
15226 $self->convertOneWayExit(
15227 FALSE, # Don't update Automapper windows yet
15228 $incomingExitObj,
15229 $roomObj,
15230 $exitObj,
15231 );
15232  
15233 # Mark the incoming exit's parent room to be redrawn
15234 push (@redrawList, $self->ivShow('modelHash', $incomingExitObj->parent));
15235  
15236 last OUTER;
15237 }
15238 }
15239 }
15240  
15241 # Update any GA::Win::Map objects using this world model (if allowed)
15242 if ($updateFlag) {
15243  
15244 foreach my $mapWin ($self->collectMapWins()) {
15245  
15246 # Redraw the rooms
15247 $mapWin->markObjs(@redrawList);
15248 $mapWin->doDraw();
15249  
15250 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15251 $mapWin->restrictWidgets();
15252 }
15253 }
15254  
15255 return 1;
15256 }
15257  
15258 sub setExitShadow {
15259  
15260 # Called by GA::Win::Map->allocateShadowCallback
15261 # Sets an exit's shadow exit
15262 #
15263 # Expected arguments
15264 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15265 # should be updated now, FALSE if not (in which case, they can be
15266 # updated later by the calling function, when it is ready)
15267 # $roomObj - The exit's parent room
15268 # $exitObj - The GA::Obj::Exit object to be modified
15269 # $shadowExitObj - The exit object which is $exitObj's new shadow exit
15270 #
15271 # Return values
15272 # 'undef' on improper arguments
15273 # 1 otherwise
15274  
15275 my ($self, $updateFlag, $roomObj, $exitObj, $shadowExitObj, $check) = @_;
15276  
15277 # Local variables
15278 my $regionObj;
15279  
15280 # Check for improper arguments
15281 if (
15282 ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
15283 || ! defined $shadowExitObj || defined $check
15284 ) {
15285 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitShadow', @_);
15286 }
15287  
15288 # Update the exit
15289 $exitObj->ivPoke('shadowExit', $shadowExitObj->number);
15290 # This exit has the same map direction as the shadow (will be set to 'undef' for
15291 # unallocatable exits)
15292 $exitObj->ivPoke('mapDir', $shadowExitObj->mapDir);
15293 # Mark the exit as 'allocated'
15294 $exitObj->ivPoke('drawMode', 'perm_alloc');
15295  
15296 # Find the parent region
15297 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15298 # Any region paths using the exit will have to be updated
15299 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15300 if ($exitObj->regionFlag) {
15301  
15302 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15303 }
15304  
15305 # Update any GA::Win::Map objects using this world model (if allowed)
15306 if ($updateFlag) {
15307  
15308 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15309  
15310 # Redraw the room
15311 $mapWin->markObjs('room', $roomObj);
15312 $mapWin->doDraw();
15313  
15314 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15315 $mapWin->restrictWidgets();
15316 }
15317 }
15318  
15319 return 1;
15320 }
15321  
15322 sub completeExits {
15323  
15324 # Called by GA::Win::Map->allocateShadowCallback
15325 # Given a list of exit objects, looking for uncertain exits which match an opposite
15326 # incomplete exit. When a pair is found, converts them into two-way exits
15327 #
15328 # Expected arguments
15329 # $session - The calling function's GA::Session
15330 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15331 # should be updated now, FALSE if not (in which case, they can be
15332 # updated later by the calling function, when it is ready)
15333 #
15334 # Optional arguments
15335 # @exitList - A list of GA::Obj::Exit objects. If an empty list, no exits are
15336 # modified
15337 #
15338 # Return values
15339 # 'undef' on improper arguments or if @exitList is empty
15340 # 1 otherwise
15341  
15342 my ($self, $session, $updateFlag, @exitList) = @_;
15343  
15344 # Local variables
15345 my (
15346 $dictObj, $regionFlag, $twinRegionFlag,
15347 @redrawList,
15348 %redrawHash,
15349 );
15350  
15351 # Check for improper arguments
15352 if (! defined $session || ! defined $updateFlag) {
15353  
15354 return $axmud::CLIENT->writeImproper($self->_objClass . '->completeExits', @_);
15355 }
15356  
15357 # Don't do anything if @exitList is empty
15358 if (! @exitList) {
15359  
15360 return undef;
15361 }
15362  
15363 # Import the current dictionary
15364 $dictObj = $session->currentDict;
15365  
15366 # Check each exit in turn
15367 OUTER: foreach my $exitObj (@exitList) {
15368  
15369 my (
15370 $roomObj, $twinRoomObj, $twinExitObj, $oppDir, $regionObj, $twinRegionObj,
15371 @oppDirList,
15372 );
15373  
15374 if ($exitObj->destRoom && (! $exitObj->twinExit) && (! $exitObj->oneWayFlag)) {
15375  
15376 # It's an uncertain exit. Is there an incomplete exit in the opposite direction?
15377  
15378 # Get the blessed references of the uncertain exit's room...
15379 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15380 # ...and of the incomplete exit's room
15381 $twinRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15382  
15383 # Get the opposite direction
15384 $oppDir = $dictObj->ivShow('combOppDirHash', $exitObj->dir);
15385 # For secondary directions, $oppDir might be several words, separated by spaces
15386 # (e.g. the scalar 'entrance in' might be the opposite of 'exit')
15387 # Split them into a list of words, e.g. ('entrance', 'in')
15388 @oppDirList = split(/\s/, $oppDir);
15389  
15390 INNER: foreach my $item (@oppDirList) {
15391  
15392 if ($twinRoomObj->ivExists('exitNumHash', $item)) {
15393  
15394 # Success! $exitObj is an uncertain exit, so get the twin exit object
15395 $twinExitObj = $self->ivShow(
15396 'exitModelHash',
15397 $twinRoomObj->ivShow('exitNumHash', $item),
15398 );
15399  
15400 last INNER;
15401 }
15402 }
15403  
15404 if ($twinExitObj) {
15405  
15406 $regionFlag = $exitObj->regionFlag;
15407 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15408 $twinRegionFlag = $twinExitObj->regionFlag;
15409 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
15410  
15411 # Connect the two rooms with twin exits
15412 $exitObj->ivPoke('twinExit', $twinExitObj->number);
15413 $twinExitObj->ivPoke('twinExit', $exitObj->number);
15414 $twinExitObj->ivPoke('destRoom', $roomObj->number);
15415  
15416 # If either room used to be an uncertain exit, tell the opposite room that it no
15417 # longer needs to keep track
15418 if ($twinRoomObj->ivExists('uncertainExitHash', $exitObj->number)) {
15419  
15420 $twinRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
15421 }
15422  
15423 if ($roomObj->ivExists('uncertainExitHash', $twinExitObj->number)) {
15424  
15425 $roomObj->ivDelete('uncertainExitHash', $twinExitObj->number);
15426 }
15427  
15428 # Any region paths using the exits will have to be updated
15429 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15430 if ($regionFlag || $exitObj->regionFlag) {
15431  
15432 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15433 }
15434  
15435 $self->ivAdd('updatePathHash', $twinExitObj->number, $twinRegionObj->name);
15436 if ($twinRegionFlag || $twinExitObj->regionFlag) {
15437  
15438 $self->ivAdd(
15439 'updateBoundaryHash',
15440 $twinExitObj->number,
15441 $twinRegionObj->name,
15442 );
15443 }
15444  
15445 # Mark the parent rooms of both exits to be redrawn
15446 $redrawHash{$roomObj->number} = $roomObj;
15447 $redrawHash{$twinRoomObj->number} = $twinRoomObj;
15448 }
15449 }
15450 }
15451  
15452 # Update any GA::Win::Map objects using this world model (if allowed)
15453 if ($updateFlag && %redrawHash) {
15454  
15455 foreach my $obj (values %redrawHash) {
15456  
15457 push (@redrawList, 'room', $obj);
15458 }
15459  
15460 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15461  
15462 # Redraw the rooms
15463 $mapWin->markObjs(@redrawList);
15464 $mapWin->doDraw();
15465  
15466 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15467 $mapWin->restrictWidgets();
15468 }
15469 }
15470  
15471 return 1;
15472 }
15473  
15474 sub checkBentExit {
15475  
15476 # Called by $self->setBrokenExit and ->connectRegionBrokenExit
15477 # When an exit is marked as a broken exit, this function decides whether its ->bentFlag
15478 # should be set to TRUE or FALSE
15479 #
15480 # Expected arguments
15481 # $exitObj - The broken exit object to check
15482 #
15483 # Optional arguments
15484 # $roomObj - The exit's parent room, if known (if 'undef', this functions finds it)
15485 # $destRoomObj - The exit's destination room, if known (if 'undef', this function
15486 # finds it)
15487 #
15488 # Return values
15489 # 'undef' on improper arguments
15490 # 1 otherwise
15491  
15492 my ($self, $exitObj, $roomObj, $destRoomObj, $check) = @_;
15493  
15494 # Check for improper arguments
15495 if (! defined $exitObj || defined $check) {
15496  
15497 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkBentExit', @_);
15498 }
15499  
15500 # Get the parent and destination rooms, if not specified
15501 if (! $roomObj) {
15502  
15503 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15504 }
15505  
15506 if (! $destRoomObj) {
15507  
15508 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15509 }
15510  
15511 # If $self->drawBentExitsFlag is set - and if the exit's parent and destination rooms are on
15512 # the same level - this exit should be drawn as a bent broken exit
15513 # (If ->bentFlag is already TRUE, because the exit was already a broken exit, dont change
15514 # anything)
15515 if (! $exitObj->bentFlag) {
15516  
15517 if (
15518 $self->drawBentExitsFlag
15519 && $destRoomObj
15520 && $destRoomObj->zPosBlocks == $roomObj->zPosBlocks
15521 ) {
15522 $exitObj->ivPoke('bentFlag', TRUE);
15523 } else {
15524 $exitObj->ivPoke('bentFlag', FALSE);
15525 $exitObj->ivEmpty('bendOffsetList');
15526 }
15527 }
15528  
15529 return 1;
15530 }
15531  
15532 sub toggleBentExit {
15533  
15534 # Called by GA::Win::Map->enableExitsColumn
15535 # Toggles a broken exit between a normal and bent broken exit
15536 #
15537 # Expected arguments
15538 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15539 # should be updated now, FALSE if not (in which case, they can be
15540 # updated later by the calling function, when it is ready)
15541 # $exitObj - The broken exit object to toggle
15542 #
15543 # Return values
15544 # 'undef' on improper arguments or if $exitObj isn't a broken exit
15545 # 1 otherwise
15546  
15547 my ($self, $updateFlag, $exitObj, $check) = @_;
15548  
15549 # Local variables
15550 my (
15551 $twinExitObj,
15552 @redrawList,
15553 );
15554  
15555 # Check for improper arguments
15556 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15557  
15558 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleBentExit', @_);
15559 }
15560  
15561 if (! $exitObj->brokenFlag) {
15562  
15563 # Not a broken exit - nothing to do
15564 return undef;
15565 }
15566  
15567 # Get the twin exit (if there is one)
15568 if ($exitObj->twinExit) {
15569  
15570 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
15571 }
15572  
15573 # Toggle the broken exit (and the twin broken exit, if there is one)
15574 if (! $exitObj->bentFlag) {
15575  
15576 $exitObj->ivPoke('bentFlag', TRUE);
15577 if ($twinExitObj) {
15578  
15579 $twinExitObj->ivPoke('bentFlag', TRUE);
15580 }
15581  
15582 } else {
15583  
15584 $exitObj->ivPoke('bentFlag', FALSE);
15585 $exitObj->ivEmpty('bendOffsetList');
15586  
15587 if ($twinExitObj) {
15588  
15589 $twinExitObj->ivPoke('bentFlag', FALSE);
15590 $twinExitObj->ivEmpty('bendOffsetList');
15591 }
15592 }
15593  
15594 # Both parent rooms must be redrawn
15595 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
15596 if ($twinExitObj) {
15597  
15598 push (@redrawList, 'room', $self->ivShow('modelHash', $twinExitObj->parent));
15599 }
15600  
15601 # Update any GA::Win::Map objects using this world model (if allowed)
15602 if ($updateFlag) {
15603  
15604 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15605  
15606 # When an unbent broken exit is selected, the destination room is drawn a different
15607 # colour. Get around the problems of making sure this colour isn't still used in
15608 # any Automapper windows by unselecting any unselected objects
15609 $mapWin->setSelectedObj();
15610  
15611 # Redraw the rooms, which redraws the broken exits
15612 $mapWin->markObjs(@redrawList);
15613 $mapWin->doDraw();
15614  
15615 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15616 $mapWin->restrictWidgets();
15617 }
15618 }
15619  
15620 return 1;
15621 }
15622  
15623 sub applyExitTag {
15624  
15625 # Called by $self->setRegionExit, $self->renameRegion, $self->connectRegionBrokenExit and
15626 # GA::Win::Map->editExitTagCallback
15627 # For the specified region exit, checks whether we're allowed to add an exit tag and, if so,
15628 # applies the exit tag and updates the parent regionmap
15629 #
15630 # Expected arguments
15631 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15632 # should be updated now, FALSE if not (in which case, they can be
15633 # updated later by the calling function, when it is ready)
15634 # $exitObj - The region exit object to modify
15635 #
15636 # Optional arguments
15637 # $regionmapObj - The exit's parent regionmap, if already known (otherwise, this
15638 # function finds it)
15639 # $customText - A string to use as the exit tag's text. If set to 'undef' or an empty
15640 # string, the standard string is useds
15641 # $overrideFlag - Set to TRUE when called by GA::Win::Map->editExitTagCallback and
15642 # $self->renameRegion; this object's ->updateExitTagFlag is not
15643 # consulted (set to FALSE, or 'undef', otherwise)
15644 #
15645 # Return values
15646 # 'undef' on improper arguments
15647 # 1 otherwise
15648  
15649 my ($self, $updateFlag, $exitObj, $regionmapObj, $customText, $overrideFlag, $check) = @_;
15650  
15651 # Local variables
15652 my ($roomObj, $regionObj, $destRoomObj, $destRegionObj, $newTag);
15653  
15654 # Check for improper arguments
15655 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15656  
15657 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyExitTag', @_);
15658 }
15659  
15660 # Don't do anything if we're not allowed to automatically add exit tags, and don't reset an
15661 # existing room tag (unless we're replacing an exit tag's standard text with some custom
15662 # text supplied by the user)
15663 if (
15664 ($self->updateExitTagFlag && ! $exitObj->exitTag)
15665 || $overrideFlag
15666 ) {
15667 # Get the parent regionmap, if not specified
15668 if (! $regionmapObj) {
15669  
15670 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15671 $regionmapObj = $self->findRegionmap($roomObj->parent);
15672 }
15673  
15674 # Get the destination room's parent region
15675 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15676 $destRegionObj = $self->ivShow('modelHash', $destRoomObj->parent);
15677  
15678 # Apply the tag
15679 if ($customText) {
15680 $exitObj->ivPoke('exitTag', $customText);
15681 } else {
15682 $exitObj->ivPoke('exitTag', $self->getExitTagText($exitObj, $destRegionObj));
15683 }
15684  
15685 # Update the regionmap
15686 $regionmapObj->storeExitTag($exitObj);
15687  
15688 # Update any GA::Win::Map objects using this world model (if allowed)
15689 if ($updateFlag) {
15690  
15691 foreach my $mapWin ($self->collectMapWins()) {
15692  
15693 # Redraw the exit
15694 $mapWin->markObjs('exit', $exitObj);
15695 $mapWin->doDraw();
15696 }
15697 }
15698 }
15699  
15700 return 1;
15701 }
15702  
15703 sub getExitTagText {
15704  
15705 # Called by $self->applyExitTag to get the text of the exit tag to apply to a particular
15706 # exit
15707 # Also called by $self->renameRegion to compare a particular exit tag's text, which may have
15708 # been modified by the user, to the default text that would be applied to the exit tag
15709 #
15710 # Expected arguments
15711 # $exitObj - The exit object to check
15712 #
15713 # Optional arguments
15714 # $destRegionObj - The GA::ModelObj::Region which is the exit's destination region (set
15715 # to 'undef' when called by ->renameRegion)
15716 # $regionName - A region name; the text returned is that which would be used, if the
15717 # exit were connected to the region (set to 'undef' when called by
15718 # ->applyExitTag)
15719 #
15720 # Return values
15721 # 'undef' on improper arguments
15722 # The text of an exit tag otherwise
15723  
15724 my ($self, $exitObj, $destRegionObj, $regionName, $check) = @_;
15725  
15726 # Local variables
15727 my $text;
15728  
15729 # Check for improper arguments
15730 if (
15731 ! defined $exitObj
15732 || (! defined $destRegionObj && ! defined $regionName)
15733 || defined $check
15734 ) {
15735 return $axmud::CLIENT->writeImproper($self->_objClass . '->getExitTagText', @_);
15736 }
15737  
15738 # Set which region name to use. If $destRegionObj is set, we're using a real region name
15739 if (! $regionName) {
15740  
15741 $regionName = $destRegionObj->name;
15742 }
15743  
15744 # For exits drawn as 'up' or 'down', use those words in the tag
15745 if (
15746 $exitObj->mapDir
15747 && ($exitObj->mapDir eq 'up' || $exitObj->mapDir eq 'down')
15748 ) {
15749 $text = $exitObj->mapDir . ' to ' . $regionName;
15750 } else {
15751 $text = 'to ' . $regionName;
15752 }
15753  
15754 if ($exitObj->oneWayFlag) {
15755  
15756 $text .= ' (>)';
15757 }
15758  
15759 return $text;
15760 }
15761  
15762 sub cancelExitTag {
15763  
15764 # Called by several functions
15765 # For the specified exit, checks whether is has an exit tag and, if so, cancels the tag and
15766 # updates the parent regionmap
15767 #
15768 # Expected arguments
15769 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15770 # should be updated now, FALSE if not (in which case, they can be
15771 # updated later by the calling function, when it is ready)
15772 # $exitObj - The exit object to modify
15773 #
15774 # Optional arguments
15775 # $regionmapObj - The exit's parent regionmap, if already known (otherwise, this
15776 # function finds it)
15777 #
15778 # Return values
15779 # 'undef' on improper arguments
15780 # 1 otherwise
15781  
15782 my ($self, $updateFlag, $exitObj, $regionmapObj, $check) = @_;
15783  
15784 # Local variables
15785 my ($roomObj, $regionObj);
15786  
15787 # Check for improper arguments
15788 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15789  
15790 return $axmud::CLIENT->writeImproper($self->_objClass . '->cancelExitTag', @_);
15791 }
15792  
15793 # Don't do anything if $exitObj doesn't have an exit tag
15794 if ($exitObj->exitTag) {
15795  
15796 # Get the parent regionmap, if not specified
15797 if (! $regionmapObj) {
15798  
15799 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15800 $regionmapObj = $self->findRegionmap($roomObj->parent);
15801 }
15802  
15803 # Cancel the tag
15804 $exitObj->ivPoke('exitTag', undef);
15805 $exitObj->ivPoke('exitTagXOffset', 0);
15806 $exitObj->ivPoke('exitTagYOffset', 0);
15807  
15808 # Update the regionmap
15809 $regionmapObj->removeExitTag($exitObj);
15810  
15811 # Update any GA::Win::Map objects using this world model (if allowed)
15812 if ($updateFlag) {
15813  
15814 foreach my $mapWin ($self->collectMapWins()) {
15815  
15816 # Redraw the exit
15817 $mapWin->markObjs('exit', $exitObj);
15818 $mapWin->doDraw();
15819 }
15820 }
15821 }
15822  
15823 return 1;
15824 }
15825  
15826 sub resetExitTag {
15827  
15828 # Called by GA::Win::Map->resetExitOffsetsCallback
15829 # Restores an exit tag to its original position on the map
15830 #
15831 # Expected arguments
15832 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
15833 # be updated now, FALSE if not (in which case, they can be updated later
15834 # by the calling function, when it is ready)
15835 # $exitObj - The GA::Obj::Exit whose tag should be repositioned
15836 #
15837 # Return values
15838 # 'undef' on improper arguments or if @roomList is empty
15839 # 1 otherwise
15840  
15841 my ($self, $updateFlag, $exitObj, $check) = @_;
15842  
15843 # Local variables
15844 my $roomObj;
15845  
15846 # Check for improper arguments
15847 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15848  
15849 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetExitTag', @_);
15850 }
15851  
15852 # Update the exit tag
15853 if ($exitObj->exitTag) {
15854  
15855 $exitObj->ivPoke('exitTagXOffset', 0);
15856 $exitObj->ivPoke('exitTagYOffset', 0);
15857  
15858 # Update any GA::Win::Map objects using this world model (if allowed)
15859 if ($updateFlag) {
15860  
15861 # Get the exit's parent room
15862 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15863  
15864 foreach my $mapWin ($self->collectMapWins()) {
15865  
15866 # Redraw the exit
15867 $mapWin->markObjs('exit', $exitObj);
15868 $mapWin->doDraw();
15869 }
15870 }
15871 }
15872  
15873 return 1;
15874 }
15875  
15876 sub addExitBend {
15877  
15878 # Called by GA::Win::Map->addBendCallback
15879 # Adds a bend at the specified position on an exit (another call to this function is
15880 # required to add the corresponding bend to the twin exit, if any)
15881 #
15882 # Expected arguments
15883 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15884 # should be updated now, FALSE if not (in which case, they can be
15885 # updated later by the calling function, when it is ready)
15886 # $exitObj - The GA::Obj::Exit to modify
15887 # $startXPos, $startYPos
15888 # - Absolute coordinates of the start of the exit's bending section
15889 # $clickXPos, $clickYPos
15890 # - The position of the mouse click, relative to the start of the bending
15891 # section of the exit
15892 # $stopXPos, $stopYPos
15893 # - The end of the bending section of the exit, relative to the start of
15894 # the bending section
15895 #
15896 # Return values
15897 # 'undef' on improper arguments
15898 # 1 otherwise
15899  
15900 my (
15901 $self, $updateFlag, $exitObj, $startXPos, $startYPos, $clickXPos, $clickYPos,
15902 $stopXPos, $stopYPos, $check,
15903 ) = @_;
15904  
15905 # Local variables
15906 my (
15907 $shortRatio, $shortRatioPosn, $roomObj,
15908 @offsetList,
15909 );
15910  
15911 # Check for improper arguments
15912 if (
15913 ! defined $updateFlag || ! defined $exitObj || ! defined $startXPos
15914 || ! defined $startYPos || ! defined $clickXPos || ! defined $clickYPos
15915 || ! defined $stopXPos || ! defined $stopYPos || defined $check
15916 ) {
15917 return $axmud::CLIENT->writeImproper($self->_objClass . '->addExitBend', @_);
15918 }
15919  
15920 # If the exit isn't already a bent broken exit, convert it to one ($self->setBrokenExit
15921 # calls ->checkBentExit to set the exit object's ->bentFlag IV)
15922 if (! $exitObj->brokenFlag) {
15923  
15924 $self->setBrokenExit(
15925 FALSE, # Don't update Automapper windows yet
15926 $exitObj,
15927 );
15928 }
15929  
15930 # If the exit currently has no bends, then our job is fairly easy
15931 if (! $exitObj->bendOffsetList) {
15932  
15933 $exitObj->ivPush('bendOffsetList', $clickXPos, $clickYPos);
15934  
15935 } else {
15936  
15937 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...) where each (x, y) pair
15938 # are the coordinates of a bend in the exit, relative to the start of the bending
15939 # section
15940 # Start by adding a pair of coordinates at the start of the bending section,
15941 # corresponding to the start of the bending section
15942 @offsetList = $exitObj->bendOffsetList;
15943 unshift(@offsetList, 0, 0);
15944 # Add another pair of coordinates, corresponding to the end of the bending section
15945 # (relative to the start)
15946 push (@offsetList, $stopXPos, $stopYPos);
15947  
15948 # Now work out where the new bend should be placed. The position of the mouse click
15949 # forms a triangle with the bends (including the start of the bending section) on
15950 # either side:
15951 # C
15952 # -- --
15953 # -- --
15954 # -- --
15955 # A --------D-------- B
15956 #
15957 # ...where A and B are existing bends (one of which might be the start/end of the
15958 # exit), and C is the position of the mouse click, very close to the line ADB. The
15959 # mouse click should create a new bend at D
15960 # The new bend is created between the bends A and B, for which the line ACB is closest
15961 # in length to ADB
15962 for (my $count = 0; $count < (scalar @offsetList - 2); $count += 2) {
15963  
15964 my ($aXPos, $aYPos, $bXPos, $bYPos, $ratio);
15965  
15966 $aXPos = $offsetList[$count];
15967 $aYPos = $offsetList[$count + 1];
15968 $bXPos = $offsetList[$count + 2];
15969 $bYPos = $offsetList[$count + 3];
15970  
15971 # Get the ratio ACB / ADB
15972 $ratio = $self->findBendRatio(
15973 $aXPos, $aYPos,
15974 $bXPos, $bYPos,
15975 $clickXPos, $clickYPos,
15976 );
15977  
15978 if (! defined $shortRatio || $ratio < $shortRatio) {
15979  
15980 # This is the first pair of bends, or the ratio for this pair of bends is the
15981 # smallest found so far
15982 $shortRatio = $ratio;
15983 $shortRatioPosn = $count + 2; # New bend is placed after bend A
15984 }
15985 }
15986  
15987 # Add the bend
15988 $exitObj->ivSplice('bendOffsetList', ($shortRatioPosn - 2), 0, $clickXPos, $clickYPos);
15989 }
15990  
15991 # Update any GA::Win::Map objects using this world model (if allowed)
15992 if ($updateFlag) {
15993  
15994 # Get the exit's parent room
15995 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15996  
15997 foreach my $mapWin ($self->collectMapWins()) {
15998  
15999 # Redraw the room
16000 $mapWin->markObjs('room', $roomObj);
16001 $mapWin->doDraw();
16002 }
16003 }
16004  
16005 return 1;
16006 }
16007  
16008 sub findBendRatio {
16009  
16010 # Called by $self->addExitBend
16011 # In a triangle ABC, works out the ratio of the length ACB to the length AB (see the
16012 # comments in the calling function)
16013 #
16014 # Expected arguments
16015 # $aXPos, $aYPos - Relative coordinates of point A
16016 # $bXPos, $bYPos - Relative coordinates of point B
16017 # $cXPos, $cYPos - Relative coordinates of point C
16018 #
16019 # Return values
16020 # 'undef' on improper arguments
16021 # Otherwise returns the ratio ACB / AB
16022  
16023 my ($self, $aXPos, $aYPos, $bXPos, $bYPos, $cXPos, $cYPos, $check) = @_;
16024  
16025 # Local variables
16026 my ($lengthAB, $lengthAC, $lengthCB);
16027  
16028 # Check for improper arguments
16029 if (
16030 ! defined $aXPos || ! defined $aYPos || ! defined $bXPos || ! defined $bYPos
16031 || ! defined $cXPos || ! defined $cYPos || defined $check
16032 ) {
16033 return $axmud::CLIENT->writeImproper($self->_objClass . '->findBendRatio', @_);
16034 }
16035  
16036 # Find the lengths AB, AC and CB
16037 $lengthAB = sqrt( (($bXPos - $aXPos) ** 2) + (($bYPos - $aYPos) ** 2));
16038 $lengthAC = sqrt( (($cXPos - $aXPos) ** 2) + (($cYPos - $aYPos) ** 2));
16039 $lengthCB = sqrt( (($cXPos - $bXPos) ** 2) + (($cYPos - $bYPos) ** 2));
16040  
16041 # Return the ratio
16042 return ( abs ( ($lengthAC + $lengthCB) / $lengthAB));
16043 }
16044  
16045 sub adjustExitBend {
16046  
16047 # Called by GA::Win::Map->continueDrag
16048 # Called while dragging an exit bend in order to update the exit's IVs
16049 #
16050 # Expected arguments
16051 # $exitObj - The GA::Obj::Exit to update
16052 # $index - The index of the bend to adjust (the bend nearest to the start of the
16053 # exit's list of bend coordinates is numbered 0)
16054 # $xPos, $yPos - The bend's new coordinates, relative to the start of the bending
16055 # section of the exit
16056 #
16057 # Return values
16058 # 'undef' on improper arguments
16059 # 1 otherwise
16060  
16061 my ($self, $exitObj, $index, $xPos, $yPos, $check) = @_;
16062  
16063 # Check for improper arguments
16064 if (
16065 ! defined $exitObj || ! defined $index || ! defined $xPos || ! defined $yPos
16066 || defined $check
16067 ) {
16068 return $axmud::CLIENT->writeImproper($self->_objClass . '->adjustExitBend', @_);
16069 }
16070  
16071 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...). Replace a single pair of
16072 # (x, y) coordinates; e.g. if $index = 2, replace the 5th and 6th coordinates
16073 $index *= 2;
16074 $exitObj->ivSplice('bendOffsetList', $index, 2, $xPos, $yPos);
16075  
16076 return 1;
16077 }
16078  
16079 sub removeExitBend {
16080  
16081 # Called by GA::Win::Map->removeBendCallback
16082 # Removes a bend at the specified position on an exit (another call to this function is
16083 # required to remove the corresponding bend from the twin exit, if any)
16084 #
16085 # Expected arguments
16086 # $session - The calling function's GA::Session
16087 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
16088 # should be updated now, FALSE if not (in which case, they can be
16089 # updated later by the calling function, when it is ready)
16090 # $exitObj - The GA::Obj::Exit to modify
16091 # $index - The index of the bend to remove (the bend nearest to the start of the
16092 # exit's list of bend coordinates is numbered 0)
16093 #
16094 # Return values
16095 # 'undef' on improper arguments
16096 # 1 otherwise
16097  
16098 my ($self, $session, $updateFlag, $exitObj, $index, $check) = @_;
16099  
16100 # Local variables
16101 my $roomObj;
16102  
16103 # Check for improper arguments
16104 if (
16105 ! defined $session || ! defined $updateFlag || ! defined $exitObj || ! defined $index
16106 || defined $check
16107 ) {
16108 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeExitBend', @_);
16109 }
16110  
16111 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...). Remove a single pair of
16112 # (x, y) coordinates; e.g. if $index = 2, remove the 5th and 6th coordinates
16113 $index *= 2;
16114 $exitObj->ivSplice('bendOffsetList', $index, 2);
16115  
16116 # Check whether the exit's destination and departure rooms are aligned. If so, we can
16117 # restore the exit to a non-broken status
16118 if (! $exitObj->bendOffsetList && $self->checkRoomAlignment($session, $exitObj)) {
16119  
16120 $self->restoreBrokenExit(
16121 $session,
16122 FALSE, # Don't update automapper windows now
16123 $exitObj,
16124 TRUE, # We've already called $self->checkRoomAlignment
16125 );
16126 }
16127  
16128 # Update any GA::Win::Map objects using this world model (if allowed)
16129 if ($updateFlag) {
16130  
16131 # Get the exit's parent room
16132 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
16133  
16134 foreach my $mapWin ($self->collectMapWins()) {
16135  
16136 # Redraw the room
16137 $mapWin->markObjs('room', $roomObj);
16138 $mapWin->doDraw();
16139 }
16140 }
16141  
16142 return 1;
16143 }
16144  
16145 sub updateExitBends {
16146  
16147 # Called by $self->moveRoomsLabels
16148 # When a room is dragged to a new position in the (same) regionmap, we must update the
16149 # position of any exit bends
16150 #
16151 # Expected arguments
16152 # $adjustXPos, $adjustYPos, $adjustZPos
16153 # - The direction of the room's movement, in gridblocks
16154 # $regionmapObj - The regionmap in which the exit's room has been moved
16155 # $exitObj - The GA::Obj::Exit whose bends must be updated
16156 #
16157 # Optional arguments
16158 # $twinExitObj - $exitObj's twin, if it has one ('undef' otherwise)
16159 #
16160 # Return values
16161 # 'undef' on improper arguments
16162 # 1 otherwise
16163  
16164 my (
16165 $self, $adjustXPos, $adjustYPos, $adjustZPos, $regionmapObj, $exitObj, $twinExitObj,
16166 $check,
16167 ) = @_;
16168  
16169 # Local variables
16170 my (@offsetList, @newList);
16171  
16172 # Check for improper arguments
16173 if (
16174 ! defined $adjustXPos || ! defined $adjustYPos || ! defined $adjustZPos
16175 || ! defined $exitObj || defined $check
16176 ) {
16177 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateExitBends', @_);
16178 }
16179  
16180 # If the room has moved up or down, remove bends altogether
16181 if ($adjustZPos) {
16182  
16183 $exitObj->ivEmpty('bendOffsetList');
16184 # (Also for the twin exit, if there is one)
16185 if ($twinExitObj) {
16186  
16187 $twinExitObj->ivEmpty('bendOffsetList');
16188 }
16189  
16190 # Otherwise, use the room's new position to update the bend's position
16191 # (We don't update the twin - if that room has also been dragged, this function will be
16192 # called again to update its bends)
16193 } else {
16194  
16195 $adjustXPos *= $regionmapObj->blockWidthPixels;
16196 $adjustYPos *= $regionmapObj->blockHeightPixels;
16197  
16198 @offsetList = $exitObj->bendOffsetList;
16199 do {
16200  
16201 # @offsetList is in the form (x, y, x, y...)
16202 push (@newList, ((shift @offsetList) - $adjustXPos));
16203 push (@newList, ((shift @offsetList) - $adjustYPos));
16204  
16205 } until (! @offsetList);
16206  
16207 $exitObj->ivPoke('bendOffsetList', @newList);
16208 }
16209  
16210 return 1;
16211 }
16212  
16213 # Modify model objects - labels
16214  
16215 sub updateLabel {
16216  
16217 # Called by GA::Win::Map->setLabelCallback and ->promptConfigLabel
16218 # Sets the specified label's ->name IV (containing the text displayed) and redraw the label
16219 # (if allowed)
16220 #
16221 # Expected arguments
16222 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
16223 # be updated now, FALSE if not (in which case, they can be updated later
16224 # by the calling function, when it is ready)
16225 # $session - The calling GA::Session
16226 # $labelObj - The GA::Obj::MapLabel to modify
16227 # $name - The new text for the label
16228 #
16229 # Optional arguments
16230 # $style - The new map label style (if 'undef', the label starts using its own IVs
16231 # to set a style)
16232 #
16233 # Return values
16234 # 'undef' on improper arguments
16235 # 1 otherwise
16236  
16237 my ($self, $updateFlag, $session, $labelObj, $name, $style, $check) = @_;
16238  
16239 # Check for improper arguments
16240 if (
16241 ! defined $updateFlag || ! defined $session || ! defined $labelObj || ! defined $name
16242 || defined $check
16243 ) {
16244 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateLabel', @_);
16245 }
16246  
16247 # Update IVs
16248 $labelObj->ivPoke('name', $name);
16249 if (defined $style) {
16250 $labelObj->set_style($session, $style);
16251 } else {
16252 $labelObj->reset_style();
16253 }
16254  
16255 # Update any GA::Win::Map objects using this world model (if allowed)
16256 if ($updateFlag) {
16257  
16258 foreach my $mapWin ($self->collectMapWins()) {
16259  
16260 # Redraw the label
16261 $mapWin->markObjs('label', $labelObj);
16262 $mapWin->doDraw();
16263 }
16264 }
16265  
16266 return 1;
16267 }
16268  
16269 # Room flag methods
16270  
16271 sub setupRoomFlags {
16272  
16273 # Called by $self->new to initialise the model's room filter and room flag IVs
16274 # Also called by $self->resetRoomFlags
16275 #
16276 # Expected arguments
16277 # $session - The calling GA::Session
16278 #
16279 # Return values
16280 # 'undef' on improper arguments
16281 # 1 otherwise
16282  
16283 my ($self, $session, $check) = @_;
16284  
16285 # Local variables
16286 my (
16287 $count,
16288 @initList, @orderedList,
16289 );
16290  
16291 # Check for improper arguments
16292 if (! defined $session || defined $check) {
16293  
16294 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupRoomFlags', @_);
16295 }
16296  
16297 # Set up ->roomFilterApplyHash, with no filters applied by default
16298 foreach my $filter ($axmud::CLIENT->constRoomFilterList) {
16299  
16300 $self->ivPoke('roomFilterApplyHash', $filter, FALSE);
16301 }
16302  
16303 # Create room flag objects, one for each room flag
16304 $count = 0;
16305 @initList = $axmud::CLIENT->constRoomFlagList;
16306 do {
16307  
16308 my ($name, $short, $filter, $colour, $descrip, $newObj);
16309  
16310 $count++;
16311  
16312 $name = shift @initList;
16313 $short = shift @initList;
16314 $filter = shift @initList;
16315 $colour = shift @initList;
16316 $descrip = shift @initList;
16317  
16318 $newObj = Games::Axmud::Obj::RoomFlag->new(
16319 $session,
16320 $name,
16321 FALSE, # Not a custom room flag
16322 );
16323  
16324 if ($newObj) {
16325  
16326 $newObj->ivPoke('shortName', $short);
16327 $newObj->ivPoke('descrip', $descrip);
16328 $newObj->ivPoke('priority', $count);
16329 $newObj->ivPoke('filter', $filter);
16330 $newObj->ivPoke('colour', $colour);
16331  
16332 $self->ivAdd('roomFlagHash', $name, $newObj);
16333 push (@orderedList, $name);
16334 }
16335  
16336 } until (! @initList);
16337  
16338 $self->ivPoke('roomFlagOrderedList', @orderedList);
16339  
16340 # Operation complete
16341 return 1;
16342 }
16343  
16344 sub resetRoomFlags {
16345  
16346 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16347 # Resets the world model's room flags to their default state, eliminating any custom room
16348 # flags
16349 # Checks every room in the model, removing any room flags that no longer exist
16350 #
16351 # Expected arguments
16352 # $session - The calling function's GA::Session
16353 #
16354 # Return values
16355 # 'undef' on improper arguments
16356 # 1 otherwise
16357  
16358 my ($self, $session, $check) = @_;
16359  
16360 # Check for improper arguments
16361 if (! defined $session || defined $check) {
16362  
16363 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRoomFlags', @_);
16364 }
16365  
16366 # Reset the IVs
16367 $self->setupRoomFlags($session);
16368  
16369 # Check every room in the model, eliminating custom room flags that no longer exist
16370 foreach my $roomObj ($self->ivValues('roomModelHash')) {
16371  
16372 foreach my $roomFlag ($roomObj->ivKeys('roomFlagHash')) {
16373  
16374 if (! $self->ivExists('roomFlagHash', $roomFlag)) {
16375  
16376 $roomObj->ivDelete('roomFlagHash', $roomFlag);
16377 }
16378 }
16379 }
16380  
16381 return 1;
16382 }
16383  
16384 sub updateRoomFlags {
16385  
16386 # Called by GA::Obj::File->updateExtractedData in order to update the room flags stored in
16387 # this world model to those used in a more recent version of Axmud
16388 #
16389 # Expected arguments
16390 # $session - The calling function's GA::Session
16391 #
16392 # Return values
16393 # 'undef' on improper arguments
16394 # 1 otherwise
16395  
16396 my ($self, $session, $check) = @_;
16397  
16398 # Local variables
16399 my (
16400 @initList,
16401 %newApplyHash,
16402 );
16403  
16404 # Check for improper arguments
16405 if (defined $check) {
16406  
16407 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRoomFlags', @_);
16408 }
16409  
16410 # Update $self->roomFilterApplyHash. Add any new filters, and remove any defunct filters
16411 # (the latter will probably never happen, but there's no harm in checking)
16412 foreach my $filter ($axmud::CLIENT->constRoomFilterList) {
16413  
16414 if ($self->ivExists('roomFilterApplyHash', $filter)) {
16415  
16416 # Keep the current setting
16417 $newApplyHash{$filter} = $self->ivShow('roomFilterApplyHash', $filter);
16418  
16419 } else {
16420  
16421 # New filter
16422 $newApplyHash{$filter} = FALSE;
16423 }
16424 }
16425  
16426 $self->ivPoke('roomFilterApplyHash', %newApplyHash);
16427  
16428 # Update $self->roomFlagHash and ->roomFlagOrderedList. Add any new room flag objects, but
16429 # don't remove any defunct room flags (as the rooms in this world model might be using
16430 # them)
16431 @initList = $axmud::CLIENT->constRoomFlagList;
16432 do {
16433  
16434 my ($name, $short, $filter, $colour, $descrip, $count, $index, $newObj);
16435  
16436 $name = shift @initList;
16437 $short = shift @initList;
16438 $filter = shift @initList;
16439 $colour = shift @initList;
16440 $descrip = shift @initList;
16441  
16442 if (! $self->ivExists('roomFlagHash', $name)) {
16443  
16444 # Go through the existing ordered list of room flags, and find the position of the
16445 # last room flag using the same filter
16446 $count = 0;
16447 foreach my $name ($self->roomFlagOrderedList) {
16448  
16449 my $oldObj;
16450  
16451 $oldObj = $self->ivShow('roomFlagHash', $name);
16452 $count++;
16453  
16454 if ($oldObj->filter eq $filter) {
16455  
16456 $index = $count;
16457 }
16458 }
16459  
16460 if (! $index) {
16461  
16462 # This room flag seems to be using a unique filter (for some reason). Insert
16463 # the new room flag at the end of the list
16464 $index = scalar ($self->roomFlagOrderedList);
16465 }
16466  
16467 # Create a new room flag object
16468 $newObj = Games::Axmud::Obj::RoomFlag->new(
16469 $session,
16470 $name,
16471 FALSE, # Not a custom room flag
16472 );
16473  
16474 # Insert it at the specified position
16475 if ($newObj) {
16476  
16477 $newObj->ivPoke('shortName', $short);
16478 $newObj->ivPoke('descrip', $descrip);
16479 $newObj->ivPoke('priority', $index + 1);
16480 $newObj->ivPoke('filter', $filter);
16481 $newObj->ivPoke('colour', $colour);
16482  
16483 $self->ivAdd('roomFlagHash', $name, $newObj);
16484 $self->ivSplice('roomFlagOrderedList', $index, 0, $name);
16485  
16486 # Update every room flag object's ->priority IV
16487 $count = 0;
16488 foreach my $name ($self->roomFlagOrderedList) {
16489  
16490 my $thisObj = $self->ivShow('roomFlagHash', $name);
16491  
16492 $count++;
16493 $thisObj->ivPoke('priority', $count);
16494 }
16495 }
16496 }
16497  
16498 } until (! @initList);
16499  
16500 # Operation complete
16501 return 1;
16502 }
16503  
16504 sub addRoomFlag {
16505  
16506 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16507 # Adds a new custom room flag and updates the priority list for all room flags
16508 #
16509 # Expected arguments
16510 # $session - The calling function's GA::Session
16511 # $name - The room flag name (max 16 characters, must be unique among room flag
16512 # names)
16513 # $shortName - The short name (max 2 characters; should ideally be unique among short
16514 # names, but that's not a hard rule)
16515 # $descrip - The room flag description (any text, but at least 1 character)
16516 # $colour - The colour used to draw the room, when this room flag is the highest-
16517 # priority room flag in the room. An RGB tag, e.g. '#ABCDEF' (case-
16518 # insensitive)
16519 #
16520 # Return values
16521 # 'undef' on improper arguments, if $name, $shortName and/or $descrip are not the right
16522 # length, if a room flag called $name already exists or if $colour is not a valid RGB
16523 # tag
16524 # 1 otherwise
16525  
16526 my ($self, $session, $name, $shortName, $descrip, $colour, $check) = @_;
16527  
16528 # Local variables
16529 my ($type, $lastMarker, $lastCustom, $priority, $newObj, $count);
16530  
16531 # Check for improper arguments
16532 if (
16533 ! defined $session || ! defined $name || ! defined $shortName || ! defined $descrip
16534 || ! defined $colour || defined $check
16535 ) {
16536 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRoomFlag', @_);
16537 }
16538  
16539 # Check the lengths of the text arguments
16540 if (
16541 length($name) < 1 || length($name) > 16
16542 || length($shortName) != 2
16543 || length($descrip) < 1
16544 ) {
16545 return undef;
16546 }
16547  
16548 # Check a room flag called $name doesn't already exist
16549 if ($self->ivExists('roomFlagHash', $name)) {
16550  
16551 return undef;
16552 }
16553  
16554 # Check $colour is a valid RGB tag
16555 ($type) = $axmud::CLIENT->checkColourTags($colour, 'rgb');
16556 if (! $type) {
16557  
16558 return undef;
16559 }
16560  
16561 # Decide the room flag's position in the priority list
16562 # Position it after the last 'custom' room flag or, if there are none, after the last
16563 # 'markers' room tag
16564 # (In the default list, all 'markers' room flags come first, followed by all 'custom' room
16565 # flags)
16566 foreach my $roomFlagObj ($self->ivValues('roomFlagHash')) {
16567  
16568 if (
16569 $roomFlagObj->filter eq 'markers'
16570 && (! defined $lastMarker || $lastMarker < $roomFlagObj->priority)
16571 ) {
16572 $lastMarker = $roomFlagObj->priority;
16573  
16574 } elsif (
16575 $roomFlagObj->filter eq 'custom'
16576 && (! defined $lastCustom || $lastCustom < $roomFlagObj->priority)
16577 ) {
16578 $lastCustom = $roomFlagObj->priority;
16579 }
16580 }
16581  
16582 if (defined $lastCustom) {
16583 $priority = $lastCustom + 1;
16584 } elsif (defined $lastMarker) {
16585 $priority = $lastMarker + 1;
16586 } else {
16587 $priority = 1; # Failsafe - should never be used
16588 }
16589  
16590 # Create a new room flag object
16591 $newObj = Games::Axmud::Obj::RoomFlag->new(
16592 $session,
16593 $name,
16594 TRUE, # Custom room flag
16595 );
16596  
16597 if ($newObj) {
16598  
16599 $self->ivAdd('roomFlagHash', $name, $newObj);
16600  
16601 # Set the object's IVs
16602 $newObj->ivPoke('shortName', $shortName);
16603 $newObj->ivPoke('descrip', $descrip);
16604 $newObj->ivPoke('priority', $priority);
16605 $newObj->ivPoke('filter', 'custom');
16606 $newObj->ivPoke('colour', $colour);
16607  
16608 # Insert it at the right position in the room flag priority list
16609 $self->ivSplice('roomFlagOrderedList', ($priority - 1), 0, $name);
16610  
16611 # Update every room flag object's ->priority IV
16612 $count = 0;
16613 foreach my $name ($self->roomFlagOrderedList) {
16614  
16615 my $thisObj = $self->ivShow('roomFlagHash', $name);
16616  
16617 $count++;
16618 $thisObj->ivPoke('priority', $count);
16619 }
16620  
16621 # Must redraw the menu in any automapper windows, so that the new room flag appears in
16622 # them
16623 $self->updateMapMenuToolbars();
16624 }
16625  
16626 # Operation complete
16627 return 1;
16628 }
16629  
16630 sub deleteRoomFlag {
16631  
16632 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16633 # Deletes custom room flag and updates the priority list for all room flags
16634 # (Room flags belonging to other filters can't be deleted)
16635 #
16636 # Expected arguments
16637 # $name - The room flag name to delete
16638 #
16639 # Return values
16640 # 'undef' on improper arguments, if the room flag doesn't exist or if it isn't a custom
16641 # room flag
16642 # 1 otherwise
16643  
16644 my ($self, $name, $check) = @_;
16645  
16646 # Local variables
16647 my ($roomFlagObj, $count);
16648  
16649 # Check for improper arguments
16650 if (! defined $name) {
16651  
16652 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRoomFlag', @_);
16653 }
16654  
16655 # Check the flag exists and is a custom room flag
16656 $roomFlagObj = $self->ivShow('roomFlagHash', $name);
16657 if (! $roomFlagObj || $roomFlagObj->filter ne 'custom') {
16658  
16659 return undef;
16660  
16661 } else {
16662  
16663 $self->ivDelete('roomFlagHash', $name);
16664  
16665 # Remove it from the room flag priority list
16666 $self->ivSplice('roomFlagOrderedList', ($roomFlagObj->priority - 1), 1);
16667  
16668 # Update every room flag object's ->priority IV
16669 $count = 0;
16670 foreach my $name ($self->roomFlagOrderedList) {
16671  
16672 my $thisObj = $self->ivShow('roomFlagHash', $name);
16673  
16674 $count++;
16675 $thisObj->ivPoke('priority', $count);
16676 }
16677  
16678 # Must redraw the menu in any automapper windows, so that the old room flag no longer
16679 # appears in them
16680 $self->updateMapMenuToolbars();
16681 }
16682  
16683 # Operation complete
16684 return 1;
16685 }
16686  
16687 sub toggleRoomFlags {
16688  
16689 # Called by GA::Win::Map->enableRoomsColumn_filterSubMenu
16690 # Toggles a room flag in one or more rooms. Redraws the rooms (if permitted) and
16691 # recalculates the regionmap's paths (if necessary)
16692 #
16693 # Expected arguments
16694 # $session - The calling function's GA::Session
16695 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
16696 # be updated now, FALSE if not (in which case, they can be updated later
16697 # by the calling function, when it is ready)
16698 # $roomFlag - The room flag to toggle (matches one of the keys in
16699 # $self->roomFlagHash)
16700 #
16701 # Optional arguments
16702 # @roomList - A list of room objects to update. If the list is empty, no flags are
16703 # toggled
16704 #
16705 # Return values
16706 # 'undef' on improper arguments
16707 # 1 otherwise
16708  
16709 my ($self, $session, $updateFlag, $roomFlag, @roomList) = @_;
16710  
16711 # Local variables
16712 my (
16713 $hazardFlag,
16714 @redrawList,
16715 %regionHash,
16716 );
16717  
16718 # Check for improper arguments
16719 if (! defined $session || ! defined $updateFlag || ! defined $roomFlag) {
16720  
16721 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleRoomFlags', @_);
16722 }
16723  
16724 # For speed, work out now whether $roomFlag is one of the hazardous room flags, or not
16725 if ($axmud::CLIENT->ivExists('constRoomHazardHash', $roomFlag)) {
16726  
16727 $hazardFlag = TRUE;
16728 }
16729  
16730 # Update each room in turn
16731 foreach my $roomObj (@roomList) {
16732  
16733 my $listRef;
16734  
16735 # (All affected rooms may be redrawn shortly)
16736 push (@redrawList, 'room', $roomObj);
16737  
16738 if ($roomObj->ivExists('roomFlagHash', $roomFlag)) {
16739  
16740 # Unset the flag by deleting the key
16741 $roomObj->ivDelete('roomFlagHash', $roomFlag);
16742  
16743 } else {
16744  
16745 # Set the flag by adding the key
16746 $roomObj->ivAdd('roomFlagHash', $roomFlag);
16747 }
16748  
16749 if ($updateFlag) {
16750  
16751 # Reset the ->lastRoomFlag IV - it'll be set to the correct value (if any)
16752 # when the room is redrawn in a moment
16753 $roomObj->ivUndef('lastRoomFlag');
16754  
16755 } else {
16756  
16757 # The room isn't going to be redrawn any time soon, so set the correct value of
16758 # ->lastRoomFlag now
16759 $roomObj->ivPoke('lastRoomFlag', $roomFlag);
16760 }
16761  
16762 # Keep track of all the affected regions. Use a hash in the form
16763 # ->regionHash{region_number} = reference_to_list_of_room_objects
16764 if (exists $regionHash{$roomObj->parent}) {
16765  
16766 $listRef = $regionHash{$roomObj->parent};
16767 push (@$listRef, $roomObj);
16768  
16769 } else {
16770  
16771 $regionHash{$roomObj->parent} = [$roomObj];
16772 }
16773 }
16774  
16775 # If the flag is one of the hazardous room flags, we need to re-calculate each regionmap's
16776 # GA::Obj::RegionPath objects (paths between exits at the boundaries of the region)
16777 if ($hazardFlag) {
16778  
16779 foreach my $regionNum (keys %regionHash) {
16780  
16781 my ($regionmapObj, $listRef);
16782  
16783 $regionmapObj = $self->findRegionmap($regionNum);
16784 $listRef = $regionHash{$regionNum};
16785  
16786 $self->recalculateSafePaths(
16787 $session,
16788 $regionmapObj,
16789 @$listRef,
16790 );
16791 }
16792 }
16793  
16794 # Update any GA::Win::Map objects using this world model (if allowed)
16795 if ($updateFlag) {
16796  
16797 foreach my $mapWin ($self->collectMapWins()) {
16798  
16799 # Redraw affected rooms in this region
16800 $mapWin->markObjs(@redrawList);
16801 $mapWin->doDraw();
16802 }
16803 }
16804  
16805 return 1;
16806 }
16807  
16808 sub getDefaultRoomFlag {
16809  
16810 # Can be called by anything
16811 # Quick and dirty method of accessing a room flag's default settings, as specified by
16812 # GA::Client->constRoomFlagList
16813 # Finds the right settings, then creates a temporary room flag object (GA::Obj::RoomFlag) to
16814 # store them, and returns the object
16815 # Note that custom room flags, added by the user, have no default settings and so this
16816 # function returns 'undef'
16817 #
16818 # Expected arguments
16819 # $session - The calling GA::Session
16820 # $name - The name of a non-custom room flag
16821 #
16822 # Return values
16823 # 'undef' on improper arguments or if a non-custom or non-existent room flag name is
16824 # specified
16825 # Otherwise, returns a temporary room flag object whose IVs contain the default settings
16826 # for that room flag
16827  
16828 my ($self, $session, $name, $check) = @_;
16829  
16830 # Local variables
16831 my (
16832 $count,
16833 @initList,
16834 );
16835  
16836 # Check for improper arguments
16837 if (! defined $session || ! defined $name || defined $check) {
16838  
16839 return $axmud::CLIENT->writeImproper($self->_objClass . '->getDefaultRoomFlag', @_);
16840 }
16841  
16842 $count = 0;
16843 @initList = $axmud::CLIENT->constRoomFlagList;
16844 do {
16845  
16846 my ($thisName, $short, $filter, $colour, $descrip, $tempObj);
16847  
16848 $count++;
16849  
16850 $thisName = shift @initList;
16851 $short = shift @initList;
16852 $filter = shift @initList;
16853 $colour = shift @initList;
16854 $descrip = shift @initList;
16855  
16856 if ($thisName eq $name) {
16857  
16858 # Create the temporary room flag object
16859 $tempObj = Games::Axmud::Obj::RoomFlag->new(
16860 $session,
16861 $name,
16862 FALSE, # Not a custom room flag
16863 );
16864  
16865 if ($tempObj) {
16866  
16867 # These are the default settings for the room flag, including its default
16868 # position in the priority list
16869 $tempObj->ivPoke('shortName', $short);
16870 $tempObj->ivPoke('descrip', $descrip);
16871 $tempObj->ivPoke('priority', $count);
16872 $tempObj->ivPoke('filter', $filter);
16873 $tempObj->ivPoke('colour', $colour);
16874  
16875 return $tempObj;
16876 }
16877 }
16878  
16879 } until (! @initList);
16880  
16881 # No matching room flag found in the default list
16882 return undef;
16883 }
16884  
16885 sub getRoomFlagsInFilter {
16886  
16887 # Can be called by anything
16888 # Returns a list of room flags (names, not objects) belonging to the specified room filter
16889 # The list is sorted in priority order
16890 #
16891 # Expected arguments
16892 # $filter - The room filter name (one of the items in GA::Client->constRoomFilterList
16893 #
16894 # Return values
16895 # An empty list on improper arguments
16896 # Otherwise returns the list of room flags, which might be empty (especially if the
16897 # specified $filter is 'custom', and the user hasn't added any custom room flags yet)
16898  
16899 my ($self, $filter, $check) = @_;
16900  
16901 # Local variables
16902 my (@emptyList, @list, @sortedList, @returnList);
16903  
16904 # Check for improper arguments
16905 if (! defined $filter || defined $check) {
16906  
16907 $axmud::CLIENT->writeImproper($self->_objClass . '->getRoomFlagsInFilter', @_);
16908 return @emptyList;
16909 }
16910  
16911 # Weed out all room flags without a matching ->filter
16912 foreach my $flagObj ($self->ivValues('roomFlagHash')) {
16913  
16914 if ($flagObj->filter eq $filter) {
16915  
16916 push (@list, $flagObj);
16917 }
16918 }
16919  
16920 # Sort by priority
16921 @sortedList = sort {$a->priority <=> $b->priority} (@list);
16922  
16923 # Convert room flag objects to room flag names
16924 foreach my $flagObj (@sortedList) {
16925  
16926 push (@returnList, $flagObj->name);
16927 }
16928  
16929 # Operation complete
16930 return @returnList;
16931 }
16932  
16933 sub getVisibleRoomFlags {
16934  
16935 # Can be called by anything
16936 # Returns a hash of room flags which should be visible in various windows, depending on the
16937 # current value of $self->roomFlagShowMode
16938 #
16939 # Expected arguments
16940 # (none besides $self)
16941 #
16942 # Return values
16943 # An empty hash on improper arguments
16944 # Otherwise returns the hash (which might be empty), in the form
16945 # $showHash{room_flag_name} = room_flag_object
16946  
16947 my ($self, $check) = @_;
16948  
16949 # Local variables
16950 my (%emptyHash, %showHash);
16951  
16952 # Check for improper arguments
16953 if (defined $check) {
16954  
16955 $axmud::CLIENT->writeImproper($self->_objClass . '->getVisibleRoomFlags', @_);
16956 return %emptyHash;
16957 }
16958  
16959 foreach my $roomFlagObj ($self->ivValues('roomFlagHash')) {
16960  
16961 if (
16962 $self->roomFlagShowMode eq 'default'
16963 || (
16964 $self->roomFlagShowMode eq 'essential'
16965 && (
16966 $roomFlagObj->customFlag
16967 || $axmud::CLIENT->ivExists('constRoomHazardHash', $roomFlagObj->name)
16968 )
16969 ) || (
16970 $self->roomFlagShowMode eq 'custom' && $roomFlagObj->customFlag
16971 )
16972 ) {
16973 $showHash{$roomFlagObj->name} = $roomFlagObj;
16974 }
16975 }
16976  
16977 # Operation complete
16978 return %showHash;
16979 }
16980  
16981 sub moveRoomFlag {
16982  
16983 # Can be called by anything, but mostly called by the world model's edit window
16984 # Moves the specified room flag to a new position in the priority list, updating IVs for
16985 # all other room flags
16986 #
16987 # Expected arguments
16988 # $name - The name of the room flag to move
16989 # $type - The type of move: 'above' to move the room flag up one position, 'below'
16990 # to move it down one position, 'top' to move it to the top of the
16991 # priority list, 'bottom' to move it to the bottom of the priority list
16992 #
16993 # Return values
16994 # 'undef' on improper arguments or if the specified room flag object can't be found
16995 # 1 otherwise
16996  
16997 my ($self, $name, $type, $check) = @_;
16998  
16999 # Local variables
17000 my (
17001 $flagObj, $posn, $count,
17002 @priorityList,
17003 );
17004  
17005 # Check for improper arguments
17006 if (
17007 ! defined $name
17008 || ! defined $type
17009 || ($type ne 'above' && $type ne 'below' && $type ne 'top' && $type ne 'bottom')
17010 || defined $check
17011 ) {
17012 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveRoomFlag', @_);
17013 }
17014  
17015 # Get the corresponding room flag object
17016 $flagObj = $self->ivShow('roomFlagHash', $name);
17017 if (! $flagObj) {
17018  
17019 return undef;
17020 }
17021  
17022 # Import the current priority list
17023 @priorityList = $self->roomFlagOrderedList;
17024 # Work out the room flag's new position in that list
17025 if ($type eq 'above') {
17026  
17027 $posn = $flagObj->priority - 2;
17028 if ($posn < 0) {
17029  
17030 $posn = 0;
17031 }
17032  
17033 } elsif ($type eq 'below') {
17034  
17035 $posn = $flagObj->priority;
17036 if ($posn >= (scalar @priorityList)) {
17037  
17038 $posn = (scalar @priorityList) - 1;
17039 }
17040  
17041 } elsif ($type eq 'top') {
17042  
17043 $posn = 0;
17044  
17045 } elsif ($type eq 'bottom') {
17046  
17047 $posn = (scalar @priorityList) - 1;
17048 }
17049  
17050 # Remove the flag from that list...
17051 splice(@priorityList, ($flagObj->priority - 1), 1);
17052 # ...and insert it at its new position
17053 splice(@priorityList, $posn, 0, $flagObj->name);
17054  
17055 # Update IVs
17056 $self->ivPoke('roomFlagOrderedList', @priorityList);
17057 # Update every room flag object's ->priority IV
17058 $count = 0;
17059 foreach my $name (@priorityList) {
17060  
17061 my $thisObj = $self->ivShow('roomFlagHash', $name);
17062  
17063 $count++;
17064 $thisObj->ivPoke('priority', $count);
17065 }
17066  
17067 # Operation complete
17068 return 1;
17069 }
17070  
17071 sub removeRoomFlagInRegion {
17072  
17073 # Called by GA::Win::Map->removeRoomFlagsCallback
17074 # Removes a room flag from every room in an existing region, and redraws the affected rooms
17075 #
17076 # Expected arguments
17077 # $regionmapObj - The GA::Obj::Regionmap whose counts should be reset
17078 # $roomFlag - The room flag to remove (matches a key in $self->roomFlagHash)
17079 #
17080 # Return values
17081 # 'undef' on improper arguments
17082 # Otherwise returns the number of modified rooms (may be 0)
17083  
17084 my ($self, $regionmapObj, $roomFlag, $check) = @_;
17085  
17086 # Local variables
17087 my (
17088 $count,
17089 @redrawList,
17090 );
17091  
17092 # Check for improper arguments
17093 if (! defined $regionmapObj || ! defined $roomFlag || defined $check) {
17094  
17095 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRoomFlagInRegion', @_);
17096 }
17097  
17098 # Remove the room flag from any room in the specified region which uses it
17099 foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) {
17100  
17101 my $roomObj = $self->ivShow('modelHash', $roomNum);
17102  
17103 if ($roomObj->ivExists('roomFlagHash', $roomFlag)) {
17104  
17105 $roomObj->ivDelete('roomFlagHash', $roomFlag);
17106 push (@redrawList, 'room', $roomObj);
17107  
17108 $count++;
17109 }
17110 }
17111  
17112 if ($count) {
17113  
17114 # Update each Automapper window (if any flags were actually removed)
17115 foreach my $mapWin ($self->collectMapWins()) {
17116  
17117 $mapWin->markObjs(@redrawList);
17118 $mapWin->doDraw();
17119 }
17120 }
17121  
17122 return $count;
17123 }
17124  
17125 # Other functions called by GA::Obj::Map and GA::Win::Map
17126  
17127 sub resetPainter {
17128  
17129 # Called by $self->new to create a painter object, or by any other function to reset the
17130 # painter object, which is a non-model GA::ModelObj::Room
17131 # (The object is 'reset' by discarding the old non-model room object and replacing it with a
17132 # new one)
17133 #
17134 # Expected arguments
17135 # $session - The calling function's GA::Session
17136 #
17137 # Return values
17138 # 'undef' on improper arguments
17139 # Otherwise, returns the non-model room object created
17140  
17141 my ($self, $session, $check) = @_;
17142  
17143 # Local variables
17144 my $roomObj;
17145  
17146 # Check for improper arguments
17147 if (! defined $session || defined $check) {
17148  
17149 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetPainter', @_);
17150 }
17151  
17152 # Create a new non-model room
17153 $roomObj = Games::Axmud::ModelObj::Room->new($session, 'painter', 'non_model');
17154 if ($roomObj) {
17155  
17156 $self->ivPoke('painterObj', $roomObj);
17157 return $roomObj;
17158  
17159 } else {
17160  
17161 $self->ivUndef('painterObj');
17162 return undef;
17163 }
17164 }
17165  
17166 sub compareRooms {
17167  
17168 # Called by GA::Obj::Map->useExistingRoom to compare the current location according to
17169 # the Locator task (GA::Task::Locator->roomObj, a non-model room object), with the current
17170 # location according to the automapper (which is in the world model)
17171 # Also called by GA::Obj::Map->autoCompareLocatorRoom, ->checkTempRandomReturn,
17172 # GA::Cmd::LocateRoom->do for the same purpose
17173 #
17174 # Called by $self->mergeMap (or by any other function) to compare two room objects in the
17175 # world model (ignoring the Locator task's room)
17176 #
17177 # How the rooms are compared depends on the values of various settings
17178 #
17179 # Expected arguments
17180 # $session - The calling function's GA::Session
17181 # $modelRoomObj - A GA::ModelObj::Room object somewhere in the world model
17182 #
17183 # Optional arguments
17184 # $otherRoomObj - When comparing two rooms in the world model, the other
17185 # GA::ModelObj::Room object. If 'undef', $modelRoomObj is compared
17186 # against the Locator task's non-model room object
17187 # $darkFlag - Set to TRUE when called by GA::Obj::Map->moveKnownDirSeen and
17188 # GA::Obj::Map->useExistingRoom, in which case the model room matches
17189 # any dark or unspecified rooms
17190 # $strictFlag - Set to TRUE when called by GA::Cmd::LocateRoom->do, in which case this
17191 # function is a little more strict; if $modelRoomObj has a room title
17192 # and/or verbose description but $otherRoomObj doesn't (or
17193 # vice-versa), they cannot be matches; titles and verbose descriptions
17194 # are also checked regardless of the settings of $self->matchTitleFlag
17195 # and ->matchDescripFlag. FALSE (or 'undef') otherwise
17196 #
17197 # Return values
17198 # An empty list on improper arguments
17199 # Otherwise, returns a list in the form (result, error_message), where:
17200 # - 'result' is set to 1 if the rooms match, or 'undef' if they don't (or if there is
17201 # an error)
17202 # - 'error_message' is a string to display on failure; otherwise 'error_message' is
17203 # 'undef'. Most 'error_message' strings refer to the Locator task, since that's
17204 # what uses the error message; any other code calling this function (for example
17205 # $self->mergeMap) should ignore the error message
17206  
17207 my ($self, $session, $modelRoomObj, $otherRoomObj, $darkFlag, $strictFlag, $check) = @_;
17208  
17209 # Local variables
17210 my (
17211 $taskObj, $taskFlag, $matchFlag,
17212 @emptyList, @patternList,
17213 %modelExitHash, %otherExitHash, %otherModHash,
17214 );
17215  
17216 # Check for improper arguments
17217 if (! defined $session || ! defined $modelRoomObj || defined $check) {
17218  
17219 $axmud::CLIENT->writeImproper($self->_objClass . '->compareRooms', @_);
17220 return @emptyList;
17221 }
17222  
17223 if (! $otherRoomObj) {
17224  
17225 # Import the Locator task
17226 $taskObj = $session->locatorTask;
17227 # If the Locator task isn't running, or if it doesn't know the current location, the
17228 # rooms aren't a match
17229 if (! $taskObj || ! $taskObj->roomObj) {
17230  
17231 return (undef, 'Lost because Locator doesn\'t exist or current location not known');
17232 }
17233  
17234 $otherRoomObj = $taskObj->roomObj;
17235 $taskFlag = TRUE;
17236  
17237 # Compare world's room vnums (if allowed)
17238 if (
17239 $self->matchVNumFlag
17240 && defined $modelRoomObj->ivShow('protocolRoomHash', 'vnum')
17241 && defined $otherRoomObj->ivShow('protocolRoomHash', 'vnum')
17242 && $modelRoomObj->ivShow('protocolRoomHash', 'vnum')
17243 ne $otherRoomObj->ivShow('protocolRoomHash', 'vnum')
17244 ) {
17245 # The two rooms' vnums don't match
17246 return (undef, 'Lost because rooms\' world vnums don\'t match');
17247 }
17248 }
17249  
17250 # If $darkFlag is set, dark and unspecified rooms are a match for any room
17251 if (
17252 $darkFlag
17253 && ($otherRoomObj->unspecifiedFlag || $otherRoomObj->currentlyDarkFlag)
17254 ) {
17255 return (1, undef); # No error message
17256 }
17257  
17258 # Compare the rooms' properties, taking into account the values of various flags
17259  
17260 # Compare room titles (if allowed)
17261 if (
17262 ($strictFlag || $self->matchTitleFlag)
17263 && $modelRoomObj->titleList
17264 && $otherRoomObj->titleList
17265 ) {
17266 $matchFlag = FALSE;
17267  
17268 OUTER: foreach my $modelTitle ($modelRoomObj->titleList) {
17269  
17270 foreach my $otherTitle ($otherRoomObj->titleList) {
17271  
17272 if ($modelTitle eq $otherTitle) {
17273  
17274 $matchFlag = TRUE;
17275 last OUTER;
17276 }
17277 }
17278 }
17279  
17280 if (! $matchFlag) {
17281  
17282 # The two rooms's titles don't match
17283 return (undef, 'Lost because rooms\' titles don\'t match');
17284 }
17285  
17286 } elsif ($strictFlag && $otherRoomObj->titleList && ! $modelRoomObj->titleList) {
17287  
17288 # The calling ';locateroom' ignores any error message, but we'll provide one anyway
17289 return (undef, 'Lost because room\'s title is unknown');
17290 }
17291  
17292 # Compare (verbose) descriptions (if allowed)
17293 if (
17294 ($strictFlag || $self->matchDescripFlag)
17295 && $modelRoomObj->descripHash
17296 && $otherRoomObj->descripHash
17297 ) {
17298 $matchFlag = FALSE;
17299  
17300 OUTER: foreach my $modelDescrip ($modelRoomObj->ivValues('descripHash')) {
17301  
17302 INNER: foreach my $otherDescrip ($otherRoomObj->ivValues('descripHash')) {
17303  
17304 # Compare the entire verbose descriptions, if allowed
17305 if (! $self->matchDescripCharCount) {
17306  
17307 if ($modelDescrip eq $otherDescrip) {
17308  
17309 $matchFlag = TRUE;
17310 last OUTER;
17311 }
17312  
17313 # Otherwise, compare the first part of the verbose descriptions - namely, the
17314 # first $self->matchDescripCharCount characters
17315 } elsif (
17316 substr($modelDescrip, 0, $self->matchDescripCharCount)
17317 eq substr ($otherDescrip, 0, $self->matchDescripCharCount)
17318 ) {
17319 $matchFlag = TRUE;
17320 last OUTER;
17321 }
17322 }
17323 }
17324  
17325 if (! $matchFlag) {
17326  
17327 # The two rooms's verbose descriptions don't match (well enough)
17328 return (
17329 undef,
17330 'Lost because rooms\' verbose descriptions don\'t match (well enough)',
17331 );
17332 }
17333  
17334 } elsif ($strictFlag && $otherRoomObj->descripHash && ! $modelRoomObj->descripHash) {
17335  
17336 # The calling ';locateroom' ignores any error message, but we'll provide one anyway
17337 return (undef, 'Lost because room\'s verbose description is unknown');
17338 }
17339  
17340 # Compare exits (if allowed)
17341 # For wilderness rooms, we don't check any exits that have been added to the map (since we
17342 # assume the world has sent a room statement with no exit list)
17343 if (
17344 $self->matchExitFlag
17345 && ! $session->currentWorld->basicMappingFlag
17346 && $modelRoomObj->wildMode eq 'normal'
17347 ) {
17348 $matchFlag = FALSE;
17349  
17350 # Import hashes of exits, in the form
17351 # $exitNumHash{direction} = exit_number_in_exit_model (model rooms)
17352 # $exitNumHash{direction} = exit_object (non-model rooms)
17353 %modelExitHash = $modelRoomObj->exitNumHash;
17354 %otherExitHash = $otherRoomObj->exitNumHash;
17355  
17356 # If the Locator task found a duplicate exit, it may have converted it using the
17357 # pattern specified by GA::Profile::World->duplicateReplaceString (e.g. it might have
17358 # converted a duplicate 'east' exit into a 'swim east' exit)
17359 # Any such duplicate exits are marked hidden. Remove them from our considerations
17360 if ($taskFlag) {
17361  
17362 foreach my $dir (keys %otherExitHash) {
17363  
17364 my $exitObj = $otherExitHash{$dir};
17365 if ($exitObj->hiddenFlag) {
17366  
17367 delete $otherExitHash{$dir};
17368 }
17369 }
17370 }
17371  
17372 # From the latter hash, also remove any transient exits (those which appear from time to
17373 # time in various locations, for example the entrance to a moving wagon)
17374 OUTER: foreach my $dir (keys %otherExitHash) {
17375  
17376 @patternList = $session->currentWorld->transientExitPatternList;
17377 if (@patternList) {
17378  
17379 do {
17380  
17381 my $pattern = shift @patternList;
17382 my $destRoom = shift @patternList;
17383  
17384 if ($dir =~ m/$pattern/) {
17385  
17386 # A transient exit; don't compare it to the model room
17387 next OUTER;
17388 }
17389  
17390 } until (! @patternList);
17391 }
17392  
17393 # Not a transient exit
17394 $otherModHash{$dir} = $otherExitHash{$dir};
17395 }
17396  
17397 %otherExitHash = %otherModHash;
17398 %otherModHash = ();
17399  
17400 # If comparing $modelRoomObj against the Locator task's current room, convert any
17401 # relative directions in $otherModHash (e.g. if the character is facing 'west',
17402 # convert the direction 'backward' into 'east')
17403 # Exception: don't convert a relative direction, like 'forward', if an exit in that
17404 # direction literally exists in the world model (by default, when an exit in a
17405 # relative direction is added to the world model, it's converted to a primary
17406 # direction)
17407 if ($taskFlag) {
17408  
17409 foreach my $dir (keys %otherExitHash) {
17410  
17411 my ($slot, $convertDir, $customDir);
17412  
17413 $slot = $session->currentDict->convertRelativeDir($dir);
17414 # $slot is in the range 0-7. Convert it into a standard primary direction
17415 # like 'north', depending on which way the character is currently facing
17416 if (defined $slot && ! exists $modelExitHash{$dir}) {
17417  
17418 $convertDir = $session->currentDict->rotateRelativeDir(
17419 $slot,
17420 $session->mapObj->facingDir,
17421 );
17422 }
17423  
17424 if (defined $convertDir) {
17425  
17426 $customDir = $session->currentDict->ivShow('primaryDirHash', $convertDir);
17427 $otherModHash{$customDir} = $otherExitHash{$dir};
17428  
17429 } else {
17430  
17431 # Not a relative exit
17432 $otherModHash{$dir} = $otherExitHash{$dir};
17433 }
17434 }
17435 }
17436  
17437 # Compare the keys in both hashes. Delete matching exits from each hash; if there are
17438 # any exits left (or missing), the rooms don't match
17439 OUTER: foreach my $dir (keys %modelExitHash) {
17440  
17441 my ($exitNum, $exitObj);
17442  
17443 $exitNum = $modelExitHash{$dir};
17444 $exitObj = $self->ivShow('exitModelHash', $exitNum);
17445 if ($exitObj && $exitObj->hiddenFlag) {
17446  
17447 # The exit should exist here
17448 delete $modelExitHash{$dir};
17449 # The exit shouldn't exist here - delete it anyway, just in case
17450 delete $otherModHash{$dir};
17451  
17452 next OUTER;
17453 }
17454  
17455 if (exists $otherModHash{$dir}) {
17456  
17457 # Exit exists in both hashes (and isn't hidden)
17458 delete $modelExitHash{$dir};
17459 delete $otherModHash{$dir};
17460  
17461 next OUTER;
17462 }
17463  
17464 if ($exitObj->altDir) {
17465  
17466 foreach my $otherDir (keys %otherModHash) {
17467  
17468 if (index ($exitObj->altDir, $otherDir) > -1) {
17469  
17470 # The exit should exist here
17471 delete $modelExitHash{$dir};
17472 # The other exit's alternative nominal direction exists here
17473 delete $otherModHash{$otherDir};
17474  
17475 next OUTER;
17476 }
17477 }
17478 }
17479  
17480 # Missing exit in $otherRoomObj, so the rooms don't match
17481 return (
17482 undef,
17483 'Lost because of missing exit (\'' . $dir . '\') in Locator task\'s'
17484 . ' current room (automapper current room is #' . $modelRoomObj->number
17485 . ', Locator room exits: ' . join(', ', $otherRoomObj->sortedExitList)
17486 . ')',
17487 );
17488 }
17489  
17490 if (%otherModHash) {
17491  
17492 # Missing exit in the model's room, so the rooms don't match
17493 return (
17494 undef,
17495 'Lost because of missing exit(s) in the automapper\'s current room: '
17496 . join(', ', keys %otherModHash) . ' (room #' . $modelRoomObj->number . ')',
17497 );
17498 }
17499 }
17500  
17501 # Compare source code paths (if allowed)
17502 if (
17503 $self->matchSourceFlag
17504 && $modelRoomObj->sourceCodePath
17505 && $otherRoomObj->sourceCodePath
17506 && $modelRoomObj->sourceCodePath ne $otherRoomObj->sourceCodePath
17507 ) {
17508 # The two rooms' source code paths don't match
17509 return (undef, 'Lost because rooms\' source code paths don\'t match');
17510 }
17511  
17512 # The rooms match
17513 return (1, undef); # No error message
17514 }
17515  
17516 sub checkOppPrimary {
17517  
17518 # Called by $self->connectRooms, GA::Win::Map->restoreOneWayExitCallback and
17519 # GA::Obj::Map->autoProcessNewRoom
17520 # Given a GA::Obj::Exit which has a destination room, see if the destination room has an
17521 # exit which is drawn on the map in the opposite direction (and return it, if found)
17522 # If the exit object doesn't have a destination room, see if a proposed destination room
17523 # supplied as an optional argument has an exit drawn on the map the opposite direction
17524 #
17525 # Expected arguments
17526 # $exitObj - The exit object leading to the destination room
17527 #
17528 # Optional arguments
17529 # $destRoomObj - The GA::ModelObj::Room which is the destination room (set to 'undef'
17530 # if the exit already has a destination room set)
17531 #
17532 # Return values
17533 # 'undef' on improper arguments or if an opposite exit can't be found
17534 # Otherwise returns the blessed reference of the exit object which leads from the
17535 # destination room back to the original room (drawn in an opposite direction to the
17536 # one used by $exitObj)
17537  
17538 my ($self, $exitObj, $destRoomObj, $check) = @_;
17539  
17540 # Local variables
17541 my (
17542 $oppMapDir,
17543 @oppList,
17544 %oppHash,
17545 );
17546  
17547 # Check for improper arguments
17548 if (! defined $exitObj || defined $check) {
17549  
17550 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkOppPrimary', @_);
17551 }
17552  
17553 # The exit's primary direction, as used to draw the exit on the map, is stored in ->mapDir.
17554 # If this exit object doesn't have a ->mapDir set (because it's unallocatable), there's
17555 # nothing we can do
17556 if (! $exitObj->mapDir) {
17557  
17558 return undef;
17559 }
17560  
17561 # Set the destination room, if not already set
17562 if (! $destRoomObj) {
17563  
17564 if (! $exitObj->destRoom) {
17565  
17566 # No destination room specified - so nothing we can do
17567 return undef;
17568  
17569 } else {
17570  
17571 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
17572 }
17573 }
17574  
17575 # Get the opposite (standard primary) direction (e.g. convert 'north' to 'south')
17576 $oppMapDir = $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir);
17577  
17578 # See if the destination room has an exit which leads back to the departure room in the
17579 # opposite (primary) direction
17580 OUTER: foreach my $exitNum ($destRoomObj->ivValues('exitNumHash')) {
17581  
17582 my $oppExitObj = $self->ivShow('exitModelHash', $exitNum);
17583 if (
17584 $oppExitObj
17585 && $oppExitObj->mapDir
17586 && $oppExitObj->mapDir eq $oppMapDir
17587 # Don't use an exit attached to a shadow exit; use the shadow exit instead)
17588 && (! $oppExitObj->shadowExit)
17589 ) {
17590 # We have found an exit in the opposite direction
17591 return $oppExitObj;
17592 }
17593 }
17594  
17595 # No exit in the opposite direction was found
17596 return undef;
17597 }
17598  
17599 sub analyseVerboseDescrip {
17600  
17601 # Called by $self->updateRoom
17602 # Compares a room model object's verbose description(s) against the current dictionary's
17603 # lists of recognised words
17604 # All recognised nouns are stored in the room object's ->nounList, and all recognised
17605 # adjectives are stored in ->adjList
17606 #
17607 # Expected arguments
17608 # $session - The calling function's GA::Session
17609 # $roomObj - The room model object to analyse
17610 #
17611 # Return values
17612 # 'undef' on improper arguments
17613 # 1 otherwise
17614  
17615 my ($self, $session, $roomObj, $check) = @_;
17616  
17617 # Local variables
17618 my (
17619 $dictObj,
17620 @nounList, @adjList,
17621 %wordHash,
17622 );
17623  
17624 # Check for improper arguments
17625 if (! defined $session || ! defined $roomObj || defined $check) {
17626  
17627 return $axmud::CLIENT->writeImproper($self->_objClass . '->analyseVerboseDescrip', @_);
17628 }
17629  
17630 # Import the current dictionary
17631 $dictObj = $session->currentDict;
17632  
17633 foreach my $descrip ($roomObj->ivValues('descripHash')) {
17634  
17635 # Split the description into words, and store them in a hash, so that each word is
17636 # checked against the dictionary only once
17637 my @wordList = split('[\s\W]+', $descrip);
17638 foreach my $word (@wordList) {
17639  
17640 $wordHash{$word} = undef;
17641 }
17642 }
17643  
17644 # Check each unique word and, if it's recognised, add it to a list
17645 foreach my $word (keys %wordHash) {
17646  
17647 if ($dictObj->ivExists('combNounHash', $word)) {
17648 push (@nounList, $word);
17649 } elsif ($dictObj->ivExists('combAdjHash', $word)) {
17650 push (@adjList, $word);
17651 }
17652 }
17653  
17654 # Sort the two lists alphabetically, and store them in the room object's IVs
17655 $roomObj->ivPoke('nounList', sort {lc($a) cmp lc($b)} (@nounList));
17656 $roomObj->ivPoke('adjList', sort {lc($a) cmp lc($b)} (@adjList));
17657  
17658 # Analysis complete
17659 return 1;
17660 }
17661  
17662 sub allocateCardinalDir {
17663  
17664 # Called by various functions
17665 # An exit object's ->mapDir is set to one of Axmud's standard primary directions (the words
17666 # 'north', 'southeast', 'up', 'northnortheast' etc), and tells us how the exit is drawn on
17667 # the map
17668 # The exit's ->dir is its nominal direction - the text that appears in a room statement
17669 # (e.g. in 'Obvious exits: north, southeast, up, out')
17670 # If ->dir is a custom primary direction, the ->mapDir is set to the equivalent standard
17671 # primary direction at the time the exit object is created. If ->dir is a recognised
17672 # secondary direction which has been given an equivalent standard primary direction, it
17673 # will have been used. Otherwise, ->mapDir will still be set to 'undef'
17674 # This function can be called once all of a new room's exits have been created in order to
17675 # allocate standard primary directions to all exits which don't have one yet. However,
17676 # this function only allocates the sixteen standard cardinal directions - it's up to the
17677 # user to manually allocate 'up' or 'down', if required
17678 #
17679 # This function is also called by $self->addExit if an existing exit is supplanted by a
17680 # new one, in an effort to allocate a new map direction for it
17681 # The calling function must update $self->updatePathHash and ->updateBoundaryHash, as
17682 # necessary
17683 #
17684 # Expected arguments
17685 # $session - The calling function's GA::Session
17686 # $roomObj - The exit object's parent room
17687 # $exitObj - The exit object whose ->mapDir must be allocated
17688 #
17689 # Optional arguments
17690 # $departRoomObj, $departExitObj, $standardDir
17691 # - When called by $self->updateRoom while temporarily allocating cardinal
17692 # directions to unallocated exits. The room object from which the
17693 # character arrived and the exit object and standard primary or
17694 # secondary direction used (if known). Often, the arrival room ($exitObj's
17695 # parent) will have only one unallocated exit, in which case we allocate
17696 # the opposite standard direction to it
17697 #
17698 # Return values
17699 # 'undef' on improper arguments or if a cardinal direction can't be allocated
17700 # Otherwise, the new value of $exitObj->mapDir
17701  
17702 my (
17703 $self, $session, $roomObj, $exitObj, $departRoomObj, $departExitObj, $standardDir,
17704 $check,
17705 ) = @_;
17706  
17707 # Local variables
17708 my (
17709 $cardinalDir, $matchFlag, $regex,
17710 @keyList, @dirList, @sortedList,
17711 );
17712  
17713 # Check for improper arguments
17714 if (! defined $session || ! defined $roomObj || ! defined $exitObj || defined $check) {
17715  
17716 return $axmud::CLIENT->writeImproper($self->_objClass . '->allocateCardinalDir', @_);
17717 }
17718  
17719 # If the exit's nominal direction ->dir is a secondary direction that should be auto-
17720 # allocated a primary direction, allocate that primary direction (unless one of the other
17721 # exits in the room is already using it)
17722 if (
17723 $session->currentDict->ivExists('secondaryDirHash', $exitObj->dir)
17724 && defined $session->currentDict->ivShow('secondaryAutoHash', $exitObj->dir)
17725 ) {
17726 $cardinalDir = $session->currentDict->ivShow('secondaryAutoHash', $exitObj->dir);
17727 }
17728  
17729 # Does the exit's nominal direction contain a custom primary direction, e.g. 'swim east'?
17730 # If so, we can auto-allocate that primary direction (unless one of the other exits in the
17731 # room is already using it)
17732 # Get a list of custom primary directions, sorted by length (so that we check 'northeast'
17733 # before 'north'), but don't use up/down because, if a mistake is made, it's inconvenient
17734 # to reallocate an exit which can't be clicked directly
17735 if (! $cardinalDir) {
17736  
17737 if (! $self->showAllPrimaryFlag) {
17738 @keyList = $axmud::CLIENT->constShortPrimaryDirList;
17739 } else {
17740 @keyList = $axmud::CLIENT->constPrimaryDirList;
17741 }
17742  
17743 foreach my $key (@keyList) {
17744  
17745 if ($key ne 'up' && $key ne 'down') {
17746  
17747 push (@dirList, $session->currentDict->ivShow('primaryDirHash', $key));
17748 }
17749 }
17750  
17751 @sortedList = sort {length($b) <=> length($a)} (@dirList);
17752  
17753 # Convert the list to a useful regex
17754 $regex = join('|', @sortedList);
17755 if ($exitObj->dir =~ m/($regex)/i) {
17756  
17757 $cardinalDir = $session->currentDict->convertStandardDir($1);
17758 }
17759 }
17760  
17761 if ($cardinalDir) {
17762  
17763 # Check that no other exits in this room are allocated to the same map direction
17764 $matchFlag = FALSE;
17765 OUTER: foreach my $otherExitNum ($roomObj->ivValues('exitNumHash')) {
17766  
17767 my $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
17768  
17769 if (
17770 $otherExitObj ne $exitObj
17771 && $otherExitObj->mapDir
17772 && $otherExitObj->mapDir eq $cardinalDir
17773 ) {
17774 $matchFlag = TRUE;
17775 last OUTER;
17776 }
17777 }
17778  
17779 if (! $matchFlag) {
17780  
17781 # Update the exit and instruct the world model to update its Automapper windows
17782 $self->setExitMapDir(
17783 $session,
17784 FALSE, # Don't update Automapper windows yet
17785 $roomObj,
17786 $exitObj,
17787 $cardinalDir,
17788 );
17789  
17790 # Allocating the primary direction destroys the checked direction, if present
17791 $roomObj->ivDelete(
17792 'checkedDirHash',
17793 $session->currentDict->ivShow('primaryDirHash', $cardinalDir),
17794 );
17795  
17796 return $cardinalDir;
17797 }
17798 }
17799  
17800 # Otherwise, decide for ourselves which primary direction to allocate
17801 if (
17802 defined $departRoomObj
17803 && defined $departExitObj
17804 && (defined $standardDir || defined $departExitObj->mapDir)
17805 ) {
17806 # The character has arrived in a newly-created room using a known exit. Often it's the
17807 # case that the room has only one unallocated exit and we definitely want to allocate
17808 # it using the opposite standard primary direction, so that it points back to the
17809 # departure room
17810  
17811 # Get the opposite standard primary direction (while checking that $standardDir isn't a
17812 # standard secondary direction)
17813 if ($standardDir && $axmud::CLIENT->ivExists('constOppDirHash', $standardDir)) {
17814 $cardinalDir = $axmud::CLIENT->ivShow('constOppDirHash', $standardDir);
17815 } else {
17816 $cardinalDir = $axmud::CLIENT->ivShow('constOppDirHash', $departExitObj->mapDir);
17817 }
17818  
17819 # However, we can't allocate an exit temporarily to 'up' or 'down'
17820 if ($cardinalDir eq 'up' || $cardinalDir eq 'down') {
17821  
17822 $cardinalDir = undef;
17823  
17824 } else {
17825  
17826 # If that standard direction isn't available, don't use it
17827 OUTER: foreach my $number ($roomObj->ivValues('exitNumHash')) {
17828  
17829 my $otherExitObj = $self->ivShow('exitModelHash', $number);
17830  
17831 if (
17832 $otherExitObj
17833 && $otherExitObj->mapDir
17834 && $otherExitObj->mapDir eq $cardinalDir
17835 ) {
17836 $cardinalDir = undef;
17837 last OUTER;
17838 }
17839 }
17840 }
17841  
17842 } else {
17843  
17844 # Get an unallocated cardinal direction, ignoring any directions which are on the end of
17845 # an incoming 1-way exit
17846 $cardinalDir = $self->chooseCardinalDir($roomObj, $exitObj, TRUE);
17847 }
17848  
17849 if (! $cardinalDir) {
17850  
17851 # If not successful the first time, repeat the process, this time including any
17852 # directions which are on the end of an incoming 1-way exit (the former was
17853 # preferable, but we can make do with the latter)
17854 $cardinalDir = $self->chooseCardinalDir($roomObj, $exitObj, FALSE);
17855 }
17856  
17857 if ($cardinalDir) {
17858  
17859 # We have found an available standard primary direction. Allocate this direction to the
17860 # exit object temporarily (it's up to the user to make it permanent)
17861 $exitObj->ivPoke('mapDir', $cardinalDir);
17862 $exitObj->ivPoke('drawMode', 'temp_alloc');
17863  
17864 # Allocating the primary direction destroys the checked direction, if present
17865 $roomObj->ivDelete(
17866 'checkedDirHash',
17867 $session->currentDict->ivShow('primaryDirHash', $cardinalDir),
17868 );
17869  
17870 return $cardinalDir;
17871  
17872 } else {
17873  
17874 # All sixteen cardinal directions are occupied. Mark the exit as 'unallocatable'
17875 $exitObj->ivUndef('mapDir');
17876 $exitObj->ivPoke('drawMode', 'temp_unalloc');
17877  
17878 return undef;
17879 }
17880 }
17881  
17882 sub chooseCardinalDir {
17883  
17884 # Called by $self->allocateCardinalDir up to two times - the first time, looking for a
17885 # cardinal direction that don't have any incoming one-way exits; the second time (if
17886 # necessary), looking for any available cardinal direction
17887 #
17888 # Expected arguments
17889 # $roomObj - The GA::Obj::Exit object's parent room
17890 # $exitObj - The exit object which needs to be allocated a cardinal direction
17891 # $ignoreFlag - Set to TRUE the first time this function called, in which case we ignore
17892 # directions that have incoming 1-way exits; set to FALSE the second
17893 # time this function called, in which case we include them
17894 #
17895 # Return values
17896 # 'undef' on improper arguments, or if all the available cardinal directions are already
17897 # occupied
17898 # Otherwise, returns the first available cardinal direction
17899  
17900 my ($self, $roomObj, $exitObj, $ignoreFlag, $check) = @_;
17901  
17902 # Local variables
17903 my @dirList;
17904  
17905 # Check for improper arguments
17906 if (! defined $roomObj || ! defined $exitObj || ! defined $ignoreFlag || defined $check) {
17907  
17908 return $axmud::CLIENT->writeImproper($self->_objClass . '->chooseCardinalDir', @_);
17909 }
17910  
17911 # (For convenience, put the longest directions at the end, but don't allocate exits to 'up'
17912 # or 'down' since they won't be visible on the map)
17913 @dirList = qw(
17914 north northeast east southeast south southwest west northwest
17915 northnortheast eastnortheast eastsoutheast southsoutheast
17916 southsouthwest westsouthwest westnorthwest northnorthwest
17917 );
17918  
17919 OUTER: foreach my $cardinalDir (@dirList) {
17920  
17921 my $matchFlag;
17922  
17923 INNER: foreach my $number ($roomObj->ivValues('exitNumHash')) {
17924  
17925 my $otherExitObj = $self->ivShow('exitModelHash', $number);
17926  
17927 if (
17928 $otherExitObj
17929 && $otherExitObj->mapDir
17930 && $otherExitObj->mapDir eq $cardinalDir
17931 ) {
17932 # This $cardinalDir has already been allocated
17933 $matchFlag = TRUE;
17934 last INNER;
17935 }
17936 }
17937  
17938 if (! $matchFlag) {
17939  
17940 # $cardinalDir is apparently available. Check for incoming one-way exits, if allowed
17941 if (! $ignoreFlag) {
17942  
17943 INNER: foreach my $number ($roomObj->ivKeys('oneWayExitHash')) {
17944  
17945 my ($otherExitObj, $oppDir);
17946  
17947 $otherExitObj = $self->ivShow('exitModelHash', $number);
17948  
17949 if ($otherExitObj && $otherExitObj->mapDir) {
17950  
17951 # Get the opposite of the incoming one-way exit's ->mapDir (the standard
17952 # primary direction used to draw the exit on the map)
17953 $oppDir
17954 = $axmud::CLIENT->ivShow('constOppDirHash', $otherExitObj->mapDir);
17955  
17956 if ($oppDir eq $cardinalDir) {
17957  
17958 # The incoming 1-way exit is using this primary direction, so ignore
17959 # it (for now), and move on to the next one
17960 next OUTER;
17961 }
17962 }
17963 }
17964 }
17965  
17966 # Available cardinal direction found
17967 return $cardinalDir;
17968 }
17969 }
17970  
17971 # All sixteen cardinal directions are unavailable
17972 return undef;
17973 }
17974  
17975 sub countRoomContents {
17976  
17977 # Called by GA::Obj::Map->updateRoom
17978 # Counts the number of living and non-living things in the Locator task's current room, and
17979 # stores them in the regionmap in which a specified room model object is stored
17980 # As a result, it's possible for the Automapper window to display the number of things in a
17981 # room the last time it was visited
17982 #
17983 # Expected arguments
17984 # $session - The calling function's GA::Session
17985 # $modelRoomObj - The room model object for which the counts are stored
17986 #
17987 # Return values
17988 # 'undef' on improper arguments, if there is no Locator task, if the Locator task doesn't
17989 # know the current location or if $modelRoomObj's regionmap can't be found
17990 # 1 otherwise
17991  
17992 my ($self, $session, $modelRoomObj, $check) = @_;
17993  
17994 # Local variables
17995 my ($regionmapObj, $livingCount, $nonLivingCount);
17996  
17997 # Check for improper arguments
17998 if (! defined $session || ! defined $modelRoomObj || defined $check) {
17999  
18000 return $axmud::CLIENT->writeImproper($self->_objClass . '->countRoomContents', @_);
18001 }
18002  
18003 # Shouldn't be possible for this function to be called when the Locator task isn't running
18004 # or doesn't know the current location - but we'll check anyway
18005 if (! $session->locatorTask || ! $session->locatorTask->roomObj) {
18006  
18007 return undef;
18008 }
18009  
18010 # Get the room's regionmap
18011 $regionmapObj = $self->findRegionmap($modelRoomObj->parent);
18012 if (! $regionmapObj) {
18013  
18014 # Again, nothing we can do
18015 return undef;
18016 }
18017  
18018 # Count the number of living and non-living things in the Locator task's room
18019 $livingCount = 0;
18020 $nonLivingCount = 0;
18021  
18022 foreach my $obj ($session->locatorTask->roomObj->tempObjList) {
18023  
18024 if ($obj->aliveFlag) {
18025 $livingCount++;
18026 } else {
18027 $nonLivingCount++;
18028 }
18029 }
18030  
18031 # Now, if the count is 0, we remove an entry from the hash IV (if it exists); otherwise we
18032 # add an entry (or replace the existing one)
18033 if ($livingCount) {
18034 $regionmapObj->storeLivingCount($modelRoomObj->number, $livingCount);
18035 } else {
18036 $regionmapObj->removeLivingCount($modelRoomObj->number);
18037 }
18038  
18039 if ($nonLivingCount) {
18040 $regionmapObj->storeNonLivingCount($modelRoomObj->number, $nonLivingCount);
18041 } else {
18042 $regionmapObj->removeNonLivingCount($modelRoomObj->number);
18043 }
18044  
18045 return 1;
18046 }
18047  
18048 sub setInteriorOffsets {
18049  
18050 # Called by GA::Obj::Map->setInteriorOffsetsCallback
18051 # Sets the offsets used when a room's grid coordinates are displayed as interior text inside
18052 # the room box
18053 #
18054 # Expected arguments
18055 # $xOffset, $yOffset - The new values to set
18056 #
18057 # Return values
18058 # 'undef' on improper arguments
18059 # 1 otherwise
18060  
18061 my ($self, $xOffset, $yOffset, $check) = @_;
18062  
18063 # Check for improper arguments
18064 if (! defined $xOffset || ! defined $yOffset || defined $check) {
18065  
18066 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInteriorOffsets', @_);
18067 }
18068  
18069 # Update IVs
18070 $self->ivPoke('roomInteriorXOffset', $xOffset);
18071 $self->ivPoke('roomInteriorYOffset', $yOffset);
18072  
18073 return 1;
18074 }
18075  
18076 sub findPathCmds {
18077  
18078 # Called by GA::Win::Map->processPathCallback
18079 # Given a list of GA::ModelObj::Room objects along a continuous path - such as one
18080 # generated by a call to $self->findPath or ->findUniversalPath - compiles a list of
18081 # commands to get from the first room on the path to the last one
18082 # Uses assisted moves, if allowed; otherwise uses only exit nominal directions
18083 #
18084 # Expected arguments
18085 # $session - The calling function's GA::Session
18086 # $step - Set to 1 if we want the commands to get from the beginning of the room
18087 # list to the end; set to -1 if we want the commands to get from the end
18088 # of the room list to the beginning
18089 # @roomList - A list of GA::ModelObj::Room objects along a continuous path
18090 #
18091 # Return values
18092 # An empty list on improper arguments, if a continuous path between the first and last
18093 # rooms on the list can't be found, or if the list contains less than two rooms
18094 # Otherwise, returns a list of commands, e.g. ('n', 'nw', 'e', 'u', 'enter cave')
18095  
18096 my ($self, $session, $step, @roomList) = @_;
18097  
18098 # Local variables
18099 my (@emptyList, @exitList, @cmdList);
18100  
18101 # Check for improper arguments
18102 if (! defined $session || ! defined $step || scalar @roomList < 2) {
18103  
18104 $axmud::CLIENT->writeImproper($self->_objClass . '->findPathCmds', @_);
18105 return @emptyList;
18106 }
18107  
18108 # Process the route in the opposite direction, if required
18109 if ($step == -1) {
18110  
18111 @roomList = reverse @roomList;
18112 }
18113  
18114 do {
18115  
18116 my ($roomObj, $nextRoomObj, $matchFlag);
18117  
18118 $roomObj = shift @roomList;
18119 if (@roomList) {
18120  
18121 # Check this room's exits, looking for one which leads to the next room in the list
18122 $nextRoomObj = $roomList[0];
18123  
18124 INNER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
18125  
18126 my ($exitObj, $destRoomNum);
18127  
18128 $exitObj = $self->ivShow('exitModelHash', $exitNum);
18129 $destRoomNum = $exitObj->destRoom;
18130  
18131 if (
18132 defined $destRoomNum
18133 && $self->ivShow('modelHash', $destRoomNum) eq $nextRoomObj
18134 ) {
18135 # This is the exit we want
18136 push (@exitList, $exitObj);
18137 $matchFlag = TRUE;
18138  
18139 last INNER;
18140 }
18141 }
18142  
18143 # There is no way to get between $roomObj and $nextRoomObj
18144 if (! $matchFlag) {
18145  
18146 return @emptyList;
18147 }
18148 }
18149  
18150 } until (! @roomList);
18151  
18152 # We have a list of exit objects from the first room on the path to the last one. Now
18153 # convert it into a list of commands. If assisted moves are turned on, use them; otherwise
18154 # just use each exit's nominal direction
18155 @cmdList = $self->convertExitList($session, @exitList);
18156  
18157 # Operation complete
18158 return @cmdList;
18159 }
18160  
18161 sub convertExitList {
18162  
18163 # Called by GA::Win::Map->processPathCallback and $self->findPathCmds
18164 # Given a list of GA::Obj::Exit objects (presumed to be along a continuous path),
18165 # compiles a list of world commands to move from one end of the path to the other
18166 # If assisted moves are allowed, uses them; otherwise uses each exit's nominal direction
18167 #
18168 # Expected arguments
18169 # $session - The calling function's GA::Session
18170 #
18171 # Optional arguments
18172 # @exitList - The list of GA::Obj::Exit objects. If the list is empty, an empty list is
18173 # returned
18174 #
18175 # Return values
18176 # 'undef' on improper arguments
18177 # 1 otherwise
18178  
18179 my ($self, $session, @exitList) = @_;
18180  
18181 # Local variables
18182 my (
18183 $assistedFlag, $cmdSep,
18184 @cmdList,
18185 );
18186  
18187 # Check for improper arguments
18188 if (! defined $session) {
18189  
18190 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertExitList', @_);
18191 }
18192  
18193 # Import the world model's ->assistedMovesFlag
18194 $assistedFlag = $self->assistedMovesFlag;
18195 # Import the client command separator
18196 $cmdSep = $axmud::CLIENT->cmdSep;
18197  
18198 OUTER: foreach my $exitObj (@exitList) {
18199  
18200 my $cmdSequence;
18201  
18202 if ($assistedFlag) {
18203  
18204 # Ask the exit to provide a command sequence (e.g. 'knock on door;open door;east')
18205 # comprising an assisted move. If no assisted move is found, just use the exit's
18206 # nominal direction
18207 $cmdSequence = $exitObj->getAssisted($session);
18208 if ($cmdSequence) {
18209 push (@cmdList, split(m/$cmdSep/, $cmdSequence));
18210 } else {
18211 push (@cmdList, $exitObj->dir);
18212 }
18213  
18214 } else {
18215  
18216 # Assisted moves turned off. Just use the exits' nominal directions
18217 push (@cmdList, $exitObj->dir);
18218 }
18219 }
18220  
18221 # Operation complete
18222 return @cmdList;
18223 }
18224  
18225 sub getExitLength {
18226  
18227 # Called by GA::Obj::Map->autoProcessNewRoom
18228 # Given a GA::Obj::Exit, return the exit length that applies to it. If the exit's ->mapDir
18229 # (the standard primary direction in which the exit is drawn on the map) is 'up' or
18230 # 'down', then use the value stored in ->verticalExitLengthBlocks. Otherwise use the
18231 # value stored in ->horizontalExitLengthBlocks
18232 #
18233 # Expected arguments
18234 # $exitObj - The exit object to check
18235 #
18236 # Return values
18237 # 'undef' on improper arguments
18238 # 1 otherwise
18239  
18240 my ($self, $exitObj, $check) = @_;
18241  
18242 # Check for improper arguments
18243 if (! defined $exitObj || defined $check) {
18244  
18245 return $axmud::CLIENT->writeImproper($self->_objClass . '->getExitLength', @_);
18246 }
18247  
18248 if (! $exitObj->mapDir) {
18249  
18250 # No standard primary direction set - use a default exit length of 1
18251 return 1;
18252  
18253 } elsif ($exitObj->mapDir eq 'up' || $exitObj->mapDir eq 'down') {
18254  
18255 return $self->verticalExitLengthBlocks;
18256  
18257 } else {
18258  
18259 return $self->horizontalExitLengthBlocks;
18260 }
18261 }
18262  
18263 sub getRegionScheme {
18264  
18265 # Can be called by anything
18266 # Get the region scheme object (GA::Obj::RegionScheme) that applies to a specified regionmap
18267 #
18268 # Expected arguments
18269 # $regionmapObj - The specified GA::Obj::Regionmap
18270 #
18271 # Return values
18272 # 'undef' on improper arguments
18273 # 1 otherwise
18274  
18275 my ($self, $regionmapObj, $check) = @_;
18276  
18277 # Check for improper arguments
18278 if (! defined $regionmapObj || defined $check) {
18279  
18280 return $axmud::CLIENT->writeImproper($self->_objClass . '->getRegionScheme', @_);
18281 }
18282  
18283 if (
18284 defined $regionmapObj->regionScheme
18285 && $self->ivExists('regionSchemeHash', $regionmapObj->regionScheme)
18286 ) {
18287 return $self->ivShow('regionSchemeHash', $regionmapObj->regionScheme);
18288  
18289 } else{
18290  
18291 # If the regionmap doesn't name a region scheme, then use the default one
18292 return $self->defaultSchemeObj;
18293 }
18294 }
18295  
18296 # (Called from GA::Win::Map menu, 'View' column)
18297  
18298 sub toggleFlag {
18299  
18300 # Called by anonymous function in GA::Win::Map->enableXXXColumn
18301 # Toggles a flag IV and updates each Automapper window
18302 #
18303 # Expected arguments
18304 # $iv - The flag IV to toggle
18305 # $ivFlag - New value of the IV (TRUE or FALSE)
18306 # $drawFlag - If set to TRUE, this function calls ->drawRegion in every affected
18307 # Automapper window. If FALSE, ->drawRegion is not called
18308 #
18309 # Optional arguments
18310 # $menuName - The name of the menu item which must be set to active, or inactive (a key
18311 # in GA::Map::Win->menuToolItemHash
18312 # $iconName - The name of the toolbar icon which must be set to active, or inactive (a
18313 # key in GA::Map::Win->menuToolItemHash. If set to 'undef', there is no
18314 # icon to modify)
18315 #
18316 # Return values
18317 # 'undef' on improper arguments
18318 # 1 otherwise
18319  
18320 my ($self, $iv, $ivFlag, $drawFlag, $menuName, $iconName, $check) = @_;
18321  
18322 # Check for improper arguments
18323 if (! defined $iv || ! defined $ivFlag || ! defined $drawFlag || defined $check) {
18324  
18325 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleFlag', @_);
18326 }
18327  
18328 # Update the IV
18329 if ($ivFlag) {
18330 $self->ivPoke($iv, TRUE);
18331 } else {
18332 $self->ivPoke($iv, FALSE);
18333 }
18334  
18335 # Update every Automapper window using this world model
18336 foreach my $mapWin ($self->collectMapWins()) {
18337  
18338 if ($drawFlag) {
18339  
18340 # Redraw all drawn regions
18341 $mapWin->redrawRegions();
18342 }
18343  
18344 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18345  
18346 # Update the menu item
18347 if ($menuName) {
18348  
18349 $mapWin->setActiveItem($menuName, $self->$iv);
18350 }
18351  
18352 # Set the equivalent toolbar button, if there is one
18353 if ($iconName) {
18354  
18355 $mapWin->setActiveItem($iconName, $self->$iv);
18356 }
18357  
18358 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18359 }
18360  
18361 return 1;
18362 }
18363  
18364 sub switchMode {
18365  
18366 # Called by anonymous function in GA::Win::Map->enableXXXColumn
18367 # Sets the new value of an IV and updates each Automapper window
18368 #
18369 # Expected arguments
18370 # $iv - The IV to set
18371 # $value - New value of the IV (can be 'undef')
18372 # $drawFlag - If set to TRUE, this function calls ->drawRegion in every affected
18373 # Automapper window. If FALSE, ->drawRegion is not called
18374 #
18375 # Optional arguments
18376 # $menuName - The name of the menu item which must be set to active, or inactive (a key
18377 # in GA::Map::Win->menuToolItemHash
18378 # $iconName - The name of the toolbar icon which must be set to active, or inactive (a
18379 # key in GA::Map::Win->menuToolItemHash. If set to 'undef', there is no
18380 # icon to modify)
18381 #
18382 # Return values
18383 # 'undef' on improper arguments
18384 # 1 otherwise
18385  
18386 my ($self, $iv, $value, $drawFlag, $menuName, $iconName, $check) = @_;
18387  
18388 # Check for improper arguments
18389 if (! defined $iv || ! defined $drawFlag || defined $check) {
18390  
18391 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchMode', @_);
18392 }
18393  
18394 # Update the IV
18395 $self->ivPoke($iv, $value);
18396  
18397 # Update every Automapper window using this world model
18398 foreach my $mapWin ($self->collectMapWins()) {
18399  
18400 if ($drawFlag && $mapWin->currentRegionmap) {
18401  
18402 # Redraw all drawn regions
18403 $mapWin->redrawRegions();
18404  
18405 } elsif ($iv eq 'currentRoomMode') {
18406  
18407 # When setting $self->currentRoomMode, redraw the current/last known/ghost rooms
18408 if ($mapWin->mapObj->currentRoom) {
18409  
18410 $mapWin->markObjs('room', $mapWin->mapObj->currentRoom);
18411 }
18412  
18413 if ($mapWin->mapObj->lastKnownRoom) {
18414  
18415 $mapWin->markObjs('room', $mapWin->mapObj->lastKnownRoom);
18416 }
18417  
18418 if ($mapWin->mapObj->ghostRoom) {
18419  
18420 $mapWin->markObjs('room', $mapWin->mapObj->ghostRoom);
18421 }
18422  
18423 $mapWin->doDraw();
18424 }
18425  
18426 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18427  
18428 # Update the menu item
18429 if ($menuName) {
18430  
18431 $mapWin->setActiveItem($menuName, TRUE);
18432 }
18433  
18434 # Set the equivalent toolbar button, if there is one
18435 if ($iconName) {
18436  
18437 $mapWin->setActiveItem($iconName, TRUE);
18438 }
18439  
18440 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18441  
18442 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18443 $mapWin->restrictWidgets();
18444 }
18445  
18446 return 1;
18447 }
18448  
18449 sub toggleWinComponents {
18450  
18451 # Called by anonymous function in GA::Win::Map->enableViewColumn
18452 # Shows (or hides) each Automapper window's major components (the menu, toolbar, treeview
18453 # and canvas)
18454 #
18455 # Expected arguments
18456 # $iv - The IV matching the component to show (or hide) - one of 'showMenuBarFlag',
18457 # 'showToolbarFlag', 'showTreeViewFlag', 'showCanvasFlag'
18458 # $flag - The new value of the IV - TRUE or FALSE
18459 #
18460 # Return values
18461 # 'undef' on improper arguments
18462 # 1 otherwise
18463  
18464 my ($self, $iv, $flag, $check) = @_;
18465  
18466 # Check for improper arguments
18467 if (! defined $iv || ! defined $flag || defined $check) {
18468  
18469 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleWinComponents', @_);
18470 }
18471  
18472 # Update the IV
18473 if ($flag) {
18474 $self->ivPoke($iv, TRUE);
18475 } else {
18476 $self->ivPoke($iv, FALSE);
18477 }
18478  
18479 # Show (or hide) the component in every Automapper window using this world model
18480 foreach my $mapWin ($self->collectMapWins()) {
18481  
18482 my $menuItem;
18483  
18484 if ($iv eq 'showMenuBarFlag') {
18485  
18486 $mapWin->redrawWidgets('menu_bar');
18487 $mapWin->setActiveItem('show_menu_bar', $self->$iv);
18488  
18489 } elsif ($iv eq 'showToolbarFlag') {
18490  
18491 $mapWin->redrawWidgets('toolbar');
18492 $mapWin->setActiveItem('show_toolbar', $self->$iv);
18493  
18494 } elsif ($iv eq 'showTreeViewFlag') {
18495  
18496 $mapWin->redrawWidgets('treeview');
18497 $mapWin->setActiveItem('show_treeview', $self->$iv);
18498  
18499 } elsif ($iv eq 'showCanvasFlag') {
18500  
18501 # If there's a current region, we don't need it any more
18502 if (! $flag && $mapWin->currentRegionmap) {
18503  
18504 $mapWin->setCurrentRegion();
18505 }
18506  
18507 $mapWin->redrawWidgets('canvas');
18508 $mapWin->setActiveItem('show_canvas', $self->$iv);
18509 }
18510 }
18511  
18512 return 1;
18513 }
18514  
18515 sub resetRegionList {
18516  
18517 # Called by anonymous function in GA::Win::Map->enableViewColumn
18518 # Resets the order of the list of regions displayed in each Automapper window's treeview
18519 #
18520 # Expected arguments
18521 # (none besides $self)
18522 #
18523 # Return values
18524 # 'undef' on improper arguments
18525 # 1 otherwise
18526  
18527 my ($self, $check) = @_;
18528  
18529 # Check for improper arguments
18530 if (defined $check) {
18531  
18532 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRegionList', @_);
18533 }
18534  
18535 # If there's a region moved to the top of the list, put back in its normal position
18536 $self->ivUndef('firstRegion');
18537 # Don't show a reversed list
18538 $self->ivPoke('reverseRegionListFlag', FALSE);
18539  
18540 # Redraw the list of regions in the treeview of every Automapper window using this world
18541 # model
18542 foreach my $mapWin ($self->collectMapWins()) {
18543  
18544 $mapWin->resetTreeView();
18545 }
18546  
18547 return 1;
18548 }
18549  
18550 sub reverseRegionList {
18551  
18552 # Called by anonymous function in GA::Win::Map->enableViewColumn
18553 # Reverses the order of the list of regions displayed in each Automapper window's treeview
18554 #
18555 # Expected arguments
18556 # (none besides $self)
18557 #
18558 # Return values
18559 # 'undef' on improper arguments
18560 # 1 otherwise
18561  
18562 my ($self, $check) = @_;
18563  
18564 # Check for improper arguments
18565 if (defined $check) {
18566  
18567 return $axmud::CLIENT->writeImproper($self->_objClass . '->reverseRegionList', @_);
18568 }
18569  
18570 if ($self->reverseRegionListFlag) {
18571  
18572 # Show normal list
18573 $self->ivPoke('reverseRegionListFlag', FALSE);
18574  
18575 } else {
18576  
18577 # Show reversed list
18578 $self->ivPoke('reverseRegionListFlag', TRUE);
18579 }
18580  
18581 # Redraw the list of regions in the treeview of every Automapper window using this world
18582 # model
18583 foreach my $mapWin ($self->collectMapWins()) {
18584  
18585 $mapWin->resetTreeView();
18586 }
18587  
18588 return 1;
18589 }
18590  
18591 sub moveRegionToTop {
18592  
18593 # Called by anonymous function in GA::Win::Map->enableViewColumn
18594 # Moves a specified region to the top of list of regions displayed in each Automapper
18595 # window's treeview
18596 #
18597 # Expected arguments
18598 # (none besides $self)
18599 #
18600 # Optional arguments
18601 # $regionmapObj - The GA::Obj::Regionmap to move. If undefined, any region already at
18602 # the top of the list is removed (and placed back in its original
18603 # position)
18604 #
18605 # Return values
18606 # 'undef' on improper arguments
18607 # 1 otherwise
18608  
18609 my ($self, $regionmapObj, $check) = @_;
18610  
18611 # Check for improper arguments
18612 if (defined $check) {
18613  
18614 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveRegionToTop', @_);
18615 }
18616  
18617 # Mark the current region as being at the top of the list (or remove an existing region from
18618 # the top of the list, if any)
18619 if ($regionmapObj) {
18620 $self->ivPoke('firstRegion', $regionmapObj->name);
18621 } else {
18622 $self->ivUndef('firstRegion');
18623 }
18624  
18625 # Redraw the list of regions in the treeview of every Automapper window using this world
18626 # model
18627 foreach my $mapWin ($self->collectMapWins()) {
18628  
18629 $mapWin->resetTreeView();
18630 }
18631  
18632 return 1;
18633 }
18634  
18635 sub toggleFilter {
18636  
18637 # Called by anonymous function in GA::Win::Map->enableViewColumn
18638 # Releases/applies the specified room filter and updates each Automapper window
18639 #
18640 # Expected arguments
18641 # $filter - The filter to apply/release
18642 # $flag - Set to TRUE to release the room filter, FALSE to apply it
18643 #
18644 # Return values
18645 # 'undef' on improper arguments
18646 # 1 otherwise
18647  
18648 my ($self, $filter, $flag, $check) = @_;
18649  
18650 # Check for improper arguments
18651 if (! defined $filter || ! defined $flag || defined $check) {
18652  
18653 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleAllFilters', @_);
18654 }
18655  
18656 if ($flag) {
18657 $self->ivAdd('roomFilterApplyHash', $filter, TRUE);
18658 } else {
18659 $self->ivAdd('roomFilterApplyHash', $filter, FALSE);
18660 }
18661  
18662 # Update every Automapper window using this world model
18663 foreach my $mapWin ($self->collectMapWins()) {
18664  
18665 # Redraw all drawn regions
18666 $mapWin->redrawRegions();
18667  
18668 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18669  
18670 # Update the menu item
18671 $mapWin->setActiveItem($filter . '_filter', $flag);
18672  
18673 # Set the equivalent toolbar button
18674 $mapWin->setActiveItem('icon_' . $filter . '_filter', $flag);
18675  
18676 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18677 }
18678  
18679 return 1;
18680 }
18681  
18682 sub switchRoomInteriorMode {
18683  
18684 # Called by anonymous function in GA::Win::Map->enableViewColumn
18685 # Sets the value of $self->roomInteriorMode and updates each Automapper window
18686 #
18687 # Expected arguments
18688 # $mode - The new value of ->roomInteriorMode
18689 #
18690 # Return values
18691 # 'undef' on improper arguments
18692 # 1 otherwise
18693  
18694 my ($self, $mode, $check) = @_;
18695  
18696 # Check for improper arguments
18697 if (! defined $mode || defined $check) {
18698  
18699 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchRoomInteriorMode', @_);
18700 }
18701  
18702 $self->ivPoke('roomInteriorMode', $mode);
18703  
18704 # Update every Automapper window using this world model
18705 foreach my $mapWin ($self->collectMapWins()) {
18706  
18707 # Redraw all drawn regions
18708 $mapWin->redrawRegions();
18709  
18710 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18711  
18712 # Update the menu item
18713 $mapWin->setActiveItem('interior_mode_' . $mode, TRUE);
18714  
18715 # Set the equivalent toolbar button
18716 $mapWin->setActiveItem('icon_interior_mode_' . $mode, TRUE);
18717  
18718 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18719 }
18720  
18721 return 1;
18722 }
18723  
18724 sub switchRegionDrawExitMode {
18725  
18726 # Called by anonymous function in GA::Win::Map->enableViewColumn
18727 # Sets the value of GA::Obj::Regionmap->drawExitMode and updates each Automapper window
18728 #
18729 # Expected arguments
18730 # $regionmapObj - The regionmap to modify
18731 # $mode - The new value of $regionmapObj->drawExitMode
18732 #
18733 # Return values
18734 # 'undef' on improper arguments
18735 # 1 otherwise
18736  
18737 my ($self, $regionmapObj, $mode, $check) = @_;
18738  
18739 # Check for improper arguments
18740 if (! defined $regionmapObj || ! defined $mode || defined $check) {
18741  
18742 return $axmud::CLIENT->writeImproper(
18743 $self->_objClass . '->switchRegionDrawExitMode',
18744 @_,
18745 );
18746 }
18747  
18748 $regionmapObj->ivPoke('drawExitMode', $mode);
18749  
18750 # Update every Automapper window using this world model
18751 foreach my $mapWin ($self->collectMapWins()) {
18752  
18753 my ($menuName, $menuItem);
18754  
18755 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18756 $mapWin->redrawRegions($regionmapObj, TRUE);
18757  
18758 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18759  
18760 # Update the menu item
18761 if ($mode eq 'no_exit') {
18762 $menuName = 'region_draw_no_exits';
18763 } elsif ($mode eq 'simple_exit') {
18764 $menuName = 'region_draw_simple_exits';
18765 } elsif ($mode eq 'complex_exit') {
18766 $menuName = 'region_draw_complex_exits';
18767 }
18768  
18769 $mapWin->setActiveItem($menuName, FALSE);
18770  
18771 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18772  
18773 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18774 $mapWin->restrictWidgets();
18775 }
18776  
18777 return 1;
18778 }
18779  
18780 sub toggleObscuredExitFlag {
18781  
18782 # Called by anonymous function in GA::Win::Map->enableViewColumn
18783 # Sets the value of GA::Obj::Regionmap->obscuredExitFlag and updates each Automapper window
18784 #
18785 # Expected arguments
18786 # $regionmapObj - The regionmap to modify
18787 #
18788 # Return values
18789 # 'undef' on improper arguments
18790 # 1 otherwise
18791  
18792 my ($self, $regionmapObj, $check) = @_;
18793  
18794 # Check for improper arguments
18795 if (! defined $regionmapObj || defined $check) {
18796  
18797 return $axmud::CLIENT->writeImproper(
18798 $self->_objClass . '->toggleObscuredExitFlag',
18799 @_,
18800 );
18801 }
18802  
18803 if (! $regionmapObj->obscuredExitFlag) {
18804 $regionmapObj->ivPoke('obscuredExitFlag', TRUE);
18805 } else {
18806 $regionmapObj->ivPoke('obscuredExitFlag', FALSE);
18807 }
18808  
18809 # Update every Automapper window using this world model
18810 foreach my $mapWin ($self->collectMapWins()) {
18811  
18812 my ($menuName, $menuItem);
18813  
18814 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18815 $mapWin->redrawRegions($regionmapObj, TRUE);
18816  
18817 # Update the menu item
18818 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18819 $mapWin->setActiveItem('obscured_exits_region', $regionmapObj->obscuredExitFlag);
18820 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18821  
18822 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18823 $mapWin->restrictWidgets();
18824 }
18825  
18826 return 1;
18827 }
18828  
18829 sub toggleObscuredExitRedrawFlag {
18830  
18831 # Called by anonymous function in GA::Win::Map->enableViewColumn
18832 # Sets the value of GA::Obj::Regionmap->obscuredExitRedrawFlag and updates each Automapper
18833 # window
18834 #
18835 # Expected arguments
18836 # $regionmapObj - The regionmap to modify
18837 #
18838 # Return values
18839 # 'undef' on improper arguments
18840 # 1 otherwise
18841  
18842 my ($self, $regionmapObj, $check) = @_;
18843  
18844 # Check for improper arguments
18845 if (! defined $regionmapObj || defined $check) {
18846  
18847 return $axmud::CLIENT->writeImproper(
18848 $self->_objClass . '->toggleObscuredExitRedrawFlag',
18849 @_,
18850 );
18851 }
18852  
18853 if (! $regionmapObj->obscuredExitRedrawFlag) {
18854 $regionmapObj->ivPoke('obscuredExitRedrawFlag', TRUE);
18855 } else {
18856 $regionmapObj->ivPoke('obscuredExitRedrawFlag', FALSE);
18857 }
18858  
18859 # Update every Automapper window using this world model
18860 foreach my $mapWin ($self->collectMapWins()) {
18861  
18862 my ($menuName, $menuItem);
18863  
18864 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18865 $mapWin->redrawRegions($regionmapObj, TRUE);
18866  
18867 # Update the menu item
18868 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18869 $mapWin->setActiveItem(
18870 'auto_redraw_obscured_region',
18871 $regionmapObj->obscuredExitRedrawFlag,
18872 );
18873 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18874  
18875 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18876 $mapWin->restrictWidgets();
18877 }
18878  
18879 return 1;
18880 }
18881  
18882 sub toggleDrawOrnamentsFlag {
18883  
18884 # Called by anonymous function in GA::Win::Map->enableViewColumn
18885 # Sets the value of GA::Obj::Regionmap->drawOrnamentsFlag and updates each Automapper window
18886 #
18887 # Expected arguments
18888 # $regionmapObj - The regionmap to modify
18889 #
18890 # Return values
18891 # 'undef' on improper arguments
18892 # 1 otherwise
18893  
18894 my ($self, $regionmapObj, $check) = @_;
18895  
18896 # Check for improper arguments
18897 if (! defined $regionmapObj || defined $check) {
18898  
18899 return $axmud::CLIENT->writeImproper(
18900 $self->_objClass . '->toggleDrawOrnamentsFlag',
18901 @_,
18902 );
18903 }
18904  
18905 if (! $regionmapObj->drawOrnamentsFlag) {
18906 $regionmapObj->ivPoke('drawOrnamentsFlag', TRUE);
18907 } else {
18908 $regionmapObj->ivPoke('drawOrnamentsFlag', FALSE);
18909 }
18910  
18911 # Update every Automapper window using this world model
18912 foreach my $mapWin ($self->collectMapWins()) {
18913  
18914 my ($menuName, $menuItem);
18915  
18916 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18917 $mapWin->redrawRegions($regionmapObj, TRUE);
18918  
18919 # Update the menu item
18920 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18921 $mapWin->setActiveItem('draw_ornaments_region', $regionmapObj->drawOrnamentsFlag);
18922 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18923  
18924 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18925 $mapWin->restrictWidgets();
18926 }
18927  
18928 return 1;
18929 }
18930  
18931 sub setMagnification {
18932  
18933 # Called by anonymous function in GA::Win::Map->enableViewColumn
18934 # Sets the value of GA::Obj::Regionmap->magnification and updates each Automapper window
18935 #
18936 # Expected arguments
18937 # $mapWin - The GA::Win::Map that initiated the zoom
18938 # $magnification - The new value of $regionmapObj->magnification
18939 #
18940 # Return values
18941 # 'undef' on improper arguments
18942 # 1 otherwise
18943  
18944 my ($self, $mapWin, $magnification, $check) = @_;
18945  
18946 # Local variables
18947 my (
18948 $regionmapObj, $oldOffsetXPos, $oldOffsetYPos, $oldStartXPos, $oldStartYPos,
18949 $oldWidth, $oldHeight, $offsetXPos, $offsetYPos, $startXPos, $startYPos, $width,
18950 $height, $adjustXFlag, $adjustYFlag,
18951 );
18952  
18953 # Check for improper arguments
18954 if (! defined $mapWin || ! defined $magnification || defined $check) {
18955  
18956 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMagnification', @_);
18957 }
18958  
18959 $regionmapObj = $mapWin->currentRegionmap;
18960 $regionmapObj->ivPoke('magnification', $magnification);
18961  
18962 # When we fully zoom out, so that there are no scroll bars visible, GooCanvas2::Canvas
18963 # helpfully forgets the scrollbar's position. This means that the current room, if we were
18964 # centred on it, is no longer centred. Therefore we have to get the scrollbar's position,
18965 # change the map's visible size, and then - if the map is fully zoomed out, and the
18966 # scrollbars have disappeared - record their position, for the next time the user zooms in
18967  
18968 # Get the visible map's size and position. The six return values are all numbers in the
18969 # range 0-1
18970 ($oldOffsetXPos, $oldOffsetYPos, $oldStartXPos, $oldStartYPos, $oldWidth, $oldHeight)
18971 = $mapWin->getMapPosn();
18972  
18973 # Update every Automapper window using this world model
18974 foreach my $otherMapWin ($self->collectMapWins()) {
18975  
18976 if ($otherMapWin->currentRegionmap && $otherMapWin->currentRegionmap eq $regionmapObj) {
18977  
18978 # Zoom in or out on this region
18979 $otherMapWin->doZoom();
18980 }
18981 }
18982  
18983 # Get the visible map's new size and position.
18984 ($offsetXPos, $offsetYPos, $startXPos, $startYPos, $width, $height)
18985 = $mapWin->getMapPosn();
18986  
18987 # The horizontal and vertical scrollbars can reach max zoom out at different times, so deal
18988 # with them separately
18989 if (
18990 ! $regionmapObj->maxZoomOutXFlag
18991 && (
18992 ($oldOffsetXPos != 0 && $offsetXPos == 0)
18993 || ($oldOffsetXPos != 1 && $offsetXPos == 1)
18994 )
18995 ) {
18996 # We have fully zoomed out, and we weren't already fully zoomed out. Inform the
18997 # regionmap
18998 $regionmapObj->ivPoke('maxZoomOutXFlag', TRUE);
18999 # Remember the position of the scrollbars before the zoom
19000 $regionmapObj->ivPoke('scrollXPos', $oldStartXPos + ($oldWidth / 2));
19001  
19002 } elsif (
19003 $regionmapObj->maxZoomOutXFlag
19004 && (
19005 ($oldOffsetXPos == 0 && $offsetXPos != 0)
19006 || ($oldOffsetXPos == 1 && $offsetXPos != 1)
19007 )
19008 ) {
19009 # We have just zoomed in from a maximum zoom out. Reset the flags in the regionmap
19010 $regionmapObj->ivPoke('maxZoomOutXFlag', FALSE);
19011 $adjustXFlag = TRUE;
19012 }
19013  
19014 if (
19015 ! $regionmapObj->maxZoomOutYFlag
19016 && (
19017 ($oldOffsetYPos != 0 && $offsetYPos == 0)
19018 || ($oldOffsetYPos != 1 && $offsetYPos == 1)
19019 )
19020 ) {
19021 $regionmapObj->ivPoke('maxZoomOutYFlag', TRUE);
19022 $regionmapObj->ivPoke('scrollYPos', $oldStartYPos + ($oldHeight / 2));
19023  
19024 } elsif (
19025 $regionmapObj->maxZoomOutYFlag
19026 && (
19027 ($oldOffsetYPos == 0 && $offsetYPos != 0)
19028 || ($oldOffsetYPos == 1 && $offsetYPos != 1)
19029 )
19030 ) {
19031 $regionmapObj->ivPoke('maxZoomOutYFlag', FALSE);
19032 $adjustYFlag = TRUE;
19033 }
19034  
19035 # In every affected Automapper window, re-centre the map at the correct position
19036 foreach my $otherMapWin ($self->collectMapWins()) {
19037  
19038 if (
19039 $otherMapWin->currentRegionmap
19040 && $otherMapWin->currentRegionmap eq $regionmapObj
19041 ) {
19042 if ($adjustXFlag && $adjustYFlag) {
19043  
19044 $otherMapWin->setMapPosn($regionmapObj->scrollXPos, $regionmapObj->scrollYPos);
19045  
19046 } elsif ($adjustXFlag) {
19047  
19048 $otherMapWin->setMapPosn(
19049 $regionmapObj->scrollXPos,
19050 ($startYPos + ($height / 2)),
19051 );
19052  
19053 } elsif ($adjustYFlag) {
19054  
19055 $otherMapWin->setMapPosn(
19056 ($startXPos + ($width / 2)),
19057 $regionmapObj->scrollYPos,
19058 );
19059 }
19060 }
19061 }
19062  
19063 return 1;
19064 }
19065  
19066 sub repositionMaps {
19067  
19068 # Called by anonymous function in GA::Win::Map->enableViewColumn
19069 # Repositions every regionmap in the world model (sets the magnification to 0, and sets the
19070 # scroll position to the middle of the map). Updates each Automapper window using this
19071 # world model
19072 #
19073 # Expected arguments
19074 # (none besides $self)
19075 #
19076 # Return values
19077 # 'undef' on improper arguments
19078 # 1 otherwise
19079  
19080 my ($self, $check) = @_;
19081  
19082 # Check for improper arguments
19083 if (defined $check) {
19084  
19085 return $axmud::CLIENT->writeImproper($self->_objClass . '->repositionMaps', @_);
19086 }
19087  
19088 # Update IVs for each regionmap
19089 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
19090  
19091 $regionmapObj->ivPoke('magnification', 1);
19092 $regionmapObj->ivPoke('scrollXPos', 0.5);
19093 $regionmapObj->ivPoke('scrollYPos', 0.5);
19094 $regionmapObj->ivPoke('currentLevel', 0);
19095 }
19096  
19097 # Update every Automapper window using this world model
19098 foreach my $mapWin ($self->collectMapWins()) {
19099  
19100 if ($mapWin->currentRegionmap) {
19101  
19102 # Reset zoom factor (magnification) to 1
19103 $mapWin->zoomCallback(1);
19104 # Reset the scrollbars
19105 $mapWin->setMapPosn(0.5, 0.5);
19106 # Redraw the map to make sure the default level is visible
19107 $mapWin->setCurrentLevel(0);
19108 }
19109 }
19110  
19111 return 1;
19112 }
19113  
19114 sub setTrackingSensitivity {
19115  
19116 # Called by anonymous function in GA::Win::Map->enableViewColumn
19117 # Sets the value of $self->trackingSensitivity and updates each Automapper window
19118 #
19119 # Expected arguments
19120 # $sensitivity - The new tracking sensitivity (one of the value 0, 0.33, 0.66 or 1)
19121 #
19122 # Return values
19123 # 'undef' on improper arguments
19124 # 1 otherwise
19125  
19126 my ($self, $sensitivity, $check) = @_;
19127  
19128 # Check for improper arguments
19129 if (! defined $sensitivity || defined $check) {
19130  
19131 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTrackingSensitivity', @_);
19132 }
19133  
19134 if (
19135 $sensitivity != 0
19136 && $sensitivity != 0.33
19137 && $sensitivity != 0.66
19138 && $sensitivity != 1
19139 ) {
19140 # Use a default value for $sensitivity
19141 $sensitivity = 0;
19142 }
19143  
19144 $self->ivPoke('trackingSensitivity', $sensitivity);
19145  
19146 # Update every Automapper window using this world model
19147 foreach my $mapWin ($self->collectMapWins()) {
19148  
19149 my $menuName;
19150  
19151 if ($sensitivity == 0) {
19152 $menuName = 'track_always';
19153 } elsif ($sensitivity == 0.33) {
19154 $menuName = 'track_near_centre';
19155 } elsif ($sensitivity == 0.66) {
19156 $menuName = 'track_near_edge';
19157 } else {
19158 $menuName = 'track_not_visible';
19159 }
19160  
19161 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19162  
19163 # Update the menu item
19164 $mapWin->setActiveItem($menuName, TRUE);
19165  
19166 # Set the equivalent toolbar button
19167 $mapWin->setActiveItem('icon_' . $menuName, TRUE);
19168  
19169 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19170 }
19171  
19172 return 1;
19173 }
19174  
19175 # (Called from GA::Win::Map menu, 'Mode' column)
19176  
19177 sub setAutoCompareMode {
19178  
19179 # Called by anonymous function in GA::Win::Map->enableModeColumn
19180 # Updates the world model's ->autoCompareMode and updates each Automapper window using this
19181 # world model
19182 #
19183 # Expected arguments
19184 # $mode - The new value of the IV - 'default', 'new' or 'current'
19185 #
19186 # Return values
19187 # 'undef' on improper arguments
19188 # 1 otherwise
19189  
19190 my ($self, $mode, $check) = @_;
19191  
19192 # Check for improper arguments
19193 if (! defined $mode || defined $check) {
19194  
19195 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAutoCompareMode', @_);
19196 }
19197  
19198 # Update the IV
19199 $self->ivPoke('autoCompareMode', $mode);
19200  
19201 # Update every Automapper window using this world model
19202 foreach my $mapWin ($self->collectMapWins()) {
19203  
19204 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19205  
19206 # Update the menu item
19207 if ($mode eq 'default') {
19208 $mapWin->setActiveItem('auto_compare_default', TRUE);
19209 } elsif ($mode eq 'default') {
19210 $mapWin->setActiveItem('auto_compare_new', TRUE);
19211 } elsif ($mode eq 'default') {
19212 $mapWin->setActiveItem('auto_compare_current', TRUE);
19213 }
19214  
19215 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19216  
19217 # If interior counts are currently showing the number of rooms that match the current
19218 # room, redraw the current room to show the counts
19219 if ($self->roomInteriorMode eq 'compare_count' && $mapWin->mapObj->currentRoom) {
19220  
19221 $mapWin->markObjs('room', $mapWin->mapObj->currentRoom);
19222 $mapWin->doDraw();
19223 }
19224 }
19225  
19226 return 1;
19227 }
19228  
19229 sub toggleAutoCompareAllFlag {
19230  
19231 # Called by anonymous function in GA::Win::Map->enableModeColumn
19232 # Toggles the world model's ->autoCompareAllFlag and updates each Automapper window using
19233 # this world model
19234 #
19235 # Expected arguments
19236 # $flag - The new value of the IV - TRUE or FALSE
19237 #
19238 # Return values
19239 # 'undef' on improper arguments
19240 # 1 otherwise
19241  
19242 my ($self, $flag, $check) = @_;
19243  
19244 # Check for improper arguments
19245 if (! defined $flag || defined $check) {
19246  
19247 return $axmud::CLIENT->writeImproper(
19248 $self->_objClass . '->toggleAutoCompareAllFlag',
19249 @_,
19250 );
19251 }
19252  
19253 # Update the IV
19254 if (! $flag) {
19255 $self->ivPoke('autoCompareAllFlag', FALSE);
19256 } else {
19257 $self->ivPoke('autoCompareAllFlag', TRUE);
19258 }
19259  
19260 # Update every Automapper window using this world model
19261 foreach my $mapWin ($self->collectMapWins()) {
19262  
19263 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19264  
19265 # Update the menu item
19266 if (! $flag) {
19267 $mapWin->setActiveItem('auto_compare_region', TRUE);
19268 } else {
19269 $mapWin->setActiveItem('auto_compare_model', TRUE);
19270 }
19271  
19272 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19273 }
19274  
19275 return 1;
19276 }
19277  
19278 sub setAutoSlideMode {
19279  
19280 # Called by anonymous function in GA::Win::Map->enableModeColumn
19281 # Updates the world model's ->autoSlideMode and updates each Automapper window using this
19282 # world model
19283 #
19284 # Expected arguments
19285 # $mode - The new value of the IV - 'default', 'orig_pull', 'orig_push', 'other_pull',
19286 # 'other_push', 'dest_pull' or 'dest_push'
19287 #
19288 # Return values
19289 # 'undef' on improper arguments
19290 # 1 otherwise
19291  
19292 my ($self, $mode, $check) = @_;
19293  
19294 # Check for improper arguments
19295 if (! defined $mode || defined $check) {
19296  
19297 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAutoSlideMode', @_);
19298 }
19299  
19300 # Update the IV
19301 $self->ivPoke('autoSlideMode', $mode);
19302  
19303 # Update every Automapper window using this world model
19304 foreach my $mapWin ($self->collectMapWins()) {
19305  
19306 my $menuItem;
19307  
19308 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19309  
19310 # Update the menu item
19311 if ($mode eq 'default') {
19312 $mapWin->setActiveItem('slide_default', TRUE);
19313 } elsif ($mode eq 'orig_pull') {
19314 $mapWin->setActiveItem('slide_orig_pull', TRUE);
19315 } elsif ($mode eq 'orig_push') {
19316 $mapWin->setActiveItem('slide_orig_push', TRUE);
19317 } elsif ($mode eq 'other_pull') {
19318 $mapWin->setActiveItem('slide_other_pull', TRUE);
19319 } elsif ($mode eq 'other_push') {
19320 $mapWin->setActiveItem('slide_other_push', TRUE);
19321 } elsif ($mode eq 'dest_pull') {
19322 $mapWin->setActiveItem('slide_dest_pull', TRUE);
19323 } elsif ($mode eq 'dest_push') {
19324 $mapWin->setActiveItem('slide_dest_push', TRUE);
19325 }
19326  
19327 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19328 }
19329  
19330 return 1;
19331 }
19332  
19333 sub toggleDisableUpdateModeFlag {
19334  
19335 # Called by anonymous function in GA::Win::Map->enableModeColumn
19336 # Toggles the world model's ->disableUpdateModeFlag and updates each Automapper window using
19337 # this world model
19338 #
19339 # Expected arguments
19340 # $flag - The new value of the IV - TRUE or FALSE
19341 #
19342 # Return values
19343 # 'undef' on improper arguments
19344 # 1 otherwise
19345  
19346 my ($self, $flag, $check) = @_;
19347  
19348 # Check for improper arguments
19349 if (! defined $flag || defined $check) {
19350  
19351 return $axmud::CLIENT->writeImproper(
19352 $self->_objClass . '->toggleDisableUpdateModeFlag',
19353 @_,
19354 );
19355 }
19356  
19357 # Update the IV
19358 if ($flag) {
19359 $self->ivPoke('disableUpdateModeFlag', TRUE);
19360 } else {
19361 $self->ivPoke('disableUpdateModeFlag', FALSE);
19362 }
19363  
19364 # Update every Automapper window using this world model
19365 foreach my $mapWin ($self->collectMapWins()) {
19366  
19367 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19368  
19369 # Update the menu item
19370 $mapWin->setActiveItem('disable_update_mode', $self->disableUpdateModeFlag);
19371  
19372 # The call to ->setMode makes sure the Automapper window's mode is switched from
19373 # 'update' to 'follow' if 'update' mode has just been disabled, and also makes sure
19374 # the menu/toolbar buttons are sensitised or not, as appropriate
19375 $mapWin->setMode($mapWin->mode);
19376  
19377 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19378 }
19379  
19380 return 1;
19381 }
19382  
19383 sub toggleShowTooltipsFlag {
19384  
19385 # Called by anonymous function in GA::Win::Map->enableModeColumn
19386 # Toggles the world model's ->showTooltipsFlag and updates each Automapper window using this
19387 # world model
19388 #
19389 # Expected arguments
19390 # $flag - The new value of the IV - TRUE or FALSE
19391 #
19392 # Return values
19393 # 'undef' on improper arguments
19394 # 1 otherwise
19395  
19396 my ($self, $flag, $check) = @_;
19397  
19398 # Check for improper arguments
19399 if (! defined $flag || defined $check) {
19400  
19401 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleShowTooltipsFlag', @_);
19402 }
19403  
19404 # Update the IV
19405 if ($flag) {
19406 $self->ivPoke('showTooltipsFlag', TRUE);
19407 } else {
19408 $self->ivPoke('showTooltipsFlag', FALSE);
19409 }
19410  
19411 # Update every Automapper window using this world model
19412 foreach my $mapWin ($self->collectMapWins()) {
19413  
19414 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19415  
19416 # Update the menu item
19417 $mapWin->setActiveItem('show_tooltips', $self->showTooltipsFlag);
19418  
19419 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19420  
19421 if (! $flag) {
19422  
19423 # If the tooltip window is currently visible, hide it
19424 $mapWin->hideTooltips();
19425 }
19426 }
19427  
19428 return 1;
19429 }
19430  
19431 # (Called from GA::Win::Map menu, 'Exits' column)
19432  
19433 sub setCheckableDirMode {
19434  
19435 # Called by anonymous function in GA::Win::Map->enableModeColumn
19436 # Updates the world model's ->checkableDirMode and updates each Automapper window using
19437 # this world model
19438 #
19439 # Expected arguments
19440 # $mode - The new value of the IV - 'simple', 'diku', 'lp' or 'complex'
19441 #
19442 # Return values
19443 # 'undef' on improper arguments
19444 # 1 otherwise
19445  
19446 my ($self, $mode, $check) = @_;
19447  
19448 # Check for improper arguments
19449 if (! defined $mode || defined $check) {
19450  
19451 return $axmud::CLIENT->writeImproper($self->_objClass . '->setCheckableDirMode', @_);
19452 }
19453  
19454 # Update the IV
19455 $self->ivPoke('checkableDirMode', $mode);
19456  
19457 # Update every Automapper window using this world model
19458 foreach my $mapWin ($self->collectMapWins()) {
19459  
19460 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19461  
19462 # Update the menu item
19463 if ($mode eq 'simple') {
19464 $mapWin->setActiveItem('checkable_dir_simple', TRUE);
19465 } elsif ($mode eq 'diku') {
19466 $mapWin->setActiveItem('checkable_dir_diku', TRUE);
19467 } elsif ($mode eq 'lp') {
19468 $mapWin->setActiveItem('checkable_dir_lp', TRUE);
19469 } elsif ($mode eq 'complex') {
19470 $mapWin->setActiveItem('checkable_dir_complex', TRUE);
19471 }
19472  
19473 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19474  
19475 # If interior counts are currently showing checked/checkable directions, redraw all
19476 # drawn regions to update those counts
19477 if ($self->roomInteriorMode eq 'checked_count') {
19478  
19479 $mapWin->redrawRegions();
19480 }
19481 }
19482  
19483 return 1;
19484 }
19485  
19486 sub getCheckableDirs {
19487  
19488 # Called by GA::Win::Map->prepareCheckedCounts, once per drawing cycle. Also called by
19489 # GA::Cmd::ModelReport->do
19490 # $self->roomInteriorMode specifies which primary directions should be checked, when
19491 # using checkable directions. This function compiles the list of primary directions, and
19492 # converts them from their standard to custom forms, which is how they are stored in
19493 # GA::ModelObj::Room->checkedDirHash
19494 #
19495 # Expected arguments
19496 # $session - The calling GA::Session
19497 #
19498 # Return values
19499 # An empty hash on improper arguments
19500 # Otherwise returns a hash (never empty), in the form
19501 # $hash{custom_primary_direction} = undef
19502  
19503 my ($self, $session, $check) = @_;
19504  
19505 # Local variables
19506 my (
19507 $dictObj,
19508 @standardList,
19509 %emptyHash, %returnHash,
19510 );
19511  
19512 # Check for improper arguments
19513 if (! defined $session || defined $check) {
19514  
19515 $axmud::CLIENT->writeImproper($self->_objClass . '->getCheckableDirs', @_);
19516 return %emptyHash;
19517 }
19518  
19519 # Import the current dictionary (for convenience)
19520 $dictObj = $session->currentDict;
19521  
19522 if ($self->checkableDirMode eq 'complex') {
19523 @standardList = $axmud::CLIENT->constPrimaryDirList;
19524 } elsif ($self->checkableDirMode eq 'lp') {
19525 @standardList = $axmud::CLIENT->constShortPrimaryDirList;
19526 } elsif ($self->checkableDirMode eq 'diku') {
19527 @standardList = qw(north south east west up down);
19528 } else {
19529 @standardList = qw(north south east west); # ->roomInteriorMode is 'simple'
19530 }
19531  
19532 foreach my $standard (@standardList) {
19533  
19534 my $custom = $dictObj->ivShow('primaryDirHash', $standard);
19535 $returnHash{$custom} = undef;
19536 }
19537  
19538 # Operation complete
19539 return %returnHash;
19540 }
19541  
19542 # A* algorithm functions (used to find a path between two rooms in the same region)
19543  
19544 sub findPath {
19545  
19546 # Can be called by any function
19547 #
19548 # A* algorithm to find a path between two rooms in the same region, based on
19549 # AI::Pathfinding::AStar by Aaron Dalton
19550 #
19551 # This function should only be called if there's reasonable certainty that a path exists
19552 # without going via another region
19553 # Any code that wants to find the shortest path, including (if necessary) going via another
19554 # region), should call $self->findUniversalPath instead (because it calls this function
19555 # anyway, if the two rooms are in the same region, and then proceeds with its own
19556 # algorithms if necessary)
19557 #
19558 # Expected arguments
19559 # $initialNode - The initial node (a GA::ModelObj::Room)
19560 # $targetNode - The target node (a GA::ModelObj::Room in the same region)
19561 #
19562 # Optional arguments
19563 # $avoidHazardsFlag
19564 # - If set to TRUE, the path won't use any rooms with a room flag on the
19565 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19566 # to FALSE (or 'undef'), those rooms can be used
19567 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19568 # should avoid hazardous rooms by default, or not. It's up to the
19569 # calling function to decide whether to use it, and to set the value
19570 # of this argument accordingly
19571 # $otherHazardListRef
19572 # - An optional reference to a list of room flags that should be
19573 # considered hazardous for the purposes of this algorithm (not an
19574 # error if it contains duplicate room flags, or if it contains room
19575 # flags already on the hazardous room flags list). Can be 'undef' or
19576 # a reference to an empty list
19577 # - NB Room flags in this list are considered hazardous, even if
19578 # $avoidHazardsFlag is FALSE
19579 # $avoidAdjacentFlag
19580 # - If set to TRUE, the algorithm won't use rooms in adjacent regions,
19581 # regardless of the value of $self->adjacentMode. If set to FALSE (or
19582 # 'undef', the value of $self->adjacentMode applies
19583 # $adjacentHashRef
19584 # - An optional hash of adjacent regions, set (in some situations) when
19585 # the calling function is $self->findUniversalPath. If defined, the
19586 # keys in the hash are the model numbers of regions that are
19587 # adjacent to $initialNode's parent region (the meaning of 'adjacent'
19588 # depends on $self->adjacentCount). $initialNode's parent region also
19589 # exists in the hash. If 'undef', this function fetches the list of
19590 # adjacent regions itself, if it needs to
19591 #
19592 # Return values
19593 # An empty list on improper arguments
19594 # Otherwise, returns two list references. The first reference contains a list of
19595 # GA::ModelObj::Room objects on the shortest path between the rooms $initialNode and
19596 # $targetNode (inclusive). The second reference contains a list of GA::Obj::Exit
19597 # objects used to move along the path. The first list contains exactly one more item
19598 # than the second (exception: if no path can be found, both lists are empty)
19599  
19600 my (
19601 $self, $initialNode, $targetNode, $avoidHazardsFlag, $otherHazardListRef,
19602 $avoidAdjacentFlag, $adjacentHashRef, $check,
19603 ) = @_;
19604  
19605 # Local variables
19606 my (
19607 $currentNode, $path, $openListObj, $nodeHashRef, $pathRoomListRef, $pathExitListRef,
19608 @emptyList,
19609 %hazardHash, %adjacentHash,
19610 );
19611  
19612 # Check for improper arguments
19613 if (! defined $initialNode || ! defined $targetNode || defined $check) {
19614  
19615 $axmud::CLIENT->writeImproper($self->_objClass . '->findPath', @_);
19616 return @emptyList;
19617 }
19618  
19619 # Create a combined hash of hazardous room flags (whose rooms must be avoided by the
19620 # algorithm). If the function returns an empty hash, then all rooms can be used
19621 if (! defined $otherHazardListRef) {
19622 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag);
19623 } else {
19624 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag, @$otherHazardListRef);
19625 }
19626  
19627 # If $self->adjacentMode is 'near', meaning that we can use adjacent regions, and if the
19628 # calling function didn't supply a hash of adjacent regions, compile our own
19629 if ($avoidAdjacentFlag) {
19630  
19631 # (The call to $self->doAStar needs a hash reference, even an empty one)
19632 $adjacentHashRef = {};
19633  
19634 } elsif (! defined $adjacentHashRef) {
19635  
19636 if ($self->adjacentMode eq 'near') {
19637  
19638 %adjacentHash = $self->compileAdjacentRegions($initialNode->parent);
19639 }
19640  
19641 # (The call to $self->doAStar needs a hash reference, even an empty one)
19642 $adjacentHashRef = \%adjacentHash;
19643 }
19644  
19645 # Create the open list, using a binomial heap
19646 $openListObj = Games::Axmud::Obj::Heap->new();
19647 # Create a reference to a hash of nodes, in the form
19648 # $nodeHash{room_object} = node
19649 # ...where 'room_object' is a GA::ModelObj::Room, and 'node' is a GA::Node::AStar object
19650 $nodeHashRef = {};
19651  
19652 # Create a node for the initial room
19653 $currentNode = Games::Axmud::Node::AStar->new(
19654 $initialNode, # A GA::ModelObj::Room
19655 0, # Initial G score
19656 0, # Initial H score
19657 );
19658  
19659 # Add this node to the open list
19660 $currentNode->ivPoke('inOpenFlag', TRUE);
19661 $openListObj->add($currentNode);
19662  
19663 # Perform the A* algorithm, starting at the room $initialNode, and aiming for the room
19664 # $targetNode
19665 $self->doAStar($targetNode, $openListObj, $nodeHashRef, \%hazardHash, $adjacentHashRef);
19666  
19667 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
19668 # path from the target room, and using the parent of each node in turn (in the standard
19669 # way)
19670 # Get two list references, one containing the rooms in the shortest path between
19671 # $initialNode and $targetNode, and the other containing the exits to move along the path
19672 ($pathRoomListRef, $pathExitListRef) = $self->fillPath_aStar(
19673 $targetNode,
19674 $openListObj,
19675 $nodeHashRef
19676 );
19677  
19678 return ($pathRoomListRef, $pathExitListRef);
19679 }
19680  
19681 sub compileRoomHazards {
19682  
19683 # Called by $self->findPath and ->smoothPath
19684 # Compiles a hash of room flags that should be considered hazardous, for the purposes of the
19685 # A-star algorithm
19686 #
19687 # Expected arguments
19688 # (none besides $self)
19689 #
19690 # Optional arguments
19691 # $avoidHazardsFlag
19692 # - If set to TRUE, the path won't use any rooms with a room flag on the
19693 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19694 # to FALSE (or 'undef'), those rooms can be used
19695 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19696 # should avoid hazardous rooms by default, or not. It's up to the
19697 # calling function to decide whether to use it, and to set the value
19698 # of this argument accordingly
19699 # @otherHazardList
19700 # - An optional list of room flags that should be considered hazardous,
19701 # for the purposes of this algorithm (not an error if it contains
19702 # duplicate room flags, or if it contains room flags already on the
19703 # hazardous room flags list)
19704 # - NB Room flags in this list are considered hazardous, even if
19705 # $avoidHazardsFlag is FALSE
19706 #
19707 # Return values
19708 # An empty hash on improper arguments
19709 # Otherwise, returns a hash of hazardous room flags (may be an empty hash), in the form
19710 # $hazardHash{room_flag} = undef
19711  
19712 my ($self, $avoidHazardsFlag, @otherHazardList) = @_;
19713  
19714 # Local variables
19715 my %hazardHash;
19716  
19717 # (No improper arguments to check)
19718  
19719 if ($avoidHazardsFlag) {
19720  
19721 # Avoid rooms with the usual hazardous room flags ('blocked_room', etc)
19722 %hazardHash = $axmud::CLIENT->constRoomHazardHash;
19723 }
19724  
19725 foreach my $roomFlag (@otherHazardList) {
19726  
19727 # Also avoid rooms that have the specified room flag
19728 $hazardHash{$roomFlag} = undef;
19729 }
19730  
19731 return %hazardHash;
19732 }
19733  
19734 sub compileAdjacentRegions {
19735  
19736 # Called by $self->findPath and ->findUniversalPath when $self->adjacentMode is set to
19737 # 'near' (meaning that the path can use rooms in adjacent regions)
19738 # Compiles a hash of regions that are adjacent to a specified region (the meaning of
19739 # 'adjacent' depends on $self->adjacentCount; 1 means regions can be connected A-B, 2
19740 # means regions can be connected A-B-C, etc. 0 means don't use adjacent regions right now)
19741 # The hash includes the specified region
19742 #
19743 # Expected arguments
19744 # $origNum - The number of a region, representing the parent region of the first room
19745 # in a path yet to be calculated
19746 #
19747 # Return values
19748 # An empty hash on improper arguments
19749 # Otherwise returns a hash containing $origNum and all of its adjacent regions in the form
19750 # $adjacentHash{region_number} = undef
19751  
19752 my ($self, $origNum, $check) = @_;
19753  
19754 # Local variables
19755 my (
19756 @regionList,
19757 %emptyHash, %checkHash, %returnHash,
19758 );
19759  
19760 # Check for improper arguments
19761 if (! defined $origNum || defined $check) {
19762  
19763 $axmud::CLIENT->writeImproper($self->_objClass . '->compileAdjacentRegions', @_);
19764 return %emptyHash;
19765 }
19766  
19767 if ($self->adjacentCount == 0) {
19768  
19769 # Can't use adjacent regions right now, but the hash must still contain the specified
19770 # region
19771 $returnHash{$origNum} = undef;
19772  
19773 return %returnHash;
19774 }
19775  
19776 # Compile a hash of all regions. If the value of $self->adjacentCount is high enough that
19777 # every region is adjacent to $regionNum, then we can stop searching immediately
19778 foreach my $regionNum ($self->ivKeys('regionModelHash')) {
19779  
19780 if ($regionNum != $origNum) {
19781  
19782 $checkHash{$regionNum} = undef;
19783 }
19784 }
19785  
19786 # Now check each region in turn, starting with $regionNum, then its connection regions,
19787 # then all of their connecting regions, and so on
19788 push (@regionList, $origNum);
19789 # (%returnHash must contain at least the specified region)
19790 $returnHash{$origNum} = undef;
19791  
19792 for (my $count = 0; $count < $self->adjacentCount; $count++) {
19793  
19794 my @nextList;
19795  
19796 foreach my $regionNum (@regionList) {
19797  
19798 my $regionmapObj = $self->findRegionmap($regionNum);
19799  
19800 foreach my $otherNum ($regionmapObj->ivValues('regionExitHash') ) {
19801  
19802 if ($otherNum != $origNum && ! exists $returnHash{$otherNum}) {
19803  
19804 # This region is adjacent...
19805 $returnHash{$otherNum} = undef;
19806 # ...so check its region exits on the next iteration of the for... loop
19807 push (@nextList, $otherNum);
19808  
19809 # Have we used up every region?
19810 delete $checkHash{$otherNum};
19811 if (! %checkHash) {
19812  
19813 # Yes, we have, so we can stop searching now
19814 return %returnHash;
19815 }
19816 }
19817 }
19818 }
19819  
19820 # On the next iteration of the for... loop, check all of the adjacent regions found
19821 # during this iteration
19822 @regionList = @nextList;
19823 }
19824  
19825 # Operation complete
19826 return %returnHash;
19827 }
19828  
19829 sub checkRoomHazards {
19830  
19831 # Called by $self->getSurrounding_aStar
19832 # Checks whether any of a room's list of room flags is on a list of hazardous room flags,
19833 # specified by the initial call to ->findPath (not necessarily the same list stored in
19834 # GA::Client->constRoomHazardHash)
19835 #
19836 # Expected arguments
19837 # $roomObj - The GA::ModelObj::Room object to check
19838 #
19839 # Optional arguments
19840 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
19841 # room flag stored as a key in this hash. If an empty hash, all rooms
19842 # are considered
19843 #
19844 # Return values
19845 # 'undef' on improper arguments, if the room has no room flags, or if none of the room's
19846 # list of room flags are on the hazardous flags list
19847 # 1 if any of the room's list of room flags are on the hazardous flags list
19848  
19849 my ($self, $roomObj, $hazardHashRef, $check) = @_;
19850  
19851 # Check for improper arguments
19852 if (! defined $roomObj || ! defined $hazardHashRef || defined $check) {
19853  
19854 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRoomHazards', @_);
19855 }
19856  
19857 # Check each flag in turn
19858 foreach my $flag ($roomObj->ivKeys('roomFlagHash')) {
19859  
19860 if (exists $$hazardHashRef{$flag}) {
19861  
19862 # This room should be avoided by the pathfinding routines
19863 return 1;
19864 }
19865 }
19866  
19867 # The room can be used by the pathfinding routines
19868 return undef;
19869 }
19870  
19871 sub smoothPath {
19872  
19873 # Called by $self->processPathCallback
19874 # After a path has been found (following a call to $self->findPath or
19875 # $self->findUniversalPath), this function can optionally be called to remove jagged edges
19876 # from the paths typically produced by the A* and Dijkstra algorithms
19877 #
19878 # Expected arguments
19879 # $session - The calling function's GA::Session
19880 # $roomListRef - A reference to a list containing a series of GA::ModelObj::Room
19881 # objects along the path between the initial and target rooms
19882 # $exitListRef - A reference to a list containing the GA::Obj::Exit objects used to
19883 # move along the path (contains one less elements than the list
19884 # referenced by $roomListRef)
19885 #
19886 # Optional arguments
19887 # $avoidHazardsFlag
19888 # - If set to TRUE, the path won't use any rooms with a room flag on the
19889 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19890 # to FALSE (or 'undef'), those rooms can be used
19891 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19892 # should avoid hazardous rooms by default, or not. It's up to the
19893 # calling function to decide whether to use it, and to set the value
19894 # of this argument accordingly
19895 # @otherHazardList
19896 # - An optional list of room flags that should be considered hazardous,
19897 # for the purposes of this algorithm (not an error if it contains
19898 # duplicate room flags, or if it contains room flags already on the
19899 # hazardous room flags list)
19900 # - NB Room flags in this list are considered hazardous, even if
19901 # $avoidHazardsFlag is FALSE
19902 #
19903 # Return values
19904 # Returns an empty list on improper arguments
19905 # Otherwise, returns a list containing the modified $roomListRef and $exitListRef, in the
19906 # form (room_list_reference, exit_list_reference)
19907  
19908 my ($self, $session, $roomListRef, $exitListRef, $avoidHazardsFlag, @otherHazardList) = @_;
19909  
19910 # Local variables
19911 my (
19912 @emptyList,
19913 %hazardHash, %vectorHash,
19914 );
19915  
19916 # Check for improper arguments
19917 if (! defined $session || ! defined $roomListRef || ! defined $exitListRef) {
19918  
19919 $axmud::CLIENT->writeImproper($self->_objClass . '->smoothPath', @_);
19920 return @emptyList;
19921 }
19922  
19923 # Create a combined hash of hazardous room flags (whose rooms must be avoided by the
19924 # algorithm). If the function returns an empty hash, then all rooms can be used
19925 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag, @otherHazardList);
19926  
19927 # The principle of A*/Dijkstra post-processing is to compare two rooms, numbered n and (n+2)
19928 # If there is a clear line of sight between them (if we can move using one of ten primary
19929 # directions from (n) to (n+2)), and if there is exactly one room between them, in the
19930 # line of site, that is not room (n+1), then we can swap room (n+1) to the room directly
19931 # between rooms (n) and (n+2)
19932 # So, this path: Is smoothed to this one:
19933 # X X n
19934 # X X n+1
19935 # X X n+2 n
19936 # X X n+1
19937 # X X n+2
19938  
19939 # Firstly, $roomListRef must contain at least three rooms
19940 if (@$roomListRef < 3) {
19941  
19942 # Return the list references, unmodified
19943 return ($roomListRef, $exitListRef);
19944 }
19945  
19946 # GA::Win::Map->constVectorHash contains unit vectors in each of the primary directions
19947 # e.g. $hash{'north'} = [0, -1, 0]
19948 # e.g. $hash{'south'} = [0, 1, 0]
19949 # Import the hash
19950 %vectorHash = $session->mapWin->constVectorHash;
19951  
19952 # Smooth each sub-group of rooms (n, n+1 and n+2)
19953 OUTER: for (my $index = 0; $index < ((scalar @$roomListRef) - 2); $index++) {
19954  
19955 my (
19956 $roomN, $roomN1, $roomN2, $exitN, $exitN1, $xGap, $yGap, $zGap, $largestGap,
19957 $vectorRef, $matchListRef, $flag,
19958 );
19959  
19960 $roomN = $$roomListRef[$index]; # n
19961 $roomN1 = $$roomListRef[$index + 1]; # n + 1
19962 $roomN2 = $$roomListRef[$index + 2]; # n + 2
19963 $exitN = $$exitListRef[$index]; # n
19964 $exitN1 = $$exitListRef[$index + 1]; # n + 1
19965  
19966 # All three rooms must be in the same region, and none of the exits between them may be
19967 # 'broken' exits
19968 if (
19969 $roomN->parent != $roomN1->parent
19970 || $roomN->parent != $roomN2->parent
19971 || $exitN->brokenFlag
19972 || $exitN1->brokenFlag
19973 ) {
19974 next OUTER;
19975 }
19976  
19977 # Find the vector between (n) and (n+2), expressed as ($xGap, $yGap, $zGap)
19978 $xGap = $roomN2->xPosBlocks - $roomN->xPosBlocks;
19979 $yGap = $roomN2->yPosBlocks - $roomN->yPosBlocks;
19980 $zGap = $roomN2->zPosBlocks - $roomN->zPosBlocks;
19981  
19982 # Find the largest distance between the rooms along a single axis
19983 $largestGap = abs($xGap);
19984 if (abs($yGap) > $largestGap) {
19985  
19986 $largestGap = abs($yGap);
19987 }
19988 if (abs($zGap) > $largestGap) {
19989  
19990 $largestGap = abs($zGap);
19991 }
19992  
19993 # We need a gap of at least two blocks between (n) and (n+2)
19994 if ($largestGap < 2) {
19995  
19996 next OUTER;
19997 }
19998  
19999 # Use the hash to find a line of sight between (n) and (n+2) in one of the primary
20000 # directions. Don't look further away than $largestGap
20001 CENTRE: for (my $count = 2; $count <= $largestGap; $count++) {
20002  
20003 foreach my $primaryDir (keys %vectorHash) {
20004  
20005 # Get a reference to a list in the form [0, -1, 0]
20006 my $matchListRef = $vectorHash{$primaryDir};
20007  
20008 # Does this vector, added to the position of (n), give us the position of (n+2)?
20009 if (
20010 ($roomN->xPosBlocks + ($$matchListRef[0] * $count))
20011 == $roomN2->xPosBlocks
20012 && ($roomN->yPosBlocks + ($$matchListRef[1] * $count))
20013 == $roomN2->yPosBlocks
20014 && ($roomN->zPosBlocks + ($$matchListRef[2] * $count))
20015 == $roomN2->zPosBlocks
20016 ) {
20017 $vectorRef = $matchListRef;
20018 last CENTRE;
20019 }
20020 }
20021 }
20022  
20023 if (! $vectorRef) {
20024  
20025 # No line of sight between (n) and (n+2) found
20026 next OUTER;
20027 }
20028  
20029 # There is a line of sight between (n) and (n+2) in one of the primary directions, which
20030 # we expressed as a vector $matchListRef in the form [0, -1, 0] (for north) or
20031 # [0, 1, 0] (for south), etc
20032 # Now, does room (n+1) also lie in this line of sight?
20033 CENTRE: for (my $count = 1; $count < $largestGap; $count++) {
20034  
20035 if (
20036 ($roomN->xPosBlocks + ($$vectorRef[0] * $count))
20037 == $roomN1->xPosBlocks
20038 && ($roomN->yPosBlocks + ($$vectorRef[1] * $count))
20039 == $roomN1->yPosBlocks
20040 && ($roomN->zPosBlocks + ($$vectorRef[2] * $count))
20041 == $roomN1->zPosBlocks
20042 ) {
20043 $flag = TRUE;
20044 last CENTRE;
20045 }
20046 }
20047  
20048 if ($flag) {
20049  
20050 # All three rooms are in the same line of site, so we don't need to smooth the path
20051 # here
20052 next OUTER;
20053 }
20054  
20055 # The path is in the form
20056 # X (n)
20057 # oX (n+1)
20058 # X (n+2)
20059 # Now we look for a room anywhere along the line of sight between (n) and (n+2), looking
20060 # for a new room, m, which can be reached via a single exit from room (n), and which
20061 # can reach room (n+2) via a single exit - a room like the one marked on the diagram
20062 # above as 'o'
20063 CENTRE: for (my $count = 1; $count < $largestGap; $count++) {
20064  
20065 my ($newRoomNum, $newRoomObj, $firstExitObj, $secondExitObj);
20066  
20067 # See if there's a room at the location marked as 'o', somewhere in the line of site
20068 # between (n) and (n+2)
20069 $newRoomNum = $session->mapWin->currentRegionmap->fetchRoom(
20070 $roomN->xPosBlocks + ($$vectorRef[0] * $count),
20071 $roomN->yPosBlocks + ($$vectorRef[1] * $count),
20072 $roomN->zPosBlocks + ($$vectorRef[2] * $count),
20073 );
20074  
20075 if ($newRoomNum) {
20076  
20077 $newRoomObj = $self->ivShow('modelHash', $newRoomNum);
20078  
20079 # Can this new room be reached from room (n)?
20080 INNER: foreach my $thisExitName ($roomN->sortedExitList) {
20081  
20082 my ($thisExitNum, $thisExitObj);
20083  
20084 # (Investigate directions in order, so that primary directions are checked
20085 # first)
20086 $thisExitNum = $roomN->ivShow('exitNumHash', $thisExitName);
20087 $thisExitObj = $self->ivShow('exitModelHash', $thisExitNum);
20088  
20089 if (
20090 $thisExitObj->destRoom
20091 && $thisExitObj->destRoom == $newRoomObj->number
20092 ) {
20093 # Success! $newRoom can be reached from room (n)
20094 $firstExitObj = $thisExitObj;
20095 last INNER;
20096 }
20097 }
20098  
20099 if (! $firstExitObj) {
20100  
20101 # Can't travel from (n) to the new room - look for a different room
20102 next CENTRE;
20103 }
20104  
20105 # Can this new room reach room (n+2) in a single step?
20106 INNER: foreach my $thisExitName ($newRoomObj->sortedExitList) {
20107  
20108 my ($thisExitNum, $thisExitObj);
20109  
20110 $thisExitNum = $newRoomObj->ivShow('exitNumHash', $thisExitName);
20111 $thisExitObj = $self->ivShow('exitModelHash', $thisExitNum);
20112  
20113 if (
20114 $thisExitObj->destRoom
20115 && $thisExitObj->destRoom == $roomN2->number
20116 ) {
20117 # Double success! $newRoom can reach room (n+2)
20118 $secondExitObj = $thisExitObj;
20119 last INNER;
20120 }
20121 }
20122  
20123 if ($secondExitObj) {
20124  
20125 # Rooms (n), $newRoomObj and (n+2) all lie on the same line of sight, but
20126 # the rooms (n), (n+1) and (n+2) do not
20127  
20128 # Check that $newRoomObj and the exits between $newRoomObj and the
20129 # surrounding rooms are available for paths (using the same rationale
20130 # as $self->getSurrounding_aStar)
20131 if (
20132 ! $newRoomObj->exclusiveFlag
20133 && ! $self->checkRoomHazards($newRoomObj, \%hazardHash)
20134 ) {
20135 # $newRoomObj is acceptable, so use it to replace room (n+1)
20136 $$roomListRef[$index + 1] = $newRoomObj;
20137 # Replace the exits leading from (n) and leading to (n+2)
20138 $$exitListRef[$index] = $firstExitObj;
20139 $$exitListRef[$index + 1] = $secondExitObj;
20140  
20141 next OUTER;
20142 }
20143 }
20144 }
20145 }
20146 }
20147  
20148 # Operation complete
20149 return ($roomListRef, $exitListRef);
20150 }
20151  
20152 sub doAStar {
20153  
20154 # Called by $self->findPath
20155 # Performs the A* algorithm on rooms in the current region, to find the shortest route
20156 # between two rooms (as described in the comments for the calling function)
20157 #
20158 # Expected arguments
20159 # $targetNode - The target node (a GA::ModelObj::Room)
20160 # $openListObj - The A* open list, stored in a binomial heap object
20161 # $nodeHashRef - Reference to the hash of nodes, in the form $hash{room} = node
20162 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
20163 # room flag stored as a key in this hash. If an empty hash, all rooms
20164 # are considered
20165 # $adjacentHashRef
20166 # - Reference to a hash of adjacent regions. An empty hash if adjacent
20167 # regions are not to be used
20168 #
20169 # Return values
20170 # 'undef' on improper arguments
20171 # 1 otherwise
20172  
20173 my (
20174 $self, $targetNode, $openListObj, $nodeHashRef, $hazardHashRef, $adjacentHashRef,
20175 $check,
20176 ) = @_;
20177  
20178 # Local variables
20179 my ($currentNode, $gScore, $nodeListRef);
20180  
20181 # Check for improper arguments
20182 if (
20183 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20184 || ! defined $hazardHashRef || ! defined $adjacentHashRef || defined $check
20185 ) {
20186 return $axmud::CLIENT->writeImproper($self->_objClass . '->doAStar', @_);
20187 }
20188  
20189 # Perform the algorithm until we either find the shortest path to the target room or run out
20190 # of rooms
20191 OUTER: while(
20192 defined $openListObj->top()
20193 && ($openListObj->top()->roomObj ne $targetNode)
20194 ) {
20195 # Remove the first remaining node in the open list
20196 $currentNode = $openListObj->extract_top();
20197 $currentNode->ivPoke('inOpenFlag', FALSE);
20198  
20199 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
20200 # number of list references, each representing a surrounding node (one linked to
20201 # $currentNode by a single exit)
20202 # The contained list references are in the form
20203 # [GA::ModelObj::Room, cost, H-Score]
20204 $nodeListRef = $self->getSurrounding_aStar(
20205 $currentNode->roomObj,
20206 $targetNode,
20207 $hazardHashRef,
20208 $adjacentHashRef,
20209 );
20210  
20211 # Process each surrounding node
20212 INNER: foreach my $nodeRef (@$nodeListRef) {
20213  
20214 my (
20215 $surroundRoomObj, $surroundExitObj, $surroundCost, $surroundHScore,
20216 $surroundNode, $currentGScore, $possibleGScore,
20217 );
20218  
20219 ($surroundRoomObj, $surroundExitObj, $surroundCost, $surroundHScore) = @$nodeRef;
20220  
20221 # Skip this node if it's in the closed list
20222 if (
20223 exists $$nodeHashRef{$surroundRoomObj}
20224 && ! $$nodeHashRef{$surroundRoomObj}->inOpenFlag
20225 ) {
20226 next INNER;
20227 }
20228  
20229 # If the node isn't in the open list, add it to the open list
20230 if (! exists $$nodeHashRef{$surroundRoomObj}) {
20231  
20232 $surroundNode = Games::Axmud::Node::AStar->new(
20233 $surroundRoomObj, # GA::ModelObj::Room
20234 $currentNode->gScore + $surroundCost, # G score
20235 $surroundHScore, # H score
20236 );
20237  
20238 $surroundNode->ivPoke('parent', $currentNode);
20239 $surroundNode->ivPoke('arriveExitObj', $surroundExitObj);
20240 $surroundNode->ivPoke('cost', $surroundCost);
20241 $surroundNode->ivPoke('inOpenFlag', TRUE);
20242 $$nodeHashRef{$surroundRoomObj} = $surroundNode;
20243 $openListObj->add($surroundNode);
20244  
20245 } else {
20246  
20247 # Otherwise the node is already in the open list. Check to see if it's cheaper
20248 # to go through the current room, compared to the previous path
20249 $surroundNode = $$nodeHashRef{$surroundRoomObj};
20250 $currentGScore = $surroundNode->gScore;
20251 $possibleGScore = $currentNode->gScore + $surroundCost;
20252  
20253 if ($possibleGScore < $currentGScore) {
20254  
20255 # Change the parent...
20256 $surroundNode->ivPoke('parent', $currentNode);
20257 # ...and the exit used to get there
20258 $surroundNode->ivPoke('arriveExitObj', $surroundExitObj);
20259 $surroundNode->ivPoke('gScore', $possibleGScore);
20260 $openListObj->decrease_key($surroundNode);
20261 }
20262 }
20263 }
20264 }
20265  
20266 # A* algorithm complete
20267 return 1;
20268 }
20269  
20270 sub fillPath_aStar {
20271  
20272 # Called by $self->findPath, after a call to $self->doAStar
20273 # The initial room and the target room are now linked, along the shortest path between them,
20274 # by a list of rooms, each the parent of the next room along the path
20275 # Compile two lists: a list of the rooms, from the initial room to the target room
20276 # (inclusive), and a corresponding list of exits used to travel between them
20277 #
20278 # Expected arguments
20279 # $targetNode - The target node (a GA::ModelObj::Room)
20280 # $openListObj - The A* open list, stored in a binomial heap object
20281 # $nodeHashRef - The hash of nodes, in the form $hash{room} = node
20282 #
20283 # Return values
20284 # Returns an empty list on improper arguments
20285 # Otherwise returns a list containing two list references. The first reference contains a
20286 # list of GA::ModelObj::Room objects on the shortest path between the initial and
20287 # target rooms (inclusive). The second reference contains a list of GA::Obj::Exit
20288 # objects to move between them. The first list contains exactly one more item than the
20289 # second (exception: if no path can be found, both lists are empty)
20290  
20291 my ($self, $targetNode, $openListObj, $nodeHashRef, $check) = @_;
20292  
20293 # Local variables
20294 my (
20295 $currentNode,
20296 @emptyList, @roomList, @exitList,
20297 );
20298  
20299 # Check for improper arguments
20300 if (
20301 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20302 || defined $check
20303 ) {
20304 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_aStar', @_);
20305 return @emptyList;
20306 }
20307  
20308 if (exists $$nodeHashRef{$targetNode}) {
20309 $currentNode = $$nodeHashRef{$targetNode};
20310 } else {
20311 $currentNode = $openListObj->top();
20312 }
20313  
20314 while (defined $currentNode) {
20315  
20316 unshift(@roomList, $currentNode->roomObj);
20317  
20318 if (defined $currentNode->arriveExitObj) {
20319  
20320 unshift(@exitList, $currentNode->arriveExitObj);
20321 }
20322  
20323 $currentNode = $currentNode->parent;
20324 }
20325  
20326 return (\@roomList, \@exitList);
20327 }
20328  
20329 sub getSurrounding_aStar {
20330  
20331 # Called by $self->doAStar
20332 # Get a list of nodes surrounding the current one
20333 # In this function, the current node is a room. We get a list of all the room's exits, and
20334 # then compile a list of those exits' destination rooms
20335 #
20336 # Expected arguments
20337 # $currentNode - The current node (a GA::ModelObj::Room)
20338 # $targetNode - The target node (a GA::ModelObj::Room)
20339 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
20340 # room flag stored as a key in this hash. If an empty hash, all rooms
20341 # are considered
20342 # $adjacentHashRef
20343 # - Reference to a hash of adjacent regions. An empty hash if adjacent
20344 # regions are not to be used
20345 #
20346 # Return values
20347 # 'undef' on improper arguments
20348 # Otherwise returns a list reference, containing a series of list references, one for each
20349 # surrounding node. The inner list references are in the form:
20350 # [
20351 # surround_node_room_object,
20352 # surrounding_node_cost,
20353 # surrounding_node_g_score,
20354 # ]
20355  
20356 my ($self, $currentNode, $targetNode, $hazardHashRef, $adjacentHashRef, $check) = @_;
20357  
20358 # Local variables
20359 my (
20360 @returnList,
20361 %roomHash,
20362 );
20363  
20364 # Check for improper arguments
20365 if (
20366 ! defined $currentNode || ! defined $targetNode || ! defined $hazardHashRef
20367 || ! defined $adjacentHashRef || defined $check
20368 ) {
20369 return $axmud::CLIENT->writeImproper($self->_objClass . '->getSurrounding_aStar', @_);
20370 }
20371  
20372 # Get a list of exits from the room $currentNode
20373 if ($currentNode->exitNumHash) {
20374  
20375 # Get a list of destination rooms. Some rooms have multiple exits leading to the same
20376 # destination room, so we use a hash to store the destination rooms
20377 # The hash is in the form
20378 # $hash{destination_room_number} = exit_object_to_get_there
20379 OUTER: foreach my $exitNum ($currentNode->ivValues('exitNumHash')) {
20380  
20381 my ($exitObj, $destRoomObj);
20382  
20383 $exitObj = $self->ivShow('exitModelHash', $exitNum);
20384 if ($exitObj->destRoom) {
20385  
20386 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
20387  
20388 # Depending on the $self->adjacentMode and $adjacentHashRef, we can either use
20389 # region exits, or not
20390 if (
20391 $exitObj->regionFlag
20392 && (
20393 $self->adjacentMode ne 'near'
20394 || ! exists $$adjacentHashRef{$destRoomObj->parent}
20395 )
20396 ) {
20397 # Can't use this region exit or its destination room
20398 next OUTER;
20399 }
20400  
20401 # We don't use a destination room if it has any of the room flags in
20402 # $hazardHashRef
20403 # We also don't use exits that have shadow exits (it's normally better to use
20404 # the 'north' shadow exit, rather than the 'open curtains' exit) and exits
20405 # which lead to rooms that can only be visited by certain guilds, races and
20406 # characters (etc); the latter restrictions saves us a whole lot of bother
20407 if (
20408 ! $destRoomObj->exclusiveFlag
20409 && ! $exitObj->shadowExit
20410 && ! $self->checkRoomHazards($destRoomObj, $hazardHashRef)
20411 ) {
20412 $roomHash{$exitObj->destRoom} = $exitObj;
20413 }
20414 }
20415 }
20416 }
20417  
20418 # For each destination room, prepare a list reference containing details about that node
20419 foreach my $destNum (keys %roomHash) {
20420  
20421 my $destRoomObj = $self->ivShow('modelHash', $destNum);
20422  
20423 push (@returnList,
20424 [
20425 $destRoomObj, # GA::ModelObj::Room
20426 $roomHash{$destNum}, # GA::Obj::Exit
20427 1, # Cost
20428 $self->calcHScore($destRoomObj, $targetNode), # H score
20429 ]
20430 );
20431 }
20432  
20433 # Return a list reference, containing some list references
20434 return \@returnList;
20435 }
20436  
20437 sub calcHScore {
20438  
20439 # Called by $self->getSurrounding_aStar
20440 # Calculates the H score for a room node, using the Manhattan heuristic
20441 #
20442 # Expected arguments
20443 # $roomObj - The GA::ModelObj::Room for this node
20444 # $targetNode - The target node (also a GA::ModelObj::Room)
20445 #
20446 # Return values
20447 # The H score (an integer)
20448  
20449 my ($self, $roomObj, $targetNode, $check) = @_;
20450  
20451 # Local variables
20452 my ($xLength, $yLength, $zLength);
20453  
20454 # Check for improper arguments
20455 if (! defined $roomObj || ! defined $targetNode || defined $check) {
20456  
20457 return $axmud::CLIENT->writeImproper($self->_objClass . '->calcHScore', @_);
20458 }
20459  
20460 # Get absolute distances on the x, y and z axes
20461 $xLength = abs($roomObj->xPosBlocks - $targetNode->xPosBlocks);
20462 $yLength = abs($roomObj->yPosBlocks - $targetNode->yPosBlocks);
20463 $zLength = abs($roomObj->zPosBlocks - $targetNode->zPosBlocks);
20464  
20465 return ($xLength + $yLength + $zLength);
20466 }
20467  
20468 # Dijkstra algorithm (used to find a path between two rooms in different regions)
20469  
20470 sub findUniversalPath {
20471  
20472 # Can be called by any function
20473 #
20474 # Dijkstra algorithm to find a path between two rooms in different regions, based on
20475 # AI::Pathfinding::AStar by Aaron Dalton
20476 #
20477 # Expected arguments
20478 # $session - The calling function's GA::Session
20479 # $initialRoomObj - The initial room (a GA::ModelObj::Room)
20480 # $targetRoomObj - The target room (a GA::ModelObj::Room), usually in a different region
20481 # (but it doesn't matter if they are in the same region)
20482 #
20483 # Optional arguments
20484 # $avoidHazardsFlag
20485 # - If set to TRUE, the path won't use any rooms with a room flag on the
20486 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
20487 # to FALSE (or 'undef'), those rooms can be used
20488 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
20489 # should avoid hazardous rooms by default, or not. It's up to the
20490 # calling function to decide whether to use it, and to set the value
20491 # of this argument accordingly
20492 # $otherHazardListRef
20493 # - An optional list of room flags that should be considered hazardous,
20494 # for the purposes of this algorithm (not an error if it contains
20495 # duplicate room flags, or if it contains room flags already on the
20496 # hazardous room flags list)
20497 # - NB This list is IGNORED if the initial and target rooms are not in
20498 # the same region
20499 # - NB Room flags in this list are considered hazardous, even if
20500 # $avoidHazardsFlag is FALSE
20501 # $avoidAdjacentFlag
20502 # - If set to TRUE and if the initial and target rooms are in the same
20503 # region, the algorithm won't use rooms in adjacent regions,
20504 # regardless of the value of $self->adjacentMode. If set to FALSE (or
20505 # 'undef') and the initial/target rooms are in the same region, the
20506 # value of $self->adjacentMode applies
20507 #
20508 # Return values
20509 # An empty list on improper arguments or if no path can be found between the initial and
20510 # target rooms
20511 # Otherwise, returns two list references. The first reference contains a list of
20512 # GA::ModelObj::Room objects on the shortest path between the rooms $initialRoomObj
20513 # and $targetRoomObj (inclusive). The second reference contains a list of
20514 # GA::Obj::Exit objects used to move along the path. The first list contains exactly
20515 # one more item than the second
20516  
20517 my (
20518 $self, $session, $initialRoomObj, $targetRoomObj, $avoidHazardsFlag,
20519 $otherHazardListRef, $avoidAdjacentFlag, $check,
20520 ) = @_;
20521  
20522 # Local variables
20523 my (
20524 $roomListRef, $exitListRef, $dummyRoomObj, $dummyExitObj, $initialRegionmapObj, $index,
20525 $dummyRoomObj2, $dummyExitObj2, $targetRegionmapObj, $openListObj, $nodeHashRef,
20526 $currentNode, $pathRoomListRef, $pathExitListRef,
20527 @emptyList, @initialExitNumList, @initialRoomList, @targetExitNumList, @targetRoomList,
20528 @returnRoomList, @returnExitList,
20529 %adjacentHash, %universalPathHash,
20530 );
20531  
20532 # Check for improper arguments
20533 if (
20534 ! defined $session || ! defined $initialRoomObj || ! defined $targetRoomObj
20535 || defined $check
20536 ) {
20537 $axmud::CLIENT->writeImproper($self->_objClass . '->findUniversalPath', @_);
20538 return @emptyList;
20539 }
20540  
20541 # Depending on the situation, we might be able to use $self->findPath instead
20542 if (
20543 $initialRoomObj->parent == $targetRoomObj->parent
20544 || $self->adjacentMode eq 'all'
20545 ) {
20546 ($roomListRef, $exitListRef) = $self->findPath(
20547 $initialRoomObj,
20548 $targetRoomObj,
20549 $avoidHazardsFlag,
20550 $otherHazardListRef,
20551 $avoidAdjacentFlag,
20552 );
20553  
20554 if (defined $roomListRef && @$roomListRef) {
20555  
20556 return ($roomListRef, $exitListRef);
20557 }
20558  
20559 } elsif ($self->adjacentMode eq 'near') {
20560  
20561 # Get a hash of regions that are adjacent to the start room's region (inclusive)
20562 if (! $avoidAdjacentFlag) {
20563  
20564 %adjacentHash = $self->compileAdjacentRegions($initialRoomObj->parent);
20565 }
20566  
20567 ($roomListRef, $exitListRef) = $self->findPath(
20568 $initialRoomObj,
20569 $targetRoomObj,
20570 $avoidHazardsFlag,
20571 $otherHazardListRef,
20572 $avoidAdjacentFlag,
20573 \%adjacentHash,
20574 );
20575  
20576 if (defined $roomListRef && @$roomListRef) {
20577  
20578 return ($roomListRef, $exitListRef);
20579 }
20580 }
20581  
20582 # If a call to $self->findPath failed to find a path between the two rooms, or if
20583 # $self->findPath wasn't called at all, we can continue with this function's algorithm
20584  
20585 # If any exits in the exit model have been modified, we may need to check and re-calculate
20586 # regions paths, before calculating a path between the two rooms
20587 if ($self->updatePathHash || $self->updateBoundaryHash) {
20588  
20589 $self->updateRegionPaths();
20590 }
20591  
20592 # The first step is to compile a hash of region paths that traverse every region in the
20593 # world model, leading from one region exit to another region exit in the same region
20594 # At either end of each path is the node we'll use in our Dijkstra algorithm. The nodes are
20595 # exits, each equivalent to a GA::Obj::Exit (which may or may not have a twin exit)
20596 #
20597 # Each regionmap stores, in its ->regionPathHash, a list of such paths. Each path is
20598 # represented by a GA::Obj::RegionPath
20599 # There is a parallel ->safeRegionPathHash which contains paths that avoid rooms with
20600 # hazardous room flags
20601 # If $avoidHazardsFlag is set, we use region paths from ->safeRegionPathHash; otherwise, we
20602 # use region paths from ->regionPathHash
20603 #
20604 # This function's hash of paths is in the form:
20605 # $universalPathHash{begin_exit_number} = hash_reference
20606 # ...where 'begin_exit_number' is the number of the GA::Obj::Exit at the start of the path
20607 # Each 'hash_reference' is in the form:
20608 # $hash_reference{end_exit_number} = GA::Obj::RegionPath
20609  
20610 # Process each regionmap in turn
20611 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
20612  
20613 my %regionPathHash;
20614  
20615 # Get the hash of GA::Obj::RegionPath objects from this regionmap
20616 if ($avoidHazardsFlag) {
20617 %regionPathHash = $regionmapObj->safeRegionPathHash;
20618 } else {
20619 %regionPathHash = $regionmapObj->regionPathHash;
20620 }
20621  
20622 foreach my $regionPathObj (values %regionPathHash) {
20623  
20624 # Add the path to our universal hash
20625 $self->addUniversalPath(\%universalPathHash, $regionPathObj);
20626 }
20627 }
20628  
20629 # Now, we need to create some new (temporary) paths, and to add them to %universalPathHash
20630  
20631 # The first set of paths connect $initialRoomObj to every region exit in the same region
20632 # The Dijkstra algorithm we'll employ uses exits as its nodes. The initial room can have
20633 # several exits, any of which might be on the shortest path to the target room. So, we'll
20634 # create a dummy room object - with a world model number set to -1 - with a dummy one-way
20635 # exit which leads to the initial room
20636 # When the algorithm is finished, we'll discard the room (and its exit)
20637 ($dummyRoomObj, $dummyExitObj) = $self->createDummyRoom($session, $initialRoomObj, -1);
20638  
20639 # Get the initial room's regionmap
20640 $initialRegionmapObj = $self->findRegionmap($initialRoomObj->parent);
20641 # Get a list of region exits in this regionmap
20642 @initialExitNumList = $initialRegionmapObj->ivKeys('regionExitHash');
20643 # From this list, get a list of rooms from which the region exits depart
20644 foreach my $exitNum (@initialExitNumList) {
20645  
20646 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
20647 push (@initialRoomList, $self->ivShow('modelHash', $exitObj->parent));
20648 }
20649  
20650 # Find the shortest path between the initial room (not the dummy room), and each of the
20651 # boundary rooms. Use the rooms themselves as nodes
20652 $index = -1;
20653 foreach my $boundaryRoomObj (@initialRoomList) {
20654  
20655 my ($miniRoomListRef, $miniExitListRef, $pathObj, $thisExitObj);
20656  
20657 $index++; # Matching indexes in @initialExitList and @initialRoomList
20658  
20659 ($miniRoomListRef, $miniExitListRef) = $self->findPath(
20660 $initialRoomObj,
20661 $boundaryRoomObj,
20662 $avoidHazardsFlag, # Avoid hazards, or not
20663 undef,
20664 TRUE, # Don't use adjacent regions
20665 );
20666  
20667 # If a path was found...
20668 if (defined $miniRoomListRef && @$miniRoomListRef) {
20669  
20670 # Add the dummy room (and its dummy exit) to the beginning of the path
20671 unshift(@$miniRoomListRef, $dummyRoomObj);
20672 unshift(@$miniExitListRef, $dummyExitObj);
20673  
20674 # Create a GA::Obj::RegionPath to stored this path. However, don't add it to the
20675 # regionmap's hash of region paths, in the normal way; add it only to our
20676 # %universalPathHash
20677 $thisExitObj = $self->ivShow('exitModelHash', $initialExitNumList[$index]);
20678  
20679 $pathObj = Games::Axmud::Obj::RegionPath->new(
20680 $session,
20681 $dummyExitObj->number,
20682 $thisExitObj->number,
20683 $miniRoomListRef,
20684 $miniExitListRef,
20685 );
20686  
20687 if ($pathObj) {
20688  
20689 $self->addUniversalPath(\%universalPathHash, $pathObj);
20690 }
20691 }
20692 }
20693  
20694 # Do the same for the target region. Find the shortest paths which connect the target room
20695 # with every region exit in the same region
20696  
20697 # Once again we need a temporary room, and a temporary exit from the target room which leads
20698 # to the temporary room. Both are removed at the end
20699 ($dummyRoomObj2, $dummyExitObj2) = $self->createDummyRoom($session, $targetRoomObj, -2);
20700  
20701 # Get the target room's regionmap
20702 $targetRegionmapObj = $self->findRegionmap($targetRoomObj->parent);
20703 # Get a list of region exits in this regionmap
20704 @targetExitNumList = $targetRegionmapObj->ivKeys('regionExitHash');
20705 # From this list, get a list of rooms from which the region exits depart
20706 foreach my $exitNum (@targetExitNumList) {
20707  
20708 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
20709 push (@targetRoomList, $self->ivShow('modelHash', $exitObj->parent));
20710 }
20711  
20712 # Find the shortest path between the target room (not the dummy room), and each of the
20713 # boundary rooms. Use the rooms themselves as nodes
20714 $index = -1;
20715 foreach my $boundaryRoomObj (@targetRoomList) {
20716  
20717 my ($miniRoomListRef, $miniExitListRef, $pathObj, $thisExitObj);
20718  
20719 $index++; # Matching indexes in @targetExitList and @targetRoomList
20720  
20721 ($miniRoomListRef, $miniExitListRef) = $self->findPath(
20722 $boundaryRoomObj,
20723 $targetRoomObj,
20724 $avoidHazardsFlag, # Avoid hazards, or not
20725 undef,
20726 TRUE, # Don't use adjacent regions
20727 );
20728  
20729 # If a path was found...
20730 if (defined $miniRoomListRef && @$miniRoomListRef) {
20731  
20732 # Add the dummy room (and its dummy exit) to the end of the path
20733 push(@$miniRoomListRef, $dummyRoomObj2);
20734 push(@$miniExitListRef, $dummyExitObj2);
20735  
20736 # Create a GA::Obj::RegionPath to stored this path. However, don't add it to the
20737 # regionmap's hash of region paths, in the normal way; add it only to our
20738 # %universalPathHash
20739 $thisExitObj = $self->ivShow('exitModelHash', $targetExitNumList[$index]);
20740  
20741 $pathObj = Games::Axmud::Obj::RegionPath->new(
20742 $session,
20743 $thisExitObj->number,
20744 $dummyExitObj2->number,
20745 $miniRoomListRef,
20746 $miniExitListRef,
20747 );
20748  
20749 if ($pathObj) {
20750  
20751 $self->addUniversalPath(\%universalPathHash, $pathObj);
20752 }
20753 }
20754 }
20755  
20756 # %universalPathHash now contains a collection of paths that traverse the whole world model,
20757 # linking together all connected regions
20758 # Now we run the Dijkstra algorithm (a modified A* algorithm in which the h-score is
20759 # always 0) to get the shortest path between the initial and target rooms
20760  
20761 # Create the open list, using a binomial heap
20762 $openListObj = Games::Axmud::Obj::Heap->new();
20763 # Create a reference to a hash of nodes, in the form
20764 # $nodeHashRef{exit_object} = node
20765 # ...where 'exit_object' is a GA::Obj::Exit, and node is a GA::Node::Dijkstra object
20766 $nodeHashRef = {};
20767  
20768 # Create a node for the initial exit
20769 $currentNode = Games::Axmud::Node::Dijkstra->new(
20770 0, # Initial G score
20771 $dummyExitObj, # Dummy exit object leading to the initial room
20772 );
20773  
20774 # Add this node to the open list
20775 $currentNode->ivPoke('inOpenFlag', TRUE);
20776 $openListObj->add($currentNode);
20777  
20778 # Perform the Dijkstra algorithm, starting at the exit $dummyExitObj, and aiming for the
20779 # exit $dummyExitObj2
20780 $self->doDijkstra($dummyExitObj2, $openListObj, $nodeHashRef, \%universalPathHash);
20781  
20782 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
20783 # path from the target room, and using the parent of each node in turn (in the standard
20784 # way)
20785 # Get two list references, one containing the rooms in the shortest path between
20786 # $dummyRoomObj and $dummyRoomObj2, and the other containing the exits to move along the
20787 # path
20788 ($pathRoomListRef, $pathExitListRef) = $self->fillPath_dijkstra(
20789 $dummyExitObj2,
20790 $openListObj,
20791 $nodeHashRef,
20792 \%universalPathHash
20793 );
20794  
20795 # The list references $pathRoomListRef and $pathExitListRef contain a list of room and
20796 # exit numbers; convert them to lists of the rooms and exits themselves
20797 foreach my $number (@$pathRoomListRef) {
20798  
20799 push (@returnRoomList, $self->ivShow('modelHash', $number));
20800 }
20801  
20802 foreach my $number (@$pathExitListRef) {
20803  
20804 push (@returnExitList, $self->ivShow('exitModelHash', $number));
20805 }
20806  
20807 # @returnRoomList contains the rooms along the path, plus the two dummy rooms at each end.
20808 # Remove the dummy rooms
20809 if (@returnRoomList) {
20810  
20811 if ($returnRoomList[0] eq $dummyRoomObj) {
20812  
20813 shift @returnRoomList;
20814 }
20815  
20816 if ($returnRoomList[-1] eq $dummyRoomObj2) {
20817  
20818 pop @returnRoomList;
20819 }
20820 }
20821  
20822 # Likewise, @returnExitList contains the exits to move along the path, plus the two dummy
20823 # exits at each end. Remove the dummy exits, too
20824 if (@returnExitList) {
20825  
20826 if ($returnExitList[0] eq $dummyExitObj) {
20827  
20828 shift @returnExitList;
20829 }
20830  
20831 if ($returnExitList[-1] eq $dummyExitObj2) {
20832  
20833 pop @returnExitList;
20834 }
20835 }
20836  
20837 # Delete the dummy rooms/objects
20838 $self->destroyDummyRoom(-1);
20839 $self->destroyDummyRoom(-2);
20840  
20841 return (\@returnRoomList, \@returnExitList);
20842 }
20843  
20844 sub doDijkstra {
20845  
20846 # Called by $self->findUniversalPath
20847 # Performs the Dijkstra algorithm on two nodes, each corresponding to an exit in two
20848 # different regions, in order to find the shortest path between them, and therefore the
20849 # shortest path between two rooms (as described in the comments for the calling function)
20850 #
20851 # Expected arguments
20852 # $targetNode - The target node (a dummy GA::Obj::Exit that the calling function
20853 # created, which leads away from the target room to a dummy
20854 # GA::ModelObj::Room)
20855 # $openListObj - The Dijkstra open list, stored in a binomial heap object
20856 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
20857 # $universalPathHashRef
20858 # - A hash of paths between the exits, each of which correspond to a node.
20859 # The hash tells us the cost of moving between two nodes
20860 #
20861 # Return values
20862 # 'undef' on improper arguments
20863 # 1 otherwise
20864  
20865 my ($self, $targetNode, $openListObj, $nodeHashRef, $universalPathHashRef, $check) = @_;
20866  
20867 # Local variables
20868 my (
20869 $currentNode, $gScore, $nodeListRef,
20870 %twinNodeHash,
20871 );
20872  
20873 # Check for improper arguments
20874 if (
20875 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20876 || ! defined $universalPathHashRef || defined $check
20877 ) {
20878 return $axmud::CLIENT->writeImproper($self->_objClass . '->doDijkstra', @_);
20879 }
20880  
20881 # Perform the algorithm until we either find the shortest path to the target node or run out
20882 # of nodes
20883 OUTER: while(
20884 defined $openListObj->top()
20885 && ($openListObj->top()->exitObj ne $targetNode)
20886 ) {
20887 # Remove the first remaining node in the open list
20888 $currentNode = $openListObj->extract_top();
20889 $currentNode->ivPoke('inOpenFlag', FALSE);
20890  
20891 # If this exit has a twin exit, we must prevent the twin from being added as a node to
20892 # the open list, later in the algorithm
20893 if ($currentNode->exitObj->twinExit) {
20894  
20895 $twinNodeHash{$currentNode->exitObj->twinExit} = undef;
20896 }
20897  
20898 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
20899 # number of list references, each representing a surrounding node (one linked to
20900 # $currentNode by a single GA::Obj::RegionPath)
20901 # The contained list references are in the form
20902 # [GA::Obj::Exit, cost]
20903 $nodeListRef = $self->getSurrounding_dijkstra(
20904 $currentNode->exitObj,
20905 $universalPathHashRef,
20906 );
20907  
20908 # Process each surrounding node
20909 INNER: foreach my $nodeRef (@$nodeListRef) {
20910  
20911 my (
20912 $surroundExitObj, $surroundCost, $surroundNode, $currentGScore, $possibleGScore,
20913 );
20914  
20915 ($surroundExitObj, $surroundCost) = @$nodeRef;
20916  
20917 # Skip this node if it's in the closed list
20918 if (
20919 exists $$nodeHashRef{$surroundExitObj}
20920 && ! $$nodeHashRef{$surroundExitObj}->inOpenFlag
20921 ) {
20922 next INNER;
20923  
20924 # Also skip this node if it's in the forbidden (twin) node list
20925 } elsif (exists $twinNodeHash{$surroundExitObj->number}) {
20926  
20927 next INNER;
20928 }
20929  
20930 # If the node isn't in the open list, add it to the open list
20931 if (! exists $$nodeHashRef{$surroundExitObj}) {
20932  
20933 $surroundNode = Games::Axmud::Node::Dijkstra->new(
20934 $currentNode->gScore + $surroundCost, # G score
20935 $surroundExitObj, # GA::Obj::Exit
20936 );
20937  
20938 $surroundNode->ivPoke('parent', $currentNode);
20939 $surroundNode->ivPoke('cost', $surroundCost);
20940 $surroundNode->ivPoke('inOpenFlag', TRUE);
20941 $$nodeHashRef{$surroundExitObj} = $surroundNode;
20942 $openListObj->add($surroundNode);
20943  
20944 } else {
20945  
20946 # Otherwise the node is already in the open list. Check to see if it's cheaper
20947 # to go through the current exit, compared to the previous path
20948 $surroundNode = $$nodeHashRef{$surroundExitObj};
20949 $currentGScore = $surroundNode->gScore;
20950 $possibleGScore = $currentNode->gScore + $surroundCost;
20951  
20952 if ($possibleGScore < $currentGScore) {
20953  
20954 # Change the parent
20955 $surroundNode->ivPoke('parent', $currentNode);
20956 $surroundNode->ivPoke('gScore', $possibleGScore);
20957 $openListObj->decrease_key($surroundNode);
20958 }
20959 }
20960 }
20961 }
20962  
20963 # Dijkstra algorithm complete
20964 return 1;
20965 }
20966  
20967 sub fillPath_dijkstra {
20968  
20969 # Called by $self->findUniversalPath, after a call to $self->doDijkstra
20970 # The initial room and the target room are now linked, along the shortest path between them,
20971 # by a list of nodes, each corresponding to a GA::Obj::Exit. The path begins with a dummy
20972 # room connected to the initial room, and another dummy room connected to the target room
20973 # Compile two lists: a list of the rooms, from one dummy room to the other (inclusive), and
20974 # a corresponding list of exits used to travel between them. It's up to the calling
20975 # function to remove the dummy rooms (and dummy exits) at the beginning/ends of the list
20976 #
20977 # Expected arguments
20978 # $targetNode - The target node (a GA::Obj::Exit object)
20979 # $openListRef - The Dijkstra open list, stored in a binomial heap object
20980 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
20981 # $universalPathHashRef
20982 # - A hash of paths between the exits which correspond to nodes, which
20983 # tells us the cost of moving between them
20984 #
20985 # Return values
20986 # Returns an empty list on improper arguments
20987 # Otherwise returns a list containing two list references. The first reference contains a
20988 # list of GA::ModelObj::Room objects on the shortest path between the two dummy
20989 # rooms (inclusive). The second reference contains a list of GA::Obj::Exit objects
20990 # to move between them. The first list contains exactly one more item than the second.
20991  
20992 my ($self, $targetNode, $openListObj, $nodeHashRef, $universalPathHashRef, $check) = @_;
20993  
20994 # Local variables
20995 my (
20996 $currentNode,
20997 @emptyList, @nodeList, @roomList, @exitList,
20998 );
20999  
21000 # Check for improper arguments
21001 if (
21002 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
21003 || ! defined $universalPathHashRef || defined $check
21004 ) {
21005 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_dijkstra', @_);
21006 return @emptyList;
21007 }
21008  
21009 if (exists $$nodeHashRef{$targetNode}) {
21010 $currentNode = $$nodeHashRef{$targetNode};
21011 } else {
21012 $currentNode = $openListObj->top();
21013 }
21014  
21015 while (defined $currentNode) {
21016  
21017 unshift(@nodeList, $currentNode->exitObj);
21018 $currentNode = $currentNode->parent;
21019 }
21020  
21021 if (@nodeList) {
21022  
21023 # Everything in @nodeList is a GA::Obj::Exit corresponding to a node along the path
21024 do {
21025  
21026 my (
21027 $thisExitObj, $hashRef, $regionPathObj, $pathListRef,
21028 @refList,
21029 );
21030  
21031 $thisExitObj = shift @nodeList;
21032  
21033 # Find the path between this node, and the next one
21034 if ($$universalPathHashRef{$thisExitObj->number}) {
21035  
21036 push (@refList, $$universalPathHashRef{$thisExitObj->number});
21037 }
21038  
21039 if ($thisExitObj->twinExit && $$universalPathHashRef{$thisExitObj->twinExit}) {
21040  
21041 push (@refList, $$universalPathHashRef{$thisExitObj->twinExit});
21042 }
21043  
21044 OUTER: foreach my $hashRef (@refList) {
21045  
21046 $regionPathObj = $$hashRef{$nodeList[0]->number};
21047 if ($regionPathObj) {
21048  
21049 # In certain circumstances, the shortest region path between two region
21050 # exits, A and B, might go via a room with its own region exit, C
21051 # Because the G score for path A-B is the same as the combined G scores for
21052 # two region paths, A-C then C-B, we might have either situation
21053 # In the latter situation, the code below has added the Exit B to @exitList
21054 # on the assumption that we're going through that exit; if we aren't, then
21055 # remove it (and remove the corresponding duplicate room that would
21056 # otherwise appear in the final @roomList)
21057 if (
21058 @roomList
21059 && $regionPathObj->roomList
21060 && $roomList[-1] == $regionPathObj->ivIndex('roomList', 0)
21061 ) {
21062 pop @roomList;
21063 pop @exitList;
21064 }
21065  
21066 # Add rooms and exits from this region path
21067 push (@roomList, $regionPathObj->roomList);
21068 push (@exitList, $regionPathObj->exitList);
21069 # At region boundaries (exit nodes), we have to add the exit itself
21070 if ($exitList[-1] ne $regionPathObj->stopExit) {
21071  
21072 push (@exitList, $regionPathObj->stopExit);
21073 }
21074  
21075 last OUTER;
21076 }
21077 }
21078  
21079 } until (@nodeList < 2);
21080 }
21081  
21082 return (\@roomList, \@exitList);
21083 }
21084  
21085 sub getSurrounding_dijkstra {
21086  
21087 # Called by $self->doDijkstra
21088 # Get a list of nodes surrounding the current one
21089 # In this function, the current node corresponds to an exit. We look up this exit in the
21090 # hash of GA::Obj::RegionPath objects we created earlier to find all the connecting
21091 # nodes
21092 #
21093 # Expected arguments
21094 # $currentNode
21095 # - The current node (a GA::Obj::Exit)
21096 # $universalPathHashRef
21097 # - A hash of hash references, in the form
21098 # $hash{begin_exit_number} = hash_reference
21099 # ...where 'begin_exit_number' is the number of the exit at one end of the path
21100 # - Each 'hash_reference' is in the form
21101 # $hash{end_exit_number} = blessed_ref_of_region_path_object
21102 # - The GA::Obj::RegionPath contains the path which connects the two nodes (exits)
21103 #
21104 # Return values
21105 # 'undef' on improper arguments
21106 # Otherwise returns a list reference, containing a series of list references, one for each
21107 # surrounding node. The inner list references are in the form
21108 # [surround_node_exit_object, surrounding_node_cost]
21109  
21110 my ($self, $currentNode, $universalPathHashRef, $check) = @_;
21111  
21112 # Local variables
21113 my (@refList, @returnList);
21114  
21115 # Check for improper arguments
21116 if (! defined $currentNode || ! defined $universalPathHashRef || defined $check) {
21117  
21118 return $axmud::CLIENT->writeImproper(
21119 $self->_objClass . '->getSurrounding_dijkstra',
21120 @_,
21121 );
21122 }
21123  
21124 # Extract hash references from $universalPathHashRef
21125 if ($$universalPathHashRef{$currentNode->number}) {
21126  
21127 push (@refList, $$universalPathHashRef{$currentNode->number});
21128 }
21129  
21130 if ($currentNode->twinExit && $$universalPathHashRef{$currentNode->twinExit}) {
21131  
21132 push (@refList, $$universalPathHashRef{$currentNode->twinExit});
21133 }
21134  
21135 foreach my $hashRef (@refList) {
21136  
21137 foreach my $regionPathObj (values %$hashRef) {
21138  
21139 push (
21140 @returnList,
21141 [
21142 $self->ivShow('exitModelHash', $regionPathObj->stopExit), # Surrounding node
21143 $regionPathObj->roomCount, # Cost
21144 ],
21145 );
21146 }
21147 }
21148  
21149 # Return a list reference, containing some list references
21150 return \@returnList;
21151 }
21152  
21153 sub addUniversalPath {
21154  
21155 # Called by $self->findUniversalPath to add a single GA::Obj::RegionPath to a hash of
21156 # hashes, in the form
21157 # $universalHash{begin_exit_number} = hash_reference
21158 # ...where 'begin_exit_number' is the number of the GA::Obj::Exit at one end of the path
21159 #
21160 # Each 'hash_reference' is in the form:
21161 # $hash_reference{end_exit_number} = blessed_ref_of_region_path_object
21162 #
21163 # Expected arguments
21164 # $universalPathHashRef - a reference to the hash described above
21165 # $regionPathObj - a GA::Obj::RegionPath to add to it
21166 #
21167 # Return values
21168 # 'undef' on improper arguments
21169 # 1 otherwise
21170  
21171 my ($self, $universalPathHashRef, $regionPathObj, $check) = @_;
21172  
21173 # Local variables
21174 my $hashRef;
21175  
21176 # Check for improper arguments
21177 if (! defined $universalPathHashRef || ! defined $regionPathObj || defined $check) {
21178  
21179 return $axmud::CLIENT->writeImproper($self->_objClass . '->addUniversalPath', @_);
21180 }
21181  
21182 if (! exists $$universalPathHashRef{$regionPathObj->startExit}) {
21183  
21184 $$universalPathHashRef{$regionPathObj->startExit} = {};
21185 }
21186  
21187 $hashRef = $$universalPathHashRef{$regionPathObj->startExit};
21188  
21189 # Add the GA::Obj::RegionPath to the existing inner hash, or to the new inner hash
21190 $$hashRef{$regionPathObj->stopExit} = $regionPathObj;
21191  
21192 return 1;
21193 }
21194  
21195 sub createDummyRoom {
21196  
21197 # Called by $self->findUniversalPath
21198 # Creates a dummy world model room (whose model number is -1), with a one-way exit (whose
21199 # exit model number is -1), leading to a real world model room
21200 # Otherwise creates a dummy world model room (whose model number is -2), with a one-way
21201 # exit (whose exit model number is -2), leading from a real world model room
21202 # Once the pathfinding algorithms are complete, $self->destroyDummyRoom() is called to
21203 # remove any traces of the room and its exit from the world model
21204 #
21205 # Expected arguments
21206 # $session - The calling function's GA::Session
21207 # $realRoomObj - The real world model room
21208 # $number - Set to -1 (for the exit node at the beginning of a path) or -2 (for
21209 # the exit node at the end of the path)
21210 #
21211 # Return values
21212 # An empty list on improper arguments
21213 # Otherwise returns a list in the form
21214 # (dummy_room_object, dummy_exit_object)
21215  
21216 my ($self, $session, $realRoomObj, $number, $check) = @_;
21217  
21218 # Local variables
21219 my (
21220 $dummyRoomObj, $dummyExitObj, $dummyDir,
21221 @emptyList,
21222 );
21223  
21224 # Check for improper arguments
21225 if (! defined $session || ! defined $realRoomObj || ! defined $number || defined $check) {
21226  
21227 $axmud::CLIENT->writeImproper($self->_objClass . '->createDummyRoom', @_);
21228 return @emptyList;
21229 }
21230  
21231 $dummyRoomObj = Games::Axmud::ModelObj::Room->new(
21232 $session,
21233 'dummy',
21234 'non_model',
21235 );
21236  
21237 $dummyRoomObj->ivPoke('number', $number);
21238 $self->ivAdd('modelHash', $number, $dummyRoomObj);
21239 $self->ivAdd('roomModelHash', $number, $dummyRoomObj);
21240 # (The dummy room is nominally 'in' the same region as the initial room)
21241 $dummyRoomObj->ivPoke('parent', $realRoomObj->parent);
21242  
21243 $dummyExitObj = Games::Axmud::Obj::Exit->new(
21244 $session,
21245 'dummy', # Use a dummy direction, too!
21246 'non_model', # Not a real exit model object
21247 );
21248  
21249 $dummyExitObj->ivPoke('number', $number);
21250 $self->ivAdd('exitModelHash', $number, $dummyExitObj);
21251  
21252 $dummyDir = 'dijkstra_dummy_exit';
21253  
21254 if ($number == -1) {
21255  
21256 # Dummy exit leading to the initial room
21257 $dummyRoomObj->ivPush('sortedExitList', $dummyDir);
21258 $dummyRoomObj->ivAdd('exitNumHash', $dummyDir, $number);
21259 $dummyExitObj->ivPoke('destRoom', $realRoomObj->number);
21260 $dummyExitObj->ivPoke('oneWayFlag', TRUE);
21261 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as an
21262 # emergency default value for ->mapDir
21263 if ($dummyExitObj->mapDir) {
21264  
21265 $dummyExitObj->ivPoke(
21266 'oneWayDir',
21267 $axmud::CLIENT->ivShow('constOppDirHash', $dummyExitObj->mapDir),
21268 );
21269  
21270 } else {
21271  
21272 # Emergency default
21273 $dummyExitObj->ivPoke('oneWayDir', 'north');
21274 }
21275  
21276 $dummyExitObj->ivPoke('parent', $dummyRoomObj->number);
21277  
21278 } else {
21279  
21280 # Dummy exit leading from the target room
21281 $realRoomObj->ivPush('sortedExitList', $dummyDir);
21282 $realRoomObj->ivAdd('exitNumHash', $dummyDir, $number);
21283 $dummyExitObj->ivPoke('destRoom', $dummyRoomObj->number);
21284 $dummyExitObj->ivPoke('oneWayFlag', TRUE);
21285 if ($dummyExitObj->mapDir) {
21286  
21287 $dummyExitObj->ivPoke(
21288 'oneWayDir',
21289 $axmud::CLIENT->ivShow('constOppDirHash', $dummyExitObj->mapDir),
21290 );
21291  
21292 } else {
21293  
21294 # Emergency default
21295 $dummyExitObj->ivPoke('oneWayDir', 'north');
21296 }
21297  
21298 $dummyExitObj->ivPoke('parent', $realRoomObj->number);
21299 }
21300  
21301 return ($dummyRoomObj, $dummyExitObj);
21302 }
21303  
21304 sub destroyDummyRoom {
21305  
21306 # Called by $self->findUniversalPath
21307 # Removes a dummy room and its dummy exit (created with a call to $self->createDummyRoom)
21308 # from the world model
21309 #
21310 # Expected arguments
21311 # $number - Set to -1 (for the exit node at the beginning of a path) or -2 (for
21312 # the exit node at the end of the path)
21313 #
21314 # Return values
21315 # 'undef' on improper arguments
21316 # 1 otherwise
21317  
21318 my ($self, $number, $check) = @_;
21319  
21320 # Local variables
21321 my (
21322 $dummyDir, $dummyExitObj, $realRoomObj,
21323 @dirList, @newDirList,
21324 );
21325  
21326 # Check for improper arguments
21327 if (! defined $number || defined $check) {
21328  
21329 return $axmud::CLIENT->writeImproper($self->_objClass . '->destroyDummyRoom', @_);
21330 }
21331  
21332 if ($number == -2) {
21333  
21334 # Dummy exit leading from the target room. Update the target room
21335 $dummyDir = 'dijkstra_dummy_exit';
21336 $dummyExitObj = $self->ivShow('exitModelHash', $number);
21337 $realRoomObj = $self->ivShow('modelHash', $dummyExitObj->parent);
21338  
21339 $realRoomObj->ivDelete('exitNumHash', $dummyDir);
21340 @dirList = $realRoomObj->sortedExitList;
21341 foreach my $dir (@dirList) {
21342  
21343 if ($dir ne $dummyDir) {
21344  
21345 push (@newDirList, $dir);
21346 }
21347 }
21348  
21349 $realRoomObj->ivPoke('sortedExitList', @newDirList);
21350 }
21351  
21352 # Remove the exit from the exit model
21353 $self->ivDelete('exitModelHash', $number);
21354 # Remove the room from the world model
21355 $self->ivDelete('modelHash', $number);
21356 $self->ivDelete('roomModelHash', $number);
21357  
21358 return 1;
21359 }
21360  
21361 # Dijkstra algorithm for GA::Obj::Route objects (used to find a path using pre-defined routes)
21362  
21363 sub findRoutePath {
21364  
21365 # Can be called by any function. Called by GA::Generic::Cmd->useRoute
21366 #
21367 # Dijkstra algorithm to find a path between two rooms using interlinked pre-defined routes,
21368 # each one stored in a GA::Obj::Route object (which are stored in route cages)
21369 # Based on AI::Pathfinding::AStar by Aaron Dalton
21370 #
21371 # Expected arguments
21372 # $session - The calling function's GA::Session
21373 # $initialRoomTag - The initial room's tag
21374 # $targetRoomTag - The target room's tag
21375 # $routeType - 'road', 'quick' or 'both'
21376 #
21377 # Return values
21378 # 'undef' on improper arguments or if no path can be found between the initial and target
21379 # rooms
21380 # Otherwise, returns a list reference containing a list of world commands to move between
21381 # the initial and target rooms
21382  
21383 my ($self, $session, $initialRoomTag, $targetRoomTag, $routeType, $check) = @_;
21384  
21385 # Local variables
21386 my (
21387 $openListObj, $nodeHashRef, $currentNode, $cmdListRef,
21388 @routeObjList,
21389 %routePathHash,
21390 );
21391  
21392 # Check for improper arguments
21393 if (
21394 ! defined $session || ! defined $initialRoomTag || ! defined $targetRoomTag
21395 || ! defined $routeType
21396 || ($routeType ne 'road' && $routeType ne 'quick' && $routeType ne 'both')
21397 || defined $check
21398 ) {
21399 return $axmud::CLIENT->writeImproper($self->_objClass . '->findRoutePath', @_);
21400 }
21401  
21402 # The first step is to compile a hash of routes available to us. Get a list of available
21403 # route GA::Obj::Route objects (ignore circuit routes altogether)
21404 if ($routeType eq 'both') {
21405 @routeObjList = $self->listAvailableRoutes($session, undef, 'road', 'quick');
21406 } else {
21407 @routeObjList = $self->listAvailableRoutes($session, undef, $routeType);
21408 }
21409  
21410 if (! @routeObjList) {
21411  
21412 # No routes with which to build a path
21413 return undef;
21414 }
21415  
21416 # Compile a hash in the form
21417 # $routeHash{start_tag} = hash_reference
21418 # where 'start_tag' is the room tag of the room at one end of the route
21419 # Each 'hash_reference' is in the form:
21420 # $hash_reference{stop_tag} = blessed_ref_of_route_object
21421 foreach my $routeObj (@routeObjList) {
21422  
21423 my $hashRef;
21424  
21425 # Use only hoppable route objects...
21426 if ($routeObj->hopFlag) {
21427  
21428 if (! exists $routePathHash{$routeObj->startRoom}) {
21429  
21430 $routePathHash{$routeObj->startRoom} = {};
21431 }
21432  
21433 $hashRef = $routePathHash{$routeObj->startRoom};
21434  
21435 # Add the RouteObj to the existing inner hash, or to the new inner hash
21436 $$hashRef{$routeObj->stopRoom} = $routeObj;
21437 }
21438 }
21439  
21440 # $routePathHashRef now contains a collection of interlinked routes, which we can search to
21441 # find the shortest route between the initial and target rooms (if they are linked by
21442 # route objects)
21443 # Now we run the Dijkstra algorithm for route objects (a modified A* algorithm in which the
21444 # h-score is always 0) to get the shortest path between the initial and target rooms
21445  
21446 # Create the open list, using a binomial heap
21447 $openListObj = Games::Axmud::Obj::Heap->new();
21448 # Create a reference to a hash of nodes, in the form
21449 # $hash{room_tag} = dijkstra_node
21450 $nodeHashRef = {};
21451  
21452 # Create a node for the initial room
21453 $currentNode = Games::Axmud::Node::Dijkstra->new(
21454 0, # Initial G score
21455 undef, # (Exit objects not used for pre-defined routes)
21456 $initialRoomTag, # Room tag of the first room object
21457 );
21458  
21459 # Add this node to the open list
21460 $currentNode->ivPoke('inOpenFlag', TRUE);
21461 $openListObj->add($currentNode);
21462  
21463 # Perform the Dijkstra algorithm, starting at the room tagged $initialRoomTag, and aiming
21464 # for the room tagged $targetRoomTag
21465 $self->doRouteDijkstra($targetRoomTag, $openListObj, $nodeHashRef, \%routePathHash);
21466  
21467 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
21468 # path from the target room, and using the parent of each node in turn (in the standard
21469 # way)
21470 # Get a list reference, containing the list of world commands to move between the initial
21471 # and target rooms
21472 $cmdListRef = $self->fillPath_routeDijkstra(
21473 $session,
21474 $targetRoomTag,
21475 $openListObj,
21476 $nodeHashRef,
21477 \%routePathHash,
21478 );
21479  
21480 return $cmdListRef;
21481 }
21482  
21483 sub doRouteDijkstra {
21484  
21485 # Called by $self->findRoutePath
21486 # Performs the Dijkstra algorithm on two nodes, each corresponding to a room tag, in order
21487 # to find the shortest path between them, and therefore the shortest path between two
21488 # rooms (as described in the comments for the calling function)
21489 #
21490 # Expected arguments
21491 # $targetNode - The target node (a room tag)
21492 # $openListObj - The Dijkstra open list, stored in a binomial heap object
21493 # $nodeHashRef - The hash of nodes, in the form $hash{tag} = node
21494 # $routePathHashRef
21495 # - A hash of paths between the tagged rooms, each of which correspond to
21496 # a node. The hash tells us the cost of moving between two nodes
21497 #
21498 # Return values
21499 # 'undef' on improper arguments
21500 # 1 otherwise
21501  
21502 my ($self, $targetNode, $openListObj, $nodeHashRef, $routePathHashRef, $check) = @_;
21503  
21504 # Local variables
21505 my (
21506 $currentNode, $gScore, $nodeListRef,
21507 %twinNodeHash,
21508 );
21509  
21510 # Check for improper arguments
21511 if (
21512 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
21513 || ! defined $routePathHashRef || defined $check
21514 ) {
21515 return $axmud::CLIENT->writeImproper($self->_objClass . '->doRouteDijkstra', @_);
21516 }
21517  
21518 # Perform the algorithm until we either find the shortest path to the target node or run out
21519 # of nodes
21520 OUTER: while(
21521 defined $openListObj->top()
21522 && ($openListObj->top()->roomTag ne $targetNode)
21523 ) {
21524 # Remove the first remaining node in the open list
21525 $currentNode = $openListObj->extract_top();
21526 $currentNode->ivPoke('inOpenFlag', FALSE);
21527  
21528 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
21529 # number of list references, each representing a surrounding node (one linked to
21530 # $currentNode by a single GA::Obj::Route)
21531 # The contained list references are in the form
21532 # [room_tag, cost]
21533 $nodeListRef = $self->getSurrounding_routeDijkstra(
21534 $currentNode->roomTag,
21535 $routePathHashRef,
21536 );
21537  
21538 # Process each surrounding node
21539 INNER: foreach my $nodeRef (@$nodeListRef) {
21540  
21541 my (
21542 $surroundRoomTag, $surroundCost, $surroundNode, $currentGScore, $possibleGScore,
21543 );
21544  
21545 ($surroundRoomTag, $surroundCost) = @$nodeRef;
21546  
21547 # Skip this node if it's in the closed list
21548 if (
21549 exists $$nodeHashRef{$surroundRoomTag}
21550 && ! $$nodeHashRef{$surroundRoomTag}->inOpenFlag
21551 ) {
21552 next INNER;
21553 }
21554  
21555 # If the node isn't in the open list, add it to the open list
21556 if (! exists $$nodeHashRef{$surroundRoomTag}) {
21557  
21558 $surroundNode = Games::Axmud::Node::Dijkstra->new(
21559 $currentNode->gScore + $surroundCost, # G score
21560 undef, # Exits not used
21561 $surroundRoomTag, # Node
21562 );
21563  
21564 $surroundNode->ivPoke('parent', $currentNode);
21565 $surroundNode->ivPoke('cost', $surroundCost);
21566 $surroundNode->ivPoke('inOpenFlag', TRUE);
21567 $$nodeHashRef{$surroundRoomTag} = $surroundNode;
21568 $openListObj->add($surroundNode);
21569  
21570 } else {
21571  
21572 # Otherwise the node is already in the open list. Check to see if it's cheaper
21573 # to go through the current exit, compared to the previous path
21574 $surroundNode = $$nodeHashRef{$surroundRoomTag};
21575 $currentGScore = $surroundNode->gScore;
21576 $possibleGScore = $currentNode->gScore + $surroundCost;
21577  
21578 if ($possibleGScore < $currentGScore) {
21579  
21580 # Change the parent
21581 $surroundNode->ivPoke('parent', $currentNode);
21582 $surroundNode->ivPoke('gScore', $possibleGScore);
21583 $openListObj->decrease_key($surroundNode);
21584 }
21585 }
21586 }
21587 }
21588  
21589 # Dijkstra algorithm complete
21590 return 1;
21591 }
21592  
21593 sub fillPath_routeDijkstra {
21594  
21595 # Called by $self->findRoutePath, after a call to $self->doRouteDijkstra
21596 # The initial room and the target room are now linked, along the shortest path between them,
21597 # by a list of nodes, each corresponding to a room tag
21598 # Compile a list of world commands to travel along this path, from the initial room to the
21599 # target room
21600 #
21601 # Expected arguments
21602 # $session - The calling function's GA::Session
21603 # $targetNode - The target node (a room tag)
21604 # $openListRef - The Dijkstra open list, stored in a binomial heap object
21605 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
21606 # $routePathHashRef
21607 # - A hash of paths between the room tags which correspond to nodes, which
21608 # tells us the cost of moving between them
21609 #
21610 # Return values
21611 # Returns an empty list on improper arguments
21612 # Otherwise returns a list reference, containing commands sequences to move between the
21613 # initial and target rooms. Each command sequence corresponds to a single route object
21614 # in the chain of route objects between the initial and target rooms, e.g.
21615 # 'north;east;north;enter cave'
21616  
21617 my (
21618 $self, $session, $targetNode, $openListObj, $nodeHashRef, $routePathHashRef, $check,
21619 ) = @_;
21620  
21621 # Local variables
21622 my (
21623 $currentNode,
21624 @emptyList, @nodeList, @cmdSequenceList,
21625 );
21626  
21627 # Check for improper arguments
21628 if (
21629 ! defined $session || ! defined $targetNode || ! defined $openListObj
21630 || ! defined $nodeHashRef || ! defined $routePathHashRef || defined $check
21631 ) {
21632 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_routeDijkstra', @_);
21633 return @emptyList;
21634 }
21635  
21636 if (exists $$nodeHashRef{$targetNode}) {
21637 $currentNode = $$nodeHashRef{$targetNode};
21638 } else {
21639 $currentNode = $openListObj->top();
21640 }
21641  
21642 while (defined $currentNode) {
21643  
21644 unshift(@nodeList, $currentNode->roomTag);
21645 $currentNode = $currentNode->parent;
21646 }
21647  
21648 if (@nodeList) {
21649  
21650 # Everything in @nodeList is a room tag corresponding to the beginning or end of a route
21651 # object
21652 do {
21653  
21654 my ($roomTag, $hashRef, $routeObj);
21655  
21656 $roomTag = shift @nodeList;
21657  
21658 # Find the path between this node, and the next one
21659 if ($$routePathHashRef{$roomTag}) {
21660  
21661 $hashRef = $$routePathHashRef{$roomTag};
21662 $routeObj = $$hashRef{$nodeList[0]};
21663 if ($routeObj) {
21664  
21665 # If $routeObj->route is a speedwalk command, convert it into a chain of
21666 # world commands
21667 if (index($routeObj->route, $axmud::CLIENT->constSpeedSigil) == 0) {
21668  
21669 push (
21670 @cmdSequenceList,
21671 join(
21672 $axmud::CLIENT->cmdSep,
21673 $session->parseSpeedWalk($routeObj->route),
21674 ),
21675 );
21676  
21677 } else {
21678  
21679 # $routeObj->route is already a single world command or a chain of
21680 # world commands
21681 push (@cmdSequenceList, $routeObj->route);
21682 }
21683 }
21684 }
21685  
21686 } until (@nodeList < 2);
21687 }
21688  
21689 return \@cmdSequenceList;
21690 }
21691  
21692 sub getSurrounding_routeDijkstra {
21693  
21694 # Called by $self->doRouteDijkstra
21695 # Get a list of nodes surrounding the current one
21696 # In this function, the current node corresponds to a room tag. We look up this node in the
21697 # hash of GA::Obj::Route objects we created earlier to find all the connecting nodes
21698 #
21699 # Expected arguments
21700 # $currentNode
21701 # - The current node (a room tag)
21702 # $routePathHashRef
21703 # - A hash of hash references, in the form
21704 # $hash{start_tag} = hash_reference
21705 # ...where 'start_tag' is the tag of a room at one end of the route
21706 # - Each 'hash_reference' is in the form
21707 # $hash{stop_tag} = blessed_ref_of_route_object
21708 # - The GA::Obj::Route contains the path which connects the two nodes (tagged rooms)
21709 #
21710 # Return values
21711 # 'undef' on improper arguments
21712 # Otherwise returns a list reference, containing a series of list references, one for each
21713 # surrounding node. The inner list references are in the form
21714 # [surround_node_exit_object, surrounding_node_cost]
21715  
21716 my ($self, $currentNode, $routePathHashRef, $check) = @_;
21717  
21718 # Local variables
21719 my (
21720 $hashRef,
21721 @returnList,
21722 );
21723  
21724 # Check for improper arguments
21725 if (! defined $currentNode || ! defined $routePathHashRef || defined $check) {
21726  
21727 return $axmud::CLIENT->writeImproper(
21728 $self->_objClass . '->getSurrounding_routeDijkstra',
21729 @_,
21730 );
21731 }
21732  
21733 # Extract hash references from $routePathHashRef
21734 if ($$routePathHashRef{$currentNode}) {
21735  
21736 $hashRef = $$routePathHashRef{$currentNode};
21737  
21738 foreach my $routeObj (values %$hashRef) {
21739  
21740 push (@returnList, [
21741 $routeObj->stopRoom, # Surrounding node
21742 $routeObj->stepCount, # Cost
21743 ]);
21744 }
21745 }
21746  
21747 # Return a list reference, containing some list references
21748 return \@returnList;
21749 }
21750  
21751 sub listAvailableRoutes {
21752  
21753 # Called by $self->findRoutePath, GA::Cmd::ListRoute->do or by any another function
21754 # Returns a list of routes that are available from the current route cages (so, if there is
21755 # a 'centre' > 'shop' road route associated with the current world's route cage, and
21756 # another one associated with the current character's route cage, only the latter appears
21757 # in the returned list, because character cage always have priority over world cage)
21758 #
21759 # Expected arguments
21760 # $session - The calling function's GA::Session
21761 #
21762 # Optional arguments
21763 # $startRoom - When called by GA::Cmd::ListRoute->do, this function returns a list of
21764 # routes starting from the room with the tag $startroom. Set to
21765 # 'undef' when called by $self->findRoutePath
21766 # @typeList - Can comprise 0, 1, 2 or 3 of the strings 'road', 'quick' and 'circuit', in
21767 # any order. If the list is not empty, only those routes matching the
21768 # elements are returned. If it empty, all eligible routes are returned (so
21769 # an empty list is the same as the list ('road', 'quick', 'circuit')
21770 #
21771 # Return values
21772 # An empty list on improper arguments, if @typeList contains invalid route types, if no
21773 # route cages are found or if $startRoom is specified, but a route from that location
21774 # doesn't exist
21775 # Otherwise, returns a list of RouteObjs
21776  
21777 my ($self, $session, $startRoom, @typeList) = @_;
21778  
21779 # Local variables
21780 my (
21781 $match,
21782 @emptyList, @returnArray, @categoryList, @cageList,
21783 %typeHash, %startRoomHash, %roadRouteHash, %quickRouteHash, %circuitRouteHash,
21784 );
21785  
21786 # Check for improper arguments
21787 if (! defined $session) {
21788  
21789 $axmud::CLIENT->writeImproper($self->_objClass . '->listAvailableRoutes', @_);
21790 return @emptyList;
21791 }
21792  
21793 # Check the contents of @typeList, and compile a hash of types
21794 if (@typeList) {
21795  
21796 foreach my $item (@typeList) {
21797  
21798 if ($item ne 'road' && $item ne 'quick' && $item ne 'circuit') {
21799  
21800 $session->writeError(
21801 'Invalid route type \'' . $item . '\'',
21802 $self->_objClass . '->listAvailableRoutes',
21803 );
21804  
21805 return @emptyList;
21806  
21807 } else {
21808  
21809 $typeHash{$item} = undef;
21810 }
21811 }
21812  
21813 } else {
21814  
21815 # If @typeList is empty, the calling function requires road, quick AND circuit routes
21816 $typeHash{'road'} = undef;
21817 $typeHash{'quick'} = undef;
21818 $typeHash{'circuit'} = undef;
21819 }
21820  
21821 # Get a list of profile categories (each possessing one route cage) in reverse priority
21822 # order (i.e., a list starting with the lowest-priority world profile)
21823 @categoryList = reverse $session->profPriorityList;
21824 # Get a list of existing route cages in the same order
21825 foreach my $category (@categoryList) {
21826  
21827 # Find the current cage for this category, if there is one
21828 my $cageObj = $session->findCurrentCage('Route', $category);
21829 if ($cageObj) {
21830  
21831 push (@cageList, $cageObj);
21832 }
21833 }
21834  
21835 if (! @cageList) {
21836  
21837 # No route cages found (very unlikely)
21838 return @emptyList;
21839 }
21840  
21841 OUTER: foreach my $cageObj (@cageList) {
21842  
21843 my (@routeObjList, @newList);
21844  
21845 # Compile a list of GA::Obj::Route objects to process
21846 @routeObjList = $cageObj->ivValues('routeHash');
21847  
21848 # If a start room was specified, eliminate all route objects with the wrong start room
21849 if ($startRoom) {
21850  
21851 foreach my $routeObj (@routeObjList) {
21852  
21853 if ($routeObj->startRoom eq $startRoom) {
21854  
21855 push (@newList, $routeObj);
21856 }
21857 }
21858  
21859 @routeObjList = @newList;
21860 }
21861  
21862 # Now copy the route objects into three hashes, one for each type of route, in the form
21863 # $roadRouteHash{'start@@@stop'} = blessed_reference_to_route_object
21864 # $quickRouteHash{'start@@@stop'} = blessed_reference_to_route_object
21865 # $circuitRouteHash{'start@@@name'} = blessed_reference_to_route_object
21866 # ...where 'start' is the start room's tag, 'stop' the stop room's tag (for 'road' and
21867 # 'quick' routes) and 'name' is the circuit name (for 'circuit' routes)
21868 # Because @categoryList (and therefore @cageList) are in reverse priority order, at the
21869 # end of the OUTER loop, these three hashes will contain the highest-priority route
21870 # between two rooms (or the highest priority circuit with a given name)
21871 foreach my $routeObj (@routeObjList) {
21872  
21873 my $key;
21874  
21875 if ($routeObj->routeType eq 'road') {
21876  
21877 $key = $routeObj->startRoom . '@@@' . $routeObj->stopRoom;
21878 $roadRouteHash{$key} = $routeObj;
21879  
21880 } elsif ($routeObj->routeType eq 'quick') {
21881  
21882 $key = $routeObj->startRoom . '@@@' . $routeObj->stopRoom;
21883 $quickRouteHash{$key} = $routeObj;
21884  
21885 } elsif ($routeObj->routeType eq 'circuit') {
21886  
21887 $key = $routeObj->startRoom . '@@@' . $routeObj->circuitName;
21888 $circuitRouteHash{$key} = $routeObj;
21889 }
21890 }
21891 }
21892  
21893 # Only return the specified route types
21894 if (exists $typeHash{'road'}) {
21895  
21896 push (@returnArray, values %roadRouteHash);
21897 }
21898  
21899 if (exists $typeHash{'quick'}) {
21900  
21901 push (@returnArray, values %quickRouteHash);
21902 }
21903  
21904 if (exists $typeHash{'circuit'}) {
21905  
21906 push (@returnArray, values %circuitRouteHash);
21907 }
21908  
21909 return @returnArray;
21910 }
21911  
21912 # Other functions called by anything (not necessarily just GA::Obj::Map and GA::Win::Map )
21913  
21914 sub parseObj {
21915  
21916 # Can be called by anything, but called frequently by the Locator task
21917 # Parses a line (or lines) containing a list of things
21918 # e.g. 'A sword, a shield and a helmet are here.'
21919 # e.g. 'Two big evil guards, a troll and three small torches.'
21920 # Creates model objects for each of the things found
21921 # e.g. Creates 2 guard 'sentient' objects, a troll 'sentient' object and three torch
21922 # 'portable' objects
21923 #
21924 # Expected arguments
21925 # $session - The parent GA::Session object
21926 # $multipleFlag - If set to TRUE, treats '5 coins' as a single object, with its
21927 # ->multiple IV set to 5. If the flag is set to FALSE, treats
21928 # '5 coins' as 5 separate objects
21929 #
21930 # Expected arguments
21931 # @lineList - A line (or lines) containing the list(s) of things (may be an empty
21932 # list)
21933 #
21934 # Return values
21935 # An empty list on improper arguments
21936 # Otherwise, returns a list of blessed references to the newly-created objects (may be
21937 # an empty list if @lineList was empty, or if the lines can't be parsed)
21938  
21939 my ($self, $session, $multipleFlag, @lineList) = @_;
21940  
21941 # Local variables
21942 my (
21943 $worldObj, $dictObj, $regex, $thingCount, $numberFlag, $guessFlag,
21944 @tempList, @tempList2, @tempList3, @andOrList, @thingArray, @articleList, @columnList,
21945 @returnArray,
21946 %pseudoObjHash, %articleHash, %numberHash,
21947 );
21948  
21949 # Check for improper arguments
21950 if (! defined $session || ! defined $multipleFlag) {
21951  
21952 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseObj', @_);
21953 }
21954  
21955 if ($axmud::CLIENT->debugParseObjFlag) {
21956  
21957 if ($multipleFlag) {
21958 $self->writeDebug('WORLD MODEL: Parsing objects multiple flag turned ON');
21959 } else {
21960 $self->writeDebug('WORLD MODEL: Parsing objects multiple flag turned OFF');
21961 }
21962 }
21963  
21964 # Import the current world profile and dictionary
21965 $worldObj = $session->currentWorld;
21966 $dictObj = $session->currentDict;
21967  
21968 # Import the hash of pseudo-objects
21969 %pseudoObjHash = $dictObj->pseudoObjHash;
21970 # Import a hash of number words
21971 %numberHash = $dictObj->numberHash;
21972 # Import a list of articles (in English, 'the', 'a' and 'an')
21973 @articleList = ($dictObj->definiteList, $dictObj->indefiniteList);
21974 # Convert to a hash for quick lookup
21975 foreach my $item (@articleList) {
21976  
21977 $articleHash{$item} = undef;
21978 }
21979  
21980 # Stage 1 - convert any capital letters into lower-case letters and remove the
21981 # characteristic room contents patterns (e.g. 'is here', 'are here' etc) from lines of
21982 # text in the list
21983 OUTER: foreach my $line (@lineList) {
21984  
21985 $line = lc($line);
21986 INNER: foreach my $pattern ($worldObj->contentPatternList) {
21987  
21988 $line =~ s/$pattern//gi;
21989 }
21990 }
21991  
21992 # Stage 2 - look for pseudo-objects (strings that will confuse the parser) and replace them
21993 # Test each pseudo-object against each line
21994 OUTER: foreach my $line (@lineList) {
21995  
21996 INNER: foreach my $pseudo (keys %pseudoObjHash) {
21997  
21998 my $replace = $pseudoObjHash{$pseudo};
21999 $line =~ s/$pseudo/$replace/g;
22000 }
22001 }
22002  
22003 # Stage 3 - remove multiples like '[ 5]' that tend to appear in worlds that use a single
22004 # object per line, optionally preceded by a multiplier. This multiplier is applied to
22005 # every object on that line
22006 $regex = '[\(\[\{\<]\s*(\d+)\s*[\)\]\}\>]';
22007 foreach my $line (@lineList) {
22008  
22009 my $num;
22010  
22011 if ($line =~ m/$regex/) {
22012  
22013 $num = $1;
22014 # Stage 5 will detect a simple integer, so replace the '[ 5]' with ' 5 '
22015 $line =~ s/$regex/$num /;
22016 }
22017 }
22018  
22019 # Stage 4 - split into a list of objects (or groups of objects)
22020 # e.g. 'Two big evil guards, a troll and three small torches.'
22021 #
22022 # @thingArray[0][n]
22023 #
22024 # [0] = two big evil guards
22025 # [1] = a troll
22026 # [2] = three small torches
22027  
22028 # Split the lines of @lineList by full stops and commas
22029 foreach my $line (@lineList) {
22030  
22031 push (@tempList, split("\\.", $line));
22032 }
22033  
22034 foreach my $item (@tempList) {
22035  
22036 push (@tempList2, split("\\,", $item));
22037 }
22038  
22039 # Further split the lines of @lineList by and/ors
22040 # Compile a list of and/or words from the current dictionary
22041 @andOrList = ($dictObj->andList, $dictObj->orList);
22042 # Surround each and/or word with whitespace, so that the word 'author' doesn't get split
22043 # into 'auth' and 'or'
22044 foreach my $andOr (@andOrList) {
22045  
22046 $andOr = ' ' . $andOr . ' ';
22047 }
22048  
22049 # Do the split
22050 foreach my $andOr (@andOrList) {
22051  
22052 foreach my $item (@tempList2) {
22053  
22054 push (@tempList3, split (/$andOr/ , $item));
22055 }
22056  
22057 # Reset the lists, ready for the next iteration of the loop (if any)
22058 @tempList2 = @tempList3;
22059 @tempList3 = ();
22060 }
22061  
22062 # Trim unnecessary whitespace from each object (or group of objects) in the list. The TRUE
22063 # argument tells the function to trim whitespace in the middle of the string, too
22064 foreach my $item (@tempList2) {
22065  
22066 $item = $axmud::CLIENT->trimWhitespace($item, TRUE);
22067 }
22068  
22069 # If a pseudo-object's replacement string is an empty string, one or more of the elements in
22070 # @tempList2 will be empty. Eliminate those lines
22071 # In addition, if a list of objects is spread over several lines, we might have artifacts
22072 # like 'the' and 'a' at the end of a line; they will now exist as items in @tempList2.
22073 # Eliminate those, too
22074 foreach my $item (@tempList2) {
22075  
22076 if ($item && (! exists $articleHash{$item})) {
22077  
22078 push (@tempList3, $item);
22079 }
22080 }
22081  
22082 # Insert the list of objects (or groups of objects) into the first column of a 2-dimensional
22083 # array
22084 # Use $thingCount to remember how many items there are
22085 $thingCount = scalar @tempList3;
22086 @thingArray = (\@tempList3);
22087  
22088 # Stage 5 - assign a number to everything in the list of objects (or group of objects)
22089 # The number might be 0, a decimal fraction, or -1 for 'unknown number greater than 1'
22090 # Remove the number word and any definite/indefinite articles
22091 #
22092 # e.g. 'Two big evil guards, a troll and three small torches.'
22093 #
22094 # @thingArray[0][n] [1][n] [2][n]
22095 #
22096 # [0] = two big evil guards [0] big evil guards [0] 2
22097 # [1] = a troll [1] troll [1] 1
22098 # [2] = three small torches [2] small torches [2] 3
22099 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22100  
22101 my (
22102 $pattern, $grpString, $string, $numberFlag,
22103 @wordList,
22104 );
22105  
22106 # Special case: if the string matches the current world's ->multiplePattern, use that as
22107 # the multiple (and remove it)
22108 $pattern = $worldObj->multiplePattern;
22109 if ($pattern && $thingArray[0][$count] =~ m/$pattern/) {
22110  
22111 $grpString = $1;
22112 if ($grpString && $grpString =~ m/^\d+$/ && $grpString > 0) {
22113  
22114 # Set the multiple
22115 $thingArray[2][$count] = $grpString;
22116 # Store the rest of the string, with the matching pattern substituted out
22117 $string = $thingArray[0][$count];
22118 $string =~ s/$pattern//;
22119 $thingArray[1][$count] = $string;
22120 next OUTER;
22121 }
22122 }
22123  
22124 # Split each thing into a list of word, e.g. ('two', 'evil', 'guards')
22125 @wordList = split(/\s+/, $thingArray[0][$count]);
22126  
22127 # If the first word is an article (and it's not the only word in the thing), remove the
22128 # article
22129 if (exists $articleHash{$wordList[0]} && scalar @wordList > 1) {
22130  
22131 # Remove the article
22132 shift @wordList;
22133 }
22134  
22135 # Remove any integer numbers from the beginning
22136 if ($axmud::CLIENT->intCheck($wordList[0])) {
22137  
22138 # Integer number found at beginning of $thing. Remove it and assign it to [2][n]
22139 $thingArray[2][$count] = $wordList[0];
22140  
22141 # Only remove the first number
22142 shift @wordList;
22143 $numberFlag = TRUE;
22144  
22145 # Remove any number words from the beginning, and convert it to a decimal number
22146 # e.g. 'two trolls' -> 2, 'half of the cake' -> 0.5, 'some cake' -> -1
22147 # (-1 represents an indeterminate number, the resulting of converting 'some')
22148 } elsif (exists $numberHash{$wordList[0]}) {
22149  
22150 # Number word found at beginning of $thing. Remove it, convert it to a decimal
22151 # number and assign it to [2][n]
22152 $thingArray[2][$count] = $numberHash{$wordList[0]};
22153  
22154 # Only remove one number word
22155 shift @wordList;
22156 $numberFlag = TRUE;
22157 }
22158  
22159 if (! $numberFlag) {
22160  
22161 # Treat this item as one thing
22162 $thingArray[2][$count] = 1;
22163 }
22164  
22165 # Recombine the word list into a string without articles or number words at
22166 # the beginning
22167 $thingArray[1][$count] = join(' ', @wordList);
22168 }
22169  
22170 # Stage 6 - extract pseudo-adjectives, because they mess everything up
22171 # Pseudo-adjectives are stored in a hash which translates them either into a simple one-word
22172 # adjective or marks them as something that should be removed completely
22173 # $hash{'slightly suspicious'} = 'suspicious'
22174 # - treat the adjective as 'suspicious'
22175 # $hash{'gruesome remains of'} = undef
22176 # - pretend this object doesn't have an adjective
22177 # The contents of [1][n] is moved to [3][n]; any pseudo-adjectives are removed from [3][n]
22178 # and the replacement is put in [4][n]
22179 #
22180 # e.g. 'A slightly suspicious cake and the gruesome remains of a corpse'
22181 #
22182 # @thingArray[0][n] [1][n] [2][n]
22183 #
22184 # [0] = a slightly suspicious cake [0] slightly suspicious cake [0] 1
22185 # [1] = the gruesome remains of a corpse [1] gruesome remains of a corpse [1] 1
22186 #
22187 # [3][n] [4][n]
22188 #
22189 # cake suspicious
22190 # a corpse undef
22191 #
22192 # e.g. 'Two big evil guards, a troll and three small torches.' (contains no
22193 # pseudo-adjectives)
22194 #
22195 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22196 #
22197 # [0] = two big evil guards [0] big evil guards [0] 2 [0] big evil guards [0] undef
22198 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22199 # [2] = three small torches [2] small torches [2] 3 [2] small torches [2] undef
22200  
22201 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22202  
22203 my $largest;
22204  
22205 # Find the largest pseudo-adjective that matches
22206 $largest = '';
22207  
22208 INNER: foreach my $pseudoAdj ($dictObj->ivKeys('pseudoAdjHash')) {
22209  
22210 if (
22211 $thingArray[1][$count] =~ m/$pseudoAdj/
22212 && length ($pseudoAdj) > length ($largest)
22213 ) {
22214 $largest = $pseudoAdj;
22215 }
22216 }
22217  
22218 if ($largest) {
22219  
22220 # Remove the largest pseudo-adjective from [1][n], and move its substitution to
22221 # [4][n]. (If the substitution is an empty string, don't put anything in [4][n])
22222 $thingArray[3][$count] = $thingArray[1][$count];
22223 $thingArray[3][$count] =~ s/$largest//;
22224 if ($dictObj->ivShow('pseudoAdjHash', $largest)) {
22225  
22226 $thingArray[4][$count] = $dictObj->ivShow('pseudoAdjHash', $largest);
22227 }
22228  
22229 } else {
22230  
22231 # No pseudo-adjective found
22232 $thingArray[3][$count] = $thingArray[1][$count];
22233 $thingArray[4][$count] = undef;
22234 }
22235 }
22236  
22237 # Stage 7 - extract pseudo-nouns from [3][n]
22238 # Pseudo-nouns are stored in a hash which translates them either into a simple one-word noun
22239 # $hash{'major general'} = 'major'
22240 # If a pseudo-noun is found, it is replaced with its substitution, and the substitution is
22241 # copied to [5][n] as the main noun
22242 #
22243 # e.g. 'An attractive major general'
22244 #
22245 # @thingArray[0][n] [1][n] [2][n]
22246 #
22247 # [0] = an attractive major general [0] attractive major general [0] 1
22248 #
22249 # [3][n] [4][n] [5][n]
22250 #
22251 # [0] attractive major [0] undef major
22252 #
22253 # e.g. 'Two big evil guards, a troll and three small torches.' (contains no pseudo-nouns)
22254 #
22255 # @thingArray[0][n] [1][n] [2][n] [3][n]
22256 #
22257 # [0] = two big evil guards [0] big evil guards [0] 2 [0] big evil guards
22258 # [1] = a troll [1] troll [1] 1 [1] troll
22259 # [2] = three small torches [2] small torches [2] 3 [2] small torches
22260 #
22261 # [4][n] [5][n]
22262 #
22263 # [0] undef [0] undef
22264 # [1] undef [1] undef
22265 # [2] undef [2] undef
22266  
22267 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22268  
22269 my ($largest, $substitution);
22270  
22271 # Find the largest pseudo-noun that matches
22272 $largest = '';
22273  
22274 INNER: foreach my $pseudoNoun ($dictObj->ivKeys('pseudoNounHash')) {
22275  
22276 if (
22277 $thingArray[3][$count] =~ m/$pseudoNoun/
22278 && length ($pseudoNoun) > length ($largest)
22279 ) {
22280 $largest = $pseudoNoun;
22281 }
22282 }
22283  
22284 if ($largest) {
22285  
22286 # Replace the largest pseudo-noun from [3][n] with its substitution
22287 $substitution = $dictObj->ivShow('pseudoNounHash', $largest);
22288 $thingArray[3][$count] =~ s/$largest/$substitution/;
22289 # Copy the substitution into [5][n] as the main noun
22290 $thingArray[5][$count] = $substitution;
22291 }
22292 }
22293  
22294 # Stage 8 - Try to separate nouns and adjectives, reducing plurals to singular forms and
22295 # declined adjectives to undeclined forms, where possible
22296 #
22297 # e.g. 'Two big evil guards, a troll and three small torches.'
22298 #
22299 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22300 #
22301 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22302 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22303 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22304 #
22305 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22306 #
22307 # [0] guards undef undef undef big evil undef undef
22308 # [1] troll undef undef undef undef undef undef
22309 # [2] torches undef undef undef undef small undef
22310 #
22311 # [5][n] contains the first word - working from right to left - that's a known noun (or
22312 # pseudo-noun)
22313 # [6][n] contains any other words which are known nouns
22314 # [7][n] contains the dictionary section the first noun was found in (e.g. 'weapon')
22315 # [8][n] contains the type of the first noun, if it's a portable or decoration (e.g.
22316 # 'torch')
22317 # [9][n] contains all words which are known adjectives
22318 # [10][n] contains all words which aren't known nouns or adjectives
22319 # [11][n] contains all declined adjectives
22320  
22321 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22322  
22323 my @wordList;
22324  
22325 # Split [3][n] into words
22326 @wordList = split(/\s+/, $thingArray[3][$count]);
22327 # If the noun is more likely to come at the end (i.e. English) than at the front (e.g.
22328 # French), reverse the order of the words
22329 if ($dictObj->nounPosn eq 'adj_noun') {
22330  
22331 @wordList = reverse (@wordList);
22332 }
22333  
22334 INNER: foreach my $word (@wordList) {
22335  
22336 my ($singular, $undeclined, $modFlag);
22337  
22338 # It's possible that $word may be an empty string, or 'undef', in an object like
22339 # 'a pair of dirty and smelly trousers', when 'pair of' is a pseudo-adjective,
22340 # 'dirty' & 'smelly' are adjectives, and 'trousers' is a noun - because the
22341 # parser will interpret this as two objects, 'a pair of dirty' and 'smelly
22342 # trousers', the former of which contains no nouns
22343 if (! $word) {
22344  
22345 next INNER;
22346 }
22347  
22348 if ($self->ivExists('knownCharHash', $word)) {
22349  
22350 # For characters, [5][n] should contain only one word, the character's name
22351 # If there's anything in [5][n] (main noun) already, move it to [6][n] (other
22352 # nouns)
22353 if (defined $thingArray[5][$count]) {
22354  
22355 if (! defined $thingArray[6][$count]) {
22356  
22357 # First word in [6][n]
22358 $thingArray[6][$count] = $thingArray[5][$count];
22359  
22360 } else {
22361  
22362 # Not first word in [6][n]
22363 $thingArray[6][$count]
22364 = $thingArray[5][$count] . ' ' . $thingArray[6][$count];
22365 }
22366 }
22367  
22368 # Character's name goes into [5][n]
22369 $thingArray[5][$count] = $word;
22370  
22371 # Remaining nouns go into [6][n]...
22372 if (! defined $thingArray[6][$count]) {
22373  
22374 # First word in [6][n]
22375 $thingArray[6][$count] = $word;
22376  
22377 } else {
22378  
22379 # Not first word in [6][n]
22380 $thingArray[6][$count] = $word . ' ' . $thingArray[6][$count];
22381 }
22382  
22383 # Mark the object as a character (in [7][n])
22384 $thingArray[7][$count] = 'char';
22385 next INNER;
22386 }
22387  
22388 # See if the word is already known, before trying to convert it to a singular (as
22389 # if it were a noun) or trying to undecline it (as if it were an adjective)
22390 if (
22391 # Word exists as a noun somewhere in the dictionary...
22392 $dictObj->ivExists('combNounHash', $word)
22393 # ...and it's not a special plural form, such as 'stadia' for stadium
22394 && (! $dictObj->ivExists('reversePluralNounHash', $word))
22395 ) {
22396 # This is a known noun. First noun goes into [5][n]
22397 if (! defined $thingArray[5][$count]) {
22398  
22399 $thingArray[5][$count] = $word;
22400  
22401 # Remaining nouns go into [6][n] (unless the same noun is already in [5][n]
22402 # after a pseudo-noun subsitution was placed there)
22403 } elsif ($word ne $thingArray[5][$count]) {
22404  
22405 if (! defined $thingArray[6][$count]) {
22406  
22407 # First word in [6][n]
22408 $thingArray[6][$count] = $word;
22409  
22410 } else {
22411  
22412 # Not first word in [6][n]
22413 $thingArray[6][$count] = $word . ' ' . $thingArray[6][$count];
22414 }
22415 }
22416  
22417 next INNER;
22418 }
22419  
22420 if (
22421 # Word exists as an adjective somewhere in the dictionary...
22422 $dictObj->ivExists('combAdjHash', $word)
22423 # ...and it's not a special declined form, e.g. 'heureuse' for heureux
22424 && (! $dictObj->ivExists('reverseDeclinedAdjHash', $word))
22425 ) {
22426 # This is a known adjective. Put it into [9][n]
22427 if (! defined $thingArray[9][$count]) {
22428  
22429 # First word in [9][n]
22430 $thingArray[9][$count] = $word;
22431  
22432 } else {
22433  
22434 # Not first word in [9][n]
22435 $thingArray[9][$count] = $word . ' ' . $thingArray[9][$count]
22436 }
22437  
22438 next INNER;
22439 }
22440  
22441 # Assume it's a plural noun, and try to reduce it to a singular noun
22442 $singular = $dictObj->convertToSingular($word);
22443 # For confirmed plurals, update the object's base string, so 'two big evil guards'
22444 # generates the base string 'big evil guard' rather 'big evil guards', as this is
22445 # useful for the Locator task window (and probably elsewhere, too)
22446 if ($thingArray[2][$count] > 1 && $singular ne $word) {
22447  
22448 $thingArray[1][$count] =~ s/$word/$singular/g;
22449 # (Only do this once per object)
22450 $modFlag = TRUE;
22451 }
22452  
22453 if ($dictObj->ivExists('combNounHash', $singular)) {
22454  
22455 # This is a known noun. First noun goes into [5][n]. If $word is in [5][n],
22456 # replace it by a singular
22457 if (! defined $thingArray[5][$count] || $thingArray[5][$count] eq $word) {
22458  
22459 $thingArray[5][$count] = $singular;
22460  
22461 # Remaining nouns go into [6][n] (unless the same noun is already in [5][n]
22462 # after a pseudo-noun subsitution was placed there)
22463 } elsif ($singular ne $thingArray[5][$count]) {
22464  
22465 if (! defined $thingArray[6][$count]) {
22466  
22467 # First word in [6][n]
22468 $thingArray[6][$count] = $singular;
22469  
22470 } else {
22471  
22472 # Not first word in [6][n]
22473 $thingArray[6][$count] = $singular . ' ' . $thingArray[6][$count];
22474 }
22475 }
22476  
22477 next INNER;
22478 }
22479  
22480 # Assume it's a declined adjective, and try to reduce it to an undeclined adjective
22481 $undeclined = $dictObj->convertToUndeclined($word);
22482 if ($dictObj->ivExists('combAdjHash', $undeclined)) {
22483  
22484 # This is a known adjective. Put it into [9][n]. If $word is in [9][n],
22485 # replace it by the undecliend form
22486 if (! defined $thingArray[9][$count] || $thingArray[9][$count] eq $word) {
22487  
22488 # First word in [9][n]
22489 $thingArray[9][$count] = $undeclined;
22490  
22491 } else {
22492  
22493 # Not first word in [9][n]
22494 $thingArray[9][$count] = $undeclined . ' ' . $thingArray[9][$count]
22495 }
22496  
22497 if ($word ne $undeclined) {
22498  
22499 # This is a known declinable adjective. Put the undeclined form into [11][n]
22500 if (! defined $thingArray[11][$count]) {
22501  
22502 # First word in [9][n]
22503 $thingArray[11][$count] = $word;
22504  
22505 } else {
22506  
22507 # Not first word in [9][n]
22508 $thingArray[11][$count] = $word . ' ' . $thingArray[11][$count]
22509 }
22510 }
22511  
22512 next INNER;
22513 }
22514  
22515 # Words which aren't known nouns or adjectives go into [10][n] (but don't add
22516 # ignorable words)
22517 if (! $dictObj->ivExists('ignoreWordHash', $word)) {
22518  
22519 if (! defined $thingArray[10][$count]) {
22520  
22521 # First word in [10][n]
22522 $thingArray[10][$count] = $word;
22523  
22524 } else {
22525  
22526 # Not first word in [10][n]
22527 $thingArray[10][$count] = $word.' '.$thingArray[10][$count]
22528 }
22529 }
22530 }
22531 }
22532  
22533 # Stage 9 - any words which aren't recognised nouns or adjectives should be added to the
22534 # dictionary's list of unknown words (if this is allowed); but words in the dictionary's
22535 # ignore list should not
22536 if ($worldObj->collectUnknownWordFlag) {
22537  
22538 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22539  
22540 if (defined $thingArray[10][$count]) {
22541  
22542 my @wordList;
22543  
22544 # Split [10][n] into words
22545 @wordList = split(/\s+/, $thingArray[10][$count]);
22546 # If the noun is more likely to come at the end (i.e. English) than at the front
22547 # (e.g. French), reverse the order of the words
22548 if ($dictObj->nounPosn eq 'adj_noun') {
22549  
22550 @wordList = reverse (@wordList);
22551 }
22552  
22553 # Empty [10][n] so it can be rebuilt, minus any ignorable words
22554 $thingArray[10][$count] = '';
22555  
22556 # Add each word to the dictionary's list of unknown words
22557 foreach my $word (@wordList) {
22558  
22559 $dictObj->ivAdd('unknownWordHash', $word, undef);
22560  
22561 if (! $thingArray[10][$count]) {
22562 $thingArray[10][$count] = $word;
22563 } else {
22564 $thingArray[10][$count] .= ' ' . $word;
22565 }
22566 }
22567 }
22568 }
22569 }
22570  
22571 # Stage 10 - if there's no recognised first noun in [5][n], we need to guess at one
22572 # Use the last (or the first) word in [10][n] (unrecognised words)
22573 # If there's nothing in [10][n], use the last (or the first) word in [9][n] (adjectives)
22574 # or [4][n] (pseudo-adjective replacement)
22575 # In either case, remove the selected word from [4][n], [9][n] or [10][n], and put it in
22576 # [5][n]
22577 #
22578 # e.g. 'Two big evil guards, a troll and three small torches.'
22579 #
22580 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22581 #
22582 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22583 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22584 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22585 #
22586 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22587 #
22588 # [0] guards undef undef undef big evil undef undef
22589 # [1] troll undef undef undef undef undef undef
22590 # [2] torches undef undef undef undef small undef
22591  
22592 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22593  
22594 my @wordList;
22595  
22596 if (! defined $thingArray[5][$count]) {
22597  
22598 # If there's anything in [10][n], use the first word (which would have been the last
22599 # word in 'three small torches', if 'torch' wasn't a recognised noun)
22600 if (defined $thingArray[10][$count]) {
22601  
22602 @wordList = split(/\s+/, $thingArray[10][$count]);
22603 # Reverse the order for French (and similar languages)
22604 if ($dictObj->nounPosn eq 'noun_adj') {
22605  
22606 @wordList = reverse (@wordList);
22607 }
22608  
22609 $thingArray[5][$count] = shift @wordList;
22610 $thingArray[10][$count] = join(' ', @wordList);
22611 $guessFlag = TRUE;
22612  
22613 } elsif (defined $thingArray[9][$count]) {
22614  
22615 @wordList = split(/\s+/, $thingArray[9][$count]);
22616 # Reverse the order for French (and similar languages)
22617 if ($dictObj->nounPosn eq 'noun_adj') {
22618  
22619 @wordList = reverse (@wordList);
22620 }
22621  
22622 $thingArray[5][$count] = shift @wordList;
22623 $thingArray[9][$count] = join(' ', @wordList);
22624 $guessFlag = TRUE;
22625  
22626 } elsif (defined $thingArray[4][$count]) {
22627  
22628 @wordList = split(/\s+/, $thingArray[4][$count]);
22629 # Reverse the order for French (and similar languages)
22630 if ($dictObj->nounPosn eq 'noun_adj') {
22631  
22632 @wordList = reverse (@wordList);
22633 }
22634  
22635 $thingArray[5][$count] = shift @wordList;
22636 $thingArray[4][$count] = join(' ', @wordList);
22637 $guessFlag = TRUE;
22638  
22639 } else {
22640  
22641 $self->writeWarning(
22642 '17056 Unable to parse object \'' . $thingArray[0][$count] . '\'',
22643 $self->_objClass . '->parseObj',
22644 );
22645  
22646 $thingArray[5][$count] = '(unparsed object)';
22647 }
22648 }
22649 }
22650  
22651 # Stage 11 - If [2][n] indicates a plural and we had to guess at the first noun, using an
22652 # unknown word (in [10][n]) or even an adjective (in [9][n]), we need to try to reduce
22653 # it to its singular form, in case it's a plural.
22654 #
22655 # e.g. 'Two big evil guards, a troll and three small torches.'
22656 #
22657 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22658 #
22659 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22660 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22661 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22662 #
22663 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22664 #
22665 # [0] guard undef undef undef big evil undef undef
22666 # [1] troll undef undef undef undef undef undef
22667 # [2] torch undef undef undef undef small undef
22668  
22669 if ($guessFlag) {
22670  
22671 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22672  
22673 my $standard;
22674  
22675 # If it's a known character, don't try to reduce it from plural to singular
22676 if (defined $thingArray[7][$count] && $thingArray[7][$count] eq 'char') {
22677  
22678 next OUTER;
22679  
22680 } elsif ($thingArray[2][$count] > 1) {
22681  
22682 $thingArray[5][$count]
22683 = $dictObj->convertToSingular($thingArray[5][$count]);
22684 }
22685 }
22686 }
22687  
22688 # Stage 12 - work out what kind of object everything is ('portable', 'creature', 'sentient',
22689 # etc). If the object is already known to be a character, skip this stage
22690 #
22691 # e.g. 'Two big evil guards, a troll and three small torches.'
22692 #
22693 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22694 #
22695 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22696 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22697 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22698 #
22699 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22700 #
22701 # [0] guard undef sentient undef big evil undef undef
22702 # [1] troll undef race undef undef undef undef
22703 # [2] torch undef portable torch undef small undef
22704  
22705 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22706  
22707 # If it's a known character, don't need to work out what kind of thing it is
22708 if (defined $thingArray[7][$count] && $thingArray[7][$count] eq 'char') {
22709  
22710 next OUTER;
22711  
22712 } elsif ($dictObj->ivExists('combNounHash', $thingArray[5][$count])) {
22713  
22714 # It's a recognised noun. The parent dictionary goes into [7][n]...
22715 my $parentDict = $dictObj->ivShow(
22716 'combNounHash',
22717 $thingArray[5][$count],
22718 );
22719 $thingArray[7][$count] = $parentDict;
22720  
22721 # ...if it's a portable or decoration, the type goes into [8][n]
22722 if ($parentDict eq 'portable') {
22723  
22724 if ($dictObj->ivExists('portableTypeHash', $thingArray[5][$count])) {
22725  
22726 $thingArray[8][$count] = $dictObj->ivShow(
22727 'portableTypeHash',
22728 $thingArray[5][$count],
22729 );
22730  
22731 } else {
22732  
22733 $thingArray[8][$count] = 'other';
22734 }
22735  
22736 } elsif ($parentDict eq 'decoration') {
22737  
22738 if (
22739 $dictObj->ivExists(
22740 'decorationTypeHash',
22741 $thingArray[5][$count]),
22742 ) {
22743 $thingArray[8][$count] = $dictObj->ivShow(
22744 'decorationTypeHash',
22745 $thingArray[5][$count],
22746 );
22747  
22748 } else {
22749  
22750 $thingArray[8][$count] = 'other';
22751 }
22752  
22753 } else {
22754 $thingArray[8][$count] = undef;
22755 }
22756  
22757 } else {
22758  
22759 # It's not a recognised noun
22760 $thingArray[7][$count] = undef;
22761 $thingArray[8][$count] = undef;
22762 }
22763 }
22764  
22765 # Stage 13 - for objects marked 'sentient' or 'creature' (or temporarily as 'race' or
22766 # 'guild'), and for objects of unknown category (because they're not in the current
22767 # dictionary), we need to know whether they are known minions. $self->minionStringHash
22768 # contains a list of keys (e.g. 'Obelix', 'hairy orc') which represent a minion
22769 # object (stored as the corresponding value). If the object's base string (in [1][n])
22770 # contains one of these minion strings, it's a minion, and [7][n] must be changed; [12][n]
22771 # is set to the matching minion string ('Obelix', 'hairy orc') and [13][n] is set for
22772 # minions which belong to the user
22773 #
22774 # e.g. 'Two big evil guards, a troll and three small torches.'
22775 #
22776 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22777 #
22778 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22779 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22780 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22781 #
22782 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n] [12][n] [13][n]
22783 #
22784 # [0] guard undef sentient undef big evil undef undef undef undef
22785 # [1] troll undef minion undef undef undef undef troll undef
22786 # [2] torch undef portable torch undef small undef undef undef
22787  
22788 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22789  
22790 if (
22791 ! defined $thingArray[7][$count]
22792 || $thingArray[7][$count] eq 'sentient' || $thingArray[7][$count] eq 'creature'
22793 || $thingArray[7][$count] eq 'race' || $thingArray[7][$count] eq 'guild'
22794 ) {
22795 INNER: foreach my $minionString ($self->ivKeys('minionStringHash')) {
22796  
22797 my $minionObj;
22798  
22799 if ($thingArray[1][$count] =~ m/$minionString/i) {
22800  
22801 # It's a minion
22802 $thingArray[7][$count] = 'minion';
22803 $thingArray[12][$count] = $minionString;
22804  
22805 # Is it one of our own minions?
22806 $minionObj = $self->ivShow('minionStringHash', $minionString);
22807 if ($minionObj->ownMinionFlag) {
22808 $thingArray[13][$count] = TRUE;
22809 } else {
22810 $thingArray[13][$count] = FALSE;
22811 }
22812  
22813 next OUTER;
22814 }
22815 }
22816 }
22817 }
22818  
22819 # Stage 14 - for each separate object, create a new non-model object, and put its blessed
22820 # reference into @returnArray
22821 #
22822 # e.g. 'Two big evil guards, a troll and three small torches.'
22823 #
22824 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22825 #
22826 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22827 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22828 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22829 #
22830 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n] [12][n] [13][n]
22831 #
22832 # [0] guard undef sentient undef big evil undef undef undef undef
22833 # [1] troll undef minion undef undef undef undef troll undef
22834 # [2] torch undef portable torch undef small undef undef undef
22835  
22836 # Trim unnecessary whitespace from every word (or group of words)
22837 OUTER: for (my $thing = 0; $thing < $thingCount; $thing++) {
22838  
22839 INNER: for (my $column = 0; $column < 11; $column++) {
22840  
22841 if (defined $thingArray[$column][$thing]) {
22842  
22843 $thingArray[$column][$thing]
22844 = $axmud::CLIENT->trimWhitespace($thingArray[$column][$thing]);
22845 }
22846 }
22847 }
22848  
22849 # Show debug information, if the global flag is set
22850 if ($axmud::CLIENT->debugParseObjFlag) {
22851  
22852 @columnList = (
22853 '(original)', # column 0
22854 '(base string)', # column 1
22855 '(multiple)', # column 2
22856 '(base string without pseudo noun/adjective)', # column 3
22857 '(pseudo adjective replacement)', # column 4
22858 '(1st noun)', # column 5
22859 '(other noun)', # column 6
22860 '(dictionary word type)', # column 7
22861 '(portable/decoration type)', # column 8
22862 '(1st adjective)', # column 9
22863 '(oth adjectives)', # column 10
22864 '(root adjective)', # column 11
22865 '(minion string)', # column 12
22866 '(own minion flag)', # column 13
22867 );
22868  
22869 $self->writeDebug('WORLD MODEL: Objects parsed: ' . $thingCount);
22870  
22871 OUTER: for (my $rowCount = 0; $rowCount < $thingCount; $rowCount++) {
22872  
22873 $self->writeDebug(' Object #' . ($rowCount + 1));
22874  
22875 INNER: for (my $columnCount = 0; $columnCount < 14; $columnCount++) {
22876  
22877 $self->writeDebug(
22878 ' Column ' . $columnCount . ' ' . $columnList[$columnCount],
22879 );
22880  
22881 if (defined $thingArray[$columnCount][$rowCount]) {
22882 $self->writeDebug(' ' . $thingArray[$columnCount][$rowCount]);
22883 } else {
22884 $self->writeDebug(' <undef>');
22885 }
22886 }
22887 }
22888  
22889 $self->writeDebug('WORLD MODEL: End of object parsing messages');
22890 }
22891  
22892 # Process each thing in $thingArray
22893 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22894  
22895 my ($total, $obj);
22896  
22897 # Don't create a non-model object for an unparsable thing
22898 if ($thingArray[5][$count] eq '(unparsed object)') {
22899  
22900 next OUTER;
22901 }
22902  
22903 # Each entry represents at least 1 object, even it its number is 0.5, 0.33 or -1
22904 $total = $thingArray[2][$count];
22905 if ($total < 2) {
22906  
22907 $total = 1;
22908 }
22909  
22910 # Sanity check - in case some idiot creates a room with "999999999 hobbits", limit
22911 # the number of world model objects to be created
22912 if ($total > $axmud::CLIENT->constParseObjMax) {
22913  
22914 $total = $axmud::CLIENT->constParseObjMax;
22915 }
22916  
22917 if ($total > 1 && $multipleFlag) {
22918  
22919 # Create a single object to represent '5 coins' or 'five coins'
22920 $obj = $self->createParsedObj($session, TRUE, \@thingArray, $count);
22921 if ($obj) {
22922  
22923 push (@returnArray, $obj);
22924 }
22925  
22926 } else {
22927  
22928 # If $total is 1, create a single object. Otherwise, create multiple objects,
22929 # e.g. create five objects for '5 axes'
22930 OUTER: for (my $number = 0; $number < $total; $number++) {
22931  
22932 $obj = $self->createParsedObj($session, FALSE, \@thingArray, $count);
22933 if ($obj) {
22934  
22935 push (@returnArray, $obj);
22936 }
22937 }
22938 }
22939 }
22940  
22941 # Parsing complete
22942 return @returnArray;
22943 }
22944  
22945 sub createParsedObj {
22946  
22947 # Called by $self->parseObj once for every non-model object to be created
22948 #
22949 # Expected arguments
22950 # $session - The parent GA::Session object
22951 # $multipleFlag - If flag is set to TRUE, treats '5 coins' as a single object, with its
22952 # ->multiple IV set to 5. If the flag is set to FALSE, treats '5
22953 # coins' as 5 seperate objects
22954 # $arrayRef - The 2D array containing information about objects in the world
22955 # collected during parsing
22956 # $count - The object in $arrayRef that's being processed. If $count = 3, then
22957 # we're processing the data in $$arrayRef[3][n]
22958 #
22959 # Return values
22960 # 'undef' on improper errors or if a non-model object isn't created
22961 # Otherwise returns the blessed reference of the object
22962  
22963 my ($self, $session, $multipleFlag, $arrayRef, $count, $check) = @_;
22964  
22965 # Local variables
22966 my (
22967 $dictObj, $obj, $deathFlag, $package,
22968 @wordList, @guildRaceList,
22969 %deathWordHash,
22970 );
22971  
22972 # Check for improper arguments
22973 if (
22974 ! defined $session || ! defined $multipleFlag || ! defined $arrayRef
22975 || ! defined $count || defined $check
22976 ) {
22977 return $axmud::CLIENT->writeImproper($self->_objClass . '->createParsedObj', @_);
22978 }
22979  
22980 # Import the current dictionary
22981 $dictObj = $session->currentDict;
22982  
22983 # For objects whose nouns are a known 'race' or 'guild' word, classify the object as a
22984 # 'sentient' (since 'sentient' has a higher priority, a word which is both a known
22985 # 'sentient' word and a known 'guild'/'race' word will already have been classified as a
22986 # 'sentient' object)
22987 # For known characters, if there's already a GA::ModelObj::Char, use that; otherwise, create
22988 # one
22989 if (defined $$arrayRef[7][$count] && $$arrayRef[7][$count] eq 'char') {
22990  
22991 if ($self->ivExists('knownCharHash', $$arrayRef[5][$count])) {
22992  
22993 # Use the existing object
22994 $obj = $self->ivShow('knownCharHash', $$arrayRef[5][$count])
22995  
22996 } else {
22997  
22998 # Create a new object temporarily, but don't save it in $self->knownCharHash
22999 $obj = Games::Axmud::ModelObj::Char->new(
23000 $session,
23001 $$arrayRef[5][$count], # Name
23002 FALSE, # Non-model object
23003 );
23004  
23005 if (! $obj) {
23006  
23007 # Couldn't create the non-model object
23008 return undef;
23009 }
23010 }
23011 }
23012  
23013 # For everything else...
23014 if (! $obj) {
23015  
23016 # Import the hash of death words
23017 %deathWordHash = $dictObj->deathWordHash;
23018  
23019 # Check all of the describing words (nouns, adjectives and unknowns); if any of them are
23020 # in the dictionary's deathlist, then this object is a corpse
23021 # Split [1][n] into words, so we can check each seperately
23022 @wordList = split(/\s+/, $$arrayRef[1][$count]);
23023 OUTER: foreach my $word (@wordList) {
23024  
23025 if (exists $deathWordHash{$word}) {
23026  
23027 # Death word found!
23028 $deathFlag = TRUE;
23029 last OUTER;
23030 }
23031 }
23032  
23033 # For dead things, classify it as a portable corpse
23034 if ($deathFlag) {
23035  
23036 # Dead minions are not GA::ModelObj::Minion objects!
23037 if (defined $$arrayRef[7][$count] && $$arrayRef[7][$count] eq 'minion') {
23038  
23039 $$arrayRef[12][$count] = undef;
23040 $$arrayRef[13][$count] = undef;
23041 }
23042  
23043 $$arrayRef[7][$count] = 'portable';
23044 $$arrayRef[8][$count] = 'corpse';
23045  
23046 # For unrecognised nouns (when [7][n] is 'undef'), classify them as 'decoration' for now
23047 } elsif (! defined $$arrayRef[7][$count] && ! $deathFlag) {
23048  
23049 $$arrayRef[7][$count] = 'decoration';
23050 $$arrayRef[8][$count] = 'other';
23051 }
23052  
23053 # Decide which package to use
23054 if ($$arrayRef[7][$count] eq 'guild' || $$arrayRef[7][$count] eq 'race') {
23055 $package = 'Games::Axmud::ModelObj::Sentient'; # Treat as a 'sentient'
23056 } else {
23057 $package = 'Games::Axmud::ModelObj::' . ucfirst($$arrayRef[7][$count]);
23058 }
23059  
23060 # Create the non-model object
23061 $obj = $package->new(
23062 $session,
23063 $$arrayRef[5][$count], # Name
23064 FALSE, # Non-model object
23065 );
23066  
23067 if (! $obj) {
23068  
23069 # Couldn't create the non-model object
23070 return undef;
23071 }
23072 }
23073  
23074 # Set the new object's IVs
23075  
23076 # Main noun
23077 $obj->ivPoke('noun', $$arrayRef[5][$count]);
23078 # (Default noun tag is the same as the main noun)
23079 $obj->ivPoke('nounTag', $$arrayRef[5][$count]);
23080  
23081 # Other nouns
23082 if (defined $$arrayRef[6][$count]) {
23083  
23084 @wordList = split(/\s+/, $$arrayRef[6][$count]);
23085 foreach my $word (@wordList) {
23086  
23087 $obj->ivPush('otherNounList', $word);
23088 }
23089 }
23090  
23091 # Adjective list
23092 if (defined $$arrayRef[9][$count]) {
23093  
23094 @wordList = split(/\s+/, $$arrayRef[9][$count]);
23095 foreach my $word (@wordList) {
23096  
23097 $obj->ivPush('adjList', $word);
23098 }
23099 }
23100  
23101 # Pseudo-adjective (modified)
23102 if (defined $$arrayRef[4][$count]) {
23103  
23104 $obj->ivPush('pseudoAdjList', $$arrayRef[4][$count]);
23105 }
23106  
23107 # Root adjective list
23108 if (defined $$arrayRef[11][$count]) {
23109  
23110 @wordList = split(/\s+/, $$arrayRef[11][$count]);
23111 foreach my $word (@wordList) {
23112  
23113 $obj->ivPush('rootAdjList', $word);
23114 }
23115 }
23116  
23117 # Unknown words
23118 if (defined $$arrayRef[10][$count]) {
23119  
23120 @wordList = split(/\s+/, $$arrayRef[10][$count]);
23121 foreach my $word (@wordList) {
23122  
23123 $obj->ivPush('unknownWordList', $word);
23124 }
23125 }
23126  
23127 # Minions
23128 if (defined $$arrayRef[12][$count]) {
23129  
23130 if ($$arrayRef[13][$count]) {
23131  
23132 $obj->ivPoke('ownMinionFlag', TRUE);
23133 }
23134 }
23135  
23136 # Set the multiple
23137 if ($multipleFlag) {
23138  
23139 # e.g. A single object represents '5 coins'
23140 $obj->ivPoke('multiple', $$arrayRef[2][$count]);
23141  
23142 } elsif ($$arrayRef[2][$count] > 1) {
23143  
23144 # e.g. One object is created for 'an axe', or five separate objects are created for
23145 # 'five axes'
23146 $obj->ivPoke('multiple', 1);
23147  
23148 } else {
23149  
23150 # When parsing 'half a cake', $$arrayRef[2][$count] is set to 0.5. Use that multiple
23151 # even though $multipleFlag isn't set
23152 $obj->ivPoke('multiple', $$arrayRef[2][$count]);
23153 }
23154  
23155 # Base string (e.g. 'big evil guards')
23156 $obj->ivPoke('baseString', $$arrayRef[1][$count]);
23157  
23158 # If it's a character, minion, sentient or creature object, we need to set those properties,
23159 # too
23160 if (
23161 $$arrayRef[7][$count] eq 'char' || $$arrayRef[7][$count] eq 'minion'
23162 || $$arrayRef[7][$count] eq 'sentient' || $$arrayRef[7][$count] eq 'creature'
23163 || $$arrayRef[7][$count] eq 'guild' # Treated as a 'sentient' object
23164 || $$arrayRef[7][$count] eq 'race' # Treated as a 'sentient' object
23165 ) {
23166 # Compile a list of words, any one of which might be a known guild or race word
23167  
23168 # Main noun
23169 @guildRaceList = ($$arrayRef[5][$count]);
23170  
23171 # Other nouns
23172 if (defined $$arrayRef[6][$count]) {
23173  
23174 push (@guildRaceList, split(/\s+/, $$arrayRef[6][$count]));
23175 }
23176  
23177 # Adjectives
23178 if (defined $$arrayRef[9][$count]) {
23179  
23180 push (@guildRaceList, split(/\s+/, $$arrayRef[9][$count]));
23181 }
23182  
23183 # Unknown words
23184 if (defined $$arrayRef[10][$count]) {
23185  
23186 push (@guildRaceList, split(/\s+/, $$arrayRef[10][$count]));
23187 }
23188  
23189 # Find the first word in @guildRaceList that's a known guild word, and use it
23190 OUTER: foreach my $word (@guildRaceList) {
23191  
23192 if ($dictObj->ivExists('guildHash', $word)) {
23193  
23194 $obj->ivPoke('guild', $word);
23195 last OUTER;
23196 }
23197 }
23198  
23199 # Find the first word in @guildRaceList that's a known race word, and use it
23200 OUTER: foreach my $word (@guildRaceList) {
23201  
23202 if ($dictObj->ivExists('raceHash', $word)) {
23203  
23204 $obj->ivPoke('race', $word);
23205 last OUTER;
23206 }
23207 }
23208 }
23209  
23210 # If it's a portable or decoration, we need to set its type
23211 if ($$arrayRef[7][$count] eq 'portable' || $$arrayRef[7][$count] eq 'decoration') {
23212  
23213 $obj->ivPoke('type', $$arrayRef[8][$count]);
23214 }
23215  
23216 # Object creation complete
23217 return $obj;
23218 }
23219  
23220 sub objCompare {
23221  
23222 # Can be called by anything to compare model objects (or non-model objects)
23223 #
23224 # Compares a $targetObj against a list of one or more possibly similar objects,
23225 # @compareList, to see whether $targetObj matches any of the objects in @compareList (i.e.
23226 # to see whether $targetObj seems to be the same object as an object in @compareList)
23227 # (If $targetObj is to be compared against a single object, then @compareList should contain
23228 # only one element)
23229 #
23230 # Assigns every object in @compareList a score from 0-100, with 0 representing totally
23231 # different objects and 100 representing absolutely identical objects
23232 # $sensitivity is also a number between 0-100. If anything in @compareList gets a score
23233 # equal to or greater than $sensitivity, we say that it matches $targetObj
23234 # We return the highest score of the first matching object, or 'undef' if no matching
23235 # objects are found
23236 # ->objCompare is very sensitive. If $targetObj has no adjectives, ->objCompare will assume
23237 # that a matching object also has no adjectives. For a less demanding comparison, use
23238 # $self->objMatch
23239 # Good values for $sensitivity are 70-80 (for a close match) or 90 (for a very close
23240 # match)
23241 #
23242 # Expected arguments
23243 # $sensitivity - A value between 0-100
23244 #
23245 # Optional arguments
23246 # $targetObj - Blessed reference of a model object (or non-model object). If 'undef',
23247 # no comparison takes place (but debug messages are displayed, if
23248 # allowed)
23249 # @compareList - List of objects against which to compare $targetObj. If an empty list,
23250 # no comparison takes place
23251 #
23252 # Return values
23253 # 'undef' on improper arguments or if nothing in @compareList matches $targetObj with a
23254 # high enough score
23255 # Otherwise, when the first match with a high enough score is found, returns the score
23256 # (which will be a value between 0-100, greater or equal to $sensitivity)
23257  
23258 my ($self, $sensitivity, $targetObj, @compareList) = @_;
23259  
23260 # Local variables
23261 my (@targetList, @otherList);
23262  
23263 # Check for improper arguments
23264 if (! defined $sensitivity) {
23265  
23266 return $axmud::CLIENT->writeImproper($self->_objClass . '->objCompare', @_);
23267 }
23268  
23269 # If no targets were specified, then there's nothing to compare
23270 if (! $targetObj || ! @compareList) {
23271  
23272 if ($axmud::CLIENT->debugCompareObjFlag) {
23273  
23274 $self->writeDebug('->objCompare');
23275 if (! $targetObj) {
23276 $self->writeDebug(' No target specified (code error?)');
23277 } elsif (! @compareList) {
23278 $self->writeDebug(' No comparison objects specified (code error?)');
23279 }
23280 }
23281  
23282 return undef;
23283 }
23284  
23285 OUTER: foreach my $compareObj (@compareList) {
23286  
23287 my $score;
23288  
23289 # Award points depending on matches between the two object's IVs
23290 $score = 0; # Points gained (out of 100)
23291  
23292 # Compare all possible nouns; if there are no nouns in common, the two objects can't
23293 # possibly be the same
23294 @targetList = ($targetObj->noun, $targetObj->otherNounList);
23295 @otherList = ($compareObj->noun, $compareObj->otherNounList);
23296 if (! $self->listCompare(\@targetList, \@otherList)) {
23297  
23298 # No nouns in common - objects must be different
23299 next OUTER;
23300 }
23301  
23302 # Check the main noun
23303 if ($targetObj->noun eq $compareObj->noun) {
23304  
23305 $score += 40;
23306 }
23307  
23308 # Check the other nouns
23309 @targetList = $targetObj->otherNounList;
23310 @otherList = $compareObj->otherNounList;
23311 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23312  
23313 # Check the adjectives
23314 @targetList = $targetObj->adjList;
23315 @otherList = $compareObj->adjList;
23316 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23317  
23318 # Check the pseudo-adjectives
23319 @targetList = $targetObj->pseudoAdjList;
23320 @otherList = $compareObj->pseudoAdjList;
23321 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23322  
23323 # Check the unknown word list
23324 @targetList = $targetObj->unknownWordList;
23325 @otherList = $compareObj->unknownWordList;
23326 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23327  
23328 # Don't need decimal places (and it ruins the confirmation message)
23329 $score = int($score);
23330  
23331 if ($axmud::CLIENT->debugCompareObjFlag) {
23332  
23333 $self->writeDebug('->objCompare');
23334 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23335 . $compareObj->noun . ', score ' . $score . ' (sensitivity ' . $sensitivity
23336 . ')',
23337 );
23338 }
23339  
23340 if ( $score >= $sensitivity) {
23341  
23342 # The two objects are close enough
23343 if ($axmud::CLIENT->debugCompareObjFlag) {
23344  
23345 $self->writeDebug(' Objects MATCH');
23346 }
23347  
23348 return $score;
23349 }
23350 }
23351  
23352 # None of the objects in @compareList match $targetObj at the specified sensitivity
23353 return undef;
23354 }
23355  
23356 sub objMatch {
23357  
23358 # Can be called by anything to compare model objects (or non-model objects)
23359 #
23360 # Compares a $targetObj against a list of one or more possibly similar objects,
23361 # @compareList, to see whether $targetObj matches any of the objects in @compareList (i.e.
23362 # to see whether $targetObj seems to be the same object as an object in @compareList)
23363 # (If $targetObj is to be compared against a single object, then @compareList should contain
23364 # only one element)
23365 #
23366 # Works much like $self->objCompare, except that this function is less demanding: it assumes
23367 # that objects in @compareList have incomplete IVs (e.g. perhaps having only their ->noun
23368 # IV set to something)
23369 # Only properties of objects in @compareList that have been set are checked against the IVs
23370 # in $targetObj
23371 # ->objCompare is more demanding - it expects that if $targetObj has no adjectives, the
23372 # things in @compareList will also have no adjectives
23373 #
23374 # Assigns every object in @compareList a score, which is then adjusted to create a
23375 # percentage score, with 0 representing totally different objects and 100 representing
23376 # objects that are complete matches
23377 # $sensitivity is also a number between 0-100. If anything in @compareList gets a score
23378 # equal to or greater than $sensitivity, we say that it matches $targetObj and return the
23379 # score. Otherwise, we return 'undef'
23380 # Good values for $sensitivity are 70-80 (for a close match) or 90 (for a very close
23381 # match).
23382 #
23383 # Expected arguments
23384 # $sensitivity - A value between 0-100
23385 # $targetObj - Blessed reference of a model object (or non-model object)
23386 #
23387 # Optional arguments
23388 # @compareList - List of objects against which to compare $targetObj (empty lists are
23389 # allowed)
23390 #
23391 # Return values
23392 # 'undef' on improper arguments or if nothing in @compareList matches $targetObj with a
23393 # high enough score
23394 # Otherwise, when the first match with a high enough score is found, returns the score
23395 # (which will be a value between 0-100, greater or equal to $sensitivity)
23396  
23397 my ($self, $sensitivity, $targetObj, @compareList) = @_;
23398  
23399 # Local variables
23400 my (@targetList, @otherList);
23401  
23402 # Check for improper arguments
23403 if (! defined $sensitivity || ! defined $targetObj) {
23404  
23405 return $axmud::CLIENT->writeImproper($self->_objClass . '->objMatch', @_);
23406 }
23407  
23408 # If @compareList is empty, then there's nothing to compare
23409 if (! @compareList) {
23410  
23411 return undef;
23412 }
23413  
23414 OUTER: foreach my $compareObj (@compareList) {
23415  
23416 my ($score, $maxScore, $percentage);
23417  
23418 # Award points depending on matches between the two object's IVs
23419 $score = 0; # Points gained
23420 $maxScore = 0; # Max points available (up to 100)
23421  
23422 # Compare all possible nouns; if there are no nouns in common, the two objects can't
23423 # possibly be the same
23424 @targetList = ($targetObj->noun, $targetObj->otherNounList);
23425 @otherList = ($compareObj->noun, $compareObj->otherNounList);
23426 if (! $self->listCompare(\@targetList, \@otherList)) {
23427  
23428 # No nouns in common - objects must be different
23429 next OUTER;
23430 }
23431  
23432 # Check the main noun (if $targetObj has one)
23433 if ($compareObj->noun && $targetObj->noun && $targetObj->noun eq $compareObj->noun) {
23434  
23435 $score += 40;
23436 $maxScore += 40;
23437 }
23438  
23439 # Check the other nouns (if $targetObj has any)
23440 if ($compareObj->otherNounList) {
23441  
23442 @targetList = $targetObj->otherNounList;
23443 @otherList = $compareObj->otherNounList;
23444 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23445 $maxScore += 15;
23446 }
23447  
23448 # Check the adjectives (if $targetObj has any)
23449 if ($compareObj->adjList) {
23450  
23451 @targetList = $targetObj->adjList;
23452 @otherList = $compareObj->adjList;
23453 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23454 $maxScore += 15;
23455 }
23456  
23457 # Check the pseudo-adjectives (if $targetObj has any)
23458 if ($compareObj->pseudoAdjList) {
23459  
23460 @targetList = $targetObj->pseudoAdjList;
23461 @otherList = $compareObj->pseudoAdjList;
23462 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23463 $maxScore += 15;
23464 }
23465  
23466 # Check the unknown word list (if $targetObj has any)
23467 if ($compareObj->unknownWordList) {
23468  
23469 @targetList = $targetObj->unknownWordList;
23470 @otherList = $compareObj->unknownWordList;
23471 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23472 $maxScore += 15;
23473 }
23474  
23475 # We don't want to divide by zero...
23476 if (! $score) {
23477  
23478 if ($axmud::CLIENT->debugCompareObjFlag) {
23479  
23480 $self->writeDebug('->objMatch');
23481 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23482 . $compareObj->noun . ', score ' . $score . ' (sensitivity ' . $sensitivity
23483 . ')',
23484 );
23485 }
23486  
23487 next OUTER;
23488 }
23489  
23490 # Adjust $score so that it's a score out of 100
23491 $percentage = int(($score / $maxScore) * 100);
23492  
23493 if ($axmud::CLIENT->debugCompareObjFlag) {
23494  
23495 $self->writeDebug('->objMatch');
23496 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23497 . $compareObj->noun . ', score ' . $score . ', max score ' . $maxScore
23498 . ', percentage ' . $percentage . '% (sensitivity ' . $sensitivity . ')',
23499 );
23500 }
23501  
23502 if ( $percentage >= $sensitivity) {
23503  
23504 # The two objects are close enough
23505 if ($axmud::CLIENT->debugCompareObjFlag) {
23506  
23507 $self->writeDebug(' Objects MATCH');
23508 }
23509  
23510 return $percentage;
23511 }
23512 }
23513  
23514 # None of the objects in @compareList match $targetObj at the specified sensitivity
23515 return undef;
23516 }
23517  
23518 sub listCompare {
23519  
23520 # Called by $self->objCompare and $self->objMatch
23521 #
23522 # Calculates the intersection between two lists, and returns a value between 0 and 1
23523 # e.g. 0 means no common elements in the lists
23524 # e.g. 1 means the lists are identical
23525 # e.g. 0.5 would be the return value for the lists (fred, barney, wilma, betty) and
23526 # (fred, barney) (because 50% of the elements of the shorter list are present in the
23527 # longer one)
23528 # N.B. It doesn't matter which of the two lists is larger
23529 #
23530 # Expected arguments
23531 # targetListRef - Reference to an (anonymous) list, e.g. the adjectives describing a
23532 # non-model object
23533 # objectListRef - Reference to an (anonymous) list, e.g. the adjectives describing a
23534 # different non-model object
23535 #
23536 # Return values
23537 # 0 (not 'undef') on improper arguments
23538 # Otheriwse, retuns a decimal number between 0 and 1
23539  
23540 my ($self, $targetListRef, $objectListRef, $check) = @_;
23541  
23542 # Local variables
23543 my (
23544 @targetList, @objectList, @intersection,
23545 %grepHash,
23546 );
23547  
23548 # Check for improper arguments
23549 if (! defined $targetListRef || ! defined $objectListRef || defined $check) {
23550  
23551 $axmud::CLIENT->writeImproper($self->_objClass . '->listCompare', @_);
23552 return 0;
23553 }
23554  
23555 # De-reference the passed lists
23556 @targetList = @$targetListRef;
23557 @objectList = @$objectListRef;
23558  
23559 # Find the intersection between the two lists
23560 if (! @targetList && ! @objectList) {
23561  
23562 # Identical (empty) lists
23563 return 1;
23564  
23565 } elsif (@targetList && @objectList) {
23566  
23567 # Neither list is empty
23568 %grepHash = map{$_ =>1} @targetList;
23569 @intersection = grep( $grepHash{$_}, @objectList);
23570  
23571 if (@targetList > @objectList) {
23572  
23573 # Return percentage of elements in @objectList that also appear in @targetList
23574 return (scalar @intersection / @targetList);
23575  
23576 } else {
23577  
23578 # Return percentage of elements in @targetList that also appear in @objectList
23579 return (scalar @intersection / @objectList);
23580 }
23581  
23582 } else {
23583  
23584 # One of the lists is empty, so they are not at all alike
23585 return 0;
23586 }
23587 }
23588  
23589 sub compileRedrawRooms {
23590  
23591 # Called by several functions (e.g. called by ->moveRoomsLabels)
23592 # Given a list of rooms which must be redrawn, expand that list to include any connecting
23593 # rooms (which guarantees that the exits between them are redrawn correctly)
23594 # Returns a list in the form that GA::Win::Map->markObjs expects
23595 #
23596 # Expected arguments
23597 # (none besides $self)
23598 #
23599 # Optional arguments
23600 # @roomList - A list of room model objects (can be an empty list)
23601 #
23602 # Return values
23603 # An empty list on improper arguments or if @roomList is empty
23604 # Otherwise, returns the expanded list of rooms, in the form
23605 # (string, room_object, string, room_object...)
23606 # ...where 'string' is the literal string 'room', and 'room_object' is an affected room
23607 # object (GA::ModelObj::Room)
23608  
23609 my ($self, @roomList) = @_;
23610  
23611 # Local variables
23612 my (
23613 @returnList,
23614 %checkHash,
23615 );
23616  
23617 # (No improper arguments to check)
23618  
23619 # Compile a hash of specified rooms (to eliminate duplicates)
23620 foreach my $roomObj (@roomList) {
23621  
23622 $checkHash{$roomObj->number} = $roomObj;
23623 }
23624  
23625 # Add any connected rooms to that hash
23626 foreach my $roomObj (@roomList) {
23627  
23628 foreach my $exitNum (
23629 # Add rooms connected by outgoing exits
23630 $roomObj->ivValues('exitNumHash'),
23631 # Add rooms connected by incoming one-way, uncertain (etc) exits
23632 $roomObj->ivKeys('uncertainExitHash'),
23633 $roomObj->ivKeys('oneWayExitHash'),
23634 $roomObj->ivKeys('randomExitHash'),
23635 ) {
23636 my ($exitObj, $roomObj);
23637  
23638 $exitObj = $self->ivShow('exitModelHash', $exitNum);
23639 if ($exitObj) {
23640  
23641 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
23642 if ($roomObj) {
23643  
23644 $checkHash{$roomObj->number} = $roomObj;
23645 }
23646 }
23647 }
23648  
23649 # Also add destination rooms for any involuntary/repulse exit patterns which specify a
23650 # destination
23651 foreach my $roomNum ($roomObj->ivKeys('invRepExitHash')) {
23652  
23653 my $roomObj = $self->ivShow('modelHash', $roomNum);
23654 if ($roomObj) {
23655  
23656 $checkHash{$roomObj->number} = $roomObj;
23657 }
23658 }
23659 }
23660  
23661 # Compose a list in the form (string, object, string, object...)
23662 foreach my $roomObj (values %checkHash) {
23663  
23664 push (@returnList, 'room', $roomObj);
23665 }
23666  
23667 # Operation complete
23668 return @returnList;
23669 }
23670  
23671 sub findObjNumber {
23672  
23673 # In a room filled with 'three hairy orcs, two ugly orcs and a dwarf', with corresponding
23674 # model objects stored in the Locator task's ->tempObjList IV as follows:
23675 #
23676 # object1 'hairy orc'
23677 # object2 'hairy orc'
23678 # object3 'hairy orc'
23679 # object4 'ugly orc'
23680 # object5 'ugly orc'
23681 # object6 'dwarf'
23682 #
23683 # ...this function works out the object's likely number on a world which numbers them
23684 # 'hairy orc 1', 'hairy orc2' or 'orc 1', ... 'orc 5'
23685 # This function is called with the blessed reference for one of these objects, $completeObj.
23686 # The function's task is to find how many of the objects occuring in the list up to and
23687 # including $completeObj match a partially-defined model object, $partialObj
23688 #
23689 # e.g. If $completeObj is object4, and if $partialObj is an 'orc', this function returns 4
23690 # If $completeObj is object4, and if $partialObj is an 'ugly orc', returns 1
23691 # If $completeObj does not appear in the Locator task's ->tempObjList, returns 'undef'
23692 #
23693 # Expected arguments
23694 # $session - The parent GA::Session
23695 # $completeObj - A real object in the Locator task's current room
23696 # $partialObj - A partially-defined matching object
23697 #
23698 # Return values
23699 # 'undef' on improper arguments, if $completeObj doesn't appear in the Locator task's
23700 # ->tempObjList or if the Locator task isn't running
23701 # Otherwise returns a number, 1 or above, matching the object's likely numbering on the
23702 # world
23703  
23704 my ($self, $session, $completeObj, $partialObj, $check) = @_;
23705  
23706 # Local variables
23707 my ($taskObj, $posn, $count, $number);
23708  
23709 # Check for improper arguments
23710 if (
23711 ! defined $session || ! defined $completeObj || ! defined $partialObj || defined $check
23712 ) {
23713 return $axmud::CLIENT->writeImproper($self->_objClass . '->findObjNumber', @_);
23714 }
23715  
23716 # Import the Locator task
23717 $taskObj = $session->locatorTask;
23718  
23719 # Check that there is a Locator task running and that $completeObj really is in the task's
23720 # current room
23721 if (! $taskObj || ! $taskObj->roomObj || ! $taskObj->roomObj->tempObjList) {
23722  
23723 return undef;
23724 }
23725  
23726 # Find $completeObj's position in the current room's object list
23727 $posn = $taskObj->roomObj->ivFind('tempObjList', $completeObj);
23728 if (! defined $posn) {
23729  
23730 # Not in the current room
23731 return undef;
23732  
23733 } elsif ($posn == 1) {
23734  
23735 # The world must number this object as #1
23736 return 1;
23737 }
23738  
23739 # Check every object in the list before $posn, to see how many match $partialObj
23740 $number = 1; # $completeObj matches $partialObj
23741 for (my $count = 0; $count < $posn; $count++) {
23742  
23743 if (
23744 $self->objMatch(
23745 100,
23746 $partialObj,
23747 $taskObj->roomObj->ivIndex('tempObjList', $count),
23748 )
23749 ) {
23750 $number++;
23751 }
23752 }
23753  
23754 return $number;
23755 }
23756  
23757 sub findRegionmap {
23758  
23759 # Can be called by anything
23760 # Given the ->number of a region model object (GA::ModelObj::Region), returns the equivalent
23761 # regionmap object (GA::Obj::Regionmap)
23762 #
23763 # Expected arguments
23764 # $number - The number of a region model object
23765 #
23766 # Return values
23767 # 'undef' on improper arguments or if no matching regionmap is found
23768 # Otherwise returns the matching GA::Obj::Regionmap
23769  
23770 my ($self, $number, $check) = @_;
23771  
23772 # Local variables
23773 my $regionObj;
23774  
23775 # Check for improper arguments
23776 if (! defined $number || defined $check) {
23777  
23778 return $axmud::CLIENT->writeImproper($self->_objClass . '->findRegionmap', @_);
23779 }
23780  
23781 $regionObj = $self->ivShow('regionModelHash', $number);
23782 if (! $regionObj) {
23783  
23784 return undef;
23785  
23786 } else {
23787  
23788 return $self->ivShow('regionmapHash', $regionObj->name);
23789 }
23790 }
23791  
23792 sub reversePath {
23793  
23794 # Attempts to convert a path, consisting of a list of directions, into the opposite path
23795 # To convert a single direction, pass a list containing just the direction
23796 # e.g. $pathList[0] = 'n' -> 's'
23797 # To convert a string consisting of several movement commands separated by the command
23798 # separator, pass a list containing just the string
23799 # e.g. $pathList[0] = 'n;nw;w;n;u' -> 'd;s;e;se;s'
23800 # To convert a list of directions, pass the list. The directions are converted into their
23801 # opposites and the list is returned in the opposite order
23802 # e.g. @pathList = ('n', 'nw', 'w') -> ('e', 'se', 's')
23803 # Only standard directions are converted into opposites. Other kinds of directions are left
23804 # alone, under the assumption that the same word is used for the exit in both directions
23805 # e.g. $pathList[0] = 'n;nw;closet;d' -> 'd;closet;se;s'
23806 # Standard secondary directions can have more than one opposite. Also, all the opposite
23807 # directions in the list can be converted to abbreviated forms, if required
23808 #
23809 # Expected arguments
23810 # $session - The calling GA::Session
23811 # $mode - 'no_abbrev' - do not abbreviate / if there is more than one opposite
23812 # direction, use the first one
23813 # - 'abbrev' - abbreviate / if there is more than one opposite direction, use
23814 # the first one
23815 # - 'no_abbrev_opp' - do not abbreviate / return all opposite directions
23816 # - 'abbrev_opp' - abbreviate / return all opposite directions
23817 # @pathList - a list of strings containing single directions or paths
23818 #
23819 # Notes
23820 # For $modes 'no_abbrev_opp' and 'abbrev_opp', the opposite directions are returned as a
23821 # string separated by a space, just as they occur in the dictionary
23822 # e.g. 'entrance' -> 'exit out'
23823 # In that case, it's up to the calling function to choose which direction to use
23824 #
23825 # Return values
23826 # An empty list on improper arguments (including if @pathList is empty or $mode isn't
23827 # a valid value)
23828 # Otherwise returns the reversed list of directions, as described above
23829  
23830 my ($self, $session, $mode, @pathList) = @_;
23831  
23832 # Local variables
23833 my (
23834 $cmdSep, $dictObj,
23835 @emptyList,
23836 );
23837  
23838 # Check for improper arguments
23839 if (
23840 ! defined $mode
23841 || (
23842 $mode ne 'no_abbrev' && $mode ne 'abbrev' && $mode ne 'no_abbrev_opp'
23843 && $mode ne 'abbrev_opp'
23844 )
23845 || ! @pathList
23846 ) {
23847 $axmud::CLIENT->writeImproper($self->_objClass . '->reversePath', @_);
23848 return @emptyList;
23849 }
23850  
23851 $cmdSep = $axmud::CLIENT->cmdSep;
23852 $dictObj = $session->currentDict;
23853  
23854 foreach my $path (@pathList) {
23855  
23856 my @dirList = split(/$cmdSep/, $path);
23857  
23858 foreach my $dir (@dirList) {
23859  
23860 # If it's a standard direction, convert it into the opposite standard direction. If
23861 # it's not a standard direction, don't change it
23862 if ($dictObj->ivExists('combDirHash', $dir)) {
23863  
23864 # Do not abbreviate
23865 if ($mode eq 'no_abbrev' || $mode eq 'no_abbrev_opp') {
23866  
23867 $dir = $dictObj->ivShow('combOppDirHash', $dir);
23868  
23869 # Abbreviate
23870 } elsif ($mode eq 'abbrev' || $mode eq 'abbrev_opp') {
23871  
23872 $dir = $dictObj->abbrevDir($dictObj->ivShow('combOppDirHash', $dir));
23873 }
23874  
23875 # If there is more than one opposite direction, use the first one
23876 if ($mode eq 'no_abbrev' || $mode eq 'abbrev') {
23877  
23878 my $position = index($dir, ' ');
23879 if ($position > -1) {
23880  
23881 $dir = substr($dir, ($position -1));
23882 }
23883 }
23884 }
23885 }
23886  
23887 @dirList = reverse @dirList;
23888 $path = join($cmdSep, @dirList);
23889 }
23890  
23891 @pathList = reverse @pathList;
23892 return (@pathList);
23893 }
23894  
23895 sub checkExitState {
23896  
23897 # Called by GA::Task::Locator->processExits (or by any other code)
23898 # On some worlds, the verbose list of exits indicates the state of an exit by surrounding
23899 # some (or all) exits with exit state strings, e.g. the brackets in
23900 # 'Obvious exits : north, (east), west'
23901 # Given a string containing a single exit (e.g. 'north' or '(east)'), this function removes
23902 # the exit state strings from the beginning, middle or end of each exit, if they occur,
23903 # and returns both the modified string and the corresponding exit state (one of the
23904 # possible values of GA::Obj::Exit->exitState, e.g. 'locked')
23905 #
23906 # Expected arguments
23907 # $profObj - The calling session's current world profile object
23908 # $exit - A string containing a single exit, optionally starting/ending or
23909 # containing exit state strings
23910 #
23911 # Return values
23912 # An empty list on improper arguments
23913 # Otherwise, returns a list in the form
23914 # (state, mod_exit)
23915 # ...where 'state' is one of the possible values of GA::Obj::Exit->exitState (e.g. 'open',
23916 # 'closed', impass'), and 'mod_exit' is the modified form of $exit, with all valid
23917 # exit state strings removed
23918  
23919 my ($self, $profObj, $exit, $check) = @_;
23920  
23921 # Local variables
23922 my (@emptyList, @stringList);
23923  
23924 # Check for improper arguments
23925 if (! defined $profObj || ! defined $exit || defined $check) {
23926  
23927 $axmud::CLIENT->writeImproper($self->_objClass . '->checkExitState', @_);
23928 return @emptyList,
23929 }
23930  
23931 @stringList = $profObj->exitStateStringList;
23932 if (@stringList) {
23933  
23934 do {
23935  
23936 my ($state, $start, $middle, $end, $result, $modExit);
23937  
23938 $state = shift @stringList;
23939 $start = shift @stringList;
23940 $middle = shift @stringList;
23941 $end = shift @stringList;
23942  
23943 # Test the exit for exit state strings, and remove them if found (e.g. remove the
23944 # brackets from '(east)'
23945 ($result, $modExit) = $self->testExitState(
23946 $exit,
23947 $start,
23948 $middle,
23949 $end,
23950 );
23951  
23952 if ($result) {
23953  
23954 return ($state, $modExit);
23955 }
23956  
23957 } until (! @stringList);
23958 }
23959  
23960 # Default exit state is 'normal' (exit is passable, or state not known)
23961 return ('normal', $exit);
23962 }
23963  
23964 sub testExitState {
23965  
23966 # Called by $self->checkExitState (only)
23967 # On some worlds, the verbose list of exits indicates the state of an exit by surrounding
23968 # some (or all) exits with exit state strings, e.g. the brackets in
23969 # 'Obvious exits : north, (east), west'
23970 # On some other worlds, the verbose list of exits indicates an exit state by surrounding
23971 # some characters at the beginning (usually just one character) with symbols, e.g.
23972 # 'Obvious exits : (n)orth, east, (w)est'
23973 # This function tests an exit string like 'north', '(north)' or '(n)orth' to see if it
23974 # contains a set of exit state strings, and then returns a list containing the result of
23975 # the test and a modified exit string, with the exit state strings removed if found
23976 #
23977 # Expected arguments
23978 # $exit - A string containing a single exit, optionally containing exit state
23979 # strings
23980 #
23981 # Optional arguments
23982 # $start - A string containing characters that should be found at the beginning of
23983 # $exit (an empty string, if nothing should be removed from the beginning)
23984 # $middle - A string containing characters that should be found in the middle of
23985 # $exit (or an empty string)
23986 # $end - A string containing characters that should be found at the end of $exit
23987 # (or an empty string)
23988 #
23989 # Return values
23990 # An empty list on improper arguments
23991 # Otherwise, returns a list in the form
23992 # (result, mod_exit)
23993 # ...where 'result' is TRUE if all the expected exit state strings are present (FALSE if
23994 # not) and where 'mod_exit' is the modified form of $exit, with all the exit state
23995 # strings removed
23996  
23997 my ($self, $exit, $start, $middle, $end, $check) = @_;
23998  
23999 # Local variables
24000 my (
24001 $modExit, $posn,
24002 @emptyList,
24003 );
24004  
24005 # Check for improper arguments
24006 if (
24007 ! defined $exit || ! defined $start || ! defined $middle || ! defined $end
24008 || defined $check
24009 ) {
24010 $axmud::CLIENT->writeImproper($self->_objClass . '->testExitState', @_);
24011 return @emptyList;
24012 }
24013  
24014 # Special case: if $start, $middle and $end are all empty strings, then no exit state is
24015 # detectable (and the exit's state will be set to 'normal'
24016 if (! $start && ! $middle && ! $end) {
24017  
24018 return (FALSE, $exit);
24019 }
24020  
24021 # $exit (e.g. 'north') has already been reduced to lower-case characters, so we must also
24022 # make sure that $start, $middle and $end are lower-case characters
24023 $start = lc($start);
24024 $middle = lc($middle);
24025 $end = lc($end);
24026  
24027 $modExit = $exit;
24028  
24029 if ($start) {
24030  
24031 if (index($modExit, $start) == 0) {
24032  
24033 # Remove the exit state string
24034 $modExit = substr($modExit, (length $start));
24035  
24036 } else {
24037  
24038 # Exit state strings not found. Return the exit string unmodified
24039 return (FALSE, $exit);
24040 }
24041 }
24042  
24043 # If $middle and $end are both non-empty strings, $middle must occur before $end. If only
24044 # $middle is set, it can occur in the middle or at the end. If only $end is set, it can
24045 # occur only at the end
24046 # Removing $middle before looking for $end accomplishes this
24047 if ($middle) {
24048  
24049 # (Second symbol can occur in middle or at end of $exit)
24050 $posn = index($modExit, $middle);
24051 if ($posn > -1) {
24052  
24053 substr($modExit, $posn, length($middle)) = '';
24054  
24055 } else {
24056  
24057 # Exit state strings not found. Return the exit string unmodified
24058 return (FALSE, $exit);
24059 }
24060 }
24061  
24062 if ($end) {
24063  
24064 $posn = index($modExit, $end);
24065 if ($posn > -1 && $posn == (length($modExit) - length($end))) {
24066  
24067 substr($modExit, $posn, length($end)) = '';
24068  
24069 } else {
24070  
24071 # Exit state strings not found. Return the exit string unmodified
24072 return (FALSE, $exit);
24073 }
24074 }
24075  
24076 # All expected exit state strings found
24077 return (TRUE, $modExit);
24078 }
24079  
24080 sub checkRoomAlignment {
24081  
24082 # Called by GA::Win::Map->moveSelectedObjects, $self->connectRegionBrokenExit and
24083 # $self->modifyIncomingExits
24084 # When an exit, which was formerly a region exit, is involved in a move operation, and when
24085 # that move places the exit's parent room and the destination room in the same regionmap,
24086 # it is probably now a broken exit
24087 # However, if (by chance) the two rooms are aligned along the direction of the exit, it's
24088 # not a broken exit but a normal one
24089 # In addition, we check whether there are any existing rooms in a direct line between the
24090 # two rooms. If any existing rooms are found, we consider that the two rooms aren't
24091 # aligned
24092 # NB Rooms are only considered to be aligned along the north-south, east-west,
24093 # northeast-southwest, northwest-southeast and up-down axes
24094 #
24095 # We also perform the same check in a 'connect to click' operation and when adding an exit
24096 # manually
24097 #
24098 # Expected arguments
24099 # $session - The calling function's GA::Session
24100 # $exitObj - The GA::Obj::Exit object to check
24101 #
24102 # Return values
24103 # 'undef' on improper arguments, if the exit is a retracing exit, if the two rooms aren't
24104 # aligned or if there are existing rooms between the exit's departure and arrival
24105 # rooms
24106 # 1 if the two rooms are aligned
24107  
24108 my ($self, $session, $exitObj, $check) = @_;
24109  
24110 # Local variables
24111 my (
24112 $departRoomObj, $arriveRoomObj, $regionmapObj, $mapDir, $listRef, $xPos, $yPos, $zPos,
24113 $xVector, $yVector, $zVector, $count,
24114 %vectorHash,
24115 );
24116  
24117 # Check for improper arguments
24118 if (! defined $session || ! defined $exitObj || defined $check) {
24119  
24120 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRoomAlignment', @_);
24121 }
24122  
24123 # Sanity check: we can't check for a room alignment if the exit's ->mapDir is not set (which
24124 # it won't be, if it's unallocatable)
24125 if (! $exitObj->mapDir) {
24126  
24127 return undef;
24128 }
24129  
24130 # Get a shortcut for the exit's ->mapDir
24131 $mapDir = $exitObj->mapDir;
24132 # We can check that ->mapDir isn't in a northnortheast direction (etc) by checking if its
24133 # length is greater than ten characters (e.g. northwest is only 9)
24134 if (length ($exitObj->mapDir) > 10) {
24135  
24136 # We don't consider that the rooms are aligned
24137 return undef;
24138 }
24139  
24140 # Get the blessed references of the exit's parent room and of the destination room
24141 $departRoomObj = $self->ivShow('modelHash', $exitObj->parent);
24142 $arriveRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
24143 # Get the regionmap to check
24144 $regionmapObj = $self->findRegionmap($departRoomObj->parent);
24145  
24146 # Import the vector hash, in the form
24147 # %vectorHash => {
24148 # north => [0, -1, 0],
24149 # northeast => [1, -1, 0],
24150 # east => [1, 0, 0],
24151 # southeast => [1, 1, 0],
24152 # south => [0, 1, 0],
24153 # southwest => [-1, 1, 0],
24154 # west => [-1, 0, 0],
24155 # northwest => [-1, -1, 0],
24156 # up => [0, 0, 1],
24157 # down => [0, 0, -1],
24158 # },
24159 # NB It also includes entries for northnorthwest, etc, but we're not using them
24160 %vectorHash = $session->mapWin->constVectorHash;
24161 $listRef = $vectorHash{$mapDir};
24162  
24163 # Check the general direction between the two rooms
24164 if (
24165 # Movement along x axis (west -> east)
24166 (($$listRef[0] == 0) && ($departRoomObj->xPosBlocks != $arriveRoomObj->xPosBlocks))
24167 || (($$listRef[0] == 1) && ($departRoomObj->xPosBlocks >= $arriveRoomObj->xPosBlocks))
24168 || (($$listRef[0] == -1) && ($departRoomObj->xPosBlocks <= $arriveRoomObj->xPosBlocks))
24169 # Movement along y axis (north -> south)
24170 || (($$listRef[1] == 0) && ($departRoomObj->yPosBlocks != $arriveRoomObj->yPosBlocks))
24171 || (($$listRef[1] == 1) && ($departRoomObj->yPosBlocks >= $arriveRoomObj->yPosBlocks))
24172 || (($$listRef[1] == -1) && ($departRoomObj->yPosBlocks <= $arriveRoomObj->yPosBlocks))
24173 # Movement along z axis (down > up)
24174 || (($$listRef[2] == 0) && ($departRoomObj->zPosBlocks != $arriveRoomObj->zPosBlocks))
24175 || (($$listRef[2] == 1) && ($departRoomObj->zPosBlocks >= $arriveRoomObj->zPosBlocks))
24176 || (($$listRef[2] == -1) && ($departRoomObj->zPosBlocks <= $arriveRoomObj->zPosBlocks))
24177 ) {
24178 # The rooms are not aligned
24179 return undef;
24180 }
24181  
24182 # Check that the path between the two rooms is in one of the ten primary directions checked
24183 # by this function
24184 $xVector = $arriveRoomObj->xPosBlocks - $departRoomObj->xPosBlocks;
24185 $yVector = $arriveRoomObj->yPosBlocks - $departRoomObj->yPosBlocks;
24186 $zVector = $arriveRoomObj->zPosBlocks - $departRoomObj->zPosBlocks;
24187  
24188 # Remove minus signs so we can test whether the magnitudes of $xVector and $yVector are
24189 # the same
24190 if ($xVector < 0) {$xVector *= -1};
24191 if ($yVector < 0) {$yVector *= -1};
24192  
24193 if (
24194 # ne, se, sw, nw
24195 ! (
24196 $$listRef[0] && $$listRef[1] && (! $$listRef[2])
24197 && $xVector && $yVector && (! $zVector) && $xVector == $yVector
24198 )
24199 # n, s
24200 && ! (
24201 (! $$listRef[0]) && $$listRef[1] && (! $$listRef[2])
24202 && (! $xVector) && $yVector && (! $zVector)
24203 )
24204 # w, e
24205 && ! (
24206 $$listRef[0] && (! $$listRef[1]) && (! $$listRef[2])
24207 && $xVector && (! $yVector) && (! $zVector)
24208 )
24209 # u, d
24210 && ! (
24211 (! $$listRef[0]) && (! $$listRef[1]) && $$listRef[2]
24212 && (! $xVector) && (! $yVector) && $zVector
24213 )
24214 ) {
24215 # The rooms are not aligned
24216 return undef;
24217 }
24218  
24219 # Check that there are no existing rooms in between $departRoomObj and $arriveRoomObj that
24220 # would clash with the drawn exit
24221 $xPos = $departRoomObj->xPosBlocks;
24222 $yPos = $departRoomObj->yPosBlocks;
24223 $zPos = $departRoomObj->zPosBlocks;
24224 $count = 0;
24225 do {
24226  
24227 $count++;
24228  
24229 # Check the next gridblock on the flightpath between $departRoomObj and
24230 # $arriveRoomObj
24231 $xPos += $$listRef[0];
24232 $yPos += $$listRef[1];
24233 $zPos += $$listRef[2];
24234  
24235 if (
24236 $xPos == $arriveRoomObj->xPosBlocks
24237 && $yPos == $arriveRoomObj->yPosBlocks
24238 && $zPos == $arriveRoomObj->zPosBlocks
24239 ) {
24240 # We've checked every gridblock between the two rooms, and found no existing
24241 # rooms on the way. In addition, the rooms are aligned in the direction
24242 # drawn as $mapDir
24243 return 1;
24244  
24245 } else {
24246  
24247 # If there's a room in this gridblock, return 0 to show that the exit can't
24248 # be drawn here, and that it must therefore be marked as a broken exit
24249 if ($regionmapObj->fetchRoom($xPos, $yPos, $zPos)) {
24250  
24251 return undef;
24252 }
24253 }
24254  
24255 # Don't bother looking beyond the maximum drawn exit size (currently 16)
24256 } until ($count >= $self->maxExitLengthBlocks);
24257  
24258 return 1;
24259 }
24260  
24261 ##################
24262 # Accessors - set
24263  
24264 # Definitely keep
24265  
24266 sub set_adjacentMode {
24267  
24268 my ($self, $mode, $count, $check) = @_;
24269  
24270 # Check for improper arguments
24271 if (! defined $mode || defined $check) {
24272  
24273 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_adjacentMode', @_);
24274 }
24275  
24276 # Update IVs
24277 $self->ivPoke('adjacentMode', $mode);
24278 if (defined $count) {
24279  
24280 $self->ivPoke('adjacentCount', $count);
24281 }
24282  
24283 return 1;
24284 }
24285  
24286 sub set_autoCompareMax {
24287  
24288 my ($self, $number, $check) = @_;
24289  
24290 # Check for improper arguments
24291 if (! defined $number || defined $check) {
24292  
24293 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoCompareMax', @_);
24294 }
24295  
24296 # Update IVs
24297 $self->ivPoke('autoCompareMax', $number);
24298  
24299 return 1;
24300 }
24301  
24302 sub set_autoSlideMax {
24303  
24304 my ($self, $number, $check) = @_;
24305  
24306 # Check for improper arguments
24307 if (! defined $number || defined $check) {
24308  
24309 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoSlideMax', @_);
24310 }
24311  
24312 # Update IVs
24313 $self->ivPoke('autoSlideMax', $number);
24314  
24315 return 1;
24316 }
24317  
24318 sub set_autoOpenWinFlag {
24319  
24320 # Called by GA::Cmd::ToggleAutomapper->do
24321  
24322 my ($self, $flag, $check) = @_;
24323  
24324 # Check for improper arguments
24325 if (! defined $flag || defined $check) {
24326  
24327 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoOpenWinFlag', @_);
24328 }
24329  
24330 if ($flag) {
24331 $self->ivPoke('autoOpenWinFlag', TRUE);
24332 } else {
24333 $self->ivPoke('autoOpenWinFlag', FALSE);
24334 }
24335  
24336 # Also need to update the check button in every Automapper window
24337 foreach my $mapWin ($self->collectMapWins()) {
24338  
24339 $self->worldModelObj->toggleFlag(
24340 'autoOpenWinFlag',
24341 $self->autoOpenWinFlag,
24342 FALSE, # Don't call $mapWin->drawRegion
24343 'auto_open_win',
24344 );
24345 }
24346  
24347 return 1;
24348 }
24349  
24350 sub add_buttonSet {
24351  
24352 # Called by GA::Win::Map->addToolbar
24353  
24354 my ($self, $set, $check) = @_;
24355  
24356 # Check for improper arguments
24357 if (! defined $set || defined $check) {
24358  
24359 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_buttonSet', @_);
24360 }
24361  
24362 $self->ivPush('buttonSetList', $set);
24363  
24364 return 1;
24365 }
24366  
24367 sub del_buttonSet {
24368  
24369 # Called by GA::Win::Map->removeToolbar
24370  
24371 my ($self, $set, $check) = @_;
24372  
24373 # Local variables
24374 my @list;
24375  
24376 # Check for improper arguments
24377 if (! defined $set || defined $check) {
24378  
24379 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_buttonSet', @_);
24380 }
24381  
24382 foreach my $item ($self->buttonSetList) {
24383  
24384 if ($item ne $set) {
24385  
24386 push (@list, $item);
24387 }
24388 }
24389  
24390 $self->ivPoke('buttonSetList', @list);
24391  
24392 return 1;
24393 }
24394  
24395 sub set_buttonSetList {
24396  
24397 # Called by GA::Win::Map->enableToolbar
24398  
24399 my ($self, @list) = @_;
24400  
24401 # (No improper arguments to check)
24402  
24403 $self->ivPoke('buttonSetList', @list);
24404  
24405 return 1;
24406 }
24407  
24408 sub set_exitAltDir {
24409  
24410 my ($self, $exitObj, $string, $check) = @_;
24411  
24412 # Check for improper arguments
24413 if (! defined $exitObj || defined $check) {
24414  
24415 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_exitAltDir', @_);
24416 }
24417  
24418 $exitObj->ivPoke('altDir', $string);
24419  
24420 return 1;
24421 }
24422  
24423 sub add_preferRoomFlag {
24424  
24425 # Called by GA::Win::Map->addRoomFlagButton
24426  
24427 my ($self, $roomFlag, $check) = @_;
24428  
24429 # Check for improper arguments
24430 if (! defined $roomFlag || defined $check) {
24431  
24432 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_preferRoomFlag', @_);
24433 }
24434  
24435 # Don't add duplicate room flags. The calling code should take care of this, but we'll
24436 # check anyway
24437 foreach my $item ($self->preferRoomFlagList) {
24438  
24439 if ($item eq $roomFlag) {
24440  
24441 return undef;
24442 }
24443 }
24444  
24445 # Update the list
24446 $self->ivPush('preferRoomFlagList', $roomFlag);
24447  
24448 return 1;
24449 }
24450  
24451 sub del_preferRoomFlag {
24452  
24453 # Called by GA::Win::Map->addRoomFlagButton
24454  
24455 my ($self, $roomFlag, $check) = @_;
24456  
24457 # Local variables
24458 my @list;
24459  
24460 # Check for improper arguments
24461 if (! defined $roomFlag || defined $check) {
24462  
24463 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_preferRoomFlag', @_);
24464 }
24465  
24466 foreach my $item ($self->preferRoomFlagList) {
24467  
24468 if ($item ne $roomFlag) {
24469  
24470 push (@list, $item);
24471 }
24472 }
24473  
24474 $self->ivPoke('preferRoomFlagList', @list);
24475  
24476 return 1;
24477 }
24478  
24479 sub reset_preferRoomFlagList {
24480  
24481 # Called by GA::Win::Map->removeRoomFlagButton
24482  
24483 my ($self, $check) = @_;
24484  
24485 # Check for improper arguments
24486 if (defined $check) {
24487  
24488 return $axmud::CLIENT->writeImproper(
24489 $self->_objClass . '->reset_preferRoomFlagList',
24490 @_,
24491 );
24492 }
24493  
24494 $self->ivEmpty('preferRoomFlagList');
24495  
24496 return 1;
24497 }
24498  
24499 sub add_preferBGColour {
24500  
24501 # Called by GA::Win::Map->addBGColourButton
24502  
24503 my ($self, $colour, $check) = @_;
24504  
24505 # Check for improper arguments
24506 if (! defined $colour || defined $check) {
24507  
24508 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_preferBGColour', @_);
24509 }
24510  
24511 # Don't add duplicate colours
24512 foreach my $item ($self->preferBGColourList) {
24513  
24514 if ($item eq $colour) {
24515  
24516 return undef;
24517 }
24518 }
24519  
24520 # Update the list
24521 $self->ivPush('preferBGColourList', $colour);
24522  
24523 return 1;
24524 }
24525  
24526 sub del_preferBGColour {
24527  
24528 # Called by GA::Win::Map->removeBGColourButton
24529  
24530 my ($self, $colour, $check) = @_;
24531  
24532 # Local variables
24533 my @list;
24534  
24535 # Check for improper arguments
24536 if (! defined $colour || defined $check) {
24537  
24538 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_preferBGColour', @_);
24539 }
24540  
24541 foreach my $item ($self->preferBGColourList) {
24542  
24543 if ($item ne $colour) {
24544  
24545 push (@list, $item);
24546 }
24547 }
24548  
24549 $self->ivPoke('preferBGColourList', @list);
24550  
24551 return 1;
24552 }
24553  
24554 sub reset_preferBGColourList {
24555  
24556 # Called by GA::Win::Map->removeBGColourButton
24557  
24558 my ($self, $check) = @_;
24559  
24560 # Check for improper arguments
24561 if (defined $check) {
24562  
24563 return $axmud::CLIENT->writeImproper(
24564 $self->_objClass . '->reset_preferBGColourList',
24565 @_,
24566 );
24567 }
24568  
24569 $self->ivEmpty('preferBGColourList');
24570  
24571 return 1;
24572 }
24573  
24574 sub toggle_componentFlag {
24575  
24576 # Called by GA::Cmd::ToggleAutomapper->do
24577  
24578 my ($self, $iv, $check) = @_;
24579  
24580 # Check for improper arguments
24581 if (! defined $iv || defined $check) {
24582  
24583 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggle_componentFlag', @_);
24584 }
24585  
24586 # Toggle the flag
24587 if ($self->$iv) {
24588 $self->ivPoke($iv, FALSE);
24589 } else {
24590 $self->ivPoke($iv, TRUE);
24591 }
24592  
24593 # Also need to update the check button in every Automapper window
24594 $self->toggleWinComponents($iv, $self->$iv);
24595  
24596 return 1;
24597 }
24598  
24599 sub set_exitLengthBlocks {
24600  
24601 my ($self, $type, $length, $check) = @_;
24602  
24603 # Check for improper arguments
24604 if (! defined $type || ! defined $length || defined $check) {
24605  
24606 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_exitLengthBlocks', @_);
24607 }
24608  
24609 if ($type eq 'vertical') {
24610 $self->ivPoke('verticalExitLengthBlocks', $length);
24611 } else {
24612 $self->ivPoke('horizontalExitLengthBlocks', $length);
24613 }
24614  
24615 return 1;
24616 }
24617  
24618 sub set_obscuredExitRadius {
24619  
24620 my ($self, $radius, $check) = @_;
24621  
24622 # Check for improper arguments
24623 if (! defined $radius || defined $check) {
24624  
24625 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_obscuredExitRadius', @_);
24626 }
24627  
24628 $self->ivPoke('obscuredExitRadius', $radius);
24629  
24630 return 1;
24631 }
24632  
24633 sub set_lightStatus {
24634  
24635 # Called by GA::Cmd::SetLightStatus->do
24636  
24637 my ($self, $status, $check) = @_;
24638  
24639 # Check for improper arguments
24640 if (! defined $status || defined $check) {
24641  
24642 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_lightStatus', @_);
24643 }
24644  
24645 $self->ivPoke('lightStatus', $status);
24646  
24647 return 1;
24648 }
24649  
24650 sub set_lightStatusList {
24651  
24652 # Called by GA::Cmd::SetLightList->do
24653  
24654 my ($self, @list) = @_;
24655  
24656 # Check for improper arguments
24657 if (! @list) {
24658  
24659 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_lightStatusList', @_);
24660 }
24661  
24662 $self->ivPoke('lightStatusList', @list);
24663  
24664 return 1;
24665 }
24666  
24667 sub set_mapLabelStyle {
24668  
24669 # Called by GA::Win::Map->addLabelAtBlockCallback, ->addLabelAtClickCallback and
24670 # ->setLabelCallback
24671  
24672 my ($self, $style, $check) = @_;
24673  
24674 # Check for improper arguments
24675 if (! defined $style || defined $check) {
24676  
24677 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_mapLabelStyle', @_);
24678 }
24679  
24680 $self->ivPoke('mapLabelStyle', $style);
24681  
24682 return 1;
24683 }
24684  
24685 sub set_matchDescripCharCount {
24686  
24687 my ($self, $number, $check) = @_;
24688  
24689 # Check for improper arguments
24690 if (! defined $number || defined $check) {
24691  
24692 return $axmud::CLIENT->writeImproper(
24693 $self->_objClass . '->set_matchDescripCharCount',
24694 @_,
24695 );
24696 }
24697  
24698 # Update IVs
24699 $self->ivPoke('matchDescripCharCount', $number);
24700  
24701 return 1;
24702 }
24703  
24704 sub set_minionStringHash {
24705  
24706 # Called by GA::Cmd::DeleteMinionString->do
24707  
24708 my ($self, %hash) = @_;
24709  
24710 # (No improper arguments to check)
24711  
24712 $self->ivPoke('minionStringHash', %hash);
24713  
24714 return 1;
24715 }
24716  
24717 sub set_paintAllRoomsFlag {
24718  
24719 my ($self, $flag, $check) = @_;
24720  
24721 # Check for improper arguments
24722 if (! defined $flag || defined $check) {
24723  
24724 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_paintAllRoomsFlag', @_);
24725 }
24726  
24727 if ($flag) {
24728 $self->ivPoke('paintAllRoomsFlag', TRUE);
24729 } else {
24730 $self->ivPoke('paintAllRoomsFlag', FALSE);
24731 }
24732  
24733 return 1;
24734 }
24735  
24736 sub set_preDrawMinRooms {
24737  
24738 my ($self, $number, $check) = @_;
24739  
24740 # Check for improper arguments
24741 if (! defined $number || defined $check) {
24742  
24743 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawMinRooms', @_);
24744 }
24745  
24746 # Update IVs
24747 $self->ivPoke('preDrawMinRooms', $number);
24748  
24749 return 1;
24750 }
24751  
24752 sub set_quickPaintMultiFlag {
24753  
24754 my ($self, $flag, $check) = @_;
24755  
24756 # Check for improper arguments
24757 if (! defined $flag || defined $check) {
24758  
24759 return $axmud::CLIENT->writeImproper(
24760 $self->_objClass . '->set_quickPaintMultiFlag',
24761 @_,
24762 );
24763 }
24764  
24765 if ($flag) {
24766 $self->ivPoke('quickPaintMultiFlag', TRUE);
24767 } else {
24768 $self->ivPoke('quickPaintMultiFlag', FALSE);
24769 }
24770  
24771 return 1;
24772 }
24773  
24774 sub set_preDrawAllocation {
24775  
24776 my ($self, $number, $check) = @_;
24777  
24778 # Check for improper arguments
24779 if (! defined $number || defined $check) {
24780  
24781 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawAllocation', @_);
24782 }
24783  
24784 # Update IVs
24785 $self->ivPoke('preDrawAllocation', $number);
24786  
24787 return 1;
24788 }
24789  
24790 sub set_preDrawRetainRooms {
24791  
24792 my ($self, $number, $check) = @_;
24793  
24794 # Check for improper arguments
24795 if (! defined $number || defined $check) {
24796  
24797 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawRetainRooms', @_);
24798 }
24799  
24800 # Update IVs
24801 $self->ivPoke('preDrawRetainRooms', $number);
24802  
24803 return 1;
24804 }
24805  
24806 sub set_roomFlagShowMode {
24807  
24808 my ($self, $mode, $check) = @_;
24809  
24810 # Check for improper arguments
24811 if (! defined $mode || defined $check) {
24812  
24813 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_roomFlagShowMode', @_);
24814 }
24815  
24816 # Update IVs
24817 $self->ivPoke('roomFlagShowMode', $mode);
24818  
24819 # Must redraw the menu in any automapper windows, so that the new room flag appears in them
24820 $self->updateMapMenuToolbars();
24821  
24822 return 1;
24823 }
24824  
24825 sub set_searchSelectRoomsFlag {
24826  
24827 my ($self, $flag, $check) = @_;
24828  
24829 # Check for improper arguments
24830 if (! defined $flag || defined $check) {
24831  
24832 return $axmud::CLIENT->writeImproper(
24833 $self->_objClass . '->set_searchSelectRoomsFlag',
24834 @_,
24835 );
24836 }
24837  
24838 if ($flag) {
24839 $self->ivPoke('searchSelectRoomsFlag', TRUE);
24840 } else {
24841 $self->ivPoke('searchSelectRoomsFlag', FALSE);
24842 }
24843  
24844 return 1;
24845 }
24846  
24847 sub set_showCanvasFlag {
24848  
24849 my ($self, $flag, $check) = @_;
24850  
24851 # Check for improper arguments
24852 if (! defined $flag || defined $check) {
24853  
24854 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showCanvasFlag', @_);
24855 }
24856  
24857 if ($flag) {
24858 $self->ivPoke('showCanvasFlag', TRUE);
24859 } else {
24860 $self->ivPoke('showCanvasFlag', FALSE);
24861 }
24862  
24863 return 1;
24864 }
24865  
24866 sub set_showMenuBarFlag {
24867  
24868 my ($self, $flag, $check) = @_;
24869  
24870 # Check for improper arguments
24871 if (! defined $flag || defined $check) {
24872  
24873 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showMenuBarFlag', @_);
24874 }
24875  
24876 if ($flag) {
24877 $self->ivPoke('showMenuBarFlag', TRUE);
24878 } else {
24879 $self->ivPoke('showMenuBarFlag', FALSE);
24880 }
24881  
24882 return 1;
24883 }
24884  
24885 sub set_showToolbarFlag {
24886  
24887 my ($self, $flag, $check) = @_;
24888  
24889 # Check for improper arguments
24890 if (! defined $flag || defined $check) {
24891  
24892 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showToolbarFlag', @_);
24893 }
24894  
24895 if ($flag) {
24896 $self->ivPoke('showToolbarFlag', TRUE);
24897 } else {
24898 $self->ivPoke('showToolbarFlag', FALSE);
24899 }
24900  
24901 return 1;
24902 }
24903  
24904 sub set_showTreeViewFlag {
24905  
24906 my ($self, $flag, $check) = @_;
24907  
24908 # Check for improper arguments
24909 if (! defined $flag || defined $check) {
24910  
24911 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showTreeViewFlag', @_);
24912 }
24913  
24914 if ($flag) {
24915 $self->ivPoke('showTreeViewFlag', TRUE);
24916 } else {
24917 $self->ivPoke('showTreeViewFlag', FALSE);
24918 }
24919  
24920 return 1;
24921 }
24922  
24923 sub add_teleport {
24924  
24925 # Called by GA::Cmd::AddTeleport
24926  
24927 my ($self, $room, $cmd, $check) = @_;
24928  
24929 # Check for improper arguments
24930 if (! defined $room || ! defined $cmd || defined $check) {
24931  
24932 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_teleport', @_);
24933 }
24934  
24935 $self->ivAdd('teleportHash', $room, $cmd);
24936  
24937 return 1;
24938 }
24939  
24940 sub del_teleport {
24941  
24942 # Called by GA::Cmd::DeleteTeleport
24943  
24944 my ($self, $room, $check) = @_;
24945  
24946 # Check for improper arguments
24947 if (! defined $room || defined $check) {
24948  
24949 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_teleport', @_);
24950 }
24951  
24952 $self->ivDelete('teleportHash', $room);
24953  
24954 return 1;
24955 }
24956  
24957 ##################
24958 # Accessors - get
24959  
24960 sub author
24961 { $_[0]->{author} }
24962 sub date
24963 { $_[0]->{date} }
24964 sub version
24965 { $_[0]->{version} }
24966 sub descripList
24967 { my $self = shift; return @{$self->{descripList}}; }
24968  
24969 sub modelCreationDate
24970 { $_[0]->{modelCreationDate} }
24971 sub modelCreationVersion
24972 { $_[0]->{modelCreationVersion} }
24973 sub modelConvertedFlag
24974 { $_[0]->{modelConvertedFlag} }
24975 sub modelConvertedVersion
24976 { $_[0]->{modelConvertedVersion} }
24977 sub modelSaveFileCount
24978 { $_[0]->{modelSaveFileCount} }
24979  
24980 sub modelHash
24981 { my $self = shift; return %{$self->{modelHash}}; }
24982 sub regionModelHash
24983 { my $self = shift; return %{$self->{regionModelHash}}; }
24984 sub roomModelHash
24985 { my $self = shift; return %{$self->{roomModelHash}}; }
24986 sub weaponModelHash
24987 { my $self = shift; return %{$self->{weaponModelHash}}; }
24988 sub armourModelHash
24989 { my $self = shift; return %{$self->{armourModelHash}}; }
24990 sub garmentModelHash
24991 { my $self = shift; return %{$self->{garmentModelHash}}; }
24992 sub charModelHash
24993 { my $self = shift; return %{$self->{charModelHash}}; }
24994 sub minionModelHash
24995 { my $self = shift; return %{$self->{minionModelHash}}; }
24996 sub sentientModelHash
24997 { my $self = shift; return %{$self->{sentientModelHash}}; }
24998 sub creatureModelHash
24999 { my $self = shift; return %{$self->{creatureModelHash}}; }
25000 sub portableModelHash
25001 { my $self = shift; return %{$self->{portableModelHash}}; }
25002 sub decorationModelHash
25003 { my $self = shift; return %{$self->{decorationModelHash}}; }
25004 sub customModelHash
25005 { my $self = shift; return %{$self->{customModelHash}}; }
25006  
25007 sub modelObjCount
25008 { $_[0]->{modelObjCount} }
25009 sub modelActualCount
25010 { $_[0]->{modelActualCount} }
25011 sub modelDeletedList
25012 { my $self = shift; return @{$self->{modelDeletedList}}; }
25013 sub modelBufferList
25014 { my $self = shift; return @{$self->{modelBufferList}}; }
25015 sub mostRecentNum
25016 { $_[0]->{mostRecentNum} }
25017  
25018 sub exitModelHash
25019 { my $self = shift; return %{$self->{exitModelHash}}; }
25020 sub exitObjCount
25021 { $_[0]->{exitObjCount} }
25022 sub exitActualCount
25023 { $_[0]->{exitActualCount} }
25024 sub exitDeletedList
25025 { my $self = shift; return @{$self->{exitDeletedList}}; }
25026 sub exitBufferList
25027 { my $self = shift; return @{$self->{exitBufferList}}; }
25028 sub mostRecentExitNum
25029 { $_[0]->{mostRecentExitNum} }
25030  
25031 sub regionmapHash
25032 { my $self = shift; return %{$self->{regionmapHash}}; }
25033 sub reverseRegionListFlag
25034 { $_[0]->{reverseRegionListFlag} }
25035 sub firstRegion
25036 { $_[0]->{firstRegion} }
25037  
25038 sub preDrawAllowFlag
25039 { $_[0]->{preDrawAllowFlag} }
25040 sub preDrawMinRooms
25041 { $_[0]->{preDrawMinRooms} }
25042 sub preDrawRetainRooms
25043 { $_[0]->{preDrawRetainRooms} }
25044 sub preDrawAllocation
25045 { $_[0]->{preDrawAllocation} }
25046  
25047 sub knownCharHash
25048 { my $self = shift; return %{$self->{knownCharHash}}; }
25049 sub minionStringHash
25050 { my $self = shift; return %{$self->{minionStringHash}}; }
25051  
25052 sub lightStatus
25053 { $_[0]->{lightStatus} }
25054 sub constLightStatusList
25055 { my $self = shift; return @{$self->{constLightStatusList}}; }
25056 sub lightStatusList
25057 { my $self = shift; return @{$self->{lightStatusList}}; }
25058  
25059 sub roomTagHash
25060 { my $self = shift; return %{$self->{roomTagHash}}; }
25061  
25062 sub teleportHash
25063 { my $self = shift; return %{$self->{teleportHash}}; }
25064  
25065 sub autoOpenWinFlag
25066 { $_[0]->{autoOpenWinFlag} }
25067 sub pseudoWinFlag
25068 { $_[0]->{pseudoWinFlag} }
25069 sub showMenuBarFlag
25070 { $_[0]->{showMenuBarFlag} }
25071 sub showToolbarFlag
25072 { $_[0]->{showToolbarFlag} }
25073 sub showTreeViewFlag
25074 { $_[0]->{showTreeViewFlag} }
25075 sub showCanvasFlag
25076 { $_[0]->{showCanvasFlag} }
25077 sub buttonSetList
25078 { my $self = shift; return @{$self->{buttonSetList}}; }
25079 sub preferRoomFlagList
25080 { my $self = shift; return @{$self->{preferRoomFlagList}}; }
25081 sub preferBGColourList
25082 { my $self = shift; return @{$self->{preferBGColourList}}; }
25083  
25084 sub defaultGridWidthBlocks
25085 { $_[0]->{defaultGridWidthBlocks} }
25086 sub defaultGridHeightBlocks
25087 { $_[0]->{defaultGridHeightBlocks} }
25088 sub defaultBlockWidthPixels
25089 { $_[0]->{defaultBlockWidthPixels} }
25090 sub defaultBlockHeightPixels
25091 { $_[0]->{defaultBlockHeightPixels} }
25092 sub defaultRoomWidthPixels
25093 { $_[0]->{defaultRoomWidthPixels} }
25094 sub defaultRoomHeightPixels
25095 { $_[0]->{defaultRoomHeightPixels} }
25096  
25097 sub maxGridWidthBlocks
25098 { $_[0]->{maxGridWidthBlocks} }
25099 sub maxGridHeightBlocks
25100 { $_[0]->{maxGridHeightBlocks} }
25101 sub maxBlockWidthPixels
25102 { $_[0]->{maxBlockWidthPixels} }
25103 sub maxBlockHeightPixels
25104 { $_[0]->{maxBlockHeightPixels} }
25105 sub maxRoomWidthPixels
25106 { $_[0]->{maxRoomWidthPixels} }
25107 sub maxRoomHeightPixels
25108 { $_[0]->{maxRoomHeightPixels} }
25109  
25110 sub defaultMapWidthPixels
25111 { $_[0]->{defaultMapWidthPixels} }
25112 sub defaultMapHeightPixels
25113 { $_[0]->{defaultMapHeightPixels} }
25114  
25115 sub regionSchemeHash
25116 { my $self = shift; return %{$self->{regionSchemeHash}}; }
25117 sub defaultSchemeObj
25118 { $_[0]->{defaultSchemeObj} }
25119  
25120 sub defaultBackgroundColour
25121 { $_[0]->{defaultBackgroundColour} }
25122 sub defaultNoBackgroundColour
25123 { $_[0]->{defaultNoBackgroundColour} }
25124 sub defaultRoomColour
25125 { $_[0]->{defaultRoomColour} }
25126 sub defaultRoomTextColour
25127 { $_[0]->{defaultRoomTextColour} }
25128 sub defaultSelectBoxColour
25129 { $_[0]->{defaultSelectBoxColour} }
25130 sub defaultBorderColour
25131 { $_[0]->{defaultBorderColour} }
25132 sub defaultCurrentBorderColour
25133 { $_[0]->{defaultCurrentBorderColour} }
25134 sub defaultCurrentFollowBorderColour
25135 { $_[0]->{defaultCurrentFollowBorderColour} }
25136 sub defaultCurrentWaitBorderColour
25137 { $_[0]->{defaultCurrentWaitBorderColour} }
25138 sub defaultCurrentSelectBorderColour
25139 { $_[0]->{defaultCurrentSelectBorderColour} }
25140 sub defaultLostBorderColour
25141 { $_[0]->{defaultLostBorderColour} }
25142 sub defaultLostSelectBorderColour
25143 { $_[0]->{defaultLostSelectBorderColour} }
25144 sub defaultGhostBorderColour
25145 { $_[0]->{defaultGhostBorderColour} }
25146 sub defaultGhostSelectBorderColour
25147 { $_[0]->{defaultGhostSelectBorderColour} }
25148 sub defaultSelectBorderColour
25149 { $_[0]->{defaultSelectBorderColour} }
25150 sub defaultRoomAboveColour
25151 { $_[0]->{defaultRoomAboveColour} }
25152 sub defaultRoomBelowColour
25153 { $_[0]->{defaultRoomBelowColour} }
25154 sub defaultRoomTagColour
25155 { $_[0]->{defaultRoomTagColour} }
25156 sub defaultSelectRoomTagColour
25157 { $_[0]->{defaultSelectRoomTagColour} }
25158 sub defaultRoomGuildColour
25159 { $_[0]->{defaultRoomGuildColour} }
25160 sub defaultSelectRoomGuildColour
25161 { $_[0]->{defaultSelectRoomGuildColour} }
25162 sub defaultExitColour
25163 { $_[0]->{defaultExitColour} }
25164 sub defaultSelectExitColour
25165 { $_[0]->{defaultSelectExitColour} }
25166 sub defaultSelectExitTwinColour
25167 { $_[0]->{defaultSelectExitTwinColour} }
25168 sub defaultSelectExitShadowColour
25169 { $_[0]->{defaultSelectExitShadowColour} }
25170 sub defaultRandomExitColour
25171 { $_[0]->{defaultRandomExitColour} }
25172 sub defaultImpassableExitColour
25173 { $_[0]->{defaultImpassableExitColour} }
25174 sub defaultMysteryExitColour
25175 { $_[0]->{defaultMysteryExitColour} }
25176 sub defaultCheckedDirColour
25177 { $_[0]->{defaultCheckedDirColour} }
25178 sub defaultDragExitColour
25179 { $_[0]->{defaultDragExitColour} }
25180 sub defaultExitTagColour
25181 { $_[0]->{defaultExitTagColour} }
25182 sub defaultSelectExitTagColour
25183 { $_[0]->{defaultSelectExitTagColour} }
25184 sub defaultMapLabelColour
25185 { $_[0]->{defaultMapLabelColour} }
25186 sub defaultSelectMapLabelColour
25187 { $_[0]->{defaultSelectMapLabelColour} }
25188  
25189 sub mapLabelStyleHash
25190 { my $self = shift; return %{$self->{mapLabelStyleHash}}; }
25191 sub mapLabelStyle
25192 { $_[0]->{mapLabelStyle} }
25193 sub mapLabelAlignXFlag
25194 { $_[0]->{mapLabelAlignXFlag} }
25195 sub mapLabelAlignYFlag
25196 { $_[0]->{mapLabelAlignYFlag} }
25197 sub mapLabelTextViewFlag
25198 { $_[0]->{mapLabelTextViewFlag} }
25199  
25200 sub roomFilterApplyHash
25201 { my $self = shift; return %{$self->{roomFilterApplyHash}}; }
25202 sub roomFlagHash
25203 { my $self = shift; return %{$self->{roomFlagHash}}; }
25204 sub roomFlagOrderedList
25205 { my $self = shift; return @{$self->{roomFlagOrderedList}}; }
25206 sub allRoomFiltersFlag
25207 { $_[0]->{allRoomFiltersFlag} }
25208 sub roomFlagShowMode
25209 { $_[0]->{roomFlagShowMode} }
25210 sub roomTerrainInitHash
25211 { my $self = shift; return %{$self->{roomTerrainInitHash}}; }
25212 sub roomTerrainHash
25213 { my $self = shift; return %{$self->{roomTerrainHash}}; }
25214  
25215 sub paintFromTitleHash
25216 { my $self = shift; return %{$self->{paintFromTitleHash}}; }
25217 sub paintFromDescripHash
25218 { my $self = shift; return %{$self->{paintFromDescripHash}}; }
25219 sub paintFromExitHash
25220 { my $self = shift; return %{$self->{paintFromExitHash}}; }
25221 sub paintFromObjHash
25222 { my $self = shift; return %{$self->{paintFromObjHash}}; }
25223 sub paintFromRoomCmdHash
25224 { my $self = shift; return %{$self->{paintFromRoomCmdHash}}; }
25225  
25226 sub currentRoomMode
25227 { $_[0]->{currentRoomMode} }
25228 sub roomInteriorMode
25229 { $_[0]->{roomInteriorMode} }
25230 sub roomInteriorXOffset
25231 { $_[0]->{roomInteriorXOffset} }
25232 sub roomInteriorYOffset
25233 { $_[0]->{roomInteriorYOffset} }
25234  
25235 sub drawExitMode
25236 { $_[0]->{drawExitMode} }
25237 sub obscuredExitFlag
25238 { $_[0]->{obscuredExitFlag} }
25239 sub obscuredExitRedrawFlag
25240 { $_[0]->{obscuredExitRedrawFlag} }
25241 sub obscuredExitRadius
25242 { $_[0]->{obscuredExitRadius} }
25243 sub maxObscuredExitRadius
25244 { $_[0]->{maxObscuredExitRadius} }
25245 sub drawOrnamentsFlag
25246 { $_[0]->{drawOrnamentsFlag} }
25247 sub horizontalExitLengthBlocks
25248 { $_[0]->{horizontalExitLengthBlocks} }
25249 sub verticalExitLengthBlocks
25250 { $_[0]->{verticalExitLengthBlocks} }
25251 sub maxExitLengthBlocks
25252 { $_[0]->{maxExitLengthBlocks} }
25253 sub drawBentExitsFlag
25254 { $_[0]->{drawBentExitsFlag} }
25255  
25256 sub matchTitleFlag
25257 { $_[0]->{matchTitleFlag} }
25258 sub matchDescripFlag
25259 { $_[0]->{matchDescripFlag} }
25260 sub matchDescripCharCount
25261 { $_[0]->{matchDescripCharCount} }
25262 sub matchExitFlag
25263 { $_[0]->{matchExitFlag} }
25264 sub analyseDescripFlag
25265 { $_[0]->{analyseDescripFlag} }
25266 sub matchSourceFlag
25267 { $_[0]->{matchSourceFlag} }
25268 sub matchVNumFlag
25269 { $_[0]->{matchVNumFlag} }
25270  
25271 sub updateTitleFlag
25272 { $_[0]->{updateTitleFlag} }
25273 sub updateDescripFlag
25274 { $_[0]->{updateDescripFlag} }
25275 sub updateExitFlag
25276 { $_[0]->{updateExitFlag} }
25277 sub updateSourceFlag
25278 { $_[0]->{updateSourceFlag} }
25279 sub updateVNumFlag
25280 { $_[0]->{updateVNumFlag} }
25281 sub updateRoomCmdFlag
25282 { $_[0]->{updateRoomCmdFlag} }
25283 sub updateOrnamentFlag
25284 { $_[0]->{updateOrnamentFlag} }
25285  
25286 sub assistedMovesFlag
25287 { $_[0]->{assistedMovesFlag} }
25288 sub assistedBreakFlag
25289 { $_[0]->{assistedBreakFlag} }
25290 sub assistedPickFlag
25291 { $_[0]->{assistedPickFlag} }
25292 sub assistedUnlockFlag
25293 { $_[0]->{assistedUnlockFlag} }
25294 sub assistedOpenFlag
25295 { $_[0]->{assistedOpenFlag} }
25296 sub assistedCloseFlag
25297 { $_[0]->{assistedCloseFlag} }
25298 sub assistedLockFlag
25299 { $_[0]->{assistedLockFlag} }
25300 sub protectedMovesFlag
25301 { $_[0]->{protectedMovesFlag} }
25302 sub superProtectedMovesFlag
25303 { $_[0]->{superProtectedMovesFlag} }
25304 sub craftyMovesFlag
25305 { $_[0]->{craftyMovesFlag} }
25306  
25307 sub setTwinOrnamentFlag
25308 { $_[0]->{setTwinOrnamentFlag} }
25309  
25310 sub newRoomScriptList
25311 { my $self = shift; return @{$self->{newRoomScriptList}}; }
25312 sub arriveScriptList
25313 { my $self = shift; return @{$self->{arriveScriptList}}; }
25314  
25315 sub countVisitsFlag
25316 { $_[0]->{countVisitsFlag} }
25317 sub allowModelScriptFlag
25318 { $_[0]->{allowModelScriptFlag} }
25319 sub allowRoomScriptFlag
25320 { $_[0]->{allowRoomScriptFlag} }
25321 sub intelligentExitsFlag
25322 { $_[0]->{intelligentExitsFlag} }
25323 sub followAnchorFlag
25324 { $_[0]->{followAnchorFlag} }
25325 sub capitalisedRoomTagFlag
25326 { $_[0]->{capitalisedRoomTagFlag} }
25327 sub showTooltipsFlag
25328 { $_[0]->{showTooltipsFlag} }
25329 sub showNotesFlag
25330 { $_[0]->{showNotesFlag} }
25331 sub explainGetLostFlag
25332 { $_[0]->{explainGetLostFlag} }
25333 sub disableUpdateModeFlag
25334 { $_[0]->{disableUpdateModeFlag} }
25335 sub updateExitTagFlag
25336 { $_[0]->{updateExitTagFlag} }
25337 sub drawRoomEchoFlag
25338 { $_[0]->{drawRoomEchoFlag} }
25339 sub allowTrackAloneFlag
25340 { $_[0]->{allowTrackAloneFlag} }
25341 sub showAllPrimaryFlag
25342 { $_[0]->{showAllPrimaryFlag} }
25343 sub allowCtrlCopyFlag
25344 { $_[0]->{allowCtrlCopyFlag} }
25345  
25346 sub autoCompareMode
25347 { $_[0]->{autoCompareMode} }
25348 sub autoCompareAllFlag
25349 { $_[0]->{autoCompareAllFlag} }
25350 sub autoCompareMax
25351 { $_[0]->{autoCompareMax} }
25352 sub autoSlideMode
25353 { $_[0]->{autoSlideMode} }
25354 sub autoSlideMax
25355 { $_[0]->{autoSlideMax} }
25356 sub autoRescueFlag
25357 { $_[0]->{autoRescueFlag} }
25358 sub autoRescueFirstFlag
25359 { $_[0]->{autoRescueFirstFlag} }
25360 sub autoRescuePromptFlag
25361 { $_[0]->{autoRescuePromptFlag} }
25362 sub autoRescueNoMoveFlag
25363 { $_[0]->{autoRescueNoMoveFlag} }
25364 sub autoRescueVisitsFlag
25365 { $_[0]->{autoRescueVisitsFlag} }
25366 sub autoRescueForceFlag
25367 { $_[0]->{autoRescueForceFlag} }
25368  
25369 sub lastFilePath
25370 { $_[0]->{lastFilePath} }
25371 sub lastVirtualAreaPath
25372 { $_[0]->{lastVirtualAreaPath} }
25373 sub trackPosnFlag
25374 { $_[0]->{trackPosnFlag} }
25375 sub trackingSensitivity
25376 { $_[0]->{trackingSensitivity} }
25377 sub avoidHazardsFlag
25378 { $_[0]->{avoidHazardsFlag} }
25379 sub postProcessingFlag
25380 { $_[0]->{postProcessingFlag} }
25381 sub quickPathFindFlag
25382 { $_[0]->{quickPathFindFlag} }
25383 sub autocompleteExitsFlag
25384 { $_[0]->{autocompleteExitsFlag} }
25385 sub collectCheckedDirsFlag
25386 { $_[0]->{collectCheckedDirsFlag} }
25387 sub drawCheckedDirsFlag
25388 { $_[0]->{drawCheckedDirsFlag} }
25389 sub checkableDirMode
25390 { $_[0]->{checkableDirMode} }
25391  
25392 sub adjacentMode
25393 { $_[0]->{adjacentMode} }
25394 sub adjacentCount
25395 { $_[0]->{adjacentCount} }
25396 sub updateBoundaryHash
25397 { my $self = shift; return %{$self->{updateBoundaryHash}}; }
25398 sub deleteBoundaryHash
25399 { my $self = shift; return %{$self->{deleteBoundaryHash}}; }
25400 sub updatePathHash
25401 { my $self = shift; return %{$self->{updatePathHash}}; }
25402 sub updateDelayFlag
25403 { $_[0]->{updateDelayFlag} }
25404 sub checkLevelsHash
25405 { my $self = shift; return %{$self->{checkLevelsHash}}; }
25406  
25407 sub mudlibPath
25408 { $_[0]->{mudlibPath} }
25409 sub mudlibExtension
25410 { $_[0]->{mudlibExtension} }
25411  
25412 sub painterObj
25413 { $_[0]->{painterObj} }
25414 sub constPainterIVList
25415 { my $self = shift; return @{$self->{constPainterIVList}}; }
25416 sub paintAllRoomsFlag
25417 { $_[0]->{paintAllRoomsFlag} }
25418 sub quickPaintMultiFlag
25419 { $_[0]->{quickPaintMultiFlag} }
25420  
25421 sub searchMaxMatches
25422 { $_[0]->{searchMaxMatches} }
25423 sub searchMaxObjects
25424 { $_[0]->{searchMaxObjects} }
25425 sub searchSelectRoomsFlag
25426 { $_[0]->{searchSelectRoomsFlag} }
25427 sub locateMaxObjects
25428 { $_[0]->{locateMaxObjects} }
25429 sub locateRandomInRegionFlag
25430 { $_[0]->{locateRandomInRegionFlag} }
25431 sub locateRandomAnywhereFlag
25432 { $_[0]->{locateRandomAnywhereFlag} }
25433  
25434 sub pathFindStepLimit
25435 { $_[0]->{pathFindStepLimit} }
25436  
25437 sub drawPauseNum
25438 { $_[0]->{drawPauseNum} }
25439 sub recalculatePauseNum
25440 { $_[0]->{recalculatePauseNum} }
25441  
25442 sub mapFont
25443 { $_[0]->{mapFont} }
25444 sub roomTagRatio
25445 { $_[0]->{roomTagRatio} }
25446 sub roomGuildRatio
25447 { $_[0]->{roomGuildRatio} }
25448 sub exitTagRatio
25449 { $_[0]->{exitTagRatio} }
25450 sub labelRatio
25451 { $_[0]->{labelRatio} }
25452 sub roomTextRatio
25453 { $_[0]->{roomTextRatio} }
25454  
25455 sub blockUnselectFlag
25456 { $_[0]->{blockUnselectFlag} }
25457 }
25458  
25459 # Package must return a true value
25460 1