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

filter: Statementstmt 0.0% 0 / 6795 Branchbran 0.0% 0 / 3082 Conditioncond 0.0% 0 / 3270 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 478 Podpod 0.0% 0 / 474 totaltotal 0.0% 0 / 14099 CC 1542 SCAR 66.0
CC
1542
Cov
0%
testModel
7482.0
parseObj
5256.0
connectRegionBrokenExit
1560.0
CRAP 732.1
1 # Copyright (C) 2011-2022 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 ! $exitObj->oneWayFlag
13632 && ! (
13633 $exitObj->destRoom
13634 && ! $exitObj->twinExit
13635 && ! $exitObj->retraceFlag
13636 && $exitObj->randomType eq 'none'
13637 )
13638 ) {
13639 return undef;
13640 }
13641 }
13642  
13643 # Reset both exits, removing their status as one-way or twin exits. The FALSE arguments mean
13644 # 'don't update Automapper windows yet'
13645 foreach my $exitObj (@exitList) {
13646  
13647 if ($exitObj->oneWayFlag) {
13648 $self->abandonOneWayExit(FALSE, $exitObj);
13649 } else {
13650 $self->abandonUncertainExit(FALSE, $exitObj);
13651 }
13652 }
13653  
13654 # Now mark each exit as the other's twin
13655 $exitObj1 = shift @exitList;
13656 $exitObj2 = shift @exitList;
13657  
13658 $exitObj1->ivPoke('twinExit', $exitObj2->number);
13659 $exitObj1->ivPoke('destRoom', $exitObj2->parent);
13660  
13661 $exitObj2->ivPoke('twinExit', $exitObj1->number);
13662 $exitObj2->ivPoke('destRoom', $exitObj1->parent);
13663  
13664 # If the exits' parent rooms are in the same region, mark it as a broken exit; otherwise
13665 # mark it as a region exit
13666 $roomObj1 = $self->ivShow('modelHash', $exitObj1->parent);
13667 $roomObj2 = $self->ivShow('modelHash', $exitObj2->parent);
13668  
13669 if ($roomObj1->parent == $roomObj2->parent) {
13670  
13671 $self->setBrokenExit(
13672 FALSE, # Don't update Automapper windows yet
13673 $exitObj1,
13674 $roomObj1->parent,
13675 );
13676  
13677 $self->setBrokenExit(
13678 FALSE, # Don't update Automapper windows yet
13679 $exitObj2,
13680 $roomObj2->parent,
13681 );
13682  
13683 } else {
13684  
13685 $self->setRegionExit(
13686 FALSE, # Don't update Automapper windows yet
13687 $exitObj1,
13688 $roomObj1->parent,
13689 );
13690  
13691 $self->setRegionExit(
13692 FALSE, # Don't update Automapper windows yet
13693 $exitObj2,
13694 $roomObj2->parent,
13695 );
13696 }
13697  
13698 # Update any GA::Win::Map objects using this world model (if allowed)
13699 if ($updateFlag) {
13700  
13701 foreach my $mapWin ($self->collectMapWins()) {
13702  
13703 # Redraw the rooms
13704 $mapWin->markObjs(
13705 'room', $roomObj1,
13706 'room', $roomObj2,
13707 );
13708  
13709 $mapWin->doDraw();
13710 }
13711 }
13712  
13713 return 1;
13714 }
13715  
13716 sub setRetracingExit {
13717  
13718 # Called by $self->connectRooms
13719 # Converts an exit into a retracing exit (resetting other IVs as necessary)
13720 #
13721 # Expected arguments
13722 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13723 # be updated now, FALSE if not (in which case, they can be updated later
13724 # by the calling function, when it is ready)
13725 # $exitObj - The GA::Obj::Exit to convert
13726 #
13727 # Return values
13728 # 'undef' on improper arguments
13729 # 1 otherwise
13730  
13731 my ($self, $updateFlag, $exitObj, $check) = @_;
13732  
13733 # Local variables
13734 my ($regionFlag, $destRoomNum, $twinExitNum, $roomObj, $regionObj);
13735  
13736 # Check for improper arguments
13737 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13738  
13739 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRetracingExit', @_);
13740 }
13741  
13742 $regionFlag = $exitObj->regionFlag;
13743  
13744 # The call to ->abandonTwinExit resets $exitObj->destRoom, so store it so that we can
13745 # restore the original value
13746 if ($exitObj->destRoom) {
13747  
13748 $destRoomNum = $exitObj->destRoom;
13749 }
13750  
13751 # Make sure the exit doesn't have an existing twin and/or shadow exit (both of which are now
13752 # obsolete)
13753 if ($exitObj->twinExit) {
13754  
13755 $twinExitNum = $exitObj->twinExit;
13756  
13757 $self->abandonTwinExit(
13758 FALSE, # Don't update Automapper windows now
13759 $exitObj,
13760 );
13761 }
13762  
13763 if ($exitObj->shadowExit) {
13764  
13765 $self->abandonShadowExit($exitObj);
13766 }
13767  
13768 # Set the exit's IVs
13769 $exitObj->ivPoke('brokenFlag', FALSE);
13770 $exitObj->ivPoke('bentFlag', FALSE);
13771 $exitObj->ivEmpty('bendOffsetList');
13772  
13773 $exitObj->ivPoke('regionFlag', FALSE);
13774 $self->cancelExitTag(
13775 FALSE, # Don't update Automapper windows yet
13776 $exitObj,
13777 );
13778  
13779 $exitObj->ivPoke('randomType', 'none');
13780 $exitObj->ivPoke('oneWayFlag', FALSE);
13781 $exitObj->ivPoke('oneWayDir', undef);
13782 $exitObj->ivPoke('retraceFlag', TRUE);
13783  
13784 if (defined $destRoomNum) {
13785  
13786 $exitObj->ivPoke('destRoom', $destRoomNum);
13787 }
13788  
13789 # If there is a twin exit, the call to ->abandonTwinExit has already updated
13790 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
13791 if (! $exitObj->twinExit) {
13792  
13793 # Find the parent region
13794 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13795 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13796 # Any region paths using the exit will have to be updated
13797 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13798 if ($regionFlag) {
13799  
13800 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13801 }
13802 }
13803  
13804 # Update any GA::Win::Map objects using this world model (if allowed)
13805 if ($updateFlag) {
13806  
13807 foreach my $mapWin ($self->collectMapWins()) {
13808  
13809 my (
13810 $twinExitObj,
13811 @list,
13812 );
13813  
13814 # Mark both the exit and its twin (if any) to be redrawn
13815 @list = ('exit', $exitObj);
13816 if ($twinExitNum) {
13817  
13818 $twinExitObj = $self->ivShow('exitModelHash', $twinExitNum);
13819 if ($twinExitObj) {
13820  
13821 push (@list, 'exit', $twinExitObj);
13822 }
13823 }
13824  
13825 # Redraw the objects
13826 $mapWin->markObjs(@list);
13827 $mapWin->doDraw();
13828 }
13829 }
13830  
13831 return 1;
13832 }
13833  
13834 sub restoreRetracingExit {
13835  
13836 # Called by GA::Win::Map->restoreRetracingExitCallback
13837 # Converts an existing retracing exit into an incomplete exit
13838 #
13839 # Expected arguments
13840 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13841 # be updated now, FALSE if not (in which case, they can be updated later
13842 # by the calling function, when it is ready)
13843 # $exitObj - The GA::Obj::Exit to convert
13844 #
13845 # Return values
13846 # 'undef' on improper arguments
13847 # 1 otherwise
13848  
13849 my ($self, $updateFlag, $exitObj, $check) = @_;
13850  
13851 # Local variables
13852 my $roomObj;
13853  
13854 # Check for improper arguments
13855 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
13856  
13857 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreRetracingExit', @_);
13858 }
13859  
13860 # Convert the exit
13861 $exitObj->ivPoke('retraceFlag', FALSE);
13862 $exitObj->ivUndef('destRoom');
13863  
13864 # Update any GA::Win::Map objects using this world model (if allowed)
13865 if ($updateFlag) {
13866  
13867 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13868  
13869 foreach my $mapWin ($self->collectMapWins()) {
13870  
13871 # Redraw the room
13872 $mapWin->markObjs('room', $roomObj);
13873 $mapWin->doDraw();
13874 }
13875 }
13876  
13877 return 1;
13878 }
13879  
13880 sub setRandomExit {
13881  
13882 # Called by GA::Win::Map->markRandomExitCallback
13883 # Converts an exit into a random exit (resetting other IVs as necessary)
13884 #
13885 # Expected arguments
13886 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
13887 # be updated now, FALSE if not (in which case, they can be updated later
13888 # by the calling function, when it is ready)
13889 # $exitObj - The GA::Obj::Exit to convert
13890 # $exitType - Set to 'same_region' if the exit leads to a random location in the current
13891 # region, 'any_region' if the exit leads to a random location in any
13892 # region, 'temp_region' if a destination should be created in a new
13893 # temporary region, or 'room_list' if the exit leads to a random location
13894 # in the exit's ->randomDestList
13895 #
13896 # Return values
13897 # 'undef' on improper arguments
13898 # 1 otherwise
13899  
13900 my ($self, $updateFlag, $exitObj, $exitType, $check) = @_;
13901  
13902 # Local variables
13903 my (
13904 $regionFlag, $currentType, $roomObj, $regionObj,
13905 @redrawList,
13906 );
13907  
13908 # Check for improper arguments
13909 if (
13910 ! defined $updateFlag || ! defined $exitObj || ! defined $exitType
13911 || (
13912 $exitType ne 'same_region' && $exitType ne 'any_region'
13913 && $exitType ne 'temp_region' && $exitType ne 'room_list'
13914 )
13915 || defined $check
13916 ) {
13917 return $axmud::CLIENT->writeImproper($self->_objClass . '->setRandomExit', @_);
13918 }
13919  
13920 $regionFlag = $exitObj->regionFlag;
13921 $currentType = $exitObj->randomType;
13922  
13923 # If the exit already has a destination room, mark it for redrawing
13924 if ($exitObj->destRoom) {
13925  
13926 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->destRoom));
13927 }
13928  
13929 # If the exit has a twin, it must be abandoned
13930 if ($exitObj->twinExit) {
13931  
13932 $self->abandonTwinExit(
13933 FALSE, # Don't update Automapper windows yet
13934 $exitObj,
13935 );
13936 }
13937  
13938 # The same applies if the exit has a shadow exit
13939 if ($exitObj->shadowExit) {
13940  
13941 $self->abandonShadowExit($exitObj);
13942 }
13943  
13944 # Update the exit
13945 $exitObj->ivPoke('brokenFlag', FALSE);
13946 $exitObj->ivPoke('bentFlag', FALSE);
13947 $exitObj->ivEmpty('bendOffsetList');
13948  
13949 $exitObj->ivPoke('regionFlag', FALSE);
13950 $self->cancelExitTag(
13951 FALSE, # Don't update Automapper windows yet
13952 $exitObj,
13953 );
13954  
13955 $exitObj->ivPoke('randomType', $exitType);
13956 $exitObj->ivPoke('oneWayFlag', FALSE);
13957 $exitObj->ivPoke('oneWayDir', undef);
13958 $exitObj->ivPoke('retraceFlag', FALSE);
13959  
13960 # If there is a twin exit, the call to ->abandonTwinExit has already updated
13961 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
13962 if (! $exitObj->twinExit) {
13963  
13964 # Find the parent region
13965 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
13966 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
13967 # Any region paths using the exit will have to be updated
13968 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
13969 if ($regionFlag) {
13970  
13971 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
13972 }
13973 }
13974  
13975 # Mark the exit's parent room to be redawn (if allowed)
13976 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
13977  
13978 # If the exit's ->randomType was set to 'room_list' (but is not set to 'same_region' or
13979 # 'any_region'), we need to update the exit's ->randomDestList and each of the former
13980 # destination rooms
13981 if ($currentType eq 'room_list' && $exitType ne 'room_list') {
13982  
13983 foreach my $destRoomNum ($exitObj->randomDestList) {
13984  
13985 my $destRoomObj = $self->ivShow('modelHash', $destRoomNum);
13986 if ($destRoomObj && $destRoomObj->ivExists('randomExitHash', $exitObj->number)) {
13987  
13988 $destRoomObj->ivDelete($exitObj->number);
13989 }
13990 }
13991  
13992 $exitObj->ivEmpty('randomDestList');
13993 }
13994  
13995 # Update any GA::Win::Map objects using this world model (if allowed)
13996 if ($updateFlag) {
13997  
13998 foreach my $mapWin ($self->collectMapWins()) {
13999  
14000 # Redraw the objects
14001 $mapWin->markObjs(@redrawList);
14002 $mapWin->doDraw();
14003 }
14004 }
14005  
14006 return 1;
14007 }
14008  
14009 sub restoreRandomExit {
14010  
14011 # Called by GA::Win::Map->restoreRandomExitCallback
14012 # Converts an existing random exit into an incomplete exit
14013 #
14014 # Expected arguments
14015 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14016 # be updated now, FALSE if not (in which case, they can be updated later
14017 # by the calling function, when it is ready)
14018 # $exitObj - The GA::Obj::Exit to convert
14019 #
14020 # Return values
14021 # 'undef' on improper arguments
14022 # 1 otherwise
14023  
14024 my ($self, $updateFlag, $exitObj, $check) = @_;
14025  
14026 # Local variables
14027 my $roomObj;
14028  
14029 # Check for improper arguments
14030 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14031  
14032 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreRandomExit', @_);
14033 }
14034  
14035  
14036 # Remove the defined list of destination rooms (for random type 'room_list'), if set
14037 foreach my $destRoomNum ($exitObj->randomDestList) {
14038  
14039 my $destRoomObj = $self->ivShow('modelHash', $destRoomNum);
14040 if ($destRoomObj && $destRoomObj->ivExists('randomExitHash', $exitObj->number)) {
14041  
14042 $destRoomObj->ivDelete($exitObj->number);
14043 }
14044  
14045 $exitObj->ivEmpty('randomDestList');
14046 }
14047  
14048 # Convert the exit
14049 $exitObj->ivPoke('randomType', 'none');
14050  
14051 # Update any GA::Win::Map objects using this world model (if allowed)
14052 if ($updateFlag) {
14053  
14054 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14055  
14056 foreach my $mapWin ($self->collectMapWins()) {
14057  
14058 # Redraw the room
14059 $mapWin->markObjs('room', $roomObj);
14060 $mapWin->doDraw();
14061 }
14062 }
14063  
14064 return 1;
14065 }
14066  
14067 sub setSuperRegionExit {
14068  
14069 # Called by GA::Win::Map->markSuperExitCallback
14070 # Converts a region exit into a super-region exit (resetting other IVs as necessary)
14071 #
14072 # Expected arguments
14073 # $session - The calling function's GA::Session
14074 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14075 # should be updated now, FALSE if not (in which case, they can be
14076 # updated later by the calling function, when it is ready)
14077 # $exitObj - The GA::Obj::Exit to convert
14078 # $exclusiveFlag - Set to TRUE if this should be the only super-region exit leading from
14079 # its parent region to its destination region. Set to FALSE if other
14080 # super-region exits between the two regions (if any) can be left as
14081 # super-region exits
14082 #
14083 # Return values
14084 # 'undef' on improper arguments, if the specified exit is already a super-region exit or
14085 # if it is not a region exit at all
14086 # 1 otherwise
14087  
14088 my ($self, $session, $updateFlag, $exitObj, $exclusiveFlag, $check) = @_;
14089  
14090 # Local variables
14091 my (
14092 $roomObj, $regionmapObj, $destRegionNum,
14093 @redrawList,
14094 %regionExitHash,
14095 );
14096  
14097 # Check for improper arguments
14098 if (
14099 ! defined $session || ! defined $updateFlag || ! defined $exitObj
14100 || ! defined $exclusiveFlag || defined $check
14101 ) {
14102 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSuperRegionExit', @_);
14103 }
14104  
14105 # Check that the specified exit isn't already a super-region exit, and that it is a region
14106 # exit
14107 if ($exitObj->superFlag || ! $exitObj->regionFlag) {
14108  
14109 return undef;
14110 }
14111  
14112 # Get the parent regionmap
14113 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14114 $regionmapObj = $self->findRegionmap($roomObj->parent);
14115  
14116 # Import the regionmap's hash of region exits (for quick lookup)
14117 %regionExitHash = $regionmapObj->regionExitHash;
14118  
14119 # Get $exitObj's destination region (stored in the regionmap)
14120 $destRegionNum = $regionExitHash{$exitObj->number};
14121  
14122 # If $exclusiveFlag is set, any super-region exits in this regionmap leading to the same
14123 # destination region must be converted to non-super region exits
14124 if ($exclusiveFlag) {
14125  
14126 OUTER: foreach my $otherExitNum (keys %regionExitHash) {
14127  
14128 my ($otherExitObj, $otherDestRegionNum);
14129  
14130 $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
14131 $otherDestRegionNum = $regionExitHash{$otherExitNum};
14132  
14133 # Ignore the entry for $exitObj itself, all normal region exits and any exit which
14134 # has a different destination region
14135 if (
14136 $otherExitNum != $exitObj->number
14137 && $otherExitObj->superFlag
14138 && $destRegionNum == $otherDestRegionNum
14139 ) {
14140 # This super-region exit must be converted to a normal region exit
14141 $otherExitObj->ivPoke('superFlag', FALSE);
14142 # The user wasn't directly responsible for this change
14143 $otherExitObj->ivPoke('notSuperFlag', FALSE);
14144  
14145 # Remove any region paths (stored in ->regionPathHash and
14146 # ->safeRegionPathHash) which were using this exit
14147 INNER: foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
14148  
14149 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
14150  
14151 if (
14152 $pathObj->startExit == $exitObj->number
14153 || $pathObj->stopExit == $exitObj->number
14154 ) {
14155 # (Update both ->regionPathHash and ->safeRegionPathHash)
14156 $regionmapObj->removePaths($exitString);
14157 }
14158 }
14159  
14160 # Any region paths using the exit will have to be updated
14161 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionmapObj->name);
14162 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionmapObj->name);
14163  
14164 # Mark the exit's parent room to be re-drawn
14165 push (@redrawList, 'room', $self->ivShow('modelHash', $otherExitObj->parent));
14166 }
14167 }
14168 }
14169  
14170 # Now convert $exitObj to a super-region exit
14171 $exitObj->ivPoke('superFlag', TRUE);
14172 $exitObj->ivPoke('notSuperFlag', FALSE);
14173  
14174 # Create region paths between this super-region exit and every other
14175 # super-region exit in the region
14176 $self->connectRegionExits(
14177 $session,
14178 $regionmapObj,
14179 $roomObj,
14180 $exitObj,
14181 );
14182  
14183 # Mark the exit's parent room to be re-drawn (if allowed)
14184 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14185  
14186 # Update any GA::Win::Map objects using this world model (if allowed)
14187 if ($updateFlag) {
14188  
14189 foreach my $mapWin ($self->collectMapWins()) {
14190  
14191 # Redraw the objects
14192 $mapWin->markObjs(@redrawList);
14193 $mapWin->doDraw();
14194 }
14195 }
14196  
14197 return 1;
14198 }
14199  
14200 sub restoreSuperRegionExit {
14201  
14202 # Called by GA::Win::Map->restoreSuperExitCallback
14203 # Converts an existing super-region exit into a normal region exit
14204 #
14205 # Expected arguments
14206 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14207 # be updated now, FALSE if not (in which case, they can be updated later
14208 # by the calling function, when it is ready)
14209 # $exitObj - The GA::Obj::Exit to convert
14210 #
14211 # Return values
14212 # 'undef' on improper arguments or if the specified exit isn't a super-region exit
14213 # 1 otherwise
14214  
14215 my ($self, $updateFlag, $exitObj, $check) = @_;
14216  
14217 # Local variables
14218 my (
14219 $roomObj, $regionObj, $regionmapObj,
14220 @redrawList,
14221 );
14222  
14223 # Check for improper arguments
14224 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14225  
14226 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreSuperRegionExit', @_);
14227 }
14228  
14229 # Check that the specified exit is a super-region exit
14230 if (! $exitObj->superFlag) {
14231  
14232 return undef;
14233 }
14234  
14235 # Get the parent regionmap
14236 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14237 $regionmapObj = $self->findRegionmap($roomObj->parent);
14238  
14239 # Convert the exit to a normal region exit
14240 $exitObj->ivPoke('superFlag', FALSE);
14241 # The user was directly responsible for this change
14242 $exitObj->ivPoke('notSuperFlag', TRUE);
14243  
14244 # Remove any region paths (stored in ->regionPathHash and
14245 # ->safeRegionPathHash) which were using this exit
14246 foreach my $exitString ($regionmapObj->ivKeys('regionPathHash')) {
14247  
14248 my $pathObj = $regionmapObj->ivShow('regionPathHash', $exitString);
14249  
14250 if (
14251 $pathObj->startExit == $exitObj->number
14252 || $pathObj->stopExit == $exitObj->number
14253 ) {
14254 # (Update both ->regionPathHash and ->safeRegionPathHash)
14255 $regionmapObj->removePaths($exitString);
14256 }
14257 }
14258  
14259 # Any region paths using the exit will have to be updated
14260 $self->ivAdd('updatePathHash', $exitObj->number, $regionmapObj->name);
14261 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionmapObj->name);
14262  
14263 # Mark the exit's parent room to be re-drawn
14264 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14265  
14266 # Update any GA::Win::Map objects using this world model (if allowed)
14267 if ($updateFlag) {
14268  
14269 foreach my $mapWin ($self->collectMapWins()) {
14270  
14271 # Redraw the objects
14272 $mapWin->markObjs(@redrawList);
14273 $mapWin->doDraw();
14274 }
14275 }
14276  
14277 return 1;
14278 }
14279  
14280 sub setImpassableExit {
14281  
14282 # Called by $self->setExitOrnament (should not be called by anything else)
14283 # Converts any kind of exit into an (incomplete) impassable or mystery exit
14284 #
14285 # Expected arguments
14286 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14287 # be updated now, FALSE if not (in which case, they can be updated later
14288 # by the calling function, when it is ready)
14289 # $exitObj - The GA::Obj::Exit to convert
14290 # $type - 'impass' or 'mystery'
14291 #
14292 # Return values
14293 # 'undef' on improper arguments
14294 # 1 otherwise
14295  
14296 my ($self, $updateFlag, $exitObj, $type, $check) = @_;
14297  
14298 # Local variables
14299 my (
14300 $destRoomObj, $regionFlag, $roomObj, $regionObj,
14301 @redrawList,
14302 );
14303  
14304 # Check for improper arguments
14305 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
14306  
14307 return $axmud::CLIENT->writeImproper($self->_objClass . '->setImpassableExit', @_);
14308 }
14309  
14310 $regionFlag = $exitObj->regionFlag;
14311  
14312 # If the exit already has a destination room, mark it for redrawing
14313 if ($exitObj->destRoom) {
14314  
14315 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
14316 push (@redrawList, 'room', $destRoomObj);
14317 }
14318  
14319 # If the exit has a twin, it must be abandoned
14320 if ($exitObj->twinExit) {
14321  
14322 $self->abandonTwinExit(
14323 FALSE, # Don't update Automapper windows yet
14324 $exitObj,
14325 );
14326 }
14327  
14328 # The same applies if the exit has a shadow exit
14329 if ($exitObj->shadowExit) {
14330  
14331 $self->abandonShadowExit($exitObj);
14332 }
14333  
14334 # Update the destination room (if any)
14335 if ($destRoomObj) {
14336  
14337 if ($destRoomObj->ivExists('uncertainExitHash', $exitObj->number)) {
14338  
14339 $destRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
14340 }
14341  
14342 if ($destRoomObj->ivExists('oneWayExitHash', $exitObj->number)) {
14343  
14344 $destRoomObj->ivDelete('oneWayExitHash', $exitObj->number);
14345 }
14346 }
14347  
14348 # Update the exit. The ->exitOrnament IV is set by the calling function
14349 $exitObj->ivPoke('brokenFlag', FALSE);
14350 $exitObj->ivPoke('bentFlag', FALSE);
14351 $exitObj->ivEmpty('bendOffsetList');
14352  
14353 $exitObj->ivPoke('regionFlag', FALSE);
14354 $self->cancelExitTag(
14355 FALSE, # Don't update Automapper windows yet
14356 $exitObj,
14357 );
14358  
14359 $exitObj->ivPoke('randomType', 'none');
14360 $exitObj->ivUndef('destRoom');
14361 $exitObj->ivPoke('oneWayFlag', FALSE);
14362 $exitObj->ivPoke('oneWayDir', undef);
14363 $exitObj->ivPoke('retraceFlag', FALSE);
14364 if ($type eq 'impass') {
14365  
14366 # (There is no exit state corresponding to a mystery exit)
14367 $exitObj->ivPoke('exitState', 'impass');
14368 }
14369  
14370 # If there is a twin exit, the call to ->abandonTwinExit has already updated
14371 # $self->updatePathHash/->updateBoundaryHash; otherwise, we need to update them now
14372 if (! $exitObj->twinExit) {
14373  
14374 # Find the parent region
14375 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14376 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14377 # Any region paths using the exit will have to be updated
14378 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14379 if ($regionFlag) {
14380  
14381 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14382 }
14383 }
14384  
14385 # Mark the exit's parent room to be redawn (if allowed)
14386 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
14387  
14388 # Update any GA::Win::Map objects using this world model (if allowed)
14389 if ($updateFlag) {
14390  
14391 foreach my $mapWin ($self->collectMapWins()) {
14392  
14393 # Redraw the objects
14394 $mapWin->markObjs(@redrawList);
14395 $mapWin->doDraw();
14396 }
14397 }
14398  
14399 return 1;
14400 }
14401  
14402 sub setExitOrnament {
14403  
14404 # Can be called by anything (especially by $self->setMultipleOrnaments)
14405 # Sets (or resets) the exit's ornament . Optionally sets (or resets) the ornament of the
14406 # twin exit (if there is one) to match
14407 #
14408 # Expected arguments
14409 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
14410 # be updated now, FALSE if not (in which case, they can be updated later
14411 # by the calling function, when it is ready)
14412 # $exitObj - The exit object to modify
14413 #
14414 # Optional arguments
14415 # $type - The exit ornament type, one of the permitted values for
14416 # GA::Obj::Exit->exitOrnament ('none', 'break', 'pick', 'lock', 'open',
14417 # 'impass', 'mystery'). If 'undef', the value 'none' is set
14418 # $twinFlag - If set to TRUE, the twin exit's ornament (if there is a twin exit) is set
14419 # to match
14420 #
14421 # Return values
14422 # 'undef' on improper arguments
14423 # 1 otherwise
14424  
14425 my ($self, $updateFlag, $exitObj, $type, $twinFlag, $check) = @_;
14426  
14427 # Local variables
14428 my (
14429 $regionFlag, $twinExitObj, $twinRegionFlag, $roomObj, $regionObj, $twinRoomObj,
14430 $twinRegionObj,
14431 );
14432  
14433 # Check for improper arguments
14434 if (
14435 ! defined $updateFlag || ! defined $exitObj
14436 || (
14437 defined $type && $type ne 'none' && $type ne 'break' && $type ne 'pick'
14438 && $type ne 'lock' && $type ne 'open' && $type ne 'impass' && $type ne 'mystery'
14439 ) || defined $check
14440 ) {
14441 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitOrnament', @_);
14442 }
14443  
14444 $regionFlag = $exitObj->regionFlag;
14445  
14446 # Set the twin exit object now (if needed), because the call to ->setImpassableExit
14447 # abandons the twin
14448 if ($twinFlag && $exitObj->twinExit) {
14449  
14450 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
14451 $twinRegionFlag = $twinExitObj->regionFlag;
14452 }
14453  
14454 # Set (or reset) the IV
14455 if (! defined $type) {
14456 $exitObj->ivPoke('exitOrnament', 'none');
14457 } else {
14458 $exitObj->ivPoke('exitOrnament', $type);
14459 }
14460  
14461 # Update impassable/mystery exit settings
14462 if ($type && ($type eq 'impass' || $type eq 'mystery')) {
14463  
14464 # Convert this exit into an incomplete impassable exit
14465 $self->setImpassableExit(
14466 FALSE, # Don't update Automapper windows yet
14467 $exitObj,
14468 $type,
14469 );
14470  
14471 } elsif ($exitObj->exitState eq 'impass') {
14472  
14473 # The exit's state is no longer impassable
14474 $exitObj->ivPoke('exitState', 'normal'); # State not known
14475 }
14476  
14477 # The call to ->setImpassableExit updates ->updatePathHash and ->updateBoundaryHash. If it
14478 # was not called, those IVs must be updated now
14479 if (! $type || $type ne 'impass') {
14480  
14481 # Find the parent region
14482 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
14483 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14484 # Update the hashes
14485 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14486 if ($exitObj->regionFlag) {
14487  
14488 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14489 }
14490 }
14491  
14492 # Reset the IVs on the twin exit, if necessary
14493 if ($twinExitObj) {
14494  
14495 $twinExitObj->ivPoke('exitOrnament', $exitObj->exitOrnament);
14496  
14497 if ($type && ($type eq 'impass' || $type eq 'mystery')) {
14498  
14499 # Convert this exit into an incomplete impassable exit
14500 $self->setImpassableExit(
14501 FALSE, # Don't update Automapper windows yet
14502 $twinExitObj,
14503 $type,
14504 );
14505  
14506 } elsif ($twinExitObj->exitState eq 'impass') {
14507  
14508 # The exit's state is no longer impassable
14509 $twinExitObj->ivPoke('exitState', 'normal'); # State not known
14510 }
14511  
14512 if (! $type || ($type ne 'impass' && $type ne 'mystery')) {
14513  
14514 # The call to ->setImpassableExit updates ->updatePathHash and ->updateBoundaryHash.
14515 # If it was not called, those IVs must be updated now
14516 # Find the parent region
14517 $twinRoomObj = $self->ivShow('modelHash', $twinExitObj->parent);
14518 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
14519 # Update the hashes
14520 $self->ivAdd('updatePathHash', $twinExitObj->number, $twinRegionObj->name);
14521 if ($twinExitObj->regionFlag) {
14522  
14523 $self->ivAdd('updateBoundaryHash', $twinExitObj->number, $twinRegionObj->name);
14524 }
14525 }
14526 }
14527  
14528 if ($updateFlag) {
14529  
14530 # Mark this exit (and its twin, if there is one) to be redrawn in every Automapper
14531 # window using this world model
14532 $self->updateMapExit($exitObj, $twinExitObj);
14533 }
14534  
14535 return 1;
14536 }
14537  
14538 sub setMultipleOrnaments {
14539  
14540 # Called by GA::Win::Map->exitOrnamentCallback
14541 # Sets ornaments for one or more exits
14542 #
14543 # Expected arguments
14544 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14545 # should be updated now, FALSE if not (in which case, they can be
14546 # updated later by the calling function, when it is ready)
14547 #
14548 # Optional arguments
14549 # $type - The exit ornament type, one of the permitted values for
14550 # GA::Obj::Exit->exitOrnament ('none', 'break', 'pick', 'lock',
14551 # 'open', 'impass', 'mystery'). If 'undef', the value 'none' is set
14552 # @exitList - A list of exit objects to modify. If the list is empty, no exits are
14553 # modified
14554 #
14555 # Return values
14556 # 'undef' on improper arguments or if @exitList is empty
14557 # 1 otherwise
14558  
14559 my ($self, $updateFlag, $type, @exitList) = @_;
14560  
14561 # Local variables
14562 my (
14563 @redrawList,
14564 %roomHash,
14565 );
14566  
14567 # Check for improper arguments
14568 if (! defined $updateFlag) {
14569  
14570 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMultipleOrnaments', @_);
14571 }
14572  
14573 # An exit's twin exit can be reset during the ornament-setting process, so compile a list of
14574 # rooms to redraw first
14575 if ($updateFlag) {
14576  
14577 foreach my $exitObj (@exitList) {
14578  
14579 my $twinExitObj;
14580  
14581 # Mark this room as needing to be redrawn (if allowed), adding it to a hash to
14582 # eliminate duplicates
14583 $roomHash{$exitObj->parent} = $self->ivShow('modelHash', $exitObj->parent);
14584 # If the exit has a twin exit, its parent must also be marked to be redrawn (e.g.
14585 # when we take a two-way exit and modify one of the twins to an impassable exit,
14586 # the other one must be redrawn, two)
14587 if ($exitObj->twinExit) {
14588  
14589 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
14590 $roomHash{$twinExitObj->parent}
14591 = $self->ivShow('modelHash', $twinExitObj->parent);
14592 }
14593 }
14594 }
14595  
14596 foreach my $exitObj (@exitList) {
14597  
14598 # Reset or set the exit's ornament IVs (and reset/set the twin exit's ornament IVs to
14599 # match, if the appropriate flag is set)
14600 $self->setExitOrnament(
14601 FALSE, # Don't update Automapper windows yet
14602 $exitObj,
14603 $type, # May be 'undef'
14604 $self->setTwinOrnamentFlag,
14605 );
14606 }
14607  
14608 # Update any GA::Win::Map objects using this world model (if allowed)
14609 if ($updateFlag) {
14610  
14611 foreach my $roomObj (values %roomHash) {
14612  
14613 push (@redrawList, 'room', $roomObj);
14614 }
14615  
14616 foreach my $mapWin ($self->collectMapWins()) {
14617  
14618 # Redraw the rooms
14619 $mapWin->markObjs(@redrawList);
14620 $mapWin->doDraw();
14621 }
14622 }
14623  
14624 return 1;
14625 }
14626  
14627 sub setAssistedMove {
14628  
14629 # Called by GA::Win::Map->addExitCallback and ->setAssistedMoveCallback
14630 # Adds or removes an assisted move to/from a specified exit object
14631 #
14632 # Expected arguments
14633 # $exitObj - The GA::Obj::Exit to be modified
14634 # $profile - The name of a profile. When it's a current profile, this assisted move
14635 # is available to the automapper object code
14636 #
14637 # Optional arguments
14638 # $cmdSequence - A sequence of one or more world commands (separated by the usual
14639 # command separator) that comprise the assisted move, e.g.
14640 # 'north;open door;east'. If 'undef' or an empty string, the assisted
14641 # move for $profile is removed
14642 #
14643 # Return values
14644 # 'undef' on improper arguments
14645 # 1 otherwise
14646  
14647 my ($self, $exitObj, $profile, $cmdSequence, $check) = @_;
14648  
14649 # Check for improper arguments
14650 if (! defined $exitObj || ! defined $profile || defined $check) {
14651  
14652 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAssistedMove', @_);
14653 }
14654  
14655 # Update the exit object
14656 if (! defined $cmdSequence || $cmdSequence eq '') {
14657 $exitObj->ivDelete('assistedHash', $profile);
14658 } else {
14659 $exitObj->ivAdd('assistedHash', $profile, $cmdSequence);
14660 }
14661  
14662 return 1;
14663 }
14664  
14665 sub modifyIncomingExits {
14666  
14667 # Called by GA::Win::Map->addExitCallback
14668 # After the new exit is added, checks the parent room's list of incoming exits. Any incoming
14669 # exits whose map direction, ->mapDir, is the opposite of the new exit's map direction
14670 # must be converted to uncertain exits
14671 #
14672 # Expected arguments
14673 # $session - The calling function's GA::Session
14674 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14675 # should be updated now, FALSE if not (in which case, they can be
14676 # updated later by the calling function, when it is ready)
14677 # $roomObj - The new exit's parent room
14678 # $exitObj - The new GA::Obj::Exit object
14679 #
14680 # Return values
14681 # 'undef' on improper arguments or if no incoming exits are converted
14682 # 1 otherwise
14683  
14684 my ($self, $session, $updateFlag, $roomObj, $exitObj, $check) = @_;
14685  
14686 # Check for improper arguments
14687 if (
14688 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14689 || defined $check
14690 ) {
14691 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyIncomingExits', @_);
14692 }
14693  
14694 # Check each incoming exit in turn
14695 foreach my $incomingNum ($roomObj->ivKeys('oneWayExitHash')) {
14696  
14697 my ($incomingExitObj, $oppDir, $incomingRoomObj, $incomingRegionObj);
14698  
14699 $incomingExitObj = $self->ivShow('exitModelHash', $incomingNum);
14700  
14701 # Only check allocated exits...
14702 if (
14703 $incomingExitObj->drawMode eq 'primary'
14704 || $incomingExitObj->drawMode eq 'perm_alloc'
14705 ) {
14706 # Get the opposite direction of the incoming exit
14707 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->dir);
14708 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->dir) {
14709  
14710 # Special case: A-O-B, where O is a gap, and B has 1-way exit pointing at A; if
14711 # we put a room at location O, and connect A and O, the exit from B should
14712 # be drawn as a broken exit
14713 if (
14714 ! $incomingExitObj->regionFlag
14715 && ! $self->checkRoomAlignment($session, $incomingExitObj)
14716 ) {
14717 $self->setBrokenExit($updateFlag, $incomingExitObj);
14718 }
14719  
14720 # Convert the incoming exit into an uncertain exit
14721 $incomingExitObj->ivPoke('oneWayFlag', FALSE);
14722 $incomingExitObj->ivPoke('oneWayDir', undef);
14723 # Remove the entry from one hash, and add it the other
14724 $roomObj->ivDelete('oneWayExitHash', $incomingExitObj->number);
14725 $roomObj->ivAdd(
14726 'uncertainExitHash',
14727 $incomingExitObj->number,
14728 $exitObj->number,
14729 );
14730  
14731 # If the incoming exit had any bends, remove them
14732 $incomingExitObj->ivEmpty('bendOffsetList');
14733  
14734 # Find the incoming exit's parent region
14735 $incomingRoomObj = $self->ivShow('modelHash', $incomingExitObj->parent);
14736 $incomingRegionObj = $self->ivShow('modelHash', $incomingRoomObj->parent);
14737 # Any region paths using the exit will have to be updated
14738 $self->ivAdd(
14739 'updatePathHash',
14740 $incomingExitObj->number,
14741 $incomingRegionObj->name,
14742 );
14743  
14744 if ($incomingExitObj->regionFlag) {
14745  
14746 $self->ivAdd(
14747 'updateBoundaryHash',
14748 $incomingExitObj->number,
14749 $incomingRegionObj->name,
14750 );
14751 }
14752  
14753 if ($updateFlag) {
14754  
14755 # Mark this incoming exit to be redrawn in every Automapper window using
14756 # this world model
14757 $self->updateMapExit($incomingExitObj);
14758 }
14759  
14760 # Return 1 to show that an exit was modified
14761 return 1;
14762 }
14763 }
14764 }
14765  
14766 # No exits were modified
14767 return undef;
14768 }
14769  
14770 sub changeShadowExitDir {
14771  
14772 # Called by GA::Win::Map->changeDirCallback
14773 # When the user tries to change the direction of an exit that's been allocated a shadow
14774 # exit, the 'change direction' operation merely reassigns it as an unallocated exit
14775 #
14776 # Expected arguments
14777 # $session - The calling function's GA::Session
14778 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14779 # should be updated now, FALSE if not (in which case, they can be
14780 # updated later by the calling function, when it is ready)
14781 # $roomObj - The exit's parent room
14782 # $exitObj - The GA::Obj::Exit object to be modified
14783 #
14784 # Return values
14785 # 'undef' on improper arguments
14786 # 1 otherwise
14787  
14788 my ($self, $session, $updateFlag, $roomObj, $exitObj, $check) = @_;
14789  
14790 # Local variables
14791 my $regionObj;
14792  
14793 # Check for improper arguments
14794 if (
14795 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14796 || defined $check
14797 ) {
14798 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeShadowExitDir', @_);
14799 }
14800  
14801 # Update the exit's IVs
14802 $exitObj->ivPoke('drawMode', 'temp_alloc');
14803 $exitObj->ivUndef('shadowExit');
14804 $exitObj->ivUndef('mapDir');
14805  
14806 # Allocate a primary direction (using the sixteen cardinal directions, but not 'up' or
14807 # 'down')
14808 $self->allocateCardinalDir($session, $roomObj, $exitObj);
14809  
14810 # Find the parent region
14811 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14812 # Any region paths using the exit will have to be updated
14813 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14814 if ($exitObj->regionFlag) {
14815  
14816 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14817 }
14818  
14819 if ($updateFlag) {
14820  
14821 # Mark this incoming exit to be redrawn in every Automapper window using this world
14822 # model
14823 $self->updateMapExit($exitObj);
14824 }
14825  
14826 return 1;
14827 }
14828  
14829 sub changeExitDir {
14830  
14831 # Called by GA::Win::Map->changeDirCallback
14832 # Changes an exit's direction
14833 #
14834 # Expected arguments
14835 # $session - The calling function's GA::Session
14836 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
14837 # should be updated now, FALSE if not (in which case, they can be
14838 # updated later by the calling function, when it is ready)
14839 # $roomObj - The exit's parent room
14840 # $exitObj - The GA::Obj::Exit object to be modified
14841 # $dir - The exit's new (nominal) direction, stored in ->dir
14842 #
14843 # Optional arguments
14844 # $mapDir - The exit's new map direction, stored in ->mapDir. If not specified, a
14845 # map direction is allocated (if possible)
14846 #
14847 # Return values
14848 # 'undef' on improper arguments or if the exit's direction can't be changed
14849 # 1 otherwise
14850  
14851 my ($self, $session, $updateFlag, $roomObj, $exitObj, $dir, $mapDir, $check) = @_;
14852  
14853 # Local variables
14854 my (
14855 $twinExitObj, $regionObj,
14856 @dirList, @sortedList, @redrawList,
14857 );
14858  
14859 # Check for improper arguments
14860 if (
14861 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
14862 || ! defined $dir || defined $check
14863 ) {
14864 return $axmud::CLIENT->writeImproper($self->_objClass . '->changeExitDir', @_);
14865 }
14866  
14867 # If $mapDir was specified and an existing exit already uses that map direction, we can't
14868 # modify the specified exit
14869 if ($mapDir) {
14870  
14871 foreach my $number ($roomObj->ivValues('exitNumHash')) {
14872  
14873 my $otherExitObj = $self->ivShow('exitModelHash', $number);
14874  
14875 if ($otherExitObj && $otherExitObj->mapDir && $otherExitObj->mapDir eq $mapDir) {
14876  
14877 return undef;
14878 }
14879 }
14880 }
14881  
14882 # Modify the exit object and its parent room object
14883  
14884 # Update the exit's ->dir
14885 $roomObj->ivDelete('exitNumHash', $exitObj->dir);
14886 $exitObj->ivPoke('dir', $dir);
14887 $roomObj->ivAdd('exitNumHash', $dir, $exitObj->number);
14888  
14889 # Delete the equivalent entry in the room's ->sortedExitList
14890 @dirList = $roomObj->ivKeys('exitNumHash');
14891 @sortedList = $session->currentDict->sortExits(@dirList);
14892 $roomObj->ivPoke('sortedExitList', @sortedList);
14893  
14894 # Set the exit's ->mapDir
14895 if ($mapDir) {
14896  
14897 $exitObj->ivPoke('mapDir', $mapDir);
14898  
14899 } else {
14900  
14901 # Allocate the exit an appropriate map direction
14902 $self->allocateCardinalDir($session, $roomObj, $exitObj);
14903 }
14904  
14905 # Set the exit type (e.g. 'primaryDir', 'primaryAbbrev', etc)
14906 $exitObj->ivPoke(
14907 'exitType',
14908 $session->currentDict->ivShow('combDirHash', $exitObj->dir),
14909 );
14910  
14911 # Find the parent region
14912 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
14913 # Any region paths using the exit will have to be updated
14914 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
14915 if ($exitObj->regionFlag) {
14916  
14917 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
14918 }
14919  
14920 # Check the parent room's exits; if any were previously unallocated exits which were
14921 # allocated the shadow exit we've just modified, then we must also modify those exits
14922 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
14923  
14924 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
14925  
14926 if (
14927 $otherExitObj->shadowExit
14928 && $otherExitObj->shadowExit == $exitObj->number
14929 && $otherExitObj->mapDir
14930 && $otherExitObj->mapDir ne $mapDir
14931 ) {
14932 # Assign the exit object a new map direction, matching its shadow's new map
14933 # direction
14934 $otherExitObj->ivPoke('mapDir', $mapDir);
14935  
14936 # Find the parent room and region
14937  
14938 # Any region paths using the exit will have to be updated
14939 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
14940 if ($otherExitObj->regionFlag) {
14941  
14942 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
14943 }
14944 }
14945 }
14946  
14947 # Now, we need to check if the room has any more unallocated exits. If they've temporarily
14948 # been assigned the primary direction 'undef', we must reallocate them
14949 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
14950  
14951 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
14952  
14953 if (! defined $otherExitObj->mapDir && $otherExitObj->drawMode eq 'primary') {
14954  
14955 # Assign the exit object a new map direction (using the sixteen cardinal directions,
14956 # but not 'up' or 'down'), if any are available
14957 $self->allocateCardinalDir($session, $roomObj, $otherExitObj);
14958  
14959 # Any region paths using the exit will have to be updated
14960 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
14961 if ($otherExitObj->regionFlag) {
14962  
14963 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
14964 }
14965 }
14966 }
14967  
14968 # Mark $roomObj to be redrawn (if allowed)
14969 push (@redrawList, 'room', $roomObj);
14970  
14971 # Now, if there are any incoming 1-way exits whose ->mapDir is now the opposite of
14972 # the exit we've just modified, the incoming exit should be marked as an uncertain exit
14973 OUTER: foreach my $incomingExitNum ($roomObj->ivKeys('oneWayExitHash')) {
14974  
14975 my ($incomingExitObj, $oppDir);
14976  
14977 $incomingExitObj = $self->ivShow('exitModelHash', $incomingExitNum);
14978  
14979 # Only check allocated exits...
14980 if (
14981 $incomingExitObj->drawMode eq 'primary'
14982 || $incomingExitObj->drawMode eq 'perm_alloc'
14983 ) {
14984 # Get the opposite direction of the incoming exit
14985 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->mapDir);
14986 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->mapDir) {
14987  
14988 # Convert the incoming exit into an uncertain exit
14989 $self->convertOneWayExit(
14990 FALSE, # Don't update Automapper windows yet
14991 $incomingExitObj,
14992 $roomObj,
14993 $exitObj,
14994 );
14995  
14996 # Mark the incoming exit's parent room to be redrawn
14997 push (
14998 @redrawList,
14999 'room',
15000 $self->ivShow('modelHash', $incomingExitObj->parent),
15001 );
15002  
15003 last OUTER;
15004 }
15005 }
15006 }
15007  
15008 # Both the exit, and its twin exit (if there is one) must be checked for alignment. If
15009 # they're no longer aligned, they must be marked as broken exits. If they are now aligned,
15010 # their broken exit status must be removed
15011 # Don't bother checking if the exit is marked as a region exit
15012 if ($exitObj->destRoom && ! $exitObj->regionFlag) {
15013  
15014 # Get the twin exit object (if any)
15015 if ($exitObj->twinExit) {
15016  
15017 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
15018 # Mark the twin exit's parent room to be redrawn
15019 push (
15020 @redrawList,
15021 'room',
15022 $self->ivShow('modelHash', $twinExitObj->parent),
15023 );
15024 }
15025  
15026 if (! $self->checkRoomAlignment($session, $exitObj)) {
15027  
15028 # Mark this exit and the twin exit, if there is one, as broken exits
15029 $self->setBrokenExit(
15030 FALSE, # Don't update Automapper windows now
15031 $exitObj,
15032 );
15033  
15034 if ($twinExitObj) {
15035  
15036 $self->setBrokenExit(
15037 FALSE, # Don't update Automapper windows now
15038 $twinExitObj,
15039 );
15040 }
15041  
15042 } elsif ($exitObj->brokenFlag) {
15043  
15044 # The rooms are now aligned, so it's no longer a broken exit (don't need to call a
15045 # separate function; there's only one IV to update)
15046 $exitObj->ivPoke('brokenFlag', FALSE);
15047 if ($twinExitObj) {
15048  
15049 $twinExitObj->ivPoke('brokenFlag', FALSE);
15050 }
15051 }
15052 }
15053  
15054 # Redraw the room(s) (and their exits), if allowed
15055 if ($updateFlag) {
15056  
15057 $self->updateMaps(@redrawList);
15058 }
15059  
15060 return 1;
15061 }
15062  
15063 sub setExitIncomingDir {
15064  
15065 # Called by GA::Win::Map->setExitTwinCallback
15066 # Changes a one-way exit's incoming direction (the direction it is drawn close to its
15067 # destination room)
15068 #
15069 # Expected arguments
15070 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15071 # should be updated now, FALSE if not (in which case, they can be
15072 # updated later by the calling function, when it is ready)
15073 # $exitObj - The GA::Obj::Exit object to be modified
15074 # $dir - The new incoming direction (should be a standard primary direction)
15075 #
15076 # Return values
15077 # 'undef' on improper arguments or if the exit's direction can't be changed
15078 # 1 otherwise
15079  
15080 my ($self, $updateFlag, $exitObj, $dir, $check) = @_;
15081  
15082 # Local variables
15083 my ($roomObj, $destRoomObj);
15084  
15085 # Check for improper arguments
15086 if (! defined $updateFlag || ! defined $exitObj || ! defined $dir || defined $check) {
15087  
15088 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitIncomingDir', @_);
15089 }
15090  
15091 # Check that $exitObj is really one-way and that $dir is really a standard primary direction
15092 if (! $exitObj->oneWayFlag || ! $axmud::CLIENT->ivExists('constOppDirHash', $dir)) {
15093  
15094 return undef;
15095  
15096 } else {
15097  
15098 $exitObj->ivPoke('oneWayDir', $dir);
15099  
15100 # Redraw the exit's parent room and its destination room, if allowed
15101 if ($updateFlag) {
15102  
15103 # Get the exit's parent room and its destination room
15104 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15105 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15106  
15107 $self->updateMaps(
15108 'room', $roomObj,
15109 'room', $destRoomObj,
15110 );
15111 }
15112  
15113 return 1;
15114 }
15115 }
15116  
15117 sub setExitMapDir {
15118  
15119 # Called by GA::Win::Map->allocateMapDirCallback
15120 # Sets an exit's map direction, ->mapDir, using a value specified by the user
15121 #
15122 # Expected arguments
15123 # $session - The calling function's GA::Session
15124 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15125 # should be updated now, FALSE if not (in which case, they can be
15126 # updated later by the calling function, when it is ready)
15127 # $roomObj - The exit's parent room
15128 # $exitObj - The GA::Obj::Exit object to be modified
15129 # $mapDir - The exit's new map direction (a standard primary direction)
15130 #
15131 # Return values
15132 # 'undef' on improper arguments or if the exit's direction can't be changed
15133 # 1 otherwise
15134  
15135 my ($self, $session, $updateFlag, $roomObj, $exitObj, $mapDir, $check) = @_;
15136  
15137 # Local variables
15138 my (
15139 $customDir, $regionObj,
15140 @redrawList,
15141 );
15142  
15143 # Check for improper arguments
15144 if (
15145 ! defined $session || ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
15146 || ! defined $mapDir || defined $check
15147 ) {
15148 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitMapDir', @_);
15149 }
15150  
15151 # Update the selected exit and mark it as 'allocated'
15152 $exitObj->ivPoke('mapDir', $mapDir);
15153 # Mark the exit as 'allocated'
15154 $exitObj->ivPoke('drawMode', 'perm_alloc');
15155 # Any checked directions in the corresponding custom primary direction are destroyed
15156 $customDir = $session->currentDict->ivShow('primaryDirHash', $mapDir);
15157 if (defined $customDir) {
15158  
15159 $roomObj->ivDelete('checkedDirHash', $customDir);
15160 }
15161  
15162 # Find the parent region
15163 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15164 # Any region paths using the exit will have to be updated
15165 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15166 if ($exitObj->regionFlag) {
15167  
15168 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15169 }
15170  
15171 # Check the parent room to see if it has any more unallocated exits. If they've temporarily
15172 # been assigned the same map direction as the map direction specified by the user,
15173 # $mapDir, we must reallocate them
15174 OUTER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
15175  
15176 my $otherExitObj = $self->ivShow('exitModelHash', $exitNum);
15177  
15178 if (
15179 $otherExitObj->mapDir
15180 && $otherExitObj->mapDir eq $mapDir
15181 && (
15182 $otherExitObj->drawMode eq 'temp_alloc'
15183 || $otherExitObj->drawMode eq 'temp_unalloc'
15184 )
15185 ) {
15186 # Assign the exit object a new map direction (using the sixteen cardinal directions,
15187 # but not 'up' or 'down'), if any are available
15188 $otherExitObj->ivUndef('mapDir');
15189 $self->allocateCardinalDir($session, $roomObj, $otherExitObj);
15190  
15191 # Any region paths using the exit will have to be updated
15192 $self->ivAdd('updatePathHash', $otherExitObj->number, $regionObj->name);
15193 if ($exitObj->regionFlag) {
15194  
15195 $self->ivAdd('updateBoundaryHash', $otherExitObj->number, $regionObj->name);
15196 }
15197  
15198 # (Having found one matching exit, we don't need to check the others)
15199 last OUTER;
15200 }
15201 }
15202  
15203 # Mark $roomObj to be redrawn (if allowed)
15204 push (@redrawList, 'room', $roomObj);
15205  
15206 # Now, if there are any incoming 1-way exits whose ->mapDir is now the opposite of
15207 # the exit we've just allocated, the incoming exit should be marked as an uncertain exit
15208 OUTER: foreach my $incomingExitNum ($roomObj->ivKeys('oneWayExitHash')) {
15209  
15210 my ($incomingExitObj, $oppDir);
15211  
15212 $incomingExitObj = $self->ivShow('exitModelHash', $incomingExitNum);
15213  
15214 # Only check allocated exits...
15215 if (
15216 $incomingExitObj->drawMode eq 'primary'
15217 || $incomingExitObj->drawMode eq 'perm_alloc'
15218 ) {
15219 # Get the opposite direction of the incoming exit
15220 $oppDir = $axmud::CLIENT->ivShow('constOppDirHash', $incomingExitObj->mapDir);
15221 if ($oppDir && $exitObj->mapDir && $oppDir eq $exitObj->mapDir) {
15222  
15223 # Convert the incoming exit into an uncertain exit
15224 $self->convertOneWayExit(
15225 FALSE, # Don't update Automapper windows yet
15226 $incomingExitObj,
15227 $roomObj,
15228 $exitObj,
15229 );
15230  
15231 # Mark the incoming exit's parent room to be redrawn
15232 push (@redrawList, $self->ivShow('modelHash', $incomingExitObj->parent));
15233  
15234 last OUTER;
15235 }
15236 }
15237 }
15238  
15239 # Update any GA::Win::Map objects using this world model (if allowed)
15240 if ($updateFlag) {
15241  
15242 foreach my $mapWin ($self->collectMapWins()) {
15243  
15244 # Redraw the rooms
15245 $mapWin->markObjs(@redrawList);
15246 $mapWin->doDraw();
15247  
15248 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15249 $mapWin->restrictWidgets();
15250 }
15251 }
15252  
15253 return 1;
15254 }
15255  
15256 sub setExitShadow {
15257  
15258 # Called by GA::Win::Map->allocateShadowCallback
15259 # Sets an exit's shadow exit
15260 #
15261 # Expected arguments
15262 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15263 # should be updated now, FALSE if not (in which case, they can be
15264 # updated later by the calling function, when it is ready)
15265 # $roomObj - The exit's parent room
15266 # $exitObj - The GA::Obj::Exit object to be modified
15267 # $shadowExitObj - The exit object which is $exitObj's new shadow exit
15268 #
15269 # Return values
15270 # 'undef' on improper arguments
15271 # 1 otherwise
15272  
15273 my ($self, $updateFlag, $roomObj, $exitObj, $shadowExitObj, $check) = @_;
15274  
15275 # Local variables
15276 my $regionObj;
15277  
15278 # Check for improper arguments
15279 if (
15280 ! defined $updateFlag || ! defined $roomObj || ! defined $exitObj
15281 || ! defined $shadowExitObj || defined $check
15282 ) {
15283 return $axmud::CLIENT->writeImproper($self->_objClass . '->setExitShadow', @_);
15284 }
15285  
15286 # Update the exit
15287 $exitObj->ivPoke('shadowExit', $shadowExitObj->number);
15288 # This exit has the same map direction as the shadow (will be set to 'undef' for
15289 # unallocatable exits)
15290 $exitObj->ivPoke('mapDir', $shadowExitObj->mapDir);
15291 # Mark the exit as 'allocated'
15292 $exitObj->ivPoke('drawMode', 'perm_alloc');
15293  
15294 # Find the parent region
15295 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15296 # Any region paths using the exit will have to be updated
15297 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15298 if ($exitObj->regionFlag) {
15299  
15300 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15301 }
15302  
15303 # Update any GA::Win::Map objects using this world model (if allowed)
15304 if ($updateFlag) {
15305  
15306 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15307  
15308 # Redraw the room
15309 $mapWin->markObjs('room', $roomObj);
15310 $mapWin->doDraw();
15311  
15312 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15313 $mapWin->restrictWidgets();
15314 }
15315 }
15316  
15317 return 1;
15318 }
15319  
15320 sub completeExits {
15321  
15322 # Called by GA::Win::Map->allocateShadowCallback
15323 # Given a list of exit objects, looking for uncertain exits which match an opposite
15324 # incomplete exit. When a pair is found, converts them into two-way exits
15325 #
15326 # Expected arguments
15327 # $session - The calling function's GA::Session
15328 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15329 # should be updated now, FALSE if not (in which case, they can be
15330 # updated later by the calling function, when it is ready)
15331 #
15332 # Optional arguments
15333 # @exitList - A list of GA::Obj::Exit objects. If an empty list, no exits are
15334 # modified
15335 #
15336 # Return values
15337 # 'undef' on improper arguments or if @exitList is empty
15338 # 1 otherwise
15339  
15340 my ($self, $session, $updateFlag, @exitList) = @_;
15341  
15342 # Local variables
15343 my (
15344 $dictObj, $regionFlag, $twinRegionFlag,
15345 @redrawList,
15346 %redrawHash,
15347 );
15348  
15349 # Check for improper arguments
15350 if (! defined $session || ! defined $updateFlag) {
15351  
15352 return $axmud::CLIENT->writeImproper($self->_objClass . '->completeExits', @_);
15353 }
15354  
15355 # Don't do anything if @exitList is empty
15356 if (! @exitList) {
15357  
15358 return undef;
15359 }
15360  
15361 # Import the current dictionary
15362 $dictObj = $session->currentDict;
15363  
15364 # Check each exit in turn
15365 OUTER: foreach my $exitObj (@exitList) {
15366  
15367 my (
15368 $roomObj, $twinRoomObj, $twinExitObj, $oppDir, $regionObj, $twinRegionObj,
15369 @oppDirList,
15370 );
15371  
15372 if ($exitObj->destRoom && (! $exitObj->twinExit) && (! $exitObj->oneWayFlag)) {
15373  
15374 # It's an uncertain exit. Is there an incomplete exit in the opposite direction?
15375  
15376 # Get the blessed references of the uncertain exit's room...
15377 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15378 # ...and of the incomplete exit's room
15379 $twinRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15380  
15381 # Get the opposite direction
15382 $oppDir = $dictObj->ivShow('combOppDirHash', $exitObj->dir);
15383 # For secondary directions, $oppDir might be several words, separated by spaces
15384 # (e.g. the scalar 'entrance in' might be the opposite of 'exit')
15385 # Split them into a list of words, e.g. ('entrance', 'in')
15386 @oppDirList = split(/\s/, $oppDir);
15387  
15388 INNER: foreach my $item (@oppDirList) {
15389  
15390 if ($twinRoomObj->ivExists('exitNumHash', $item)) {
15391  
15392 # Success! $exitObj is an uncertain exit, so get the twin exit object
15393 $twinExitObj = $self->ivShow(
15394 'exitModelHash',
15395 $twinRoomObj->ivShow('exitNumHash', $item),
15396 );
15397  
15398 last INNER;
15399 }
15400 }
15401  
15402 if ($twinExitObj) {
15403  
15404 $regionFlag = $exitObj->regionFlag;
15405 $regionObj = $self->ivShow('modelHash', $roomObj->parent);
15406 $twinRegionFlag = $twinExitObj->regionFlag;
15407 $twinRegionObj = $self->ivShow('modelHash', $twinRoomObj->parent);
15408  
15409 # Connect the two rooms with twin exits
15410 $exitObj->ivPoke('twinExit', $twinExitObj->number);
15411 $twinExitObj->ivPoke('twinExit', $exitObj->number);
15412 $twinExitObj->ivPoke('destRoom', $roomObj->number);
15413  
15414 # If either room used to be an uncertain exit, tell the opposite room that it no
15415 # longer needs to keep track
15416 if ($twinRoomObj->ivExists('uncertainExitHash', $exitObj->number)) {
15417  
15418 $twinRoomObj->ivDelete('uncertainExitHash', $exitObj->number);
15419 }
15420  
15421 if ($roomObj->ivExists('uncertainExitHash', $twinExitObj->number)) {
15422  
15423 $roomObj->ivDelete('uncertainExitHash', $twinExitObj->number);
15424 }
15425  
15426 # Any region paths using the exits will have to be updated
15427 $self->ivAdd('updatePathHash', $exitObj->number, $regionObj->name);
15428 if ($regionFlag || $exitObj->regionFlag) {
15429  
15430 $self->ivAdd('updateBoundaryHash', $exitObj->number, $regionObj->name);
15431 }
15432  
15433 $self->ivAdd('updatePathHash', $twinExitObj->number, $twinRegionObj->name);
15434 if ($twinRegionFlag || $twinExitObj->regionFlag) {
15435  
15436 $self->ivAdd(
15437 'updateBoundaryHash',
15438 $twinExitObj->number,
15439 $twinRegionObj->name,
15440 );
15441 }
15442  
15443 # Mark the parent rooms of both exits to be redrawn
15444 $redrawHash{$roomObj->number} = $roomObj;
15445 $redrawHash{$twinRoomObj->number} = $twinRoomObj;
15446 }
15447 }
15448 }
15449  
15450 # Update any GA::Win::Map objects using this world model (if allowed)
15451 if ($updateFlag && %redrawHash) {
15452  
15453 foreach my $obj (values %redrawHash) {
15454  
15455 push (@redrawList, 'room', $obj);
15456 }
15457  
15458 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15459  
15460 # Redraw the rooms
15461 $mapWin->markObjs(@redrawList);
15462 $mapWin->doDraw();
15463  
15464 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15465 $mapWin->restrictWidgets();
15466 }
15467 }
15468  
15469 return 1;
15470 }
15471  
15472 sub checkBentExit {
15473  
15474 # Called by $self->setBrokenExit and ->connectRegionBrokenExit
15475 # When an exit is marked as a broken exit, this function decides whether its ->bentFlag
15476 # should be set to TRUE or FALSE
15477 #
15478 # Expected arguments
15479 # $exitObj - The broken exit object to check
15480 #
15481 # Optional arguments
15482 # $roomObj - The exit's parent room, if known (if 'undef', this functions finds it)
15483 # $destRoomObj - The exit's destination room, if known (if 'undef', this function
15484 # finds it)
15485 #
15486 # Return values
15487 # 'undef' on improper arguments
15488 # 1 otherwise
15489  
15490 my ($self, $exitObj, $roomObj, $destRoomObj, $check) = @_;
15491  
15492 # Check for improper arguments
15493 if (! defined $exitObj || defined $check) {
15494  
15495 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkBentExit', @_);
15496 }
15497  
15498 # Get the parent and destination rooms, if not specified
15499 if (! $roomObj) {
15500  
15501 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15502 }
15503  
15504 if (! $destRoomObj) {
15505  
15506 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15507 }
15508  
15509 # If $self->drawBentExitsFlag is set - and if the exit's parent and destination rooms are on
15510 # the same level - this exit should be drawn as a bent broken exit
15511 # (If ->bentFlag is already TRUE, because the exit was already a broken exit, dont change
15512 # anything)
15513 if (! $exitObj->bentFlag) {
15514  
15515 if (
15516 $self->drawBentExitsFlag
15517 && $destRoomObj
15518 && $destRoomObj->zPosBlocks == $roomObj->zPosBlocks
15519 ) {
15520 $exitObj->ivPoke('bentFlag', TRUE);
15521 } else {
15522 $exitObj->ivPoke('bentFlag', FALSE);
15523 $exitObj->ivEmpty('bendOffsetList');
15524 }
15525 }
15526  
15527 return 1;
15528 }
15529  
15530 sub toggleBentExit {
15531  
15532 # Called by GA::Win::Map->enableExitsColumn
15533 # Toggles a broken exit between a normal and bent broken exit
15534 #
15535 # Expected arguments
15536 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15537 # should be updated now, FALSE if not (in which case, they can be
15538 # updated later by the calling function, when it is ready)
15539 # $exitObj - The broken exit object to toggle
15540 #
15541 # Return values
15542 # 'undef' on improper arguments or if $exitObj isn't a broken exit
15543 # 1 otherwise
15544  
15545 my ($self, $updateFlag, $exitObj, $check) = @_;
15546  
15547 # Local variables
15548 my (
15549 $twinExitObj,
15550 @redrawList,
15551 );
15552  
15553 # Check for improper arguments
15554 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15555  
15556 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleBentExit', @_);
15557 }
15558  
15559 if (! $exitObj->brokenFlag) {
15560  
15561 # Not a broken exit - nothing to do
15562 return undef;
15563 }
15564  
15565 # Get the twin exit (if there is one)
15566 if ($exitObj->twinExit) {
15567  
15568 $twinExitObj = $self->ivShow('exitModelHash', $exitObj->twinExit);
15569 }
15570  
15571 # Toggle the broken exit (and the twin broken exit, if there is one)
15572 if (! $exitObj->bentFlag) {
15573  
15574 $exitObj->ivPoke('bentFlag', TRUE);
15575 if ($twinExitObj) {
15576  
15577 $twinExitObj->ivPoke('bentFlag', TRUE);
15578 }
15579  
15580 } else {
15581  
15582 $exitObj->ivPoke('bentFlag', FALSE);
15583 $exitObj->ivEmpty('bendOffsetList');
15584  
15585 if ($twinExitObj) {
15586  
15587 $twinExitObj->ivPoke('bentFlag', FALSE);
15588 $twinExitObj->ivEmpty('bendOffsetList');
15589 }
15590 }
15591  
15592 # Both parent rooms must be redrawn
15593 push (@redrawList, 'room', $self->ivShow('modelHash', $exitObj->parent));
15594 if ($twinExitObj) {
15595  
15596 push (@redrawList, 'room', $self->ivShow('modelHash', $twinExitObj->parent));
15597 }
15598  
15599 # Update any GA::Win::Map objects using this world model (if allowed)
15600 if ($updateFlag) {
15601  
15602 OUTER: foreach my $mapWin ($self->collectMapWins()) {
15603  
15604 # When an unbent broken exit is selected, the destination room is drawn a different
15605 # colour. Get around the problems of making sure this colour isn't still used in
15606 # any Automapper windows by unselecting any unselected objects
15607 $mapWin->setSelectedObj();
15608  
15609 # Redraw the rooms, which redraws the broken exits
15610 $mapWin->markObjs(@redrawList);
15611 $mapWin->doDraw();
15612  
15613 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
15614 $mapWin->restrictWidgets();
15615 }
15616 }
15617  
15618 return 1;
15619 }
15620  
15621 sub applyExitTag {
15622  
15623 # Called by $self->setRegionExit, $self->renameRegion, $self->connectRegionBrokenExit and
15624 # GA::Win::Map->editExitTagCallback
15625 # For the specified region exit, checks whether we're allowed to add an exit tag and, if so,
15626 # applies the exit tag and updates the parent regionmap
15627 #
15628 # Expected arguments
15629 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15630 # should be updated now, FALSE if not (in which case, they can be
15631 # updated later by the calling function, when it is ready)
15632 # $exitObj - The region exit object to modify
15633 #
15634 # Optional arguments
15635 # $regionmapObj - The exit's parent regionmap, if already known (otherwise, this
15636 # function finds it)
15637 # $customText - A string to use as the exit tag's text. If set to 'undef' or an empty
15638 # string, the standard string is useds
15639 # $overrideFlag - Set to TRUE when called by GA::Win::Map->editExitTagCallback and
15640 # $self->renameRegion; this object's ->updateExitTagFlag is not
15641 # consulted (set to FALSE, or 'undef', otherwise)
15642 #
15643 # Return values
15644 # 'undef' on improper arguments
15645 # 1 otherwise
15646  
15647 my ($self, $updateFlag, $exitObj, $regionmapObj, $customText, $overrideFlag, $check) = @_;
15648  
15649 # Local variables
15650 my ($roomObj, $regionObj, $destRoomObj, $destRegionObj, $newTag);
15651  
15652 # Check for improper arguments
15653 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15654  
15655 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyExitTag', @_);
15656 }
15657  
15658 # Don't do anything if we're not allowed to automatically add exit tags, and don't reset an
15659 # existing room tag (unless we're replacing an exit tag's standard text with some custom
15660 # text supplied by the user)
15661 if (
15662 ($self->updateExitTagFlag && ! $exitObj->exitTag)
15663 || $overrideFlag
15664 ) {
15665 # Get the parent regionmap, if not specified
15666 if (! $regionmapObj) {
15667  
15668 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15669 $regionmapObj = $self->findRegionmap($roomObj->parent);
15670 }
15671  
15672 # Get the destination room's parent region
15673 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
15674 $destRegionObj = $self->ivShow('modelHash', $destRoomObj->parent);
15675  
15676 # Apply the tag
15677 if ($customText) {
15678 $exitObj->ivPoke('exitTag', $customText);
15679 } else {
15680 $exitObj->ivPoke('exitTag', $self->getExitTagText($exitObj, $destRegionObj));
15681 }
15682  
15683 # Update the regionmap
15684 $regionmapObj->storeExitTag($exitObj);
15685  
15686 # Update any GA::Win::Map objects using this world model (if allowed)
15687 if ($updateFlag) {
15688  
15689 foreach my $mapWin ($self->collectMapWins()) {
15690  
15691 # Redraw the exit
15692 $mapWin->markObjs('exit', $exitObj);
15693 $mapWin->doDraw();
15694 }
15695 }
15696 }
15697  
15698 return 1;
15699 }
15700  
15701 sub getExitTagText {
15702  
15703 # Called by $self->applyExitTag to get the text of the exit tag to apply to a particular
15704 # exit
15705 # Also called by $self->renameRegion to compare a particular exit tag's text, which may have
15706 # been modified by the user, to the default text that would be applied to the exit tag
15707 #
15708 # Expected arguments
15709 # $exitObj - The exit object to check
15710 #
15711 # Optional arguments
15712 # $destRegionObj - The GA::ModelObj::Region which is the exit's destination region (set
15713 # to 'undef' when called by ->renameRegion)
15714 # $regionName - A region name; the text returned is that which would be used, if the
15715 # exit were connected to the region (set to 'undef' when called by
15716 # ->applyExitTag)
15717 #
15718 # Return values
15719 # 'undef' on improper arguments
15720 # The text of an exit tag otherwise
15721  
15722 my ($self, $exitObj, $destRegionObj, $regionName, $check) = @_;
15723  
15724 # Local variables
15725 my $text;
15726  
15727 # Check for improper arguments
15728 if (
15729 ! defined $exitObj
15730 || (! defined $destRegionObj && ! defined $regionName)
15731 || defined $check
15732 ) {
15733 return $axmud::CLIENT->writeImproper($self->_objClass . '->getExitTagText', @_);
15734 }
15735  
15736 # Set which region name to use. If $destRegionObj is set, we're using a real region name
15737 if (! $regionName) {
15738  
15739 $regionName = $destRegionObj->name;
15740 }
15741  
15742 # For exits drawn as 'up' or 'down', use those words in the tag
15743 if (
15744 $exitObj->mapDir
15745 && ($exitObj->mapDir eq 'up' || $exitObj->mapDir eq 'down')
15746 ) {
15747 $text = $exitObj->mapDir . ' to ' . $regionName;
15748 } else {
15749 $text = 'to ' . $regionName;
15750 }
15751  
15752 if ($exitObj->oneWayFlag) {
15753  
15754 $text .= ' (>)';
15755 }
15756  
15757 return $text;
15758 }
15759  
15760 sub cancelExitTag {
15761  
15762 # Called by several functions
15763 # For the specified exit, checks whether is has an exit tag and, if so, cancels the tag and
15764 # updates the parent regionmap
15765 #
15766 # Expected arguments
15767 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15768 # should be updated now, FALSE if not (in which case, they can be
15769 # updated later by the calling function, when it is ready)
15770 # $exitObj - The exit object to modify
15771 #
15772 # Optional arguments
15773 # $regionmapObj - The exit's parent regionmap, if already known (otherwise, this
15774 # function finds it)
15775 #
15776 # Return values
15777 # 'undef' on improper arguments
15778 # 1 otherwise
15779  
15780 my ($self, $updateFlag, $exitObj, $regionmapObj, $check) = @_;
15781  
15782 # Local variables
15783 my ($roomObj, $regionObj);
15784  
15785 # Check for improper arguments
15786 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15787  
15788 return $axmud::CLIENT->writeImproper($self->_objClass . '->cancelExitTag', @_);
15789 }
15790  
15791 # Don't do anything if $exitObj doesn't have an exit tag
15792 if ($exitObj->exitTag) {
15793  
15794 # Get the parent regionmap, if not specified
15795 if (! $regionmapObj) {
15796  
15797 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15798 $regionmapObj = $self->findRegionmap($roomObj->parent);
15799 }
15800  
15801 # Cancel the tag
15802 $exitObj->ivPoke('exitTag', undef);
15803 $exitObj->ivPoke('exitTagXOffset', 0);
15804 $exitObj->ivPoke('exitTagYOffset', 0);
15805  
15806 # Update the regionmap
15807 $regionmapObj->removeExitTag($exitObj);
15808  
15809 # Update any GA::Win::Map objects using this world model (if allowed)
15810 if ($updateFlag) {
15811  
15812 foreach my $mapWin ($self->collectMapWins()) {
15813  
15814 # Redraw the exit
15815 $mapWin->markObjs('exit', $exitObj);
15816 $mapWin->doDraw();
15817 }
15818 }
15819 }
15820  
15821 return 1;
15822 }
15823  
15824 sub resetExitTag {
15825  
15826 # Called by GA::Win::Map->resetExitOffsetsCallback
15827 # Restores an exit tag to its original position on the map
15828 #
15829 # Expected arguments
15830 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
15831 # be updated now, FALSE if not (in which case, they can be updated later
15832 # by the calling function, when it is ready)
15833 # $exitObj - The GA::Obj::Exit whose tag should be repositioned
15834 #
15835 # Return values
15836 # 'undef' on improper arguments or if @roomList is empty
15837 # 1 otherwise
15838  
15839 my ($self, $updateFlag, $exitObj, $check) = @_;
15840  
15841 # Local variables
15842 my $roomObj;
15843  
15844 # Check for improper arguments
15845 if (! defined $updateFlag || ! defined $exitObj || defined $check) {
15846  
15847 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetExitTag', @_);
15848 }
15849  
15850 # Update the exit tag
15851 if ($exitObj->exitTag) {
15852  
15853 $exitObj->ivPoke('exitTagXOffset', 0);
15854 $exitObj->ivPoke('exitTagYOffset', 0);
15855  
15856 # Update any GA::Win::Map objects using this world model (if allowed)
15857 if ($updateFlag) {
15858  
15859 # Get the exit's parent room
15860 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15861  
15862 foreach my $mapWin ($self->collectMapWins()) {
15863  
15864 # Redraw the exit
15865 $mapWin->markObjs('exit', $exitObj);
15866 $mapWin->doDraw();
15867 }
15868 }
15869 }
15870  
15871 return 1;
15872 }
15873  
15874 sub addExitBend {
15875  
15876 # Called by GA::Win::Map->addBendCallback
15877 # Adds a bend at the specified position on an exit (another call to this function is
15878 # required to add the corresponding bend to the twin exit, if any)
15879 #
15880 # Expected arguments
15881 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
15882 # should be updated now, FALSE if not (in which case, they can be
15883 # updated later by the calling function, when it is ready)
15884 # $exitObj - The GA::Obj::Exit to modify
15885 # $startXPos, $startYPos
15886 # - Absolute coordinates of the start of the exit's bending section
15887 # $clickXPos, $clickYPos
15888 # - The position of the mouse click, relative to the start of the bending
15889 # section of the exit
15890 # $stopXPos, $stopYPos
15891 # - The end of the bending section of the exit, relative to the start of
15892 # the bending section
15893 #
15894 # Return values
15895 # 'undef' on improper arguments
15896 # 1 otherwise
15897  
15898 my (
15899 $self, $updateFlag, $exitObj, $startXPos, $startYPos, $clickXPos, $clickYPos,
15900 $stopXPos, $stopYPos, $check,
15901 ) = @_;
15902  
15903 # Local variables
15904 my (
15905 $shortRatio, $shortRatioPosn, $roomObj,
15906 @offsetList,
15907 );
15908  
15909 # Check for improper arguments
15910 if (
15911 ! defined $updateFlag || ! defined $exitObj || ! defined $startXPos
15912 || ! defined $startYPos || ! defined $clickXPos || ! defined $clickYPos
15913 || ! defined $stopXPos || ! defined $stopYPos || defined $check
15914 ) {
15915 return $axmud::CLIENT->writeImproper($self->_objClass . '->addExitBend', @_);
15916 }
15917  
15918 # If the exit isn't already a bent broken exit, convert it to one ($self->setBrokenExit
15919 # calls ->checkBentExit to set the exit object's ->bentFlag IV)
15920 if (! $exitObj->brokenFlag) {
15921  
15922 $self->setBrokenExit(
15923 FALSE, # Don't update Automapper windows yet
15924 $exitObj,
15925 );
15926 }
15927  
15928 # If the exit currently has no bends, then our job is fairly easy
15929 if (! $exitObj->bendOffsetList) {
15930  
15931 $exitObj->ivPush('bendOffsetList', $clickXPos, $clickYPos);
15932  
15933 } else {
15934  
15935 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...) where each (x, y) pair
15936 # are the coordinates of a bend in the exit, relative to the start of the bending
15937 # section
15938 # Start by adding a pair of coordinates at the start of the bending section,
15939 # corresponding to the start of the bending section
15940 @offsetList = $exitObj->bendOffsetList;
15941 unshift(@offsetList, 0, 0);
15942 # Add another pair of coordinates, corresponding to the end of the bending section
15943 # (relative to the start)
15944 push (@offsetList, $stopXPos, $stopYPos);
15945  
15946 # Now work out where the new bend should be placed. The position of the mouse click
15947 # forms a triangle with the bends (including the start of the bending section) on
15948 # either side:
15949 # C
15950 # -- --
15951 # -- --
15952 # -- --
15953 # A --------D-------- B
15954 #
15955 # ...where A and B are existing bends (one of which might be the start/end of the
15956 # exit), and C is the position of the mouse click, very close to the line ADB. The
15957 # mouse click should create a new bend at D
15958 # The new bend is created between the bends A and B, for which the line ACB is closest
15959 # in length to ADB
15960 for (my $count = 0; $count < (scalar @offsetList - 2); $count += 2) {
15961  
15962 my ($aXPos, $aYPos, $bXPos, $bYPos, $ratio);
15963  
15964 $aXPos = $offsetList[$count];
15965 $aYPos = $offsetList[$count + 1];
15966 $bXPos = $offsetList[$count + 2];
15967 $bYPos = $offsetList[$count + 3];
15968  
15969 # Get the ratio ACB / ADB
15970 $ratio = $self->findBendRatio(
15971 $aXPos, $aYPos,
15972 $bXPos, $bYPos,
15973 $clickXPos, $clickYPos,
15974 );
15975  
15976 if (! defined $shortRatio || $ratio < $shortRatio) {
15977  
15978 # This is the first pair of bends, or the ratio for this pair of bends is the
15979 # smallest found so far
15980 $shortRatio = $ratio;
15981 $shortRatioPosn = $count + 2; # New bend is placed after bend A
15982 }
15983 }
15984  
15985 # Add the bend
15986 $exitObj->ivSplice('bendOffsetList', ($shortRatioPosn - 2), 0, $clickXPos, $clickYPos);
15987 }
15988  
15989 # Update any GA::Win::Map objects using this world model (if allowed)
15990 if ($updateFlag) {
15991  
15992 # Get the exit's parent room
15993 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
15994  
15995 foreach my $mapWin ($self->collectMapWins()) {
15996  
15997 # Redraw the room
15998 $mapWin->markObjs('room', $roomObj);
15999 $mapWin->doDraw();
16000 }
16001 }
16002  
16003 return 1;
16004 }
16005  
16006 sub findBendRatio {
16007  
16008 # Called by $self->addExitBend
16009 # In a triangle ABC, works out the ratio of the length ACB to the length AB (see the
16010 # comments in the calling function)
16011 #
16012 # Expected arguments
16013 # $aXPos, $aYPos - Relative coordinates of point A
16014 # $bXPos, $bYPos - Relative coordinates of point B
16015 # $cXPos, $cYPos - Relative coordinates of point C
16016 #
16017 # Return values
16018 # 'undef' on improper arguments
16019 # Otherwise returns the ratio ACB / AB
16020  
16021 my ($self, $aXPos, $aYPos, $bXPos, $bYPos, $cXPos, $cYPos, $check) = @_;
16022  
16023 # Local variables
16024 my ($lengthAB, $lengthAC, $lengthCB);
16025  
16026 # Check for improper arguments
16027 if (
16028 ! defined $aXPos || ! defined $aYPos || ! defined $bXPos || ! defined $bYPos
16029 || ! defined $cXPos || ! defined $cYPos || defined $check
16030 ) {
16031 return $axmud::CLIENT->writeImproper($self->_objClass . '->findBendRatio', @_);
16032 }
16033  
16034 # Find the lengths AB, AC and CB
16035 $lengthAB = sqrt( (($bXPos - $aXPos) ** 2) + (($bYPos - $aYPos) ** 2));
16036 $lengthAC = sqrt( (($cXPos - $aXPos) ** 2) + (($cYPos - $aYPos) ** 2));
16037 $lengthCB = sqrt( (($cXPos - $bXPos) ** 2) + (($cYPos - $bYPos) ** 2));
16038  
16039 # Return the ratio
16040 return ( abs ( ($lengthAC + $lengthCB) / $lengthAB));
16041 }
16042  
16043 sub adjustExitBend {
16044  
16045 # Called by GA::Win::Map->continueDrag
16046 # Called while dragging an exit bend in order to update the exit's IVs
16047 #
16048 # Expected arguments
16049 # $exitObj - The GA::Obj::Exit to update
16050 # $index - The index of the bend to adjust (the bend nearest to the start of the
16051 # exit's list of bend coordinates is numbered 0)
16052 # $xPos, $yPos - The bend's new coordinates, relative to the start of the bending
16053 # section of the exit
16054 #
16055 # Return values
16056 # 'undef' on improper arguments
16057 # 1 otherwise
16058  
16059 my ($self, $exitObj, $index, $xPos, $yPos, $check) = @_;
16060  
16061 # Check for improper arguments
16062 if (
16063 ! defined $exitObj || ! defined $index || ! defined $xPos || ! defined $yPos
16064 || defined $check
16065 ) {
16066 return $axmud::CLIENT->writeImproper($self->_objClass . '->adjustExitBend', @_);
16067 }
16068  
16069 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...). Replace a single pair of
16070 # (x, y) coordinates; e.g. if $index = 2, replace the 5th and 6th coordinates
16071 $index *= 2;
16072 $exitObj->ivSplice('bendOffsetList', $index, 2, $xPos, $yPos);
16073  
16074 return 1;
16075 }
16076  
16077 sub removeExitBend {
16078  
16079 # Called by GA::Win::Map->removeBendCallback
16080 # Removes a bend at the specified position on an exit (another call to this function is
16081 # required to remove the corresponding bend from the twin exit, if any)
16082 #
16083 # Expected arguments
16084 # $session - The calling function's GA::Session
16085 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model
16086 # should be updated now, FALSE if not (in which case, they can be
16087 # updated later by the calling function, when it is ready)
16088 # $exitObj - The GA::Obj::Exit to modify
16089 # $index - The index of the bend to remove (the bend nearest to the start of the
16090 # exit's list of bend coordinates is numbered 0)
16091 #
16092 # Return values
16093 # 'undef' on improper arguments
16094 # 1 otherwise
16095  
16096 my ($self, $session, $updateFlag, $exitObj, $index, $check) = @_;
16097  
16098 # Local variables
16099 my $roomObj;
16100  
16101 # Check for improper arguments
16102 if (
16103 ! defined $session || ! defined $updateFlag || ! defined $exitObj || ! defined $index
16104 || defined $check
16105 ) {
16106 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeExitBend', @_);
16107 }
16108  
16109 # GA::Obj::Exit->bendOffsetList is in the form (x, y, x, y...). Remove a single pair of
16110 # (x, y) coordinates; e.g. if $index = 2, remove the 5th and 6th coordinates
16111 $index *= 2;
16112 $exitObj->ivSplice('bendOffsetList', $index, 2);
16113  
16114 # Check whether the exit's destination and departure rooms are aligned. If so, we can
16115 # restore the exit to a non-broken status
16116 if (! $exitObj->bendOffsetList && $self->checkRoomAlignment($session, $exitObj)) {
16117  
16118 $self->restoreBrokenExit(
16119 $session,
16120 FALSE, # Don't update automapper windows now
16121 $exitObj,
16122 TRUE, # We've already called $self->checkRoomAlignment
16123 );
16124 }
16125  
16126 # Update any GA::Win::Map objects using this world model (if allowed)
16127 if ($updateFlag) {
16128  
16129 # Get the exit's parent room
16130 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
16131  
16132 foreach my $mapWin ($self->collectMapWins()) {
16133  
16134 # Redraw the room
16135 $mapWin->markObjs('room', $roomObj);
16136 $mapWin->doDraw();
16137 }
16138 }
16139  
16140 return 1;
16141 }
16142  
16143 sub updateExitBends {
16144  
16145 # Called by $self->moveRoomsLabels
16146 # When a room is dragged to a new position in the (same) regionmap, we must update the
16147 # position of any exit bends
16148 #
16149 # Expected arguments
16150 # $adjustXPos, $adjustYPos, $adjustZPos
16151 # - The direction of the room's movement, in gridblocks
16152 # $regionmapObj - The regionmap in which the exit's room has been moved
16153 # $exitObj - The GA::Obj::Exit whose bends must be updated
16154 #
16155 # Optional arguments
16156 # $twinExitObj - $exitObj's twin, if it has one ('undef' otherwise)
16157 #
16158 # Return values
16159 # 'undef' on improper arguments
16160 # 1 otherwise
16161  
16162 my (
16163 $self, $adjustXPos, $adjustYPos, $adjustZPos, $regionmapObj, $exitObj, $twinExitObj,
16164 $check,
16165 ) = @_;
16166  
16167 # Local variables
16168 my (@offsetList, @newList);
16169  
16170 # Check for improper arguments
16171 if (
16172 ! defined $adjustXPos || ! defined $adjustYPos || ! defined $adjustZPos
16173 || ! defined $exitObj || defined $check
16174 ) {
16175 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateExitBends', @_);
16176 }
16177  
16178 # If the room has moved up or down, remove bends altogether
16179 if ($adjustZPos) {
16180  
16181 $exitObj->ivEmpty('bendOffsetList');
16182 # (Also for the twin exit, if there is one)
16183 if ($twinExitObj) {
16184  
16185 $twinExitObj->ivEmpty('bendOffsetList');
16186 }
16187  
16188 # Otherwise, use the room's new position to update the bend's position
16189 # (We don't update the twin - if that room has also been dragged, this function will be
16190 # called again to update its bends)
16191 } else {
16192  
16193 $adjustXPos *= $regionmapObj->blockWidthPixels;
16194 $adjustYPos *= $regionmapObj->blockHeightPixels;
16195  
16196 @offsetList = $exitObj->bendOffsetList;
16197 do {
16198  
16199 # @offsetList is in the form (x, y, x, y...)
16200 push (@newList, ((shift @offsetList) - $adjustXPos));
16201 push (@newList, ((shift @offsetList) - $adjustYPos));
16202  
16203 } until (! @offsetList);
16204  
16205 $exitObj->ivPoke('bendOffsetList', @newList);
16206 }
16207  
16208 return 1;
16209 }
16210  
16211 # Modify model objects - labels
16212  
16213 sub updateLabel {
16214  
16215 # Called by GA::Win::Map->setLabelCallback and ->promptConfigLabel
16216 # Sets the specified label's ->name IV (containing the text displayed) and redraw the label
16217 # (if allowed)
16218 #
16219 # Expected arguments
16220 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
16221 # be updated now, FALSE if not (in which case, they can be updated later
16222 # by the calling function, when it is ready)
16223 # $session - The calling GA::Session
16224 # $labelObj - The GA::Obj::MapLabel to modify
16225 # $name - The new text for the label
16226 #
16227 # Optional arguments
16228 # $style - The new map label style (if 'undef', the label starts using its own IVs
16229 # to set a style)
16230 #
16231 # Return values
16232 # 'undef' on improper arguments
16233 # 1 otherwise
16234  
16235 my ($self, $updateFlag, $session, $labelObj, $name, $style, $check) = @_;
16236  
16237 # Check for improper arguments
16238 if (
16239 ! defined $updateFlag || ! defined $session || ! defined $labelObj || ! defined $name
16240 || defined $check
16241 ) {
16242 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateLabel', @_);
16243 }
16244  
16245 # Update IVs
16246 $labelObj->ivPoke('name', $name);
16247 if (defined $style) {
16248 $labelObj->set_style($session, $style);
16249 } else {
16250 $labelObj->reset_style();
16251 }
16252  
16253 # Update any GA::Win::Map objects using this world model (if allowed)
16254 if ($updateFlag) {
16255  
16256 foreach my $mapWin ($self->collectMapWins()) {
16257  
16258 # Redraw the label
16259 $mapWin->markObjs('label', $labelObj);
16260 $mapWin->doDraw();
16261 }
16262 }
16263  
16264 return 1;
16265 }
16266  
16267 # Room flag methods
16268  
16269 sub setupRoomFlags {
16270  
16271 # Called by $self->new to initialise the model's room filter and room flag IVs
16272 # Also called by $self->resetRoomFlags
16273 #
16274 # Expected arguments
16275 # $session - The calling GA::Session
16276 #
16277 # Return values
16278 # 'undef' on improper arguments
16279 # 1 otherwise
16280  
16281 my ($self, $session, $check) = @_;
16282  
16283 # Local variables
16284 my (
16285 $count,
16286 @initList, @orderedList,
16287 );
16288  
16289 # Check for improper arguments
16290 if (! defined $session || defined $check) {
16291  
16292 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupRoomFlags', @_);
16293 }
16294  
16295 # Set up ->roomFilterApplyHash, with no filters applied by default
16296 foreach my $filter ($axmud::CLIENT->constRoomFilterList) {
16297  
16298 $self->ivPoke('roomFilterApplyHash', $filter, FALSE);
16299 }
16300  
16301 # Create room flag objects, one for each room flag
16302 $count = 0;
16303 @initList = $axmud::CLIENT->constRoomFlagList;
16304 do {
16305  
16306 my ($name, $short, $filter, $colour, $descrip, $newObj);
16307  
16308 $count++;
16309  
16310 $name = shift @initList;
16311 $short = shift @initList;
16312 $filter = shift @initList;
16313 $colour = shift @initList;
16314 $descrip = shift @initList;
16315  
16316 $newObj = Games::Axmud::Obj::RoomFlag->new(
16317 $session,
16318 $name,
16319 FALSE, # Not a custom room flag
16320 );
16321  
16322 if ($newObj) {
16323  
16324 $newObj->ivPoke('shortName', $short);
16325 $newObj->ivPoke('descrip', $descrip);
16326 $newObj->ivPoke('priority', $count);
16327 $newObj->ivPoke('filter', $filter);
16328 $newObj->ivPoke('colour', $colour);
16329  
16330 $self->ivAdd('roomFlagHash', $name, $newObj);
16331 push (@orderedList, $name);
16332 }
16333  
16334 } until (! @initList);
16335  
16336 $self->ivPoke('roomFlagOrderedList', @orderedList);
16337  
16338 # Operation complete
16339 return 1;
16340 }
16341  
16342 sub resetRoomFlags {
16343  
16344 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16345 # Resets the world model's room flags to their default state, eliminating any custom room
16346 # flags
16347 # Checks every room in the model, removing any room flags that no longer exist
16348 #
16349 # Expected arguments
16350 # $session - The calling function's GA::Session
16351 #
16352 # Return values
16353 # 'undef' on improper arguments
16354 # 1 otherwise
16355  
16356 my ($self, $session, $check) = @_;
16357  
16358 # Check for improper arguments
16359 if (! defined $session || defined $check) {
16360  
16361 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRoomFlags', @_);
16362 }
16363  
16364 # Reset the IVs
16365 $self->setupRoomFlags($session);
16366  
16367 # Check every room in the model, eliminating custom room flags that no longer exist
16368 foreach my $roomObj ($self->ivValues('roomModelHash')) {
16369  
16370 foreach my $roomFlag ($roomObj->ivKeys('roomFlagHash')) {
16371  
16372 if (! $self->ivExists('roomFlagHash', $roomFlag)) {
16373  
16374 $roomObj->ivDelete('roomFlagHash', $roomFlag);
16375 }
16376 }
16377 }
16378  
16379 return 1;
16380 }
16381  
16382 sub updateRoomFlags {
16383  
16384 # Called by GA::Obj::File->updateExtractedData in order to update the room flags stored in
16385 # this world model to those used in a more recent version of Axmud
16386 #
16387 # Expected arguments
16388 # $session - The calling function's GA::Session
16389 #
16390 # Return values
16391 # 'undef' on improper arguments
16392 # 1 otherwise
16393  
16394 my ($self, $session, $check) = @_;
16395  
16396 # Local variables
16397 my (
16398 @initList,
16399 %newApplyHash,
16400 );
16401  
16402 # Check for improper arguments
16403 if (defined $check) {
16404  
16405 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRoomFlags', @_);
16406 }
16407  
16408 # Update $self->roomFilterApplyHash. Add any new filters, and remove any defunct filters
16409 # (the latter will probably never happen, but there's no harm in checking)
16410 foreach my $filter ($axmud::CLIENT->constRoomFilterList) {
16411  
16412 if ($self->ivExists('roomFilterApplyHash', $filter)) {
16413  
16414 # Keep the current setting
16415 $newApplyHash{$filter} = $self->ivShow('roomFilterApplyHash', $filter);
16416  
16417 } else {
16418  
16419 # New filter
16420 $newApplyHash{$filter} = FALSE;
16421 }
16422 }
16423  
16424 $self->ivPoke('roomFilterApplyHash', %newApplyHash);
16425  
16426 # Update $self->roomFlagHash and ->roomFlagOrderedList. Add any new room flag objects, but
16427 # don't remove any defunct room flags (as the rooms in this world model might be using
16428 # them)
16429 @initList = $axmud::CLIENT->constRoomFlagList;
16430 do {
16431  
16432 my ($name, $short, $filter, $colour, $descrip, $count, $index, $newObj);
16433  
16434 $name = shift @initList;
16435 $short = shift @initList;
16436 $filter = shift @initList;
16437 $colour = shift @initList;
16438 $descrip = shift @initList;
16439  
16440 if (! $self->ivExists('roomFlagHash', $name)) {
16441  
16442 # Go through the existing ordered list of room flags, and find the position of the
16443 # last room flag using the same filter
16444 $count = 0;
16445 foreach my $name ($self->roomFlagOrderedList) {
16446  
16447 my $oldObj;
16448  
16449 $oldObj = $self->ivShow('roomFlagHash', $name);
16450 $count++;
16451  
16452 if ($oldObj->filter eq $filter) {
16453  
16454 $index = $count;
16455 }
16456 }
16457  
16458 if (! $index) {
16459  
16460 # This room flag seems to be using a unique filter (for some reason). Insert
16461 # the new room flag at the end of the list
16462 $index = scalar ($self->roomFlagOrderedList);
16463 }
16464  
16465 # Create a new room flag object
16466 $newObj = Games::Axmud::Obj::RoomFlag->new(
16467 $session,
16468 $name,
16469 FALSE, # Not a custom room flag
16470 );
16471  
16472 # Insert it at the specified position
16473 if ($newObj) {
16474  
16475 $newObj->ivPoke('shortName', $short);
16476 $newObj->ivPoke('descrip', $descrip);
16477 $newObj->ivPoke('priority', $index + 1);
16478 $newObj->ivPoke('filter', $filter);
16479 $newObj->ivPoke('colour', $colour);
16480  
16481 $self->ivAdd('roomFlagHash', $name, $newObj);
16482 $self->ivSplice('roomFlagOrderedList', $index, 0, $name);
16483  
16484 # Update every room flag object's ->priority IV
16485 $count = 0;
16486 foreach my $name ($self->roomFlagOrderedList) {
16487  
16488 my $thisObj = $self->ivShow('roomFlagHash', $name);
16489  
16490 $count++;
16491 $thisObj->ivPoke('priority', $count);
16492 }
16493 }
16494 }
16495  
16496 } until (! @initList);
16497  
16498 # Operation complete
16499 return 1;
16500 }
16501  
16502 sub addRoomFlag {
16503  
16504 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16505 # Adds a new custom room flag and updates the priority list for all room flags
16506 #
16507 # Expected arguments
16508 # $session - The calling function's GA::Session
16509 # $name - The room flag name (max 16 characters, must be unique among room flag
16510 # names)
16511 # $shortName - The short name (max 2 characters; should ideally be unique among short
16512 # names, but that's not a hard rule)
16513 # $descrip - The room flag description (any text, but at least 1 character)
16514 # $colour - The colour used to draw the room, when this room flag is the highest-
16515 # priority room flag in the room. An RGB tag, e.g. '#ABCDEF' (case-
16516 # insensitive)
16517 #
16518 # Return values
16519 # 'undef' on improper arguments, if $name, $shortName and/or $descrip are not the right
16520 # length, if a room flag called $name already exists or if $colour is not a valid RGB
16521 # tag
16522 # 1 otherwise
16523  
16524 my ($self, $session, $name, $shortName, $descrip, $colour, $check) = @_;
16525  
16526 # Local variables
16527 my ($type, $lastMarker, $lastCustom, $priority, $newObj, $count);
16528  
16529 # Check for improper arguments
16530 if (
16531 ! defined $session || ! defined $name || ! defined $shortName || ! defined $descrip
16532 || ! defined $colour || defined $check
16533 ) {
16534 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRoomFlag', @_);
16535 }
16536  
16537 # Check the lengths of the text arguments
16538 if (
16539 length($name) < 1 || length($name) > 16
16540 || length($shortName) != 2
16541 || length($descrip) < 1
16542 ) {
16543 return undef;
16544 }
16545  
16546 # Check a room flag called $name doesn't already exist
16547 if ($self->ivExists('roomFlagHash', $name)) {
16548  
16549 return undef;
16550 }
16551  
16552 # Check $colour is a valid RGB tag
16553 ($type) = $axmud::CLIENT->checkColourTags($colour, 'rgb');
16554 if (! $type) {
16555  
16556 return undef;
16557 }
16558  
16559 # Decide the room flag's position in the priority list
16560 # Position it after the last 'custom' room flag or, if there are none, after the last
16561 # 'markers' room tag
16562 # (In the default list, all 'markers' room flags come first, followed by all 'custom' room
16563 # flags)
16564 foreach my $roomFlagObj ($self->ivValues('roomFlagHash')) {
16565  
16566 if (
16567 $roomFlagObj->filter eq 'markers'
16568 && (! defined $lastMarker || $lastMarker < $roomFlagObj->priority)
16569 ) {
16570 $lastMarker = $roomFlagObj->priority;
16571  
16572 } elsif (
16573 $roomFlagObj->filter eq 'custom'
16574 && (! defined $lastCustom || $lastCustom < $roomFlagObj->priority)
16575 ) {
16576 $lastCustom = $roomFlagObj->priority;
16577 }
16578 }
16579  
16580 if (defined $lastCustom) {
16581 $priority = $lastCustom + 1;
16582 } elsif (defined $lastMarker) {
16583 $priority = $lastMarker + 1;
16584 } else {
16585 $priority = 1; # Failsafe - should never be used
16586 }
16587  
16588 # Create a new room flag object
16589 $newObj = Games::Axmud::Obj::RoomFlag->new(
16590 $session,
16591 $name,
16592 TRUE, # Custom room flag
16593 );
16594  
16595 if ($newObj) {
16596  
16597 $self->ivAdd('roomFlagHash', $name, $newObj);
16598  
16599 # Set the object's IVs
16600 $newObj->ivPoke('shortName', $shortName);
16601 $newObj->ivPoke('descrip', $descrip);
16602 $newObj->ivPoke('priority', $priority);
16603 $newObj->ivPoke('filter', 'custom');
16604 $newObj->ivPoke('colour', $colour);
16605  
16606 # Insert it at the right position in the room flag priority list
16607 $self->ivSplice('roomFlagOrderedList', ($priority - 1), 0, $name);
16608  
16609 # Update every room flag object's ->priority IV
16610 $count = 0;
16611 foreach my $name ($self->roomFlagOrderedList) {
16612  
16613 my $thisObj = $self->ivShow('roomFlagHash', $name);
16614  
16615 $count++;
16616 $thisObj->ivPoke('priority', $count);
16617 }
16618  
16619 # Must redraw the menu in any automapper windows, so that the new room flag appears in
16620 # them
16621 $self->updateMapMenuToolbars();
16622 }
16623  
16624 # Operation complete
16625 return 1;
16626 }
16627  
16628 sub deleteRoomFlag {
16629  
16630 # Called by GA::EditWin::WorldModel->roomFlags1Tab
16631 # Deletes custom room flag and updates the priority list for all room flags
16632 # (Room flags belonging to other filters can't be deleted)
16633 #
16634 # Expected arguments
16635 # $name - The room flag name to delete
16636 #
16637 # Return values
16638 # 'undef' on improper arguments, if the room flag doesn't exist or if it isn't a custom
16639 # room flag
16640 # 1 otherwise
16641  
16642 my ($self, $name, $check) = @_;
16643  
16644 # Local variables
16645 my ($roomFlagObj, $count);
16646  
16647 # Check for improper arguments
16648 if (! defined $name) {
16649  
16650 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRoomFlag', @_);
16651 }
16652  
16653 # Check the flag exists and is a custom room flag
16654 $roomFlagObj = $self->ivShow('roomFlagHash', $name);
16655 if (! $roomFlagObj || $roomFlagObj->filter ne 'custom') {
16656  
16657 return undef;
16658  
16659 } else {
16660  
16661 $self->ivDelete('roomFlagHash', $name);
16662  
16663 # Remove it from the room flag priority list
16664 $self->ivSplice('roomFlagOrderedList', ($roomFlagObj->priority - 1), 1);
16665  
16666 # Update every room flag object's ->priority IV
16667 $count = 0;
16668 foreach my $name ($self->roomFlagOrderedList) {
16669  
16670 my $thisObj = $self->ivShow('roomFlagHash', $name);
16671  
16672 $count++;
16673 $thisObj->ivPoke('priority', $count);
16674 }
16675  
16676 # Must redraw the menu in any automapper windows, so that the old room flag no longer
16677 # appears in them
16678 $self->updateMapMenuToolbars();
16679 }
16680  
16681 # Operation complete
16682 return 1;
16683 }
16684  
16685 sub toggleRoomFlags {
16686  
16687 # Called by GA::Win::Map->enableRoomsColumn_filterSubMenu
16688 # Toggles a room flag in one or more rooms. Redraws the rooms (if permitted) and
16689 # recalculates the regionmap's paths (if necessary)
16690 #
16691 # Expected arguments
16692 # $session - The calling function's GA::Session
16693 # $updateFlag - Flag set to TRUE if all Automapper windows using this world model should
16694 # be updated now, FALSE if not (in which case, they can be updated later
16695 # by the calling function, when it is ready)
16696 # $roomFlag - The room flag to toggle (matches one of the keys in
16697 # $self->roomFlagHash)
16698 #
16699 # Optional arguments
16700 # @roomList - A list of room objects to update. If the list is empty, no flags are
16701 # toggled
16702 #
16703 # Return values
16704 # 'undef' on improper arguments
16705 # 1 otherwise
16706  
16707 my ($self, $session, $updateFlag, $roomFlag, @roomList) = @_;
16708  
16709 # Local variables
16710 my (
16711 $hazardFlag,
16712 @redrawList,
16713 %regionHash,
16714 );
16715  
16716 # Check for improper arguments
16717 if (! defined $session || ! defined $updateFlag || ! defined $roomFlag) {
16718  
16719 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleRoomFlags', @_);
16720 }
16721  
16722 # For speed, work out now whether $roomFlag is one of the hazardous room flags, or not
16723 if ($axmud::CLIENT->ivExists('constRoomHazardHash', $roomFlag)) {
16724  
16725 $hazardFlag = TRUE;
16726 }
16727  
16728 # Update each room in turn
16729 foreach my $roomObj (@roomList) {
16730  
16731 my $listRef;
16732  
16733 # (All affected rooms may be redrawn shortly)
16734 push (@redrawList, 'room', $roomObj);
16735  
16736 if ($roomObj->ivExists('roomFlagHash', $roomFlag)) {
16737  
16738 # Unset the flag by deleting the key
16739 $roomObj->ivDelete('roomFlagHash', $roomFlag);
16740  
16741 } else {
16742  
16743 # Set the flag by adding the key
16744 $roomObj->ivAdd('roomFlagHash', $roomFlag);
16745 }
16746  
16747 if ($updateFlag) {
16748  
16749 # Reset the ->lastRoomFlag IV - it'll be set to the correct value (if any)
16750 # when the room is redrawn in a moment
16751 $roomObj->ivUndef('lastRoomFlag');
16752  
16753 } else {
16754  
16755 # The room isn't going to be redrawn any time soon, so set the correct value of
16756 # ->lastRoomFlag now
16757 $roomObj->ivPoke('lastRoomFlag', $roomFlag);
16758 }
16759  
16760 # Keep track of all the affected regions. Use a hash in the form
16761 # ->regionHash{region_number} = reference_to_list_of_room_objects
16762 if (exists $regionHash{$roomObj->parent}) {
16763  
16764 $listRef = $regionHash{$roomObj->parent};
16765 push (@$listRef, $roomObj);
16766  
16767 } else {
16768  
16769 $regionHash{$roomObj->parent} = [$roomObj];
16770 }
16771 }
16772  
16773 # If the flag is one of the hazardous room flags, we need to re-calculate each regionmap's
16774 # GA::Obj::RegionPath objects (paths between exits at the boundaries of the region)
16775 if ($hazardFlag) {
16776  
16777 foreach my $regionNum (keys %regionHash) {
16778  
16779 my ($regionmapObj, $listRef);
16780  
16781 $regionmapObj = $self->findRegionmap($regionNum);
16782 $listRef = $regionHash{$regionNum};
16783  
16784 $self->recalculateSafePaths(
16785 $session,
16786 $regionmapObj,
16787 @$listRef,
16788 );
16789 }
16790 }
16791  
16792 # Update any GA::Win::Map objects using this world model (if allowed)
16793 if ($updateFlag) {
16794  
16795 foreach my $mapWin ($self->collectMapWins()) {
16796  
16797 # Redraw affected rooms in this region
16798 $mapWin->markObjs(@redrawList);
16799 $mapWin->doDraw();
16800 }
16801 }
16802  
16803 return 1;
16804 }
16805  
16806 sub getDefaultRoomFlag {
16807  
16808 # Can be called by anything
16809 # Quick and dirty method of accessing a room flag's default settings, as specified by
16810 # GA::Client->constRoomFlagList
16811 # Finds the right settings, then creates a temporary room flag object (GA::Obj::RoomFlag) to
16812 # store them, and returns the object
16813 # Note that custom room flags, added by the user, have no default settings and so this
16814 # function returns 'undef'
16815 #
16816 # Expected arguments
16817 # $session - The calling GA::Session
16818 # $name - The name of a non-custom room flag
16819 #
16820 # Return values
16821 # 'undef' on improper arguments or if a non-custom or non-existent room flag name is
16822 # specified
16823 # Otherwise, returns a temporary room flag object whose IVs contain the default settings
16824 # for that room flag
16825  
16826 my ($self, $session, $name, $check) = @_;
16827  
16828 # Local variables
16829 my (
16830 $count,
16831 @initList,
16832 );
16833  
16834 # Check for improper arguments
16835 if (! defined $session || ! defined $name || defined $check) {
16836  
16837 return $axmud::CLIENT->writeImproper($self->_objClass . '->getDefaultRoomFlag', @_);
16838 }
16839  
16840 $count = 0;
16841 @initList = $axmud::CLIENT->constRoomFlagList;
16842 do {
16843  
16844 my ($thisName, $short, $filter, $colour, $descrip, $tempObj);
16845  
16846 $count++;
16847  
16848 $thisName = shift @initList;
16849 $short = shift @initList;
16850 $filter = shift @initList;
16851 $colour = shift @initList;
16852 $descrip = shift @initList;
16853  
16854 if ($thisName eq $name) {
16855  
16856 # Create the temporary room flag object
16857 $tempObj = Games::Axmud::Obj::RoomFlag->new(
16858 $session,
16859 $name,
16860 FALSE, # Not a custom room flag
16861 );
16862  
16863 if ($tempObj) {
16864  
16865 # These are the default settings for the room flag, including its default
16866 # position in the priority list
16867 $tempObj->ivPoke('shortName', $short);
16868 $tempObj->ivPoke('descrip', $descrip);
16869 $tempObj->ivPoke('priority', $count);
16870 $tempObj->ivPoke('filter', $filter);
16871 $tempObj->ivPoke('colour', $colour);
16872  
16873 return $tempObj;
16874 }
16875 }
16876  
16877 } until (! @initList);
16878  
16879 # No matching room flag found in the default list
16880 return undef;
16881 }
16882  
16883 sub getRoomFlagsInFilter {
16884  
16885 # Can be called by anything
16886 # Returns a list of room flags (names, not objects) belonging to the specified room filter
16887 # The list is sorted in priority order
16888 #
16889 # Expected arguments
16890 # $filter - The room filter name (one of the items in GA::Client->constRoomFilterList
16891 #
16892 # Return values
16893 # An empty list on improper arguments
16894 # Otherwise returns the list of room flags, which might be empty (especially if the
16895 # specified $filter is 'custom', and the user hasn't added any custom room flags yet)
16896  
16897 my ($self, $filter, $check) = @_;
16898  
16899 # Local variables
16900 my (@emptyList, @list, @sortedList, @returnList);
16901  
16902 # Check for improper arguments
16903 if (! defined $filter || defined $check) {
16904  
16905 $axmud::CLIENT->writeImproper($self->_objClass . '->getRoomFlagsInFilter', @_);
16906 return @emptyList;
16907 }
16908  
16909 # Weed out all room flags without a matching ->filter
16910 foreach my $flagObj ($self->ivValues('roomFlagHash')) {
16911  
16912 if ($flagObj->filter eq $filter) {
16913  
16914 push (@list, $flagObj);
16915 }
16916 }
16917  
16918 # Sort by priority
16919 @sortedList = sort {$a->priority <=> $b->priority} (@list);
16920  
16921 # Convert room flag objects to room flag names
16922 foreach my $flagObj (@sortedList) {
16923  
16924 push (@returnList, $flagObj->name);
16925 }
16926  
16927 # Operation complete
16928 return @returnList;
16929 }
16930  
16931 sub getVisibleRoomFlags {
16932  
16933 # Can be called by anything
16934 # Returns a hash of room flags which should be visible in various windows, depending on the
16935 # current value of $self->roomFlagShowMode
16936 #
16937 # Expected arguments
16938 # (none besides $self)
16939 #
16940 # Return values
16941 # An empty hash on improper arguments
16942 # Otherwise returns the hash (which might be empty), in the form
16943 # $showHash{room_flag_name} = room_flag_object
16944  
16945 my ($self, $check) = @_;
16946  
16947 # Local variables
16948 my (%emptyHash, %showHash);
16949  
16950 # Check for improper arguments
16951 if (defined $check) {
16952  
16953 $axmud::CLIENT->writeImproper($self->_objClass . '->getVisibleRoomFlags', @_);
16954 return %emptyHash;
16955 }
16956  
16957 foreach my $roomFlagObj ($self->ivValues('roomFlagHash')) {
16958  
16959 if (
16960 $self->roomFlagShowMode eq 'default'
16961 || (
16962 $self->roomFlagShowMode eq 'essential'
16963 && (
16964 $roomFlagObj->customFlag
16965 || $axmud::CLIENT->ivExists('constRoomHazardHash', $roomFlagObj->name)
16966 )
16967 ) || (
16968 $self->roomFlagShowMode eq 'custom' && $roomFlagObj->customFlag
16969 )
16970 ) {
16971 $showHash{$roomFlagObj->name} = $roomFlagObj;
16972 }
16973 }
16974  
16975 # Operation complete
16976 return %showHash;
16977 }
16978  
16979 sub moveRoomFlag {
16980  
16981 # Can be called by anything, but mostly called by the world model's edit window
16982 # Moves the specified room flag to a new position in the priority list, updating IVs for
16983 # all other room flags
16984 #
16985 # Expected arguments
16986 # $name - The name of the room flag to move
16987 # $type - The type of move: 'above' to move the room flag up one position, 'below'
16988 # to move it down one position, 'top' to move it to the top of the
16989 # priority list, 'bottom' to move it to the bottom of the priority list
16990 #
16991 # Return values
16992 # 'undef' on improper arguments or if the specified room flag object can't be found
16993 # 1 otherwise
16994  
16995 my ($self, $name, $type, $check) = @_;
16996  
16997 # Local variables
16998 my (
16999 $flagObj, $posn, $count,
17000 @priorityList,
17001 );
17002  
17003 # Check for improper arguments
17004 if (
17005 ! defined $name
17006 || ! defined $type
17007 || ($type ne 'above' && $type ne 'below' && $type ne 'top' && $type ne 'bottom')
17008 || defined $check
17009 ) {
17010 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveRoomFlag', @_);
17011 }
17012  
17013 # Get the corresponding room flag object
17014 $flagObj = $self->ivShow('roomFlagHash', $name);
17015 if (! $flagObj) {
17016  
17017 return undef;
17018 }
17019  
17020 # Import the current priority list
17021 @priorityList = $self->roomFlagOrderedList;
17022 # Work out the room flag's new position in that list
17023 if ($type eq 'above') {
17024  
17025 $posn = $flagObj->priority - 2;
17026 if ($posn < 0) {
17027  
17028 $posn = 0;
17029 }
17030  
17031 } elsif ($type eq 'below') {
17032  
17033 $posn = $flagObj->priority;
17034 if ($posn >= (scalar @priorityList)) {
17035  
17036 $posn = (scalar @priorityList) - 1;
17037 }
17038  
17039 } elsif ($type eq 'top') {
17040  
17041 $posn = 0;
17042  
17043 } elsif ($type eq 'bottom') {
17044  
17045 $posn = (scalar @priorityList) - 1;
17046 }
17047  
17048 # Remove the flag from that list...
17049 splice(@priorityList, ($flagObj->priority - 1), 1);
17050 # ...and insert it at its new position
17051 splice(@priorityList, $posn, 0, $flagObj->name);
17052  
17053 # Update IVs
17054 $self->ivPoke('roomFlagOrderedList', @priorityList);
17055 # Update every room flag object's ->priority IV
17056 $count = 0;
17057 foreach my $name (@priorityList) {
17058  
17059 my $thisObj = $self->ivShow('roomFlagHash', $name);
17060  
17061 $count++;
17062 $thisObj->ivPoke('priority', $count);
17063 }
17064  
17065 # Operation complete
17066 return 1;
17067 }
17068  
17069 sub removeRoomFlagInRegion {
17070  
17071 # Called by GA::Win::Map->removeRoomFlagsCallback
17072 # Removes a room flag from every room in an existing region, and redraws the affected rooms
17073 #
17074 # Expected arguments
17075 # $regionmapObj - The GA::Obj::Regionmap whose counts should be reset
17076 # $roomFlag - The room flag to remove (matches a key in $self->roomFlagHash)
17077 #
17078 # Return values
17079 # 'undef' on improper arguments
17080 # Otherwise returns the number of modified rooms (may be 0)
17081  
17082 my ($self, $regionmapObj, $roomFlag, $check) = @_;
17083  
17084 # Local variables
17085 my (
17086 $count,
17087 @redrawList,
17088 );
17089  
17090 # Check for improper arguments
17091 if (! defined $regionmapObj || ! defined $roomFlag || defined $check) {
17092  
17093 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRoomFlagInRegion', @_);
17094 }
17095  
17096 # Remove the room flag from any room in the specified region which uses it
17097 foreach my $roomNum ($regionmapObj->ivValues('gridRoomHash')) {
17098  
17099 my $roomObj = $self->ivShow('modelHash', $roomNum);
17100  
17101 if ($roomObj->ivExists('roomFlagHash', $roomFlag)) {
17102  
17103 $roomObj->ivDelete('roomFlagHash', $roomFlag);
17104 push (@redrawList, 'room', $roomObj);
17105  
17106 $count++;
17107 }
17108 }
17109  
17110 if ($count) {
17111  
17112 # Update each Automapper window (if any flags were actually removed)
17113 foreach my $mapWin ($self->collectMapWins()) {
17114  
17115 $mapWin->markObjs(@redrawList);
17116 $mapWin->doDraw();
17117 }
17118 }
17119  
17120 return $count;
17121 }
17122  
17123 # Other functions called by GA::Obj::Map and GA::Win::Map
17124  
17125 sub resetPainter {
17126  
17127 # Called by $self->new to create a painter object, or by any other function to reset the
17128 # painter object, which is a non-model GA::ModelObj::Room
17129 # (The object is 'reset' by discarding the old non-model room object and replacing it with a
17130 # new one)
17131 #
17132 # Expected arguments
17133 # $session - The calling function's GA::Session
17134 #
17135 # Return values
17136 # 'undef' on improper arguments
17137 # Otherwise, returns the non-model room object created
17138  
17139 my ($self, $session, $check) = @_;
17140  
17141 # Local variables
17142 my $roomObj;
17143  
17144 # Check for improper arguments
17145 if (! defined $session || defined $check) {
17146  
17147 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetPainter', @_);
17148 }
17149  
17150 # Create a new non-model room
17151 $roomObj = Games::Axmud::ModelObj::Room->new($session, 'painter', 'non_model');
17152 if ($roomObj) {
17153  
17154 $self->ivPoke('painterObj', $roomObj);
17155 return $roomObj;
17156  
17157 } else {
17158  
17159 $self->ivUndef('painterObj');
17160 return undef;
17161 }
17162 }
17163  
17164 sub compareRooms {
17165  
17166 # Called by GA::Obj::Map->useExistingRoom to compare the current location according to
17167 # the Locator task (GA::Task::Locator->roomObj, a non-model room object), with the current
17168 # location according to the automapper (which is in the world model)
17169 # Also called by GA::Obj::Map->autoCompareLocatorRoom, ->checkTempRandomReturn,
17170 # GA::Cmd::LocateRoom->do for the same purpose
17171 #
17172 # Called by $self->mergeMap (or by any other function) to compare two room objects in the
17173 # world model (ignoring the Locator task's room)
17174 #
17175 # How the rooms are compared depends on the values of various settings
17176 #
17177 # Expected arguments
17178 # $session - The calling function's GA::Session
17179 # $modelRoomObj - A GA::ModelObj::Room object somewhere in the world model
17180 #
17181 # Optional arguments
17182 # $otherRoomObj - When comparing two rooms in the world model, the other
17183 # GA::ModelObj::Room object. If 'undef', $modelRoomObj is compared
17184 # against the Locator task's non-model room object
17185 # $darkFlag - Set to TRUE when called by GA::Obj::Map->moveKnownDirSeen and
17186 # GA::Obj::Map->useExistingRoom, in which case the model room matches
17187 # any dark or unspecified rooms
17188 # $strictFlag - Set to TRUE when called by GA::Cmd::LocateRoom->do, in which case this
17189 # function is a little more strict; if $modelRoomObj has a room title
17190 # and/or verbose description but $otherRoomObj doesn't (or
17191 # vice-versa), they cannot be matches; titles and verbose descriptions
17192 # are also checked regardless of the settings of $self->matchTitleFlag
17193 # and ->matchDescripFlag. FALSE (or 'undef') otherwise
17194 #
17195 # Return values
17196 # An empty list on improper arguments
17197 # Otherwise, returns a list in the form (result, error_message), where:
17198 # - 'result' is set to 1 if the rooms match, or 'undef' if they don't (or if there is
17199 # an error)
17200 # - 'error_message' is a string to display on failure; otherwise 'error_message' is
17201 # 'undef'. Most 'error_message' strings refer to the Locator task, since that's
17202 # what uses the error message; any other code calling this function (for example
17203 # $self->mergeMap) should ignore the error message
17204  
17205 my ($self, $session, $modelRoomObj, $otherRoomObj, $darkFlag, $strictFlag, $check) = @_;
17206  
17207 # Local variables
17208 my (
17209 $taskObj, $taskFlag, $matchFlag,
17210 @emptyList, @patternList,
17211 %modelExitHash, %otherExitHash, %otherModHash,
17212 );
17213  
17214 # Check for improper arguments
17215 if (! defined $session || ! defined $modelRoomObj || defined $check) {
17216  
17217 $axmud::CLIENT->writeImproper($self->_objClass . '->compareRooms', @_);
17218 return @emptyList;
17219 }
17220  
17221 if (! $otherRoomObj) {
17222  
17223 # Import the Locator task
17224 $taskObj = $session->locatorTask;
17225 # If the Locator task isn't running, or if it doesn't know the current location, the
17226 # rooms aren't a match
17227 if (! $taskObj || ! $taskObj->roomObj) {
17228  
17229 return (undef, 'Lost because Locator doesn\'t exist or current location not known');
17230 }
17231  
17232 $otherRoomObj = $taskObj->roomObj;
17233 $taskFlag = TRUE;
17234  
17235 # Compare world's room vnums (if allowed)
17236 if (
17237 $self->matchVNumFlag
17238 && defined $modelRoomObj->ivShow('protocolRoomHash', 'vnum')
17239 && defined $otherRoomObj->ivShow('protocolRoomHash', 'vnum')
17240 && $modelRoomObj->ivShow('protocolRoomHash', 'vnum')
17241 ne $otherRoomObj->ivShow('protocolRoomHash', 'vnum')
17242 ) {
17243 # The two rooms' vnums don't match
17244 return (undef, 'Lost because rooms\' world vnums don\'t match');
17245 }
17246 }
17247  
17248 # If $darkFlag is set, dark and unspecified rooms are a match for any room
17249 if (
17250 $darkFlag
17251 && ($otherRoomObj->unspecifiedFlag || $otherRoomObj->currentlyDarkFlag)
17252 ) {
17253 return (1, undef); # No error message
17254 }
17255  
17256 # Compare the rooms' properties, taking into account the values of various flags
17257  
17258 # Compare room titles (if allowed)
17259 if (
17260 ($strictFlag || $self->matchTitleFlag)
17261 && $modelRoomObj->titleList
17262 && $otherRoomObj->titleList
17263 ) {
17264 $matchFlag = FALSE;
17265  
17266 OUTER: foreach my $modelTitle ($modelRoomObj->titleList) {
17267  
17268 foreach my $otherTitle ($otherRoomObj->titleList) {
17269  
17270 if ($modelTitle eq $otherTitle) {
17271  
17272 $matchFlag = TRUE;
17273 last OUTER;
17274 }
17275 }
17276 }
17277  
17278 if (! $matchFlag) {
17279  
17280 # The two rooms's titles don't match
17281 return (undef, 'Lost because rooms\' titles don\'t match');
17282 }
17283  
17284 } elsif ($strictFlag && $otherRoomObj->titleList && ! $modelRoomObj->titleList) {
17285  
17286 # The calling ';locateroom' ignores any error message, but we'll provide one anyway
17287 return (undef, 'Lost because room\'s title is unknown');
17288 }
17289  
17290 # Compare (verbose) descriptions (if allowed)
17291 if (
17292 ($strictFlag || $self->matchDescripFlag)
17293 && $modelRoomObj->descripHash
17294 && $otherRoomObj->descripHash
17295 ) {
17296 $matchFlag = FALSE;
17297  
17298 OUTER: foreach my $modelDescrip ($modelRoomObj->ivValues('descripHash')) {
17299  
17300 INNER: foreach my $otherDescrip ($otherRoomObj->ivValues('descripHash')) {
17301  
17302 # Compare the entire verbose descriptions, if allowed
17303 if (! $self->matchDescripCharCount) {
17304  
17305 if ($modelDescrip eq $otherDescrip) {
17306  
17307 $matchFlag = TRUE;
17308 last OUTER;
17309 }
17310  
17311 # Otherwise, compare the first part of the verbose descriptions - namely, the
17312 # first $self->matchDescripCharCount characters
17313 } elsif (
17314 substr($modelDescrip, 0, $self->matchDescripCharCount)
17315 eq substr ($otherDescrip, 0, $self->matchDescripCharCount)
17316 ) {
17317 $matchFlag = TRUE;
17318 last OUTER;
17319 }
17320 }
17321 }
17322  
17323 if (! $matchFlag) {
17324  
17325 # The two rooms's verbose descriptions don't match (well enough)
17326 return (
17327 undef,
17328 'Lost because rooms\' verbose descriptions don\'t match (well enough)',
17329 );
17330 }
17331  
17332 } elsif ($strictFlag && $otherRoomObj->descripHash && ! $modelRoomObj->descripHash) {
17333  
17334 # The calling ';locateroom' ignores any error message, but we'll provide one anyway
17335 return (undef, 'Lost because room\'s verbose description is unknown');
17336 }
17337  
17338 # Compare exits (if allowed)
17339 # For wilderness rooms, we don't check any exits that have been added to the map (since we
17340 # assume the world has sent a room statement with no exit list)
17341 if (
17342 $self->matchExitFlag
17343 && ! $session->currentWorld->basicMappingFlag
17344 && $modelRoomObj->wildMode eq 'normal'
17345 ) {
17346 $matchFlag = FALSE;
17347  
17348 # Import hashes of exits, in the form
17349 # $exitNumHash{direction} = exit_number_in_exit_model (model rooms)
17350 # $exitNumHash{direction} = exit_object (non-model rooms)
17351 %modelExitHash = $modelRoomObj->exitNumHash;
17352 %otherExitHash = $otherRoomObj->exitNumHash;
17353  
17354 # If the Locator task found a duplicate exit, it may have converted it using the
17355 # pattern specified by GA::Profile::World->duplicateReplaceString (e.g. it might have
17356 # converted a duplicate 'east' exit into a 'swim east' exit)
17357 # Any such duplicate exits are marked hidden. Remove them from our considerations
17358 if ($taskFlag) {
17359  
17360 foreach my $dir (keys %otherExitHash) {
17361  
17362 my $exitObj = $otherExitHash{$dir};
17363 if ($exitObj->hiddenFlag) {
17364  
17365 delete $otherExitHash{$dir};
17366 }
17367 }
17368 }
17369  
17370 # From the latter hash, also remove any transient exits (those which appear from time to
17371 # time in various locations, for example the entrance to a moving wagon)
17372 OUTER: foreach my $dir (keys %otherExitHash) {
17373  
17374 @patternList = $session->currentWorld->transientExitPatternList;
17375 if (@patternList) {
17376  
17377 do {
17378  
17379 my $pattern = shift @patternList;
17380 my $destRoom = shift @patternList;
17381  
17382 if ($dir =~ m/$pattern/) {
17383  
17384 # A transient exit; don't compare it to the model room
17385 next OUTER;
17386 }
17387  
17388 } until (! @patternList);
17389 }
17390  
17391 # Not a transient exit
17392 $otherModHash{$dir} = $otherExitHash{$dir};
17393 }
17394  
17395 %otherExitHash = %otherModHash;
17396 %otherModHash = ();
17397  
17398 # If comparing $modelRoomObj against the Locator task's current room, convert any
17399 # relative directions in $otherModHash (e.g. if the character is facing 'west',
17400 # convert the direction 'backward' into 'east')
17401 # Exception: don't convert a relative direction, like 'forward', if an exit in that
17402 # direction literally exists in the world model (by default, when an exit in a
17403 # relative direction is added to the world model, it's converted to a primary
17404 # direction)
17405 if ($taskFlag) {
17406  
17407 foreach my $dir (keys %otherExitHash) {
17408  
17409 my ($slot, $convertDir, $customDir);
17410  
17411 $slot = $session->currentDict->convertRelativeDir($dir);
17412 # $slot is in the range 0-7. Convert it into a standard primary direction
17413 # like 'north', depending on which way the character is currently facing
17414 if (defined $slot && ! exists $modelExitHash{$dir}) {
17415  
17416 $convertDir = $session->currentDict->rotateRelativeDir(
17417 $slot,
17418 $session->mapObj->facingDir,
17419 );
17420 }
17421  
17422 if (defined $convertDir) {
17423  
17424 $customDir = $session->currentDict->ivShow('primaryDirHash', $convertDir);
17425 $otherModHash{$customDir} = $otherExitHash{$dir};
17426  
17427 } else {
17428  
17429 # Not a relative exit
17430 $otherModHash{$dir} = $otherExitHash{$dir};
17431 }
17432 }
17433 }
17434  
17435 # Compare the keys in both hashes. Delete matching exits from each hash; if there are
17436 # any exits left (or missing), the rooms don't match
17437 OUTER: foreach my $dir (keys %modelExitHash) {
17438  
17439 my ($exitNum, $exitObj);
17440  
17441 $exitNum = $modelExitHash{$dir};
17442 $exitObj = $self->ivShow('exitModelHash', $exitNum);
17443 if ($exitObj && $exitObj->hiddenFlag) {
17444  
17445 # The exit should exist here
17446 delete $modelExitHash{$dir};
17447 # The exit shouldn't exist here - delete it anyway, just in case
17448 delete $otherModHash{$dir};
17449  
17450 next OUTER;
17451 }
17452  
17453 if (exists $otherModHash{$dir}) {
17454  
17455 # Exit exists in both hashes (and isn't hidden)
17456 delete $modelExitHash{$dir};
17457 delete $otherModHash{$dir};
17458  
17459 next OUTER;
17460 }
17461  
17462 if ($exitObj->altDir) {
17463  
17464 foreach my $otherDir (keys %otherModHash) {
17465  
17466 if (index ($exitObj->altDir, $otherDir) > -1) {
17467  
17468 # The exit should exist here
17469 delete $modelExitHash{$dir};
17470 # The other exit's alternative nominal direction exists here
17471 delete $otherModHash{$otherDir};
17472  
17473 next OUTER;
17474 }
17475 }
17476 }
17477  
17478 # Missing exit in $otherRoomObj, so the rooms don't match
17479 return (
17480 undef,
17481 'Lost because of missing exit (\'' . $dir . '\') in Locator task\'s'
17482 . ' current room (automapper current room is #' . $modelRoomObj->number
17483 . ', Locator room exits: ' . join(', ', $otherRoomObj->sortedExitList)
17484 . ')',
17485 );
17486 }
17487  
17488 if (%otherModHash) {
17489  
17490 # Missing exit in the model's room, so the rooms don't match
17491 return (
17492 undef,
17493 'Lost because of missing exit(s) in the automapper\'s current room: '
17494 . join(', ', keys %otherModHash) . ' (room #' . $modelRoomObj->number . ')',
17495 );
17496 }
17497 }
17498  
17499 # Compare source code paths (if allowed)
17500 if (
17501 $self->matchSourceFlag
17502 && $modelRoomObj->sourceCodePath
17503 && $otherRoomObj->sourceCodePath
17504 && $modelRoomObj->sourceCodePath ne $otherRoomObj->sourceCodePath
17505 ) {
17506 # The two rooms' source code paths don't match
17507 return (undef, 'Lost because rooms\' source code paths don\'t match');
17508 }
17509  
17510 # The rooms match
17511 return (1, undef); # No error message
17512 }
17513  
17514 sub checkOppPrimary {
17515  
17516 # Called by $self->connectRooms, GA::Win::Map->restoreOneWayExitCallback and
17517 # GA::Obj::Map->autoProcessNewRoom
17518 # Given a GA::Obj::Exit which has a destination room, see if the destination room has an
17519 # exit which is drawn on the map in the opposite direction (and return it, if found)
17520 # If the exit object doesn't have a destination room, see if a proposed destination room
17521 # supplied as an optional argument has an exit drawn on the map the opposite direction
17522 #
17523 # Expected arguments
17524 # $exitObj - The exit object leading to the destination room
17525 #
17526 # Optional arguments
17527 # $destRoomObj - The GA::ModelObj::Room which is the destination room (set to 'undef'
17528 # if the exit already has a destination room set)
17529 #
17530 # Return values
17531 # 'undef' on improper arguments or if an opposite exit can't be found
17532 # Otherwise returns the blessed reference of the exit object which leads from the
17533 # destination room back to the original room (drawn in an opposite direction to the
17534 # one used by $exitObj)
17535  
17536 my ($self, $exitObj, $destRoomObj, $check) = @_;
17537  
17538 # Local variables
17539 my (
17540 $oppMapDir,
17541 @oppList,
17542 %oppHash,
17543 );
17544  
17545 # Check for improper arguments
17546 if (! defined $exitObj || defined $check) {
17547  
17548 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkOppPrimary', @_);
17549 }
17550  
17551 # The exit's primary direction, as used to draw the exit on the map, is stored in ->mapDir.
17552 # If this exit object doesn't have a ->mapDir set (because it's unallocatable), there's
17553 # nothing we can do
17554 if (! $exitObj->mapDir) {
17555  
17556 return undef;
17557 }
17558  
17559 # Set the destination room, if not already set
17560 if (! $destRoomObj) {
17561  
17562 if (! $exitObj->destRoom) {
17563  
17564 # No destination room specified - so nothing we can do
17565 return undef;
17566  
17567 } else {
17568  
17569 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
17570 }
17571 }
17572  
17573 # Get the opposite (standard primary) direction (e.g. convert 'north' to 'south')
17574 $oppMapDir = $axmud::CLIENT->ivShow('constOppDirHash', $exitObj->mapDir);
17575  
17576 # See if the destination room has an exit which leads back to the departure room in the
17577 # opposite (primary) direction
17578 OUTER: foreach my $exitNum ($destRoomObj->ivValues('exitNumHash')) {
17579  
17580 my $oppExitObj = $self->ivShow('exitModelHash', $exitNum);
17581 if (
17582 $oppExitObj
17583 && $oppExitObj->mapDir
17584 && $oppExitObj->mapDir eq $oppMapDir
17585 # Don't use an exit attached to a shadow exit; use the shadow exit instead)
17586 && (! $oppExitObj->shadowExit)
17587 ) {
17588 # We have found an exit in the opposite direction
17589 return $oppExitObj;
17590 }
17591 }
17592  
17593 # No exit in the opposite direction was found
17594 return undef;
17595 }
17596  
17597 sub analyseVerboseDescrip {
17598  
17599 # Called by $self->updateRoom
17600 # Compares a room model object's verbose description(s) against the current dictionary's
17601 # lists of recognised words
17602 # All recognised nouns are stored in the room object's ->nounList, and all recognised
17603 # adjectives are stored in ->adjList
17604 #
17605 # Expected arguments
17606 # $session - The calling function's GA::Session
17607 # $roomObj - The room model object to analyse
17608 #
17609 # Return values
17610 # 'undef' on improper arguments
17611 # 1 otherwise
17612  
17613 my ($self, $session, $roomObj, $check) = @_;
17614  
17615 # Local variables
17616 my (
17617 $dictObj,
17618 @nounList, @adjList,
17619 %wordHash,
17620 );
17621  
17622 # Check for improper arguments
17623 if (! defined $session || ! defined $roomObj || defined $check) {
17624  
17625 return $axmud::CLIENT->writeImproper($self->_objClass . '->analyseVerboseDescrip', @_);
17626 }
17627  
17628 # Import the current dictionary
17629 $dictObj = $session->currentDict;
17630  
17631 foreach my $descrip ($roomObj->ivValues('descripHash')) {
17632  
17633 # Split the description into words, and store them in a hash, so that each word is
17634 # checked against the dictionary only once
17635 my @wordList = split('[\s\W]+', $descrip);
17636 foreach my $word (@wordList) {
17637  
17638 $wordHash{$word} = undef;
17639 }
17640 }
17641  
17642 # Check each unique word and, if it's recognised, add it to a list
17643 foreach my $word (keys %wordHash) {
17644  
17645 if ($dictObj->ivExists('combNounHash', $word)) {
17646 push (@nounList, $word);
17647 } elsif ($dictObj->ivExists('combAdjHash', $word)) {
17648 push (@adjList, $word);
17649 }
17650 }
17651  
17652 # Sort the two lists alphabetically, and store them in the room object's IVs
17653 $roomObj->ivPoke('nounList', sort {lc($a) cmp lc($b)} (@nounList));
17654 $roomObj->ivPoke('adjList', sort {lc($a) cmp lc($b)} (@adjList));
17655  
17656 # Analysis complete
17657 return 1;
17658 }
17659  
17660 sub allocateCardinalDir {
17661  
17662 # Called by various functions
17663 # An exit object's ->mapDir is set to one of Axmud's standard primary directions (the words
17664 # 'north', 'southeast', 'up', 'northnortheast' etc), and tells us how the exit is drawn on
17665 # the map
17666 # The exit's ->dir is its nominal direction - the text that appears in a room statement
17667 # (e.g. in 'Obvious exits: north, southeast, up, out')
17668 # If ->dir is a custom primary direction, the ->mapDir is set to the equivalent standard
17669 # primary direction at the time the exit object is created. If ->dir is a recognised
17670 # secondary direction which has been given an equivalent standard primary direction, it
17671 # will have been used. Otherwise, ->mapDir will still be set to 'undef'
17672 # This function can be called once all of a new room's exits have been created in order to
17673 # allocate standard primary directions to all exits which don't have one yet. However,
17674 # this function only allocates the sixteen standard cardinal directions - it's up to the
17675 # user to manually allocate 'up' or 'down', if required
17676 #
17677 # This function is also called by $self->addExit if an existing exit is supplanted by a
17678 # new one, in an effort to allocate a new map direction for it
17679 # The calling function must update $self->updatePathHash and ->updateBoundaryHash, as
17680 # necessary
17681 #
17682 # Expected arguments
17683 # $session - The calling function's GA::Session
17684 # $roomObj - The exit object's parent room
17685 # $exitObj - The exit object whose ->mapDir must be allocated
17686 #
17687 # Optional arguments
17688 # $departRoomObj, $departExitObj, $standardDir
17689 # - When called by $self->updateRoom while temporarily allocating cardinal
17690 # directions to unallocated exits. The room object from which the
17691 # character arrived and the exit object and standard primary or
17692 # secondary direction used (if known). Often, the arrival room ($exitObj's
17693 # parent) will have only one unallocated exit, in which case we allocate
17694 # the opposite standard direction to it
17695 #
17696 # Return values
17697 # 'undef' on improper arguments or if a cardinal direction can't be allocated
17698 # Otherwise, the new value of $exitObj->mapDir
17699  
17700 my (
17701 $self, $session, $roomObj, $exitObj, $departRoomObj, $departExitObj, $standardDir,
17702 $check,
17703 ) = @_;
17704  
17705 # Local variables
17706 my (
17707 $cardinalDir, $matchFlag, $regex,
17708 @keyList, @dirList, @sortedList,
17709 );
17710  
17711 # Check for improper arguments
17712 if (! defined $session || ! defined $roomObj || ! defined $exitObj || defined $check) {
17713  
17714 return $axmud::CLIENT->writeImproper($self->_objClass . '->allocateCardinalDir', @_);
17715 }
17716  
17717 # If the exit's nominal direction ->dir is a secondary direction that should be auto-
17718 # allocated a primary direction, allocate that primary direction (unless one of the other
17719 # exits in the room is already using it)
17720 if (
17721 $session->currentDict->ivExists('secondaryDirHash', $exitObj->dir)
17722 && defined $session->currentDict->ivShow('secondaryAutoHash', $exitObj->dir)
17723 ) {
17724 $cardinalDir = $session->currentDict->ivShow('secondaryAutoHash', $exitObj->dir);
17725 }
17726  
17727 # Does the exit's nominal direction contain a custom primary direction, e.g. 'swim east'?
17728 # If so, we can auto-allocate that primary direction (unless one of the other exits in the
17729 # room is already using it)
17730 # Get a list of custom primary directions, sorted by length (so that we check 'northeast'
17731 # before 'north'), but don't use up/down because, if a mistake is made, it's inconvenient
17732 # to reallocate an exit which can't be clicked directly
17733 if (! $cardinalDir) {
17734  
17735 if (! $self->showAllPrimaryFlag) {
17736 @keyList = $axmud::CLIENT->constShortPrimaryDirList;
17737 } else {
17738 @keyList = $axmud::CLIENT->constPrimaryDirList;
17739 }
17740  
17741 foreach my $key (@keyList) {
17742  
17743 if ($key ne 'up' && $key ne 'down') {
17744  
17745 push (@dirList, $session->currentDict->ivShow('primaryDirHash', $key));
17746 }
17747 }
17748  
17749 @sortedList = sort {length($b) <=> length($a)} (@dirList);
17750  
17751 # Convert the list to a useful regex
17752 $regex = join('|', @sortedList);
17753 if ($exitObj->dir =~ m/($regex)/i) {
17754  
17755 $cardinalDir = $session->currentDict->convertStandardDir($1);
17756 }
17757 }
17758  
17759 if ($cardinalDir) {
17760  
17761 # Check that no other exits in this room are allocated to the same map direction
17762 $matchFlag = FALSE;
17763 OUTER: foreach my $otherExitNum ($roomObj->ivValues('exitNumHash')) {
17764  
17765 my $otherExitObj = $self->ivShow('exitModelHash', $otherExitNum);
17766  
17767 if (
17768 $otherExitObj ne $exitObj
17769 && $otherExitObj->mapDir
17770 && $otherExitObj->mapDir eq $cardinalDir
17771 ) {
17772 $matchFlag = TRUE;
17773 last OUTER;
17774 }
17775 }
17776  
17777 if (! $matchFlag) {
17778  
17779 # Update the exit and instruct the world model to update its Automapper windows
17780 $self->setExitMapDir(
17781 $session,
17782 FALSE, # Don't update Automapper windows yet
17783 $roomObj,
17784 $exitObj,
17785 $cardinalDir,
17786 );
17787  
17788 # Allocating the primary direction destroys the checked direction, if present
17789 $roomObj->ivDelete(
17790 'checkedDirHash',
17791 $session->currentDict->ivShow('primaryDirHash', $cardinalDir),
17792 );
17793  
17794 return $cardinalDir;
17795 }
17796 }
17797  
17798 # Otherwise, decide for ourselves which primary direction to allocate
17799 if (
17800 defined $departRoomObj
17801 && defined $departExitObj
17802 && (defined $standardDir || defined $departExitObj->mapDir)
17803 ) {
17804 # The character has arrived in a newly-created room using a known exit. Often it's the
17805 # case that the room has only one unallocated exit and we definitely want to allocate
17806 # it using the opposite standard primary direction, so that it points back to the
17807 # departure room
17808  
17809 # Get the opposite standard primary direction (while checking that $standardDir isn't a
17810 # standard secondary direction)
17811 if ($standardDir && $axmud::CLIENT->ivExists('constOppDirHash', $standardDir)) {
17812 $cardinalDir = $axmud::CLIENT->ivShow('constOppDirHash', $standardDir);
17813 } else {
17814 $cardinalDir = $axmud::CLIENT->ivShow('constOppDirHash', $departExitObj->mapDir);
17815 }
17816  
17817 # However, we can't allocate an exit temporarily to 'up' or 'down'
17818 if ($cardinalDir eq 'up' || $cardinalDir eq 'down') {
17819  
17820 $cardinalDir = undef;
17821  
17822 } else {
17823  
17824 # If that standard direction isn't available, don't use it
17825 OUTER: foreach my $number ($roomObj->ivValues('exitNumHash')) {
17826  
17827 my $otherExitObj = $self->ivShow('exitModelHash', $number);
17828  
17829 if (
17830 $otherExitObj
17831 && $otherExitObj->mapDir
17832 && $otherExitObj->mapDir eq $cardinalDir
17833 ) {
17834 $cardinalDir = undef;
17835 last OUTER;
17836 }
17837 }
17838 }
17839  
17840 } else {
17841  
17842 # Get an unallocated cardinal direction, ignoring any directions which are on the end of
17843 # an incoming 1-way exit
17844 $cardinalDir = $self->chooseCardinalDir($roomObj, $exitObj, TRUE);
17845 }
17846  
17847 if (! $cardinalDir) {
17848  
17849 # If not successful the first time, repeat the process, this time including any
17850 # directions which are on the end of an incoming 1-way exit (the former was
17851 # preferable, but we can make do with the latter)
17852 $cardinalDir = $self->chooseCardinalDir($roomObj, $exitObj, FALSE);
17853 }
17854  
17855 if ($cardinalDir) {
17856  
17857 # We have found an available standard primary direction. Allocate this direction to the
17858 # exit object temporarily (it's up to the user to make it permanent)
17859 $exitObj->ivPoke('mapDir', $cardinalDir);
17860 $exitObj->ivPoke('drawMode', 'temp_alloc');
17861  
17862 # Allocating the primary direction destroys the checked direction, if present
17863 $roomObj->ivDelete(
17864 'checkedDirHash',
17865 $session->currentDict->ivShow('primaryDirHash', $cardinalDir),
17866 );
17867  
17868 return $cardinalDir;
17869  
17870 } else {
17871  
17872 # All sixteen cardinal directions are occupied. Mark the exit as 'unallocatable'
17873 $exitObj->ivUndef('mapDir');
17874 $exitObj->ivPoke('drawMode', 'temp_unalloc');
17875  
17876 return undef;
17877 }
17878 }
17879  
17880 sub chooseCardinalDir {
17881  
17882 # Called by $self->allocateCardinalDir up to two times - the first time, looking for a
17883 # cardinal direction that don't have any incoming one-way exits; the second time (if
17884 # necessary), looking for any available cardinal direction
17885 #
17886 # Expected arguments
17887 # $roomObj - The GA::Obj::Exit object's parent room
17888 # $exitObj - The exit object which needs to be allocated a cardinal direction
17889 # $ignoreFlag - Set to TRUE the first time this function called, in which case we ignore
17890 # directions that have incoming 1-way exits; set to FALSE the second
17891 # time this function called, in which case we include them
17892 #
17893 # Return values
17894 # 'undef' on improper arguments, or if all the available cardinal directions are already
17895 # occupied
17896 # Otherwise, returns the first available cardinal direction
17897  
17898 my ($self, $roomObj, $exitObj, $ignoreFlag, $check) = @_;
17899  
17900 # Local variables
17901 my @dirList;
17902  
17903 # Check for improper arguments
17904 if (! defined $roomObj || ! defined $exitObj || ! defined $ignoreFlag || defined $check) {
17905  
17906 return $axmud::CLIENT->writeImproper($self->_objClass . '->chooseCardinalDir', @_);
17907 }
17908  
17909 # (For convenience, put the longest directions at the end, but don't allocate exits to 'up'
17910 # or 'down' since they won't be visible on the map)
17911 @dirList = qw(
17912 north northeast east southeast south southwest west northwest
17913 northnortheast eastnortheast eastsoutheast southsoutheast
17914 southsouthwest westsouthwest westnorthwest northnorthwest
17915 );
17916  
17917 OUTER: foreach my $cardinalDir (@dirList) {
17918  
17919 my $matchFlag;
17920  
17921 INNER: foreach my $number ($roomObj->ivValues('exitNumHash')) {
17922  
17923 my $otherExitObj = $self->ivShow('exitModelHash', $number);
17924  
17925 if (
17926 $otherExitObj
17927 && $otherExitObj->mapDir
17928 && $otherExitObj->mapDir eq $cardinalDir
17929 ) {
17930 # This $cardinalDir has already been allocated
17931 $matchFlag = TRUE;
17932 last INNER;
17933 }
17934 }
17935  
17936 if (! $matchFlag) {
17937  
17938 # $cardinalDir is apparently available. Check for incoming one-way exits, if allowed
17939 if (! $ignoreFlag) {
17940  
17941 INNER: foreach my $number ($roomObj->ivKeys('oneWayExitHash')) {
17942  
17943 my ($otherExitObj, $oppDir);
17944  
17945 $otherExitObj = $self->ivShow('exitModelHash', $number);
17946  
17947 if ($otherExitObj && $otherExitObj->mapDir) {
17948  
17949 # Get the opposite of the incoming one-way exit's ->mapDir (the standard
17950 # primary direction used to draw the exit on the map)
17951 $oppDir
17952 = $axmud::CLIENT->ivShow('constOppDirHash', $otherExitObj->mapDir);
17953  
17954 if ($oppDir eq $cardinalDir) {
17955  
17956 # The incoming 1-way exit is using this primary direction, so ignore
17957 # it (for now), and move on to the next one
17958 next OUTER;
17959 }
17960 }
17961 }
17962 }
17963  
17964 # Available cardinal direction found
17965 return $cardinalDir;
17966 }
17967 }
17968  
17969 # All sixteen cardinal directions are unavailable
17970 return undef;
17971 }
17972  
17973 sub countRoomContents {
17974  
17975 # Called by GA::Obj::Map->updateRoom
17976 # Counts the number of living and non-living things in the Locator task's current room, and
17977 # stores them in the regionmap in which a specified room model object is stored
17978 # As a result, it's possible for the Automapper window to display the number of things in a
17979 # room the last time it was visited
17980 #
17981 # Expected arguments
17982 # $session - The calling function's GA::Session
17983 # $modelRoomObj - The room model object for which the counts are stored
17984 #
17985 # Return values
17986 # 'undef' on improper arguments, if there is no Locator task, if the Locator task doesn't
17987 # know the current location or if $modelRoomObj's regionmap can't be found
17988 # 1 otherwise
17989  
17990 my ($self, $session, $modelRoomObj, $check) = @_;
17991  
17992 # Local variables
17993 my ($regionmapObj, $livingCount, $nonLivingCount);
17994  
17995 # Check for improper arguments
17996 if (! defined $session || ! defined $modelRoomObj || defined $check) {
17997  
17998 return $axmud::CLIENT->writeImproper($self->_objClass . '->countRoomContents', @_);
17999 }
18000  
18001 # Shouldn't be possible for this function to be called when the Locator task isn't running
18002 # or doesn't know the current location - but we'll check anyway
18003 if (! $session->locatorTask || ! $session->locatorTask->roomObj) {
18004  
18005 return undef;
18006 }
18007  
18008 # Get the room's regionmap
18009 $regionmapObj = $self->findRegionmap($modelRoomObj->parent);
18010 if (! $regionmapObj) {
18011  
18012 # Again, nothing we can do
18013 return undef;
18014 }
18015  
18016 # Count the number of living and non-living things in the Locator task's room
18017 $livingCount = 0;
18018 $nonLivingCount = 0;
18019  
18020 foreach my $obj ($session->locatorTask->roomObj->tempObjList) {
18021  
18022 if ($obj->aliveFlag) {
18023 $livingCount++;
18024 } else {
18025 $nonLivingCount++;
18026 }
18027 }
18028  
18029 # Now, if the count is 0, we remove an entry from the hash IV (if it exists); otherwise we
18030 # add an entry (or replace the existing one)
18031 if ($livingCount) {
18032 $regionmapObj->storeLivingCount($modelRoomObj->number, $livingCount);
18033 } else {
18034 $regionmapObj->removeLivingCount($modelRoomObj->number);
18035 }
18036  
18037 if ($nonLivingCount) {
18038 $regionmapObj->storeNonLivingCount($modelRoomObj->number, $nonLivingCount);
18039 } else {
18040 $regionmapObj->removeNonLivingCount($modelRoomObj->number);
18041 }
18042  
18043 return 1;
18044 }
18045  
18046 sub setInteriorOffsets {
18047  
18048 # Called by GA::Obj::Map->setInteriorOffsetsCallback
18049 # Sets the offsets used when a room's grid coordinates are displayed as interior text inside
18050 # the room box
18051 #
18052 # Expected arguments
18053 # $xOffset, $yOffset - The new values to set
18054 #
18055 # Return values
18056 # 'undef' on improper arguments
18057 # 1 otherwise
18058  
18059 my ($self, $xOffset, $yOffset, $check) = @_;
18060  
18061 # Check for improper arguments
18062 if (! defined $xOffset || ! defined $yOffset || defined $check) {
18063  
18064 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInteriorOffsets', @_);
18065 }
18066  
18067 # Update IVs
18068 $self->ivPoke('roomInteriorXOffset', $xOffset);
18069 $self->ivPoke('roomInteriorYOffset', $yOffset);
18070  
18071 return 1;
18072 }
18073  
18074 sub findPathCmds {
18075  
18076 # Called by GA::Win::Map->processPathCallback
18077 # Given a list of GA::ModelObj::Room objects along a continuous path - such as one
18078 # generated by a call to $self->findPath or ->findUniversalPath - compiles a list of
18079 # commands to get from the first room on the path to the last one
18080 # Uses assisted moves, if allowed; otherwise uses only exit nominal directions
18081 #
18082 # Expected arguments
18083 # $session - The calling function's GA::Session
18084 # $step - Set to 1 if we want the commands to get from the beginning of the room
18085 # list to the end; set to -1 if we want the commands to get from the end
18086 # of the room list to the beginning
18087 # @roomList - A list of GA::ModelObj::Room objects along a continuous path
18088 #
18089 # Return values
18090 # An empty list on improper arguments, if a continuous path between the first and last
18091 # rooms on the list can't be found, or if the list contains less than two rooms
18092 # Otherwise, returns a list of commands, e.g. ('n', 'nw', 'e', 'u', 'enter cave')
18093  
18094 my ($self, $session, $step, @roomList) = @_;
18095  
18096 # Local variables
18097 my (@emptyList, @exitList, @cmdList);
18098  
18099 # Check for improper arguments
18100 if (! defined $session || ! defined $step || scalar @roomList < 2) {
18101  
18102 $axmud::CLIENT->writeImproper($self->_objClass . '->findPathCmds', @_);
18103 return @emptyList;
18104 }
18105  
18106 # Process the route in the opposite direction, if required
18107 if ($step == -1) {
18108  
18109 @roomList = reverse @roomList;
18110 }
18111  
18112 do {
18113  
18114 my ($roomObj, $nextRoomObj, $matchFlag);
18115  
18116 $roomObj = shift @roomList;
18117 if (@roomList) {
18118  
18119 # Check this room's exits, looking for one which leads to the next room in the list
18120 $nextRoomObj = $roomList[0];
18121  
18122 INNER: foreach my $exitNum ($roomObj->ivValues('exitNumHash')) {
18123  
18124 my ($exitObj, $destRoomNum);
18125  
18126 $exitObj = $self->ivShow('exitModelHash', $exitNum);
18127 $destRoomNum = $exitObj->destRoom;
18128  
18129 if (
18130 defined $destRoomNum
18131 && $self->ivShow('modelHash', $destRoomNum) eq $nextRoomObj
18132 ) {
18133 # This is the exit we want
18134 push (@exitList, $exitObj);
18135 $matchFlag = TRUE;
18136  
18137 last INNER;
18138 }
18139 }
18140  
18141 # There is no way to get between $roomObj and $nextRoomObj
18142 if (! $matchFlag) {
18143  
18144 return @emptyList;
18145 }
18146 }
18147  
18148 } until (! @roomList);
18149  
18150 # We have a list of exit objects from the first room on the path to the last one. Now
18151 # convert it into a list of commands. If assisted moves are turned on, use them; otherwise
18152 # just use each exit's nominal direction
18153 @cmdList = $self->convertExitList($session, @exitList);
18154  
18155 # Operation complete
18156 return @cmdList;
18157 }
18158  
18159 sub convertExitList {
18160  
18161 # Called by GA::Win::Map->processPathCallback and $self->findPathCmds
18162 # Given a list of GA::Obj::Exit objects (presumed to be along a continuous path),
18163 # compiles a list of world commands to move from one end of the path to the other
18164 # If assisted moves are allowed, uses them; otherwise uses each exit's nominal direction
18165 #
18166 # Expected arguments
18167 # $session - The calling function's GA::Session
18168 #
18169 # Optional arguments
18170 # @exitList - The list of GA::Obj::Exit objects. If the list is empty, an empty list is
18171 # returned
18172 #
18173 # Return values
18174 # 'undef' on improper arguments
18175 # 1 otherwise
18176  
18177 my ($self, $session, @exitList) = @_;
18178  
18179 # Local variables
18180 my (
18181 $assistedFlag, $cmdSep,
18182 @cmdList,
18183 );
18184  
18185 # Check for improper arguments
18186 if (! defined $session) {
18187  
18188 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertExitList', @_);
18189 }
18190  
18191 # Import the world model's ->assistedMovesFlag
18192 $assistedFlag = $self->assistedMovesFlag;
18193 # Import the client command separator
18194 $cmdSep = $axmud::CLIENT->cmdSep;
18195  
18196 OUTER: foreach my $exitObj (@exitList) {
18197  
18198 my $cmdSequence;
18199  
18200 if ($assistedFlag) {
18201  
18202 # Ask the exit to provide a command sequence (e.g. 'knock on door;open door;east')
18203 # comprising an assisted move. If no assisted move is found, just use the exit's
18204 # nominal direction
18205 $cmdSequence = $exitObj->getAssisted($session);
18206 if ($cmdSequence) {
18207 push (@cmdList, split(m/$cmdSep/, $cmdSequence));
18208 } else {
18209 push (@cmdList, $exitObj->dir);
18210 }
18211  
18212 } else {
18213  
18214 # Assisted moves turned off. Just use the exits' nominal directions
18215 push (@cmdList, $exitObj->dir);
18216 }
18217 }
18218  
18219 # Operation complete
18220 return @cmdList;
18221 }
18222  
18223 sub getExitLength {
18224  
18225 # Called by GA::Obj::Map->autoProcessNewRoom
18226 # Given a GA::Obj::Exit, return the exit length that applies to it. If the exit's ->mapDir
18227 # (the standard primary direction in which the exit is drawn on the map) is 'up' or
18228 # 'down', then use the value stored in ->verticalExitLengthBlocks. Otherwise use the
18229 # value stored in ->horizontalExitLengthBlocks
18230 #
18231 # Expected arguments
18232 # $exitObj - The exit object to check
18233 #
18234 # Return values
18235 # 'undef' on improper arguments
18236 # 1 otherwise
18237  
18238 my ($self, $exitObj, $check) = @_;
18239  
18240 # Check for improper arguments
18241 if (! defined $exitObj || defined $check) {
18242  
18243 return $axmud::CLIENT->writeImproper($self->_objClass . '->getExitLength', @_);
18244 }
18245  
18246 if (! $exitObj->mapDir) {
18247  
18248 # No standard primary direction set - use a default exit length of 1
18249 return 1;
18250  
18251 } elsif ($exitObj->mapDir eq 'up' || $exitObj->mapDir eq 'down') {
18252  
18253 return $self->verticalExitLengthBlocks;
18254  
18255 } else {
18256  
18257 return $self->horizontalExitLengthBlocks;
18258 }
18259 }
18260  
18261 sub getRegionScheme {
18262  
18263 # Can be called by anything
18264 # Get the region scheme object (GA::Obj::RegionScheme) that applies to a specified regionmap
18265 #
18266 # Expected arguments
18267 # $regionmapObj - The specified GA::Obj::Regionmap
18268 #
18269 # Return values
18270 # 'undef' on improper arguments
18271 # 1 otherwise
18272  
18273 my ($self, $regionmapObj, $check) = @_;
18274  
18275 # Check for improper arguments
18276 if (! defined $regionmapObj || defined $check) {
18277  
18278 return $axmud::CLIENT->writeImproper($self->_objClass . '->getRegionScheme', @_);
18279 }
18280  
18281 if (
18282 defined $regionmapObj->regionScheme
18283 && $self->ivExists('regionSchemeHash', $regionmapObj->regionScheme)
18284 ) {
18285 return $self->ivShow('regionSchemeHash', $regionmapObj->regionScheme);
18286  
18287 } else{
18288  
18289 # If the regionmap doesn't name a region scheme, then use the default one
18290 return $self->defaultSchemeObj;
18291 }
18292 }
18293  
18294 # (Called from GA::Win::Map menu, 'View' column)
18295  
18296 sub toggleFlag {
18297  
18298 # Called by anonymous function in GA::Win::Map->enableXXXColumn
18299 # Toggles a flag IV and updates each Automapper window
18300 #
18301 # Expected arguments
18302 # $iv - The flag IV to toggle
18303 # $ivFlag - New value of the IV (TRUE or FALSE)
18304 # $drawFlag - If set to TRUE, this function calls ->drawRegion in every affected
18305 # Automapper window. If FALSE, ->drawRegion is not called
18306 #
18307 # Optional arguments
18308 # $menuName - The name of the menu item which must be set to active, or inactive (a key
18309 # in GA::Map::Win->menuToolItemHash
18310 # $iconName - The name of the toolbar icon which must be set to active, or inactive (a
18311 # key in GA::Map::Win->menuToolItemHash. If set to 'undef', there is no
18312 # icon to modify)
18313 #
18314 # Return values
18315 # 'undef' on improper arguments
18316 # 1 otherwise
18317  
18318 my ($self, $iv, $ivFlag, $drawFlag, $menuName, $iconName, $check) = @_;
18319  
18320 # Check for improper arguments
18321 if (! defined $iv || ! defined $ivFlag || ! defined $drawFlag || defined $check) {
18322  
18323 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleFlag', @_);
18324 }
18325  
18326 # Update the IV
18327 if ($ivFlag) {
18328 $self->ivPoke($iv, TRUE);
18329 } else {
18330 $self->ivPoke($iv, FALSE);
18331 }
18332  
18333 # Update every Automapper window using this world model
18334 foreach my $mapWin ($self->collectMapWins()) {
18335  
18336 if ($drawFlag) {
18337  
18338 # Redraw all drawn regions
18339 $mapWin->redrawRegions();
18340 }
18341  
18342 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18343  
18344 # Update the menu item
18345 if ($menuName) {
18346  
18347 $mapWin->setActiveItem($menuName, $self->$iv);
18348 }
18349  
18350 # Set the equivalent toolbar button, if there is one
18351 if ($iconName) {
18352  
18353 $mapWin->setActiveItem($iconName, $self->$iv);
18354 }
18355  
18356 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18357 }
18358  
18359 return 1;
18360 }
18361  
18362 sub switchMode {
18363  
18364 # Called by anonymous function in GA::Win::Map->enableXXXColumn
18365 # Sets the new value of an IV and updates each Automapper window
18366 #
18367 # Expected arguments
18368 # $iv - The IV to set
18369 # $value - New value of the IV (can be 'undef')
18370 # $drawFlag - If set to TRUE, this function calls ->drawRegion in every affected
18371 # Automapper window. If FALSE, ->drawRegion is not called
18372 #
18373 # Optional arguments
18374 # $menuName - The name of the menu item which must be set to active, or inactive (a key
18375 # in GA::Map::Win->menuToolItemHash
18376 # $iconName - The name of the toolbar icon which must be set to active, or inactive (a
18377 # key in GA::Map::Win->menuToolItemHash. If set to 'undef', there is no
18378 # icon to modify)
18379 #
18380 # Return values
18381 # 'undef' on improper arguments
18382 # 1 otherwise
18383  
18384 my ($self, $iv, $value, $drawFlag, $menuName, $iconName, $check) = @_;
18385  
18386 # Check for improper arguments
18387 if (! defined $iv || ! defined $drawFlag || defined $check) {
18388  
18389 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchMode', @_);
18390 }
18391  
18392 # Update the IV
18393 $self->ivPoke($iv, $value);
18394  
18395 # Update every Automapper window using this world model
18396 foreach my $mapWin ($self->collectMapWins()) {
18397  
18398 if ($drawFlag && $mapWin->currentRegionmap) {
18399  
18400 # Redraw all drawn regions
18401 $mapWin->redrawRegions();
18402  
18403 } elsif ($iv eq 'currentRoomMode') {
18404  
18405 # When setting $self->currentRoomMode, redraw the current/last known/ghost rooms
18406 if ($mapWin->mapObj->currentRoom) {
18407  
18408 $mapWin->markObjs('room', $mapWin->mapObj->currentRoom);
18409 }
18410  
18411 if ($mapWin->mapObj->lastKnownRoom) {
18412  
18413 $mapWin->markObjs('room', $mapWin->mapObj->lastKnownRoom);
18414 }
18415  
18416 if ($mapWin->mapObj->ghostRoom) {
18417  
18418 $mapWin->markObjs('room', $mapWin->mapObj->ghostRoom);
18419 }
18420  
18421 $mapWin->doDraw();
18422 }
18423  
18424 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18425  
18426 # Update the menu item
18427 if ($menuName) {
18428  
18429 $mapWin->setActiveItem($menuName, TRUE);
18430 }
18431  
18432 # Set the equivalent toolbar button, if there is one
18433 if ($iconName) {
18434  
18435 $mapWin->setActiveItem($iconName, TRUE);
18436 }
18437  
18438 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18439  
18440 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18441 $mapWin->restrictWidgets();
18442 }
18443  
18444 return 1;
18445 }
18446  
18447 sub toggleWinComponents {
18448  
18449 # Called by anonymous function in GA::Win::Map->enableViewColumn
18450 # Shows (or hides) each Automapper window's major components (the menu, toolbar, treeview
18451 # and canvas)
18452 #
18453 # Expected arguments
18454 # $iv - The IV matching the component to show (or hide) - one of 'showMenuBarFlag',
18455 # 'showToolbarFlag', 'showTreeViewFlag', 'showCanvasFlag'
18456 # $flag - The new value of the IV - TRUE or FALSE
18457 #
18458 # Return values
18459 # 'undef' on improper arguments
18460 # 1 otherwise
18461  
18462 my ($self, $iv, $flag, $check) = @_;
18463  
18464 # Check for improper arguments
18465 if (! defined $iv || ! defined $flag || defined $check) {
18466  
18467 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleWinComponents', @_);
18468 }
18469  
18470 # Update the IV
18471 if ($flag) {
18472 $self->ivPoke($iv, TRUE);
18473 } else {
18474 $self->ivPoke($iv, FALSE);
18475 }
18476  
18477 # Show (or hide) the component in every Automapper window using this world model
18478 foreach my $mapWin ($self->collectMapWins()) {
18479  
18480 my $menuItem;
18481  
18482 if ($iv eq 'showMenuBarFlag') {
18483  
18484 $mapWin->redrawWidgets('menu_bar');
18485 $mapWin->setActiveItem('show_menu_bar', $self->$iv);
18486  
18487 } elsif ($iv eq 'showToolbarFlag') {
18488  
18489 $mapWin->redrawWidgets('toolbar');
18490 $mapWin->setActiveItem('show_toolbar', $self->$iv);
18491  
18492 } elsif ($iv eq 'showTreeViewFlag') {
18493  
18494 $mapWin->redrawWidgets('treeview');
18495 $mapWin->setActiveItem('show_treeview', $self->$iv);
18496  
18497 } elsif ($iv eq 'showCanvasFlag') {
18498  
18499 # If there's a current region, we don't need it any more
18500 if (! $flag && $mapWin->currentRegionmap) {
18501  
18502 $mapWin->setCurrentRegion();
18503 }
18504  
18505 $mapWin->redrawWidgets('canvas');
18506 $mapWin->setActiveItem('show_canvas', $self->$iv);
18507 }
18508 }
18509  
18510 return 1;
18511 }
18512  
18513 sub resetRegionList {
18514  
18515 # Called by anonymous function in GA::Win::Map->enableViewColumn
18516 # Resets the order of the list of regions displayed in each Automapper window's treeview
18517 #
18518 # Expected arguments
18519 # (none besides $self)
18520 #
18521 # Return values
18522 # 'undef' on improper arguments
18523 # 1 otherwise
18524  
18525 my ($self, $check) = @_;
18526  
18527 # Check for improper arguments
18528 if (defined $check) {
18529  
18530 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetRegionList', @_);
18531 }
18532  
18533 # If there's a region moved to the top of the list, put back in its normal position
18534 $self->ivUndef('firstRegion');
18535 # Don't show a reversed list
18536 $self->ivPoke('reverseRegionListFlag', FALSE);
18537  
18538 # Redraw the list of regions in the treeview of every Automapper window using this world
18539 # model
18540 foreach my $mapWin ($self->collectMapWins()) {
18541  
18542 $mapWin->resetTreeView();
18543 }
18544  
18545 return 1;
18546 }
18547  
18548 sub reverseRegionList {
18549  
18550 # Called by anonymous function in GA::Win::Map->enableViewColumn
18551 # Reverses the order of the list of regions displayed in each Automapper window's treeview
18552 #
18553 # Expected arguments
18554 # (none besides $self)
18555 #
18556 # Return values
18557 # 'undef' on improper arguments
18558 # 1 otherwise
18559  
18560 my ($self, $check) = @_;
18561  
18562 # Check for improper arguments
18563 if (defined $check) {
18564  
18565 return $axmud::CLIENT->writeImproper($self->_objClass . '->reverseRegionList', @_);
18566 }
18567  
18568 if ($self->reverseRegionListFlag) {
18569  
18570 # Show normal list
18571 $self->ivPoke('reverseRegionListFlag', FALSE);
18572  
18573 } else {
18574  
18575 # Show reversed list
18576 $self->ivPoke('reverseRegionListFlag', TRUE);
18577 }
18578  
18579 # Redraw the list of regions in the treeview of every Automapper window using this world
18580 # model
18581 foreach my $mapWin ($self->collectMapWins()) {
18582  
18583 $mapWin->resetTreeView();
18584 }
18585  
18586 return 1;
18587 }
18588  
18589 sub moveRegionToTop {
18590  
18591 # Called by anonymous function in GA::Win::Map->enableViewColumn
18592 # Moves a specified region to the top of list of regions displayed in each Automapper
18593 # window's treeview
18594 #
18595 # Expected arguments
18596 # (none besides $self)
18597 #
18598 # Optional arguments
18599 # $regionmapObj - The GA::Obj::Regionmap to move. If undefined, any region already at
18600 # the top of the list is removed (and placed back in its original
18601 # position)
18602 #
18603 # Return values
18604 # 'undef' on improper arguments
18605 # 1 otherwise
18606  
18607 my ($self, $regionmapObj, $check) = @_;
18608  
18609 # Check for improper arguments
18610 if (defined $check) {
18611  
18612 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveRegionToTop', @_);
18613 }
18614  
18615 # Mark the current region as being at the top of the list (or remove an existing region from
18616 # the top of the list, if any)
18617 if ($regionmapObj) {
18618 $self->ivPoke('firstRegion', $regionmapObj->name);
18619 } else {
18620 $self->ivUndef('firstRegion');
18621 }
18622  
18623 # Redraw the list of regions in the treeview of every Automapper window using this world
18624 # model
18625 foreach my $mapWin ($self->collectMapWins()) {
18626  
18627 $mapWin->resetTreeView();
18628 }
18629  
18630 return 1;
18631 }
18632  
18633 sub toggleFilter {
18634  
18635 # Called by anonymous function in GA::Win::Map->enableViewColumn
18636 # Releases/applies the specified room filter and updates each Automapper window
18637 #
18638 # Expected arguments
18639 # $filter - The filter to apply/release
18640 # $flag - Set to TRUE to release the room filter, FALSE to apply it
18641 #
18642 # Return values
18643 # 'undef' on improper arguments
18644 # 1 otherwise
18645  
18646 my ($self, $filter, $flag, $check) = @_;
18647  
18648 # Check for improper arguments
18649 if (! defined $filter || ! defined $flag || defined $check) {
18650  
18651 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleAllFilters', @_);
18652 }
18653  
18654 if ($flag) {
18655 $self->ivAdd('roomFilterApplyHash', $filter, TRUE);
18656 } else {
18657 $self->ivAdd('roomFilterApplyHash', $filter, FALSE);
18658 }
18659  
18660 # Update every Automapper window using this world model
18661 foreach my $mapWin ($self->collectMapWins()) {
18662  
18663 # Redraw all drawn regions
18664 $mapWin->redrawRegions();
18665  
18666 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18667  
18668 # Update the menu item
18669 $mapWin->setActiveItem($filter . '_filter', $flag);
18670  
18671 # Set the equivalent toolbar button
18672 $mapWin->setActiveItem('icon_' . $filter . '_filter', $flag);
18673  
18674 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18675 }
18676  
18677 return 1;
18678 }
18679  
18680 sub switchRoomInteriorMode {
18681  
18682 # Called by anonymous function in GA::Win::Map->enableViewColumn
18683 # Sets the value of $self->roomInteriorMode and updates each Automapper window
18684 #
18685 # Expected arguments
18686 # $mode - The new value of ->roomInteriorMode
18687 #
18688 # Return values
18689 # 'undef' on improper arguments
18690 # 1 otherwise
18691  
18692 my ($self, $mode, $check) = @_;
18693  
18694 # Check for improper arguments
18695 if (! defined $mode || defined $check) {
18696  
18697 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchRoomInteriorMode', @_);
18698 }
18699  
18700 $self->ivPoke('roomInteriorMode', $mode);
18701  
18702 # Update every Automapper window using this world model
18703 foreach my $mapWin ($self->collectMapWins()) {
18704  
18705 # Redraw all drawn regions
18706 $mapWin->redrawRegions();
18707  
18708 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18709  
18710 # Update the menu item
18711 $mapWin->setActiveItem('interior_mode_' . $mode, TRUE);
18712  
18713 # Set the equivalent toolbar button
18714 $mapWin->setActiveItem('icon_interior_mode_' . $mode, TRUE);
18715  
18716 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18717 }
18718  
18719 return 1;
18720 }
18721  
18722 sub switchRegionDrawExitMode {
18723  
18724 # Called by anonymous function in GA::Win::Map->enableViewColumn
18725 # Sets the value of GA::Obj::Regionmap->drawExitMode and updates each Automapper window
18726 #
18727 # Expected arguments
18728 # $regionmapObj - The regionmap to modify
18729 # $mode - The new value of $regionmapObj->drawExitMode
18730 #
18731 # Return values
18732 # 'undef' on improper arguments
18733 # 1 otherwise
18734  
18735 my ($self, $regionmapObj, $mode, $check) = @_;
18736  
18737 # Check for improper arguments
18738 if (! defined $regionmapObj || ! defined $mode || defined $check) {
18739  
18740 return $axmud::CLIENT->writeImproper(
18741 $self->_objClass . '->switchRegionDrawExitMode',
18742 @_,
18743 );
18744 }
18745  
18746 $regionmapObj->ivPoke('drawExitMode', $mode);
18747  
18748 # Update every Automapper window using this world model
18749 foreach my $mapWin ($self->collectMapWins()) {
18750  
18751 my ($menuName, $menuItem);
18752  
18753 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18754 $mapWin->redrawRegions($regionmapObj, TRUE);
18755  
18756 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18757  
18758 # Update the menu item
18759 if ($mode eq 'no_exit') {
18760 $menuName = 'region_draw_no_exits';
18761 } elsif ($mode eq 'simple_exit') {
18762 $menuName = 'region_draw_simple_exits';
18763 } elsif ($mode eq 'complex_exit') {
18764 $menuName = 'region_draw_complex_exits';
18765 }
18766  
18767 $mapWin->setActiveItem($menuName, FALSE);
18768  
18769 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18770  
18771 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18772 $mapWin->restrictWidgets();
18773 }
18774  
18775 return 1;
18776 }
18777  
18778 sub toggleObscuredExitFlag {
18779  
18780 # Called by anonymous function in GA::Win::Map->enableViewColumn
18781 # Sets the value of GA::Obj::Regionmap->obscuredExitFlag and updates each Automapper window
18782 #
18783 # Expected arguments
18784 # $regionmapObj - The regionmap to modify
18785 #
18786 # Return values
18787 # 'undef' on improper arguments
18788 # 1 otherwise
18789  
18790 my ($self, $regionmapObj, $check) = @_;
18791  
18792 # Check for improper arguments
18793 if (! defined $regionmapObj || defined $check) {
18794  
18795 return $axmud::CLIENT->writeImproper(
18796 $self->_objClass . '->toggleObscuredExitFlag',
18797 @_,
18798 );
18799 }
18800  
18801 if (! $regionmapObj->obscuredExitFlag) {
18802 $regionmapObj->ivPoke('obscuredExitFlag', TRUE);
18803 } else {
18804 $regionmapObj->ivPoke('obscuredExitFlag', FALSE);
18805 }
18806  
18807 # Update every Automapper window using this world model
18808 foreach my $mapWin ($self->collectMapWins()) {
18809  
18810 my ($menuName, $menuItem);
18811  
18812 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18813 $mapWin->redrawRegions($regionmapObj, TRUE);
18814  
18815 # Update the menu item
18816 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18817 $mapWin->setActiveItem('obscured_exits_region', $regionmapObj->obscuredExitFlag);
18818 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18819  
18820 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18821 $mapWin->restrictWidgets();
18822 }
18823  
18824 return 1;
18825 }
18826  
18827 sub toggleObscuredExitRedrawFlag {
18828  
18829 # Called by anonymous function in GA::Win::Map->enableViewColumn
18830 # Sets the value of GA::Obj::Regionmap->obscuredExitRedrawFlag and updates each Automapper
18831 # window
18832 #
18833 # Expected arguments
18834 # $regionmapObj - The regionmap to modify
18835 #
18836 # Return values
18837 # 'undef' on improper arguments
18838 # 1 otherwise
18839  
18840 my ($self, $regionmapObj, $check) = @_;
18841  
18842 # Check for improper arguments
18843 if (! defined $regionmapObj || defined $check) {
18844  
18845 return $axmud::CLIENT->writeImproper(
18846 $self->_objClass . '->toggleObscuredExitRedrawFlag',
18847 @_,
18848 );
18849 }
18850  
18851 if (! $regionmapObj->obscuredExitRedrawFlag) {
18852 $regionmapObj->ivPoke('obscuredExitRedrawFlag', TRUE);
18853 } else {
18854 $regionmapObj->ivPoke('obscuredExitRedrawFlag', FALSE);
18855 }
18856  
18857 # Update every Automapper window using this world model
18858 foreach my $mapWin ($self->collectMapWins()) {
18859  
18860 my ($menuName, $menuItem);
18861  
18862 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18863 $mapWin->redrawRegions($regionmapObj, TRUE);
18864  
18865 # Update the menu item
18866 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18867 $mapWin->setActiveItem(
18868 'auto_redraw_obscured_region',
18869 $regionmapObj->obscuredExitRedrawFlag,
18870 );
18871 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18872  
18873 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18874 $mapWin->restrictWidgets();
18875 }
18876  
18877 return 1;
18878 }
18879  
18880 sub toggleDrawOrnamentsFlag {
18881  
18882 # Called by anonymous function in GA::Win::Map->enableViewColumn
18883 # Sets the value of GA::Obj::Regionmap->drawOrnamentsFlag and updates each Automapper window
18884 #
18885 # Expected arguments
18886 # $regionmapObj - The regionmap to modify
18887 #
18888 # Return values
18889 # 'undef' on improper arguments
18890 # 1 otherwise
18891  
18892 my ($self, $regionmapObj, $check) = @_;
18893  
18894 # Check for improper arguments
18895 if (! defined $regionmapObj || defined $check) {
18896  
18897 return $axmud::CLIENT->writeImproper(
18898 $self->_objClass . '->toggleDrawOrnamentsFlag',
18899 @_,
18900 );
18901 }
18902  
18903 if (! $regionmapObj->drawOrnamentsFlag) {
18904 $regionmapObj->ivPoke('drawOrnamentsFlag', TRUE);
18905 } else {
18906 $regionmapObj->ivPoke('drawOrnamentsFlag', FALSE);
18907 }
18908  
18909 # Update every Automapper window using this world model
18910 foreach my $mapWin ($self->collectMapWins()) {
18911  
18912 my ($menuName, $menuItem);
18913  
18914 # Redraw the specified regionmap (the TRUE argument means don't redraw other regionmaps)
18915 $mapWin->redrawRegions($regionmapObj, TRUE);
18916  
18917 # Update the menu item
18918 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
18919 $mapWin->setActiveItem('draw_ornaments_region', $regionmapObj->drawOrnamentsFlag);
18920 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
18921  
18922 # Sensitise/desensitise menu bar/toolbar items, depending on current conditions
18923 $mapWin->restrictWidgets();
18924 }
18925  
18926 return 1;
18927 }
18928  
18929 sub setMagnification {
18930  
18931 # Called by anonymous function in GA::Win::Map->enableViewColumn
18932 # Sets the value of GA::Obj::Regionmap->magnification and updates each Automapper window
18933 #
18934 # Expected arguments
18935 # $mapWin - The GA::Win::Map that initiated the zoom
18936 # $magnification - The new value of $regionmapObj->magnification
18937 #
18938 # Return values
18939 # 'undef' on improper arguments
18940 # 1 otherwise
18941  
18942 my ($self, $mapWin, $magnification, $check) = @_;
18943  
18944 # Local variables
18945 my (
18946 $regionmapObj, $oldOffsetXPos, $oldOffsetYPos, $oldStartXPos, $oldStartYPos,
18947 $oldWidth, $oldHeight, $offsetXPos, $offsetYPos, $startXPos, $startYPos, $width,
18948 $height, $adjustXFlag, $adjustYFlag,
18949 );
18950  
18951 # Check for improper arguments
18952 if (! defined $mapWin || ! defined $magnification || defined $check) {
18953  
18954 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMagnification', @_);
18955 }
18956  
18957 $regionmapObj = $mapWin->currentRegionmap;
18958 $regionmapObj->ivPoke('magnification', $magnification);
18959  
18960 # When we fully zoom out, so that there are no scroll bars visible, GooCanvas2::Canvas
18961 # helpfully forgets the scrollbar's position. This means that the current room, if we were
18962 # centred on it, is no longer centred. Therefore we have to get the scrollbar's position,
18963 # change the map's visible size, and then - if the map is fully zoomed out, and the
18964 # scrollbars have disappeared - record their position, for the next time the user zooms in
18965  
18966 # Get the visible map's size and position. The six return values are all numbers in the
18967 # range 0-1
18968 ($oldOffsetXPos, $oldOffsetYPos, $oldStartXPos, $oldStartYPos, $oldWidth, $oldHeight)
18969 = $mapWin->getMapPosn();
18970  
18971 # Update every Automapper window using this world model
18972 foreach my $otherMapWin ($self->collectMapWins()) {
18973  
18974 if ($otherMapWin->currentRegionmap && $otherMapWin->currentRegionmap eq $regionmapObj) {
18975  
18976 # Zoom in or out on this region
18977 $otherMapWin->doZoom();
18978 }
18979 }
18980  
18981 # Get the visible map's new size and position.
18982 ($offsetXPos, $offsetYPos, $startXPos, $startYPos, $width, $height)
18983 = $mapWin->getMapPosn();
18984  
18985 # The horizontal and vertical scrollbars can reach max zoom out at different times, so deal
18986 # with them separately
18987 if (
18988 ! $regionmapObj->maxZoomOutXFlag
18989 && (
18990 ($oldOffsetXPos != 0 && $offsetXPos == 0)
18991 || ($oldOffsetXPos != 1 && $offsetXPos == 1)
18992 )
18993 ) {
18994 # We have fully zoomed out, and we weren't already fully zoomed out. Inform the
18995 # regionmap
18996 $regionmapObj->ivPoke('maxZoomOutXFlag', TRUE);
18997 # Remember the position of the scrollbars before the zoom
18998 $regionmapObj->ivPoke('scrollXPos', $oldStartXPos + ($oldWidth / 2));
18999  
19000 } elsif (
19001 $regionmapObj->maxZoomOutXFlag
19002 && (
19003 ($oldOffsetXPos == 0 && $offsetXPos != 0)
19004 || ($oldOffsetXPos == 1 && $offsetXPos != 1)
19005 )
19006 ) {
19007 # We have just zoomed in from a maximum zoom out. Reset the flags in the regionmap
19008 $regionmapObj->ivPoke('maxZoomOutXFlag', FALSE);
19009 $adjustXFlag = TRUE;
19010 }
19011  
19012 if (
19013 ! $regionmapObj->maxZoomOutYFlag
19014 && (
19015 ($oldOffsetYPos != 0 && $offsetYPos == 0)
19016 || ($oldOffsetYPos != 1 && $offsetYPos == 1)
19017 )
19018 ) {
19019 $regionmapObj->ivPoke('maxZoomOutYFlag', TRUE);
19020 $regionmapObj->ivPoke('scrollYPos', $oldStartYPos + ($oldHeight / 2));
19021  
19022 } elsif (
19023 $regionmapObj->maxZoomOutYFlag
19024 && (
19025 ($oldOffsetYPos == 0 && $offsetYPos != 0)
19026 || ($oldOffsetYPos == 1 && $offsetYPos != 1)
19027 )
19028 ) {
19029 $regionmapObj->ivPoke('maxZoomOutYFlag', FALSE);
19030 $adjustYFlag = TRUE;
19031 }
19032  
19033 # In every affected Automapper window, re-centre the map at the correct position
19034 foreach my $otherMapWin ($self->collectMapWins()) {
19035  
19036 if (
19037 $otherMapWin->currentRegionmap
19038 && $otherMapWin->currentRegionmap eq $regionmapObj
19039 ) {
19040 if ($adjustXFlag && $adjustYFlag) {
19041  
19042 $otherMapWin->setMapPosn($regionmapObj->scrollXPos, $regionmapObj->scrollYPos);
19043  
19044 } elsif ($adjustXFlag) {
19045  
19046 $otherMapWin->setMapPosn(
19047 $regionmapObj->scrollXPos,
19048 ($startYPos + ($height / 2)),
19049 );
19050  
19051 } elsif ($adjustYFlag) {
19052  
19053 $otherMapWin->setMapPosn(
19054 ($startXPos + ($width / 2)),
19055 $regionmapObj->scrollYPos,
19056 );
19057 }
19058 }
19059 }
19060  
19061 return 1;
19062 }
19063  
19064 sub repositionMaps {
19065  
19066 # Called by anonymous function in GA::Win::Map->enableViewColumn
19067 # Repositions every regionmap in the world model (sets the magnification to 0, and sets the
19068 # scroll position to the middle of the map). Updates each Automapper window using this
19069 # world model
19070 #
19071 # Expected arguments
19072 # (none besides $self)
19073 #
19074 # Return values
19075 # 'undef' on improper arguments
19076 # 1 otherwise
19077  
19078 my ($self, $check) = @_;
19079  
19080 # Check for improper arguments
19081 if (defined $check) {
19082  
19083 return $axmud::CLIENT->writeImproper($self->_objClass . '->repositionMaps', @_);
19084 }
19085  
19086 # Update IVs for each regionmap
19087 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
19088  
19089 $regionmapObj->ivPoke('magnification', 1);
19090 $regionmapObj->ivPoke('scrollXPos', 0.5);
19091 $regionmapObj->ivPoke('scrollYPos', 0.5);
19092 $regionmapObj->ivPoke('currentLevel', 0);
19093 }
19094  
19095 # Update every Automapper window using this world model
19096 foreach my $mapWin ($self->collectMapWins()) {
19097  
19098 if ($mapWin->currentRegionmap) {
19099  
19100 # Reset zoom factor (magnification) to 1
19101 $mapWin->zoomCallback(1);
19102 # Reset the scrollbars
19103 $mapWin->setMapPosn(0.5, 0.5);
19104 # Redraw the map to make sure the default level is visible
19105 $mapWin->setCurrentLevel(0);
19106 }
19107 }
19108  
19109 return 1;
19110 }
19111  
19112 sub setTrackingSensitivity {
19113  
19114 # Called by anonymous function in GA::Win::Map->enableViewColumn
19115 # Sets the value of $self->trackingSensitivity and updates each Automapper window
19116 #
19117 # Expected arguments
19118 # $sensitivity - The new tracking sensitivity (one of the value 0, 0.33, 0.66 or 1)
19119 #
19120 # Return values
19121 # 'undef' on improper arguments
19122 # 1 otherwise
19123  
19124 my ($self, $sensitivity, $check) = @_;
19125  
19126 # Check for improper arguments
19127 if (! defined $sensitivity || defined $check) {
19128  
19129 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTrackingSensitivity', @_);
19130 }
19131  
19132 if (
19133 $sensitivity != 0
19134 && $sensitivity != 0.33
19135 && $sensitivity != 0.66
19136 && $sensitivity != 1
19137 ) {
19138 # Use a default value for $sensitivity
19139 $sensitivity = 0;
19140 }
19141  
19142 $self->ivPoke('trackingSensitivity', $sensitivity);
19143  
19144 # Update every Automapper window using this world model
19145 foreach my $mapWin ($self->collectMapWins()) {
19146  
19147 my $menuName;
19148  
19149 if ($sensitivity == 0) {
19150 $menuName = 'track_always';
19151 } elsif ($sensitivity == 0.33) {
19152 $menuName = 'track_near_centre';
19153 } elsif ($sensitivity == 0.66) {
19154 $menuName = 'track_near_edge';
19155 } else {
19156 $menuName = 'track_not_visible';
19157 }
19158  
19159 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19160  
19161 # Update the menu item
19162 $mapWin->setActiveItem($menuName, TRUE);
19163  
19164 # Set the equivalent toolbar button
19165 $mapWin->setActiveItem('icon_' . $menuName, TRUE);
19166  
19167 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19168 }
19169  
19170 return 1;
19171 }
19172  
19173 # (Called from GA::Win::Map menu, 'Mode' column)
19174  
19175 sub setAutoCompareMode {
19176  
19177 # Called by anonymous function in GA::Win::Map->enableModeColumn
19178 # Updates the world model's ->autoCompareMode and updates each Automapper window using this
19179 # world model
19180 #
19181 # Expected arguments
19182 # $mode - The new value of the IV - 'default', 'new' or 'current'
19183 #
19184 # Return values
19185 # 'undef' on improper arguments
19186 # 1 otherwise
19187  
19188 my ($self, $mode, $check) = @_;
19189  
19190 # Check for improper arguments
19191 if (! defined $mode || defined $check) {
19192  
19193 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAutoCompareMode', @_);
19194 }
19195  
19196 # Update the IV
19197 $self->ivPoke('autoCompareMode', $mode);
19198  
19199 # Update every Automapper window using this world model
19200 foreach my $mapWin ($self->collectMapWins()) {
19201  
19202 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19203  
19204 # Update the menu item
19205 if ($mode eq 'default') {
19206 $mapWin->setActiveItem('auto_compare_default', TRUE);
19207 } elsif ($mode eq 'default') {
19208 $mapWin->setActiveItem('auto_compare_new', TRUE);
19209 } elsif ($mode eq 'default') {
19210 $mapWin->setActiveItem('auto_compare_current', TRUE);
19211 }
19212  
19213 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19214  
19215 # If interior counts are currently showing the number of rooms that match the current
19216 # room, redraw the current room to show the counts
19217 if ($self->roomInteriorMode eq 'compare_count' && $mapWin->mapObj->currentRoom) {
19218  
19219 $mapWin->markObjs('room', $mapWin->mapObj->currentRoom);
19220 $mapWin->doDraw();
19221 }
19222 }
19223  
19224 return 1;
19225 }
19226  
19227 sub toggleAutoCompareAllFlag {
19228  
19229 # Called by anonymous function in GA::Win::Map->enableModeColumn
19230 # Toggles the world model's ->autoCompareAllFlag and updates each Automapper window using
19231 # this world model
19232 #
19233 # Expected arguments
19234 # $flag - The new value of the IV - TRUE or FALSE
19235 #
19236 # Return values
19237 # 'undef' on improper arguments
19238 # 1 otherwise
19239  
19240 my ($self, $flag, $check) = @_;
19241  
19242 # Check for improper arguments
19243 if (! defined $flag || defined $check) {
19244  
19245 return $axmud::CLIENT->writeImproper(
19246 $self->_objClass . '->toggleAutoCompareAllFlag',
19247 @_,
19248 );
19249 }
19250  
19251 # Update the IV
19252 if (! $flag) {
19253 $self->ivPoke('autoCompareAllFlag', FALSE);
19254 } else {
19255 $self->ivPoke('autoCompareAllFlag', TRUE);
19256 }
19257  
19258 # Update every Automapper window using this world model
19259 foreach my $mapWin ($self->collectMapWins()) {
19260  
19261 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19262  
19263 # Update the menu item
19264 if (! $flag) {
19265 $mapWin->setActiveItem('auto_compare_region', TRUE);
19266 } else {
19267 $mapWin->setActiveItem('auto_compare_model', TRUE);
19268 }
19269  
19270 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19271 }
19272  
19273 return 1;
19274 }
19275  
19276 sub setAutoSlideMode {
19277  
19278 # Called by anonymous function in GA::Win::Map->enableModeColumn
19279 # Updates the world model's ->autoSlideMode and updates each Automapper window using this
19280 # world model
19281 #
19282 # Expected arguments
19283 # $mode - The new value of the IV - 'default', 'orig_pull', 'orig_push', 'other_pull',
19284 # 'other_push', 'dest_pull' or 'dest_push'
19285 #
19286 # Return values
19287 # 'undef' on improper arguments
19288 # 1 otherwise
19289  
19290 my ($self, $mode, $check) = @_;
19291  
19292 # Check for improper arguments
19293 if (! defined $mode || defined $check) {
19294  
19295 return $axmud::CLIENT->writeImproper($self->_objClass . '->setAutoSlideMode', @_);
19296 }
19297  
19298 # Update the IV
19299 $self->ivPoke('autoSlideMode', $mode);
19300  
19301 # Update every Automapper window using this world model
19302 foreach my $mapWin ($self->collectMapWins()) {
19303  
19304 my $menuItem;
19305  
19306 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19307  
19308 # Update the menu item
19309 if ($mode eq 'default') {
19310 $mapWin->setActiveItem('slide_default', TRUE);
19311 } elsif ($mode eq 'orig_pull') {
19312 $mapWin->setActiveItem('slide_orig_pull', TRUE);
19313 } elsif ($mode eq 'orig_push') {
19314 $mapWin->setActiveItem('slide_orig_push', TRUE);
19315 } elsif ($mode eq 'other_pull') {
19316 $mapWin->setActiveItem('slide_other_pull', TRUE);
19317 } elsif ($mode eq 'other_push') {
19318 $mapWin->setActiveItem('slide_other_push', TRUE);
19319 } elsif ($mode eq 'dest_pull') {
19320 $mapWin->setActiveItem('slide_dest_pull', TRUE);
19321 } elsif ($mode eq 'dest_push') {
19322 $mapWin->setActiveItem('slide_dest_push', TRUE);
19323 }
19324  
19325 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19326 }
19327  
19328 return 1;
19329 }
19330  
19331 sub toggleDisableUpdateModeFlag {
19332  
19333 # Called by anonymous function in GA::Win::Map->enableModeColumn
19334 # Toggles the world model's ->disableUpdateModeFlag and updates each Automapper window using
19335 # this world model
19336 #
19337 # Expected arguments
19338 # $flag - The new value of the IV - TRUE or FALSE
19339 #
19340 # Return values
19341 # 'undef' on improper arguments
19342 # 1 otherwise
19343  
19344 my ($self, $flag, $check) = @_;
19345  
19346 # Check for improper arguments
19347 if (! defined $flag || defined $check) {
19348  
19349 return $axmud::CLIENT->writeImproper(
19350 $self->_objClass . '->toggleDisableUpdateModeFlag',
19351 @_,
19352 );
19353 }
19354  
19355 # Update the IV
19356 if ($flag) {
19357 $self->ivPoke('disableUpdateModeFlag', TRUE);
19358 } else {
19359 $self->ivPoke('disableUpdateModeFlag', FALSE);
19360 }
19361  
19362 # Update every Automapper window using this world model
19363 foreach my $mapWin ($self->collectMapWins()) {
19364  
19365 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19366  
19367 # Update the menu item
19368 $mapWin->setActiveItem('disable_update_mode', $self->disableUpdateModeFlag);
19369  
19370 # The call to ->setMode makes sure the Automapper window's mode is switched from
19371 # 'update' to 'follow' if 'update' mode has just been disabled, and also makes sure
19372 # the menu/toolbar buttons are sensitised or not, as appropriate
19373 $mapWin->setMode($mapWin->mode);
19374  
19375 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19376 }
19377  
19378 return 1;
19379 }
19380  
19381 sub toggleShowTooltipsFlag {
19382  
19383 # Called by anonymous function in GA::Win::Map->enableModeColumn
19384 # Toggles the world model's ->showTooltipsFlag and updates each Automapper window using this
19385 # world model
19386 #
19387 # Expected arguments
19388 # $flag - The new value of the IV - TRUE or FALSE
19389 #
19390 # Return values
19391 # 'undef' on improper arguments
19392 # 1 otherwise
19393  
19394 my ($self, $flag, $check) = @_;
19395  
19396 # Check for improper arguments
19397 if (! defined $flag || defined $check) {
19398  
19399 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleShowTooltipsFlag', @_);
19400 }
19401  
19402 # Update the IV
19403 if ($flag) {
19404 $self->ivPoke('showTooltipsFlag', TRUE);
19405 } else {
19406 $self->ivPoke('showTooltipsFlag', FALSE);
19407 }
19408  
19409 # Update every Automapper window using this world model
19410 foreach my $mapWin ($self->collectMapWins()) {
19411  
19412 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19413  
19414 # Update the menu item
19415 $mapWin->setActiveItem('show_tooltips', $self->showTooltipsFlag);
19416  
19417 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19418  
19419 if (! $flag) {
19420  
19421 # If the tooltip window is currently visible, hide it
19422 $mapWin->hideTooltips();
19423 }
19424 }
19425  
19426 return 1;
19427 }
19428  
19429 # (Called from GA::Win::Map menu, 'Exits' column)
19430  
19431 sub setCheckableDirMode {
19432  
19433 # Called by anonymous function in GA::Win::Map->enableModeColumn
19434 # Updates the world model's ->checkableDirMode and updates each Automapper window using
19435 # this world model
19436 #
19437 # Expected arguments
19438 # $mode - The new value of the IV - 'simple', 'diku', 'lp' or 'complex'
19439 #
19440 # Return values
19441 # 'undef' on improper arguments
19442 # 1 otherwise
19443  
19444 my ($self, $mode, $check) = @_;
19445  
19446 # Check for improper arguments
19447 if (! defined $mode || defined $check) {
19448  
19449 return $axmud::CLIENT->writeImproper($self->_objClass . '->setCheckableDirMode', @_);
19450 }
19451  
19452 # Update the IV
19453 $self->ivPoke('checkableDirMode', $mode);
19454  
19455 # Update every Automapper window using this world model
19456 foreach my $mapWin ($self->collectMapWins()) {
19457  
19458 $mapWin->set_ignoreMenuUpdateFlag(TRUE);
19459  
19460 # Update the menu item
19461 if ($mode eq 'simple') {
19462 $mapWin->setActiveItem('checkable_dir_simple', TRUE);
19463 } elsif ($mode eq 'diku') {
19464 $mapWin->setActiveItem('checkable_dir_diku', TRUE);
19465 } elsif ($mode eq 'lp') {
19466 $mapWin->setActiveItem('checkable_dir_lp', TRUE);
19467 } elsif ($mode eq 'complex') {
19468 $mapWin->setActiveItem('checkable_dir_complex', TRUE);
19469 }
19470  
19471 $mapWin->set_ignoreMenuUpdateFlag(FALSE);
19472  
19473 # If interior counts are currently showing checked/checkable directions, redraw all
19474 # drawn regions to update those counts
19475 if ($self->roomInteriorMode eq 'checked_count') {
19476  
19477 $mapWin->redrawRegions();
19478 }
19479 }
19480  
19481 return 1;
19482 }
19483  
19484 sub getCheckableDirs {
19485  
19486 # Called by GA::Win::Map->prepareCheckedCounts, once per drawing cycle. Also called by
19487 # GA::Cmd::ModelReport->do
19488 # $self->roomInteriorMode specifies which primary directions should be checked, when
19489 # using checkable directions. This function compiles the list of primary directions, and
19490 # converts them from their standard to custom forms, which is how they are stored in
19491 # GA::ModelObj::Room->checkedDirHash
19492 #
19493 # Expected arguments
19494 # $session - The calling GA::Session
19495 #
19496 # Return values
19497 # An empty hash on improper arguments
19498 # Otherwise returns a hash (never empty), in the form
19499 # $hash{custom_primary_direction} = undef
19500  
19501 my ($self, $session, $check) = @_;
19502  
19503 # Local variables
19504 my (
19505 $dictObj,
19506 @standardList,
19507 %emptyHash, %returnHash,
19508 );
19509  
19510 # Check for improper arguments
19511 if (! defined $session || defined $check) {
19512  
19513 $axmud::CLIENT->writeImproper($self->_objClass . '->getCheckableDirs', @_);
19514 return %emptyHash;
19515 }
19516  
19517 # Import the current dictionary (for convenience)
19518 $dictObj = $session->currentDict;
19519  
19520 if ($self->checkableDirMode eq 'complex') {
19521 @standardList = $axmud::CLIENT->constPrimaryDirList;
19522 } elsif ($self->checkableDirMode eq 'lp') {
19523 @standardList = $axmud::CLIENT->constShortPrimaryDirList;
19524 } elsif ($self->checkableDirMode eq 'diku') {
19525 @standardList = qw(north south east west up down);
19526 } else {
19527 @standardList = qw(north south east west); # ->roomInteriorMode is 'simple'
19528 }
19529  
19530 foreach my $standard (@standardList) {
19531  
19532 my $custom = $dictObj->ivShow('primaryDirHash', $standard);
19533 $returnHash{$custom} = undef;
19534 }
19535  
19536 # Operation complete
19537 return %returnHash;
19538 }
19539  
19540 # A* algorithm functions (used to find a path between two rooms in the same region)
19541  
19542 sub findPath {
19543  
19544 # Can be called by any function
19545 #
19546 # A* algorithm to find a path between two rooms in the same region, based on
19547 # AI::Pathfinding::AStar by Aaron Dalton
19548 #
19549 # This function should only be called if there's reasonable certainty that a path exists
19550 # without going via another region
19551 # Any code that wants to find the shortest path, including (if necessary) going via another
19552 # region), should call $self->findUniversalPath instead (because it calls this function
19553 # anyway, if the two rooms are in the same region, and then proceeds with its own
19554 # algorithms if necessary)
19555 #
19556 # Expected arguments
19557 # $initialNode - The initial node (a GA::ModelObj::Room)
19558 # $targetNode - The target node (a GA::ModelObj::Room in the same region)
19559 #
19560 # Optional arguments
19561 # $avoidHazardsFlag
19562 # - If set to TRUE, the path won't use any rooms with a room flag on the
19563 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19564 # to FALSE (or 'undef'), those rooms can be used
19565 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19566 # should avoid hazardous rooms by default, or not. It's up to the
19567 # calling function to decide whether to use it, and to set the value
19568 # of this argument accordingly
19569 # $otherHazardListRef
19570 # - An optional reference to a list of room flags that should be
19571 # considered hazardous for the purposes of this algorithm (not an
19572 # error if it contains duplicate room flags, or if it contains room
19573 # flags already on the hazardous room flags list). Can be 'undef' or
19574 # a reference to an empty list
19575 # - NB Room flags in this list are considered hazardous, even if
19576 # $avoidHazardsFlag is FALSE
19577 # $avoidAdjacentFlag
19578 # - If set to TRUE, the algorithm won't use rooms in adjacent regions,
19579 # regardless of the value of $self->adjacentMode. If set to FALSE (or
19580 # 'undef', the value of $self->adjacentMode applies
19581 # $adjacentHashRef
19582 # - An optional hash of adjacent regions, set (in some situations) when
19583 # the calling function is $self->findUniversalPath. If defined, the
19584 # keys in the hash are the model numbers of regions that are
19585 # adjacent to $initialNode's parent region (the meaning of 'adjacent'
19586 # depends on $self->adjacentCount). $initialNode's parent region also
19587 # exists in the hash. If 'undef', this function fetches the list of
19588 # adjacent regions itself, if it needs to
19589 #
19590 # Return values
19591 # An empty list on improper arguments
19592 # Otherwise, returns two list references. The first reference contains a list of
19593 # GA::ModelObj::Room objects on the shortest path between the rooms $initialNode and
19594 # $targetNode (inclusive). The second reference contains a list of GA::Obj::Exit
19595 # objects used to move along the path. The first list contains exactly one more item
19596 # than the second (exception: if no path can be found, both lists are empty)
19597  
19598 my (
19599 $self, $initialNode, $targetNode, $avoidHazardsFlag, $otherHazardListRef,
19600 $avoidAdjacentFlag, $adjacentHashRef, $check,
19601 ) = @_;
19602  
19603 # Local variables
19604 my (
19605 $currentNode, $path, $openListObj, $nodeHashRef, $pathRoomListRef, $pathExitListRef,
19606 @emptyList,
19607 %hazardHash, %adjacentHash,
19608 );
19609  
19610 # Check for improper arguments
19611 if (! defined $initialNode || ! defined $targetNode || defined $check) {
19612  
19613 $axmud::CLIENT->writeImproper($self->_objClass . '->findPath', @_);
19614 return @emptyList;
19615 }
19616  
19617 # Create a combined hash of hazardous room flags (whose rooms must be avoided by the
19618 # algorithm). If the function returns an empty hash, then all rooms can be used
19619 if (! defined $otherHazardListRef) {
19620 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag);
19621 } else {
19622 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag, @$otherHazardListRef);
19623 }
19624  
19625 # If $self->adjacentMode is 'near', meaning that we can use adjacent regions, and if the
19626 # calling function didn't supply a hash of adjacent regions, compile our own
19627 if ($avoidAdjacentFlag) {
19628  
19629 # (The call to $self->doAStar needs a hash reference, even an empty one)
19630 $adjacentHashRef = {};
19631  
19632 } elsif (! defined $adjacentHashRef) {
19633  
19634 if ($self->adjacentMode eq 'near') {
19635  
19636 %adjacentHash = $self->compileAdjacentRegions($initialNode->parent);
19637 }
19638  
19639 # (The call to $self->doAStar needs a hash reference, even an empty one)
19640 $adjacentHashRef = \%adjacentHash;
19641 }
19642  
19643 # Create the open list, using a binomial heap
19644 $openListObj = Games::Axmud::Obj::Heap->new();
19645 # Create a reference to a hash of nodes, in the form
19646 # $nodeHash{room_object} = node
19647 # ...where 'room_object' is a GA::ModelObj::Room, and 'node' is a GA::Node::AStar object
19648 $nodeHashRef = {};
19649  
19650 # Create a node for the initial room
19651 $currentNode = Games::Axmud::Node::AStar->new(
19652 $initialNode, # A GA::ModelObj::Room
19653 0, # Initial G score
19654 0, # Initial H score
19655 );
19656  
19657 # Add this node to the open list
19658 $currentNode->ivPoke('inOpenFlag', TRUE);
19659 $openListObj->add($currentNode);
19660  
19661 # Perform the A* algorithm, starting at the room $initialNode, and aiming for the room
19662 # $targetNode
19663 $self->doAStar($targetNode, $openListObj, $nodeHashRef, \%hazardHash, $adjacentHashRef);
19664  
19665 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
19666 # path from the target room, and using the parent of each node in turn (in the standard
19667 # way)
19668 # Get two list references, one containing the rooms in the shortest path between
19669 # $initialNode and $targetNode, and the other containing the exits to move along the path
19670 ($pathRoomListRef, $pathExitListRef) = $self->fillPath_aStar(
19671 $targetNode,
19672 $openListObj,
19673 $nodeHashRef
19674 );
19675  
19676 return ($pathRoomListRef, $pathExitListRef);
19677 }
19678  
19679 sub compileRoomHazards {
19680  
19681 # Called by $self->findPath and ->smoothPath
19682 # Compiles a hash of room flags that should be considered hazardous, for the purposes of the
19683 # A-star algorithm
19684 #
19685 # Expected arguments
19686 # (none besides $self)
19687 #
19688 # Optional arguments
19689 # $avoidHazardsFlag
19690 # - If set to TRUE, the path won't use any rooms with a room flag on the
19691 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19692 # to FALSE (or 'undef'), those rooms can be used
19693 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19694 # should avoid hazardous rooms by default, or not. It's up to the
19695 # calling function to decide whether to use it, and to set the value
19696 # of this argument accordingly
19697 # @otherHazardList
19698 # - An optional list of room flags that should be considered hazardous,
19699 # for the purposes of this algorithm (not an error if it contains
19700 # duplicate room flags, or if it contains room flags already on the
19701 # hazardous room flags list)
19702 # - NB Room flags in this list are considered hazardous, even if
19703 # $avoidHazardsFlag is FALSE
19704 #
19705 # Return values
19706 # An empty hash on improper arguments
19707 # Otherwise, returns a hash of hazardous room flags (may be an empty hash), in the form
19708 # $hazardHash{room_flag} = undef
19709  
19710 my ($self, $avoidHazardsFlag, @otherHazardList) = @_;
19711  
19712 # Local variables
19713 my %hazardHash;
19714  
19715 # (No improper arguments to check)
19716  
19717 if ($avoidHazardsFlag) {
19718  
19719 # Avoid rooms with the usual hazardous room flags ('blocked_room', etc)
19720 %hazardHash = $axmud::CLIENT->constRoomHazardHash;
19721 }
19722  
19723 foreach my $roomFlag (@otherHazardList) {
19724  
19725 # Also avoid rooms that have the specified room flag
19726 $hazardHash{$roomFlag} = undef;
19727 }
19728  
19729 return %hazardHash;
19730 }
19731  
19732 sub compileAdjacentRegions {
19733  
19734 # Called by $self->findPath and ->findUniversalPath when $self->adjacentMode is set to
19735 # 'near' (meaning that the path can use rooms in adjacent regions)
19736 # Compiles a hash of regions that are adjacent to a specified region (the meaning of
19737 # 'adjacent' depends on $self->adjacentCount; 1 means regions can be connected A-B, 2
19738 # means regions can be connected A-B-C, etc. 0 means don't use adjacent regions right now)
19739 # The hash includes the specified region
19740 #
19741 # Expected arguments
19742 # $origNum - The number of a region, representing the parent region of the first room
19743 # in a path yet to be calculated
19744 #
19745 # Return values
19746 # An empty hash on improper arguments
19747 # Otherwise returns a hash containing $origNum and all of its adjacent regions in the form
19748 # $adjacentHash{region_number} = undef
19749  
19750 my ($self, $origNum, $check) = @_;
19751  
19752 # Local variables
19753 my (
19754 @regionList,
19755 %emptyHash, %checkHash, %returnHash,
19756 );
19757  
19758 # Check for improper arguments
19759 if (! defined $origNum || defined $check) {
19760  
19761 $axmud::CLIENT->writeImproper($self->_objClass . '->compileAdjacentRegions', @_);
19762 return %emptyHash;
19763 }
19764  
19765 if ($self->adjacentCount == 0) {
19766  
19767 # Can't use adjacent regions right now, but the hash must still contain the specified
19768 # region
19769 $returnHash{$origNum} = undef;
19770  
19771 return %returnHash;
19772 }
19773  
19774 # Compile a hash of all regions. If the value of $self->adjacentCount is high enough that
19775 # every region is adjacent to $regionNum, then we can stop searching immediately
19776 foreach my $regionNum ($self->ivKeys('regionModelHash')) {
19777  
19778 if ($regionNum != $origNum) {
19779  
19780 $checkHash{$regionNum} = undef;
19781 }
19782 }
19783  
19784 # Now check each region in turn, starting with $regionNum, then its connection regions,
19785 # then all of their connecting regions, and so on
19786 push (@regionList, $origNum);
19787 # (%returnHash must contain at least the specified region)
19788 $returnHash{$origNum} = undef;
19789  
19790 for (my $count = 0; $count < $self->adjacentCount; $count++) {
19791  
19792 my @nextList;
19793  
19794 foreach my $regionNum (@regionList) {
19795  
19796 my $regionmapObj = $self->findRegionmap($regionNum);
19797  
19798 foreach my $otherNum ($regionmapObj->ivValues('regionExitHash') ) {
19799  
19800 if ($otherNum != $origNum && ! exists $returnHash{$otherNum}) {
19801  
19802 # This region is adjacent...
19803 $returnHash{$otherNum} = undef;
19804 # ...so check its region exits on the next iteration of the for... loop
19805 push (@nextList, $otherNum);
19806  
19807 # Have we used up every region?
19808 delete $checkHash{$otherNum};
19809 if (! %checkHash) {
19810  
19811 # Yes, we have, so we can stop searching now
19812 return %returnHash;
19813 }
19814 }
19815 }
19816 }
19817  
19818 # On the next iteration of the for... loop, check all of the adjacent regions found
19819 # during this iteration
19820 @regionList = @nextList;
19821 }
19822  
19823 # Operation complete
19824 return %returnHash;
19825 }
19826  
19827 sub checkRoomHazards {
19828  
19829 # Called by $self->getSurrounding_aStar
19830 # Checks whether any of a room's list of room flags is on a list of hazardous room flags,
19831 # specified by the initial call to ->findPath (not necessarily the same list stored in
19832 # GA::Client->constRoomHazardHash)
19833 #
19834 # Expected arguments
19835 # $roomObj - The GA::ModelObj::Room object to check
19836 #
19837 # Optional arguments
19838 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
19839 # room flag stored as a key in this hash. If an empty hash, all rooms
19840 # are considered
19841 #
19842 # Return values
19843 # 'undef' on improper arguments, if the room has no room flags, or if none of the room's
19844 # list of room flags are on the hazardous flags list
19845 # 1 if any of the room's list of room flags are on the hazardous flags list
19846  
19847 my ($self, $roomObj, $hazardHashRef, $check) = @_;
19848  
19849 # Check for improper arguments
19850 if (! defined $roomObj || ! defined $hazardHashRef || defined $check) {
19851  
19852 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRoomHazards', @_);
19853 }
19854  
19855 # Check each flag in turn
19856 foreach my $flag ($roomObj->ivKeys('roomFlagHash')) {
19857  
19858 if (exists $$hazardHashRef{$flag}) {
19859  
19860 # This room should be avoided by the pathfinding routines
19861 return 1;
19862 }
19863 }
19864  
19865 # The room can be used by the pathfinding routines
19866 return undef;
19867 }
19868  
19869 sub smoothPath {
19870  
19871 # Called by $self->processPathCallback
19872 # After a path has been found (following a call to $self->findPath or
19873 # $self->findUniversalPath), this function can optionally be called to remove jagged edges
19874 # from the paths typically produced by the A* and Dijkstra algorithms
19875 #
19876 # Expected arguments
19877 # $session - The calling function's GA::Session
19878 # $roomListRef - A reference to a list containing a series of GA::ModelObj::Room
19879 # objects along the path between the initial and target rooms
19880 # $exitListRef - A reference to a list containing the GA::Obj::Exit objects used to
19881 # move along the path (contains one less elements than the list
19882 # referenced by $roomListRef)
19883 #
19884 # Optional arguments
19885 # $avoidHazardsFlag
19886 # - If set to TRUE, the path won't use any rooms with a room flag on the
19887 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
19888 # to FALSE (or 'undef'), those rooms can be used
19889 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
19890 # should avoid hazardous rooms by default, or not. It's up to the
19891 # calling function to decide whether to use it, and to set the value
19892 # of this argument accordingly
19893 # @otherHazardList
19894 # - An optional list of room flags that should be considered hazardous,
19895 # for the purposes of this algorithm (not an error if it contains
19896 # duplicate room flags, or if it contains room flags already on the
19897 # hazardous room flags list)
19898 # - NB Room flags in this list are considered hazardous, even if
19899 # $avoidHazardsFlag is FALSE
19900 #
19901 # Return values
19902 # Returns an empty list on improper arguments
19903 # Otherwise, returns a list containing the modified $roomListRef and $exitListRef, in the
19904 # form (room_list_reference, exit_list_reference)
19905  
19906 my ($self, $session, $roomListRef, $exitListRef, $avoidHazardsFlag, @otherHazardList) = @_;
19907  
19908 # Local variables
19909 my (
19910 @emptyList,
19911 %hazardHash, %vectorHash,
19912 );
19913  
19914 # Check for improper arguments
19915 if (! defined $session || ! defined $roomListRef || ! defined $exitListRef) {
19916  
19917 $axmud::CLIENT->writeImproper($self->_objClass . '->smoothPath', @_);
19918 return @emptyList;
19919 }
19920  
19921 # Create a combined hash of hazardous room flags (whose rooms must be avoided by the
19922 # algorithm). If the function returns an empty hash, then all rooms can be used
19923 %hazardHash = $self->compileRoomHazards($avoidHazardsFlag, @otherHazardList);
19924  
19925 # The principle of A*/Dijkstra post-processing is to compare two rooms, numbered n and (n+2)
19926 # If there is a clear line of sight between them (if we can move using one of ten primary
19927 # directions from (n) to (n+2)), and if there is exactly one room between them, in the
19928 # line of site, that is not room (n+1), then we can swap room (n+1) to the room directly
19929 # between rooms (n) and (n+2)
19930 # So, this path: Is smoothed to this one:
19931 # X X n
19932 # X X n+1
19933 # X X n+2 n
19934 # X X n+1
19935 # X X n+2
19936  
19937 # Firstly, $roomListRef must contain at least three rooms
19938 if (@$roomListRef < 3) {
19939  
19940 # Return the list references, unmodified
19941 return ($roomListRef, $exitListRef);
19942 }
19943  
19944 # GA::Win::Map->constVectorHash contains unit vectors in each of the primary directions
19945 # e.g. $hash{'north'} = [0, -1, 0]
19946 # e.g. $hash{'south'} = [0, 1, 0]
19947 # Import the hash
19948 %vectorHash = $session->mapWin->constVectorHash;
19949  
19950 # Smooth each sub-group of rooms (n, n+1 and n+2)
19951 OUTER: for (my $index = 0; $index < ((scalar @$roomListRef) - 2); $index++) {
19952  
19953 my (
19954 $roomN, $roomN1, $roomN2, $exitN, $exitN1, $xGap, $yGap, $zGap, $largestGap,
19955 $vectorRef, $matchListRef, $flag,
19956 );
19957  
19958 $roomN = $$roomListRef[$index]; # n
19959 $roomN1 = $$roomListRef[$index + 1]; # n + 1
19960 $roomN2 = $$roomListRef[$index + 2]; # n + 2
19961 $exitN = $$exitListRef[$index]; # n
19962 $exitN1 = $$exitListRef[$index + 1]; # n + 1
19963  
19964 # All three rooms must be in the same region, and none of the exits between them may be
19965 # 'broken' exits
19966 if (
19967 $roomN->parent != $roomN1->parent
19968 || $roomN->parent != $roomN2->parent
19969 || $exitN->brokenFlag
19970 || $exitN1->brokenFlag
19971 ) {
19972 next OUTER;
19973 }
19974  
19975 # Find the vector between (n) and (n+2), expressed as ($xGap, $yGap, $zGap)
19976 $xGap = $roomN2->xPosBlocks - $roomN->xPosBlocks;
19977 $yGap = $roomN2->yPosBlocks - $roomN->yPosBlocks;
19978 $zGap = $roomN2->zPosBlocks - $roomN->zPosBlocks;
19979  
19980 # Find the largest distance between the rooms along a single axis
19981 $largestGap = abs($xGap);
19982 if (abs($yGap) > $largestGap) {
19983  
19984 $largestGap = abs($yGap);
19985 }
19986 if (abs($zGap) > $largestGap) {
19987  
19988 $largestGap = abs($zGap);
19989 }
19990  
19991 # We need a gap of at least two blocks between (n) and (n+2)
19992 if ($largestGap < 2) {
19993  
19994 next OUTER;
19995 }
19996  
19997 # Use the hash to find a line of sight between (n) and (n+2) in one of the primary
19998 # directions. Don't look further away than $largestGap
19999 CENTRE: for (my $count = 2; $count <= $largestGap; $count++) {
20000  
20001 foreach my $primaryDir (keys %vectorHash) {
20002  
20003 # Get a reference to a list in the form [0, -1, 0]
20004 my $matchListRef = $vectorHash{$primaryDir};
20005  
20006 # Does this vector, added to the position of (n), give us the position of (n+2)?
20007 if (
20008 ($roomN->xPosBlocks + ($$matchListRef[0] * $count))
20009 == $roomN2->xPosBlocks
20010 && ($roomN->yPosBlocks + ($$matchListRef[1] * $count))
20011 == $roomN2->yPosBlocks
20012 && ($roomN->zPosBlocks + ($$matchListRef[2] * $count))
20013 == $roomN2->zPosBlocks
20014 ) {
20015 $vectorRef = $matchListRef;
20016 last CENTRE;
20017 }
20018 }
20019 }
20020  
20021 if (! $vectorRef) {
20022  
20023 # No line of sight between (n) and (n+2) found
20024 next OUTER;
20025 }
20026  
20027 # There is a line of sight between (n) and (n+2) in one of the primary directions, which
20028 # we expressed as a vector $matchListRef in the form [0, -1, 0] (for north) or
20029 # [0, 1, 0] (for south), etc
20030 # Now, does room (n+1) also lie in this line of sight?
20031 CENTRE: for (my $count = 1; $count < $largestGap; $count++) {
20032  
20033 if (
20034 ($roomN->xPosBlocks + ($$vectorRef[0] * $count))
20035 == $roomN1->xPosBlocks
20036 && ($roomN->yPosBlocks + ($$vectorRef[1] * $count))
20037 == $roomN1->yPosBlocks
20038 && ($roomN->zPosBlocks + ($$vectorRef[2] * $count))
20039 == $roomN1->zPosBlocks
20040 ) {
20041 $flag = TRUE;
20042 last CENTRE;
20043 }
20044 }
20045  
20046 if ($flag) {
20047  
20048 # All three rooms are in the same line of site, so we don't need to smooth the path
20049 # here
20050 next OUTER;
20051 }
20052  
20053 # The path is in the form
20054 # X (n)
20055 # oX (n+1)
20056 # X (n+2)
20057 # Now we look for a room anywhere along the line of sight between (n) and (n+2), looking
20058 # for a new room, m, which can be reached via a single exit from room (n), and which
20059 # can reach room (n+2) via a single exit - a room like the one marked on the diagram
20060 # above as 'o'
20061 CENTRE: for (my $count = 1; $count < $largestGap; $count++) {
20062  
20063 my ($newRoomNum, $newRoomObj, $firstExitObj, $secondExitObj);
20064  
20065 # See if there's a room at the location marked as 'o', somewhere in the line of site
20066 # between (n) and (n+2)
20067 $newRoomNum = $session->mapWin->currentRegionmap->fetchRoom(
20068 $roomN->xPosBlocks + ($$vectorRef[0] * $count),
20069 $roomN->yPosBlocks + ($$vectorRef[1] * $count),
20070 $roomN->zPosBlocks + ($$vectorRef[2] * $count),
20071 );
20072  
20073 if ($newRoomNum) {
20074  
20075 $newRoomObj = $self->ivShow('modelHash', $newRoomNum);
20076  
20077 # Can this new room be reached from room (n)?
20078 INNER: foreach my $thisExitName ($roomN->sortedExitList) {
20079  
20080 my ($thisExitNum, $thisExitObj);
20081  
20082 # (Investigate directions in order, so that primary directions are checked
20083 # first)
20084 $thisExitNum = $roomN->ivShow('exitNumHash', $thisExitName);
20085 $thisExitObj = $self->ivShow('exitModelHash', $thisExitNum);
20086  
20087 if (
20088 $thisExitObj->destRoom
20089 && $thisExitObj->destRoom == $newRoomObj->number
20090 ) {
20091 # Success! $newRoom can be reached from room (n)
20092 $firstExitObj = $thisExitObj;
20093 last INNER;
20094 }
20095 }
20096  
20097 if (! $firstExitObj) {
20098  
20099 # Can't travel from (n) to the new room - look for a different room
20100 next CENTRE;
20101 }
20102  
20103 # Can this new room reach room (n+2) in a single step?
20104 INNER: foreach my $thisExitName ($newRoomObj->sortedExitList) {
20105  
20106 my ($thisExitNum, $thisExitObj);
20107  
20108 $thisExitNum = $newRoomObj->ivShow('exitNumHash', $thisExitName);
20109 $thisExitObj = $self->ivShow('exitModelHash', $thisExitNum);
20110  
20111 if (
20112 $thisExitObj->destRoom
20113 && $thisExitObj->destRoom == $roomN2->number
20114 ) {
20115 # Double success! $newRoom can reach room (n+2)
20116 $secondExitObj = $thisExitObj;
20117 last INNER;
20118 }
20119 }
20120  
20121 if ($secondExitObj) {
20122  
20123 # Rooms (n), $newRoomObj and (n+2) all lie on the same line of sight, but
20124 # the rooms (n), (n+1) and (n+2) do not
20125  
20126 # Check that $newRoomObj and the exits between $newRoomObj and the
20127 # surrounding rooms are available for paths (using the same rationale
20128 # as $self->getSurrounding_aStar)
20129 if (
20130 ! $newRoomObj->exclusiveFlag
20131 && ! $self->checkRoomHazards($newRoomObj, \%hazardHash)
20132 ) {
20133 # $newRoomObj is acceptable, so use it to replace room (n+1)
20134 $$roomListRef[$index + 1] = $newRoomObj;
20135 # Replace the exits leading from (n) and leading to (n+2)
20136 $$exitListRef[$index] = $firstExitObj;
20137 $$exitListRef[$index + 1] = $secondExitObj;
20138  
20139 next OUTER;
20140 }
20141 }
20142 }
20143 }
20144 }
20145  
20146 # Operation complete
20147 return ($roomListRef, $exitListRef);
20148 }
20149  
20150 sub doAStar {
20151  
20152 # Called by $self->findPath
20153 # Performs the A* algorithm on rooms in the current region, to find the shortest route
20154 # between two rooms (as described in the comments for the calling function)
20155 #
20156 # Expected arguments
20157 # $targetNode - The target node (a GA::ModelObj::Room)
20158 # $openListObj - The A* open list, stored in a binomial heap object
20159 # $nodeHashRef - Reference to the hash of nodes, in the form $hash{room} = node
20160 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
20161 # room flag stored as a key in this hash. If an empty hash, all rooms
20162 # are considered
20163 # $adjacentHashRef
20164 # - Reference to a hash of adjacent regions. An empty hash if adjacent
20165 # regions are not to be used
20166 #
20167 # Return values
20168 # 'undef' on improper arguments
20169 # 1 otherwise
20170  
20171 my (
20172 $self, $targetNode, $openListObj, $nodeHashRef, $hazardHashRef, $adjacentHashRef,
20173 $check,
20174 ) = @_;
20175  
20176 # Local variables
20177 my ($currentNode, $gScore, $nodeListRef);
20178  
20179 # Check for improper arguments
20180 if (
20181 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20182 || ! defined $hazardHashRef || ! defined $adjacentHashRef || defined $check
20183 ) {
20184 return $axmud::CLIENT->writeImproper($self->_objClass . '->doAStar', @_);
20185 }
20186  
20187 # Perform the algorithm until we either find the shortest path to the target room or run out
20188 # of rooms
20189 OUTER: while(
20190 defined $openListObj->top()
20191 && ($openListObj->top()->roomObj ne $targetNode)
20192 ) {
20193 # Remove the first remaining node in the open list
20194 $currentNode = $openListObj->extract_top();
20195 $currentNode->ivPoke('inOpenFlag', FALSE);
20196  
20197 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
20198 # number of list references, each representing a surrounding node (one linked to
20199 # $currentNode by a single exit)
20200 # The contained list references are in the form
20201 # [GA::ModelObj::Room, cost, H-Score]
20202 $nodeListRef = $self->getSurrounding_aStar(
20203 $currentNode->roomObj,
20204 $targetNode,
20205 $hazardHashRef,
20206 $adjacentHashRef,
20207 );
20208  
20209 # Process each surrounding node
20210 INNER: foreach my $nodeRef (@$nodeListRef) {
20211  
20212 my (
20213 $surroundRoomObj, $surroundExitObj, $surroundCost, $surroundHScore,
20214 $surroundNode, $currentGScore, $possibleGScore,
20215 );
20216  
20217 ($surroundRoomObj, $surroundExitObj, $surroundCost, $surroundHScore) = @$nodeRef;
20218  
20219 # Skip this node if it's in the closed list
20220 if (
20221 exists $$nodeHashRef{$surroundRoomObj}
20222 && ! $$nodeHashRef{$surroundRoomObj}->inOpenFlag
20223 ) {
20224 next INNER;
20225 }
20226  
20227 # If the node isn't in the open list, add it to the open list
20228 if (! exists $$nodeHashRef{$surroundRoomObj}) {
20229  
20230 $surroundNode = Games::Axmud::Node::AStar->new(
20231 $surroundRoomObj, # GA::ModelObj::Room
20232 $currentNode->gScore + $surroundCost, # G score
20233 $surroundHScore, # H score
20234 );
20235  
20236 $surroundNode->ivPoke('parent', $currentNode);
20237 $surroundNode->ivPoke('arriveExitObj', $surroundExitObj);
20238 $surroundNode->ivPoke('cost', $surroundCost);
20239 $surroundNode->ivPoke('inOpenFlag', TRUE);
20240 $$nodeHashRef{$surroundRoomObj} = $surroundNode;
20241 $openListObj->add($surroundNode);
20242  
20243 } else {
20244  
20245 # Otherwise the node is already in the open list. Check to see if it's cheaper
20246 # to go through the current room, compared to the previous path
20247 $surroundNode = $$nodeHashRef{$surroundRoomObj};
20248 $currentGScore = $surroundNode->gScore;
20249 $possibleGScore = $currentNode->gScore + $surroundCost;
20250  
20251 if ($possibleGScore < $currentGScore) {
20252  
20253 # Change the parent...
20254 $surroundNode->ivPoke('parent', $currentNode);
20255 # ...and the exit used to get there
20256 $surroundNode->ivPoke('arriveExitObj', $surroundExitObj);
20257 $surroundNode->ivPoke('gScore', $possibleGScore);
20258 $openListObj->decrease_key($surroundNode);
20259 }
20260 }
20261 }
20262 }
20263  
20264 # A* algorithm complete
20265 return 1;
20266 }
20267  
20268 sub fillPath_aStar {
20269  
20270 # Called by $self->findPath, after a call to $self->doAStar
20271 # The initial room and the target room are now linked, along the shortest path between them,
20272 # by a list of rooms, each the parent of the next room along the path
20273 # Compile two lists: a list of the rooms, from the initial room to the target room
20274 # (inclusive), and a corresponding list of exits used to travel between them
20275 #
20276 # Expected arguments
20277 # $targetNode - The target node (a GA::ModelObj::Room)
20278 # $openListObj - The A* open list, stored in a binomial heap object
20279 # $nodeHashRef - The hash of nodes, in the form $hash{room} = node
20280 #
20281 # Return values
20282 # Returns an empty list on improper arguments
20283 # Otherwise returns a list containing two list references. The first reference contains a
20284 # list of GA::ModelObj::Room objects on the shortest path between the initial and
20285 # target rooms (inclusive). The second reference contains a list of GA::Obj::Exit
20286 # objects to move between them. The first list contains exactly one more item than the
20287 # second (exception: if no path can be found, both lists are empty)
20288  
20289 my ($self, $targetNode, $openListObj, $nodeHashRef, $check) = @_;
20290  
20291 # Local variables
20292 my (
20293 $currentNode,
20294 @emptyList, @roomList, @exitList,
20295 );
20296  
20297 # Check for improper arguments
20298 if (
20299 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20300 || defined $check
20301 ) {
20302 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_aStar', @_);
20303 return @emptyList;
20304 }
20305  
20306 if (exists $$nodeHashRef{$targetNode}) {
20307 $currentNode = $$nodeHashRef{$targetNode};
20308 } else {
20309 $currentNode = $openListObj->top();
20310 }
20311  
20312 while (defined $currentNode) {
20313  
20314 unshift(@roomList, $currentNode->roomObj);
20315  
20316 if (defined $currentNode->arriveExitObj) {
20317  
20318 unshift(@exitList, $currentNode->arriveExitObj);
20319 }
20320  
20321 $currentNode = $currentNode->parent;
20322 }
20323  
20324 return (\@roomList, \@exitList);
20325 }
20326  
20327 sub getSurrounding_aStar {
20328  
20329 # Called by $self->doAStar
20330 # Get a list of nodes surrounding the current one
20331 # In this function, the current node is a room. We get a list of all the room's exits, and
20332 # then compile a list of those exits' destination rooms
20333 #
20334 # Expected arguments
20335 # $currentNode - The current node (a GA::ModelObj::Room)
20336 # $targetNode - The target node (a GA::ModelObj::Room)
20337 # $hazardHashRef - Reference to a hash of room flags. The path won't use any rooms with a
20338 # room flag stored as a key in this hash. If an empty hash, all rooms
20339 # are considered
20340 # $adjacentHashRef
20341 # - Reference to a hash of adjacent regions. An empty hash if adjacent
20342 # regions are not to be used
20343 #
20344 # Return values
20345 # 'undef' on improper arguments
20346 # Otherwise returns a list reference, containing a series of list references, one for each
20347 # surrounding node. The inner list references are in the form:
20348 # [
20349 # surround_node_room_object,
20350 # surrounding_node_cost,
20351 # surrounding_node_g_score,
20352 # ]
20353  
20354 my ($self, $currentNode, $targetNode, $hazardHashRef, $adjacentHashRef, $check) = @_;
20355  
20356 # Local variables
20357 my (
20358 @returnList,
20359 %roomHash,
20360 );
20361  
20362 # Check for improper arguments
20363 if (
20364 ! defined $currentNode || ! defined $targetNode || ! defined $hazardHashRef
20365 || ! defined $adjacentHashRef || defined $check
20366 ) {
20367 return $axmud::CLIENT->writeImproper($self->_objClass . '->getSurrounding_aStar', @_);
20368 }
20369  
20370 # Get a list of exits from the room $currentNode
20371 if ($currentNode->exitNumHash) {
20372  
20373 # Get a list of destination rooms. Some rooms have multiple exits leading to the same
20374 # destination room, so we use a hash to store the destination rooms
20375 # The hash is in the form
20376 # $hash{destination_room_number} = exit_object_to_get_there
20377 OUTER: foreach my $exitNum ($currentNode->ivValues('exitNumHash')) {
20378  
20379 my ($exitObj, $destRoomObj);
20380  
20381 $exitObj = $self->ivShow('exitModelHash', $exitNum);
20382 if ($exitObj->destRoom) {
20383  
20384 $destRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
20385  
20386 # Depending on the $self->adjacentMode and $adjacentHashRef, we can either use
20387 # region exits, or not
20388 if (
20389 $exitObj->regionFlag
20390 && (
20391 $self->adjacentMode ne 'near'
20392 || ! exists $$adjacentHashRef{$destRoomObj->parent}
20393 )
20394 ) {
20395 # Can't use this region exit or its destination room
20396 next OUTER;
20397 }
20398  
20399 # We don't use a destination room if it has any of the room flags in
20400 # $hazardHashRef
20401 # We also don't use exits that have shadow exits (it's normally better to use
20402 # the 'north' shadow exit, rather than the 'open curtains' exit) and exits
20403 # which lead to rooms that can only be visited by certain guilds, races and
20404 # characters (etc); the latter restrictions saves us a whole lot of bother
20405 if (
20406 ! $destRoomObj->exclusiveFlag
20407 && ! $exitObj->shadowExit
20408 && ! $self->checkRoomHazards($destRoomObj, $hazardHashRef)
20409 ) {
20410 $roomHash{$exitObj->destRoom} = $exitObj;
20411 }
20412 }
20413 }
20414 }
20415  
20416 # For each destination room, prepare a list reference containing details about that node
20417 foreach my $destNum (keys %roomHash) {
20418  
20419 my $destRoomObj = $self->ivShow('modelHash', $destNum);
20420  
20421 push (@returnList,
20422 [
20423 $destRoomObj, # GA::ModelObj::Room
20424 $roomHash{$destNum}, # GA::Obj::Exit
20425 1, # Cost
20426 $self->calcHScore($destRoomObj, $targetNode), # H score
20427 ]
20428 );
20429 }
20430  
20431 # Return a list reference, containing some list references
20432 return \@returnList;
20433 }
20434  
20435 sub calcHScore {
20436  
20437 # Called by $self->getSurrounding_aStar
20438 # Calculates the H score for a room node, using the Manhattan heuristic
20439 #
20440 # Expected arguments
20441 # $roomObj - The GA::ModelObj::Room for this node
20442 # $targetNode - The target node (also a GA::ModelObj::Room)
20443 #
20444 # Return values
20445 # The H score (an integer)
20446  
20447 my ($self, $roomObj, $targetNode, $check) = @_;
20448  
20449 # Local variables
20450 my ($xLength, $yLength, $zLength);
20451  
20452 # Check for improper arguments
20453 if (! defined $roomObj || ! defined $targetNode || defined $check) {
20454  
20455 return $axmud::CLIENT->writeImproper($self->_objClass . '->calcHScore', @_);
20456 }
20457  
20458 # Get absolute distances on the x, y and z axes
20459 $xLength = abs($roomObj->xPosBlocks - $targetNode->xPosBlocks);
20460 $yLength = abs($roomObj->yPosBlocks - $targetNode->yPosBlocks);
20461 $zLength = abs($roomObj->zPosBlocks - $targetNode->zPosBlocks);
20462  
20463 return ($xLength + $yLength + $zLength);
20464 }
20465  
20466 # Dijkstra algorithm (used to find a path between two rooms in different regions)
20467  
20468 sub findUniversalPath {
20469  
20470 # Can be called by any function
20471 #
20472 # Dijkstra algorithm to find a path between two rooms in different regions, based on
20473 # AI::Pathfinding::AStar by Aaron Dalton
20474 #
20475 # Expected arguments
20476 # $session - The calling function's GA::Session
20477 # $initialRoomObj - The initial room (a GA::ModelObj::Room)
20478 # $targetRoomObj - The target room (a GA::ModelObj::Room), usually in a different region
20479 # (but it doesn't matter if they are in the same region)
20480 #
20481 # Optional arguments
20482 # $avoidHazardsFlag
20483 # - If set to TRUE, the path won't use any rooms with a room flag on the
20484 # hazardous room flags list (GA::Client->constRoomHazardHash). If set
20485 # to FALSE (or 'undef'), those rooms can be used
20486 # - NB $self->avoidHazardsFlag specifies whether pathfinding functions
20487 # should avoid hazardous rooms by default, or not. It's up to the
20488 # calling function to decide whether to use it, and to set the value
20489 # of this argument accordingly
20490 # $otherHazardListRef
20491 # - An optional list of room flags that should be considered hazardous,
20492 # for the purposes of this algorithm (not an error if it contains
20493 # duplicate room flags, or if it contains room flags already on the
20494 # hazardous room flags list)
20495 # - NB This list is IGNORED if the initial and target rooms are not in
20496 # the same region
20497 # - NB Room flags in this list are considered hazardous, even if
20498 # $avoidHazardsFlag is FALSE
20499 # $avoidAdjacentFlag
20500 # - If set to TRUE and if the initial and target rooms are in the same
20501 # region, the algorithm won't use rooms in adjacent regions,
20502 # regardless of the value of $self->adjacentMode. If set to FALSE (or
20503 # 'undef') and the initial/target rooms are in the same region, the
20504 # value of $self->adjacentMode applies
20505 #
20506 # Return values
20507 # An empty list on improper arguments or if no path can be found between the initial and
20508 # target rooms
20509 # Otherwise, returns two list references. The first reference contains a list of
20510 # GA::ModelObj::Room objects on the shortest path between the rooms $initialRoomObj
20511 # and $targetRoomObj (inclusive). The second reference contains a list of
20512 # GA::Obj::Exit objects used to move along the path. The first list contains exactly
20513 # one more item than the second
20514  
20515 my (
20516 $self, $session, $initialRoomObj, $targetRoomObj, $avoidHazardsFlag,
20517 $otherHazardListRef, $avoidAdjacentFlag, $check,
20518 ) = @_;
20519  
20520 # Local variables
20521 my (
20522 $roomListRef, $exitListRef, $dummyRoomObj, $dummyExitObj, $initialRegionmapObj, $index,
20523 $dummyRoomObj2, $dummyExitObj2, $targetRegionmapObj, $openListObj, $nodeHashRef,
20524 $currentNode, $pathRoomListRef, $pathExitListRef,
20525 @emptyList, @initialExitNumList, @initialRoomList, @targetExitNumList, @targetRoomList,
20526 @returnRoomList, @returnExitList,
20527 %adjacentHash, %universalPathHash,
20528 );
20529  
20530 # Check for improper arguments
20531 if (
20532 ! defined $session || ! defined $initialRoomObj || ! defined $targetRoomObj
20533 || defined $check
20534 ) {
20535 $axmud::CLIENT->writeImproper($self->_objClass . '->findUniversalPath', @_);
20536 return @emptyList;
20537 }
20538  
20539 # Depending on the situation, we might be able to use $self->findPath instead
20540 if (
20541 $initialRoomObj->parent == $targetRoomObj->parent
20542 || $self->adjacentMode eq 'all'
20543 ) {
20544 ($roomListRef, $exitListRef) = $self->findPath(
20545 $initialRoomObj,
20546 $targetRoomObj,
20547 $avoidHazardsFlag,
20548 $otherHazardListRef,
20549 $avoidAdjacentFlag,
20550 );
20551  
20552 if (defined $roomListRef && @$roomListRef) {
20553  
20554 return ($roomListRef, $exitListRef);
20555 }
20556  
20557 } elsif ($self->adjacentMode eq 'near') {
20558  
20559 # Get a hash of regions that are adjacent to the start room's region (inclusive)
20560 if (! $avoidAdjacentFlag) {
20561  
20562 %adjacentHash = $self->compileAdjacentRegions($initialRoomObj->parent);
20563 }
20564  
20565 ($roomListRef, $exitListRef) = $self->findPath(
20566 $initialRoomObj,
20567 $targetRoomObj,
20568 $avoidHazardsFlag,
20569 $otherHazardListRef,
20570 $avoidAdjacentFlag,
20571 \%adjacentHash,
20572 );
20573  
20574 if (defined $roomListRef && @$roomListRef) {
20575  
20576 return ($roomListRef, $exitListRef);
20577 }
20578 }
20579  
20580 # If a call to $self->findPath failed to find a path between the two rooms, or if
20581 # $self->findPath wasn't called at all, we can continue with this function's algorithm
20582  
20583 # If any exits in the exit model have been modified, we may need to check and re-calculate
20584 # regions paths, before calculating a path between the two rooms
20585 if ($self->updatePathHash || $self->updateBoundaryHash) {
20586  
20587 $self->updateRegionPaths();
20588 }
20589  
20590 # The first step is to compile a hash of region paths that traverse every region in the
20591 # world model, leading from one region exit to another region exit in the same region
20592 # At either end of each path is the node we'll use in our Dijkstra algorithm. The nodes are
20593 # exits, each equivalent to a GA::Obj::Exit (which may or may not have a twin exit)
20594 #
20595 # Each regionmap stores, in its ->regionPathHash, a list of such paths. Each path is
20596 # represented by a GA::Obj::RegionPath
20597 # There is a parallel ->safeRegionPathHash which contains paths that avoid rooms with
20598 # hazardous room flags
20599 # If $avoidHazardsFlag is set, we use region paths from ->safeRegionPathHash; otherwise, we
20600 # use region paths from ->regionPathHash
20601 #
20602 # This function's hash of paths is in the form:
20603 # $universalPathHash{begin_exit_number} = hash_reference
20604 # ...where 'begin_exit_number' is the number of the GA::Obj::Exit at the start of the path
20605 # Each 'hash_reference' is in the form:
20606 # $hash_reference{end_exit_number} = GA::Obj::RegionPath
20607  
20608 # Process each regionmap in turn
20609 foreach my $regionmapObj ($self->ivValues('regionmapHash')) {
20610  
20611 my %regionPathHash;
20612  
20613 # Get the hash of GA::Obj::RegionPath objects from this regionmap
20614 if ($avoidHazardsFlag) {
20615 %regionPathHash = $regionmapObj->safeRegionPathHash;
20616 } else {
20617 %regionPathHash = $regionmapObj->regionPathHash;
20618 }
20619  
20620 foreach my $regionPathObj (values %regionPathHash) {
20621  
20622 # Add the path to our universal hash
20623 $self->addUniversalPath(\%universalPathHash, $regionPathObj);
20624 }
20625 }
20626  
20627 # Now, we need to create some new (temporary) paths, and to add them to %universalPathHash
20628  
20629 # The first set of paths connect $initialRoomObj to every region exit in the same region
20630 # The Dijkstra algorithm we'll employ uses exits as its nodes. The initial room can have
20631 # several exits, any of which might be on the shortest path to the target room. So, we'll
20632 # create a dummy room object - with a world model number set to -1 - with a dummy one-way
20633 # exit which leads to the initial room
20634 # When the algorithm is finished, we'll discard the room (and its exit)
20635 ($dummyRoomObj, $dummyExitObj) = $self->createDummyRoom($session, $initialRoomObj, -1);
20636  
20637 # Get the initial room's regionmap
20638 $initialRegionmapObj = $self->findRegionmap($initialRoomObj->parent);
20639 # Get a list of region exits in this regionmap
20640 @initialExitNumList = $initialRegionmapObj->ivKeys('regionExitHash');
20641 # From this list, get a list of rooms from which the region exits depart
20642 foreach my $exitNum (@initialExitNumList) {
20643  
20644 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
20645 push (@initialRoomList, $self->ivShow('modelHash', $exitObj->parent));
20646 }
20647  
20648 # Find the shortest path between the initial room (not the dummy room), and each of the
20649 # boundary rooms. Use the rooms themselves as nodes
20650 $index = -1;
20651 foreach my $boundaryRoomObj (@initialRoomList) {
20652  
20653 my ($miniRoomListRef, $miniExitListRef, $pathObj, $thisExitObj);
20654  
20655 $index++; # Matching indexes in @initialExitList and @initialRoomList
20656  
20657 ($miniRoomListRef, $miniExitListRef) = $self->findPath(
20658 $initialRoomObj,
20659 $boundaryRoomObj,
20660 $avoidHazardsFlag, # Avoid hazards, or not
20661 undef,
20662 TRUE, # Don't use adjacent regions
20663 );
20664  
20665 # If a path was found...
20666 if (defined $miniRoomListRef && @$miniRoomListRef) {
20667  
20668 # Add the dummy room (and its dummy exit) to the beginning of the path
20669 unshift(@$miniRoomListRef, $dummyRoomObj);
20670 unshift(@$miniExitListRef, $dummyExitObj);
20671  
20672 # Create a GA::Obj::RegionPath to stored this path. However, don't add it to the
20673 # regionmap's hash of region paths, in the normal way; add it only to our
20674 # %universalPathHash
20675 $thisExitObj = $self->ivShow('exitModelHash', $initialExitNumList[$index]);
20676  
20677 $pathObj = Games::Axmud::Obj::RegionPath->new(
20678 $session,
20679 $dummyExitObj->number,
20680 $thisExitObj->number,
20681 $miniRoomListRef,
20682 $miniExitListRef,
20683 );
20684  
20685 if ($pathObj) {
20686  
20687 $self->addUniversalPath(\%universalPathHash, $pathObj);
20688 }
20689 }
20690 }
20691  
20692 # Do the same for the target region. Find the shortest paths which connect the target room
20693 # with every region exit in the same region
20694  
20695 # Once again we need a temporary room, and a temporary exit from the target room which leads
20696 # to the temporary room. Both are removed at the end
20697 ($dummyRoomObj2, $dummyExitObj2) = $self->createDummyRoom($session, $targetRoomObj, -2);
20698  
20699 # Get the target room's regionmap
20700 $targetRegionmapObj = $self->findRegionmap($targetRoomObj->parent);
20701 # Get a list of region exits in this regionmap
20702 @targetExitNumList = $targetRegionmapObj->ivKeys('regionExitHash');
20703 # From this list, get a list of rooms from which the region exits depart
20704 foreach my $exitNum (@targetExitNumList) {
20705  
20706 my $exitObj = $self->ivShow('exitModelHash', $exitNum);
20707 push (@targetRoomList, $self->ivShow('modelHash', $exitObj->parent));
20708 }
20709  
20710 # Find the shortest path between the target room (not the dummy room), and each of the
20711 # boundary rooms. Use the rooms themselves as nodes
20712 $index = -1;
20713 foreach my $boundaryRoomObj (@targetRoomList) {
20714  
20715 my ($miniRoomListRef, $miniExitListRef, $pathObj, $thisExitObj);
20716  
20717 $index++; # Matching indexes in @targetExitList and @targetRoomList
20718  
20719 ($miniRoomListRef, $miniExitListRef) = $self->findPath(
20720 $boundaryRoomObj,
20721 $targetRoomObj,
20722 $avoidHazardsFlag, # Avoid hazards, or not
20723 undef,
20724 TRUE, # Don't use adjacent regions
20725 );
20726  
20727 # If a path was found...
20728 if (defined $miniRoomListRef && @$miniRoomListRef) {
20729  
20730 # Add the dummy room (and its dummy exit) to the end of the path
20731 push(@$miniRoomListRef, $dummyRoomObj2);
20732 push(@$miniExitListRef, $dummyExitObj2);
20733  
20734 # Create a GA::Obj::RegionPath to stored this path. However, don't add it to the
20735 # regionmap's hash of region paths, in the normal way; add it only to our
20736 # %universalPathHash
20737 $thisExitObj = $self->ivShow('exitModelHash', $targetExitNumList[$index]);
20738  
20739 $pathObj = Games::Axmud::Obj::RegionPath->new(
20740 $session,
20741 $thisExitObj->number,
20742 $dummyExitObj2->number,
20743 $miniRoomListRef,
20744 $miniExitListRef,
20745 );
20746  
20747 if ($pathObj) {
20748  
20749 $self->addUniversalPath(\%universalPathHash, $pathObj);
20750 }
20751 }
20752 }
20753  
20754 # %universalPathHash now contains a collection of paths that traverse the whole world model,
20755 # linking together all connected regions
20756 # Now we run the Dijkstra algorithm (a modified A* algorithm in which the h-score is
20757 # always 0) to get the shortest path between the initial and target rooms
20758  
20759 # Create the open list, using a binomial heap
20760 $openListObj = Games::Axmud::Obj::Heap->new();
20761 # Create a reference to a hash of nodes, in the form
20762 # $nodeHashRef{exit_object} = node
20763 # ...where 'exit_object' is a GA::Obj::Exit, and node is a GA::Node::Dijkstra object
20764 $nodeHashRef = {};
20765  
20766 # Create a node for the initial exit
20767 $currentNode = Games::Axmud::Node::Dijkstra->new(
20768 0, # Initial G score
20769 $dummyExitObj, # Dummy exit object leading to the initial room
20770 );
20771  
20772 # Add this node to the open list
20773 $currentNode->ivPoke('inOpenFlag', TRUE);
20774 $openListObj->add($currentNode);
20775  
20776 # Perform the Dijkstra algorithm, starting at the exit $dummyExitObj, and aiming for the
20777 # exit $dummyExitObj2
20778 $self->doDijkstra($dummyExitObj2, $openListObj, $nodeHashRef, \%universalPathHash);
20779  
20780 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
20781 # path from the target room, and using the parent of each node in turn (in the standard
20782 # way)
20783 # Get two list references, one containing the rooms in the shortest path between
20784 # $dummyRoomObj and $dummyRoomObj2, and the other containing the exits to move along the
20785 # path
20786 ($pathRoomListRef, $pathExitListRef) = $self->fillPath_dijkstra(
20787 $dummyExitObj2,
20788 $openListObj,
20789 $nodeHashRef,
20790 \%universalPathHash
20791 );
20792  
20793 # The list references $pathRoomListRef and $pathExitListRef contain a list of room and
20794 # exit numbers; convert them to lists of the rooms and exits themselves
20795 foreach my $number (@$pathRoomListRef) {
20796  
20797 push (@returnRoomList, $self->ivShow('modelHash', $number));
20798 }
20799  
20800 foreach my $number (@$pathExitListRef) {
20801  
20802 push (@returnExitList, $self->ivShow('exitModelHash', $number));
20803 }
20804  
20805 # @returnRoomList contains the rooms along the path, plus the two dummy rooms at each end.
20806 # Remove the dummy rooms
20807 if (@returnRoomList) {
20808  
20809 if ($returnRoomList[0] eq $dummyRoomObj) {
20810  
20811 shift @returnRoomList;
20812 }
20813  
20814 if ($returnRoomList[-1] eq $dummyRoomObj2) {
20815  
20816 pop @returnRoomList;
20817 }
20818 }
20819  
20820 # Likewise, @returnExitList contains the exits to move along the path, plus the two dummy
20821 # exits at each end. Remove the dummy exits, too
20822 if (@returnExitList) {
20823  
20824 if ($returnExitList[0] eq $dummyExitObj) {
20825  
20826 shift @returnExitList;
20827 }
20828  
20829 if ($returnExitList[-1] eq $dummyExitObj2) {
20830  
20831 pop @returnExitList;
20832 }
20833 }
20834  
20835 # Delete the dummy rooms/objects
20836 $self->destroyDummyRoom(-1);
20837 $self->destroyDummyRoom(-2);
20838  
20839 return (\@returnRoomList, \@returnExitList);
20840 }
20841  
20842 sub doDijkstra {
20843  
20844 # Called by $self->findUniversalPath
20845 # Performs the Dijkstra algorithm on two nodes, each corresponding to an exit in two
20846 # different regions, in order to find the shortest path between them, and therefore the
20847 # shortest path between two rooms (as described in the comments for the calling function)
20848 #
20849 # Expected arguments
20850 # $targetNode - The target node (a dummy GA::Obj::Exit that the calling function
20851 # created, which leads away from the target room to a dummy
20852 # GA::ModelObj::Room)
20853 # $openListObj - The Dijkstra open list, stored in a binomial heap object
20854 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
20855 # $universalPathHashRef
20856 # - A hash of paths between the exits, each of which correspond to a node.
20857 # The hash tells us the cost of moving between two nodes
20858 #
20859 # Return values
20860 # 'undef' on improper arguments
20861 # 1 otherwise
20862  
20863 my ($self, $targetNode, $openListObj, $nodeHashRef, $universalPathHashRef, $check) = @_;
20864  
20865 # Local variables
20866 my (
20867 $currentNode, $gScore, $nodeListRef,
20868 %twinNodeHash,
20869 );
20870  
20871 # Check for improper arguments
20872 if (
20873 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
20874 || ! defined $universalPathHashRef || defined $check
20875 ) {
20876 return $axmud::CLIENT->writeImproper($self->_objClass . '->doDijkstra', @_);
20877 }
20878  
20879 # Perform the algorithm until we either find the shortest path to the target node or run out
20880 # of nodes
20881 OUTER: while(
20882 defined $openListObj->top()
20883 && ($openListObj->top()->exitObj ne $targetNode)
20884 ) {
20885 # Remove the first remaining node in the open list
20886 $currentNode = $openListObj->extract_top();
20887 $currentNode->ivPoke('inOpenFlag', FALSE);
20888  
20889 # If this exit has a twin exit, we must prevent the twin from being added as a node to
20890 # the open list, later in the algorithm
20891 if ($currentNode->exitObj->twinExit) {
20892  
20893 $twinNodeHash{$currentNode->exitObj->twinExit} = undef;
20894 }
20895  
20896 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
20897 # number of list references, each representing a surrounding node (one linked to
20898 # $currentNode by a single GA::Obj::RegionPath)
20899 # The contained list references are in the form
20900 # [GA::Obj::Exit, cost]
20901 $nodeListRef = $self->getSurrounding_dijkstra(
20902 $currentNode->exitObj,
20903 $universalPathHashRef,
20904 );
20905  
20906 # Process each surrounding node
20907 INNER: foreach my $nodeRef (@$nodeListRef) {
20908  
20909 my (
20910 $surroundExitObj, $surroundCost, $surroundNode, $currentGScore, $possibleGScore,
20911 );
20912  
20913 ($surroundExitObj, $surroundCost) = @$nodeRef;
20914  
20915 # Skip this node if it's in the closed list
20916 if (
20917 exists $$nodeHashRef{$surroundExitObj}
20918 && ! $$nodeHashRef{$surroundExitObj}->inOpenFlag
20919 ) {
20920 next INNER;
20921  
20922 # Also skip this node if it's in the forbidden (twin) node list
20923 } elsif (exists $twinNodeHash{$surroundExitObj->number}) {
20924  
20925 next INNER;
20926 }
20927  
20928 # If the node isn't in the open list, add it to the open list
20929 if (! exists $$nodeHashRef{$surroundExitObj}) {
20930  
20931 $surroundNode = Games::Axmud::Node::Dijkstra->new(
20932 $currentNode->gScore + $surroundCost, # G score
20933 $surroundExitObj, # GA::Obj::Exit
20934 );
20935  
20936 $surroundNode->ivPoke('parent', $currentNode);
20937 $surroundNode->ivPoke('cost', $surroundCost);
20938 $surroundNode->ivPoke('inOpenFlag', TRUE);
20939 $$nodeHashRef{$surroundExitObj} = $surroundNode;
20940 $openListObj->add($surroundNode);
20941  
20942 } else {
20943  
20944 # Otherwise the node is already in the open list. Check to see if it's cheaper
20945 # to go through the current exit, compared to the previous path
20946 $surroundNode = $$nodeHashRef{$surroundExitObj};
20947 $currentGScore = $surroundNode->gScore;
20948 $possibleGScore = $currentNode->gScore + $surroundCost;
20949  
20950 if ($possibleGScore < $currentGScore) {
20951  
20952 # Change the parent
20953 $surroundNode->ivPoke('parent', $currentNode);
20954 $surroundNode->ivPoke('gScore', $possibleGScore);
20955 $openListObj->decrease_key($surroundNode);
20956 }
20957 }
20958 }
20959 }
20960  
20961 # Dijkstra algorithm complete
20962 return 1;
20963 }
20964  
20965 sub fillPath_dijkstra {
20966  
20967 # Called by $self->findUniversalPath, after a call to $self->doDijkstra
20968 # The initial room and the target room are now linked, along the shortest path between them,
20969 # by a list of nodes, each corresponding to a GA::Obj::Exit. The path begins with a dummy
20970 # room connected to the initial room, and another dummy room connected to the target room
20971 # Compile two lists: a list of the rooms, from one dummy room to the other (inclusive), and
20972 # a corresponding list of exits used to travel between them. It's up to the calling
20973 # function to remove the dummy rooms (and dummy exits) at the beginning/ends of the list
20974 #
20975 # Expected arguments
20976 # $targetNode - The target node (a GA::Obj::Exit object)
20977 # $openListRef - The Dijkstra open list, stored in a binomial heap object
20978 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
20979 # $universalPathHashRef
20980 # - A hash of paths between the exits which correspond to nodes, which
20981 # tells us the cost of moving between them
20982 #
20983 # Return values
20984 # Returns an empty list on improper arguments
20985 # Otherwise returns a list containing two list references. The first reference contains a
20986 # list of GA::ModelObj::Room objects on the shortest path between the two dummy
20987 # rooms (inclusive). The second reference contains a list of GA::Obj::Exit objects
20988 # to move between them. The first list contains exactly one more item than the second.
20989  
20990 my ($self, $targetNode, $openListObj, $nodeHashRef, $universalPathHashRef, $check) = @_;
20991  
20992 # Local variables
20993 my (
20994 $currentNode,
20995 @emptyList, @nodeList, @roomList, @exitList,
20996 );
20997  
20998 # Check for improper arguments
20999 if (
21000 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
21001 || ! defined $universalPathHashRef || defined $check
21002 ) {
21003 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_dijkstra', @_);
21004 return @emptyList;
21005 }
21006  
21007 if (exists $$nodeHashRef{$targetNode}) {
21008 $currentNode = $$nodeHashRef{$targetNode};
21009 } else {
21010 $currentNode = $openListObj->top();
21011 }
21012  
21013 while (defined $currentNode) {
21014  
21015 unshift(@nodeList, $currentNode->exitObj);
21016 $currentNode = $currentNode->parent;
21017 }
21018  
21019 if (@nodeList) {
21020  
21021 # Everything in @nodeList is a GA::Obj::Exit corresponding to a node along the path
21022 do {
21023  
21024 my (
21025 $thisExitObj, $hashRef, $regionPathObj, $pathListRef,
21026 @refList,
21027 );
21028  
21029 $thisExitObj = shift @nodeList;
21030  
21031 # Find the path between this node, and the next one
21032 if ($$universalPathHashRef{$thisExitObj->number}) {
21033  
21034 push (@refList, $$universalPathHashRef{$thisExitObj->number});
21035 }
21036  
21037 if ($thisExitObj->twinExit && $$universalPathHashRef{$thisExitObj->twinExit}) {
21038  
21039 push (@refList, $$universalPathHashRef{$thisExitObj->twinExit});
21040 }
21041  
21042 OUTER: foreach my $hashRef (@refList) {
21043  
21044 $regionPathObj = $$hashRef{$nodeList[0]->number};
21045 if ($regionPathObj) {
21046  
21047 # In certain circumstances, the shortest region path between two region
21048 # exits, A and B, might go via a room with its own region exit, C
21049 # Because the G score for path A-B is the same as the combined G scores for
21050 # two region paths, A-C then C-B, we might have either situation
21051 # In the latter situation, the code below has added the Exit B to @exitList
21052 # on the assumption that we're going through that exit; if we aren't, then
21053 # remove it (and remove the corresponding duplicate room that would
21054 # otherwise appear in the final @roomList)
21055 if (
21056 @roomList
21057 && $regionPathObj->roomList
21058 && $roomList[-1] == $regionPathObj->ivIndex('roomList', 0)
21059 ) {
21060 pop @roomList;
21061 pop @exitList;
21062 }
21063  
21064 # Add rooms and exits from this region path
21065 push (@roomList, $regionPathObj->roomList);
21066 push (@exitList, $regionPathObj->exitList);
21067 # At region boundaries (exit nodes), we have to add the exit itself
21068 if ($exitList[-1] ne $regionPathObj->stopExit) {
21069  
21070 push (@exitList, $regionPathObj->stopExit);
21071 }
21072  
21073 last OUTER;
21074 }
21075 }
21076  
21077 } until (@nodeList < 2);
21078 }
21079  
21080 return (\@roomList, \@exitList);
21081 }
21082  
21083 sub getSurrounding_dijkstra {
21084  
21085 # Called by $self->doDijkstra
21086 # Get a list of nodes surrounding the current one
21087 # In this function, the current node corresponds to an exit. We look up this exit in the
21088 # hash of GA::Obj::RegionPath objects we created earlier to find all the connecting
21089 # nodes
21090 #
21091 # Expected arguments
21092 # $currentNode
21093 # - The current node (a GA::Obj::Exit)
21094 # $universalPathHashRef
21095 # - A hash of hash references, in the form
21096 # $hash{begin_exit_number} = hash_reference
21097 # ...where 'begin_exit_number' is the number of the exit at one end of the path
21098 # - Each 'hash_reference' is in the form
21099 # $hash{end_exit_number} = blessed_ref_of_region_path_object
21100 # - The GA::Obj::RegionPath contains the path which connects the two nodes (exits)
21101 #
21102 # Return values
21103 # 'undef' on improper arguments
21104 # Otherwise returns a list reference, containing a series of list references, one for each
21105 # surrounding node. The inner list references are in the form
21106 # [surround_node_exit_object, surrounding_node_cost]
21107  
21108 my ($self, $currentNode, $universalPathHashRef, $check) = @_;
21109  
21110 # Local variables
21111 my (@refList, @returnList);
21112  
21113 # Check for improper arguments
21114 if (! defined $currentNode || ! defined $universalPathHashRef || defined $check) {
21115  
21116 return $axmud::CLIENT->writeImproper(
21117 $self->_objClass . '->getSurrounding_dijkstra',
21118 @_,
21119 );
21120 }
21121  
21122 # Extract hash references from $universalPathHashRef
21123 if ($$universalPathHashRef{$currentNode->number}) {
21124  
21125 push (@refList, $$universalPathHashRef{$currentNode->number});
21126 }
21127  
21128 if ($currentNode->twinExit && $$universalPathHashRef{$currentNode->twinExit}) {
21129  
21130 push (@refList, $$universalPathHashRef{$currentNode->twinExit});
21131 }
21132  
21133 foreach my $hashRef (@refList) {
21134  
21135 foreach my $regionPathObj (values %$hashRef) {
21136  
21137 push (
21138 @returnList,
21139 [
21140 $self->ivShow('exitModelHash', $regionPathObj->stopExit), # Surrounding node
21141 $regionPathObj->roomCount, # Cost
21142 ],
21143 );
21144 }
21145 }
21146  
21147 # Return a list reference, containing some list references
21148 return \@returnList;
21149 }
21150  
21151 sub addUniversalPath {
21152  
21153 # Called by $self->findUniversalPath to add a single GA::Obj::RegionPath to a hash of
21154 # hashes, in the form
21155 # $universalHash{begin_exit_number} = hash_reference
21156 # ...where 'begin_exit_number' is the number of the GA::Obj::Exit at one end of the path
21157 #
21158 # Each 'hash_reference' is in the form:
21159 # $hash_reference{end_exit_number} = blessed_ref_of_region_path_object
21160 #
21161 # Expected arguments
21162 # $universalPathHashRef - a reference to the hash described above
21163 # $regionPathObj - a GA::Obj::RegionPath to add to it
21164 #
21165 # Return values
21166 # 'undef' on improper arguments
21167 # 1 otherwise
21168  
21169 my ($self, $universalPathHashRef, $regionPathObj, $check) = @_;
21170  
21171 # Local variables
21172 my $hashRef;
21173  
21174 # Check for improper arguments
21175 if (! defined $universalPathHashRef || ! defined $regionPathObj || defined $check) {
21176  
21177 return $axmud::CLIENT->writeImproper($self->_objClass . '->addUniversalPath', @_);
21178 }
21179  
21180 if (! exists $$universalPathHashRef{$regionPathObj->startExit}) {
21181  
21182 $$universalPathHashRef{$regionPathObj->startExit} = {};
21183 }
21184  
21185 $hashRef = $$universalPathHashRef{$regionPathObj->startExit};
21186  
21187 # Add the GA::Obj::RegionPath to the existing inner hash, or to the new inner hash
21188 $$hashRef{$regionPathObj->stopExit} = $regionPathObj;
21189  
21190 return 1;
21191 }
21192  
21193 sub createDummyRoom {
21194  
21195 # Called by $self->findUniversalPath
21196 # Creates a dummy world model room (whose model number is -1), with a one-way exit (whose
21197 # exit model number is -1), leading to a real world model room
21198 # Otherwise creates a dummy world model room (whose model number is -2), with a one-way
21199 # exit (whose exit model number is -2), leading from a real world model room
21200 # Once the pathfinding algorithms are complete, $self->destroyDummyRoom() is called to
21201 # remove any traces of the room and its exit from the world model
21202 #
21203 # Expected arguments
21204 # $session - The calling function's GA::Session
21205 # $realRoomObj - The real world model room
21206 # $number - Set to -1 (for the exit node at the beginning of a path) or -2 (for
21207 # the exit node at the end of the path)
21208 #
21209 # Return values
21210 # An empty list on improper arguments
21211 # Otherwise returns a list in the form
21212 # (dummy_room_object, dummy_exit_object)
21213  
21214 my ($self, $session, $realRoomObj, $number, $check) = @_;
21215  
21216 # Local variables
21217 my (
21218 $dummyRoomObj, $dummyExitObj, $dummyDir,
21219 @emptyList,
21220 );
21221  
21222 # Check for improper arguments
21223 if (! defined $session || ! defined $realRoomObj || ! defined $number || defined $check) {
21224  
21225 $axmud::CLIENT->writeImproper($self->_objClass . '->createDummyRoom', @_);
21226 return @emptyList;
21227 }
21228  
21229 $dummyRoomObj = Games::Axmud::ModelObj::Room->new(
21230 $session,
21231 'dummy',
21232 'non_model',
21233 );
21234  
21235 $dummyRoomObj->ivPoke('number', $number);
21236 $self->ivAdd('modelHash', $number, $dummyRoomObj);
21237 $self->ivAdd('roomModelHash', $number, $dummyRoomObj);
21238 # (The dummy room is nominally 'in' the same region as the initial room)
21239 $dummyRoomObj->ivPoke('parent', $realRoomObj->parent);
21240  
21241 $dummyExitObj = Games::Axmud::Obj::Exit->new(
21242 $session,
21243 'dummy', # Use a dummy direction, too!
21244 'non_model', # Not a real exit model object
21245 );
21246  
21247 $dummyExitObj->ivPoke('number', $number);
21248 $self->ivAdd('exitModelHash', $number, $dummyExitObj);
21249  
21250 $dummyDir = 'dijkstra_dummy_exit';
21251  
21252 if ($number == -1) {
21253  
21254 # Dummy exit leading to the initial room
21255 $dummyRoomObj->ivPush('sortedExitList', $dummyDir);
21256 $dummyRoomObj->ivAdd('exitNumHash', $dummyDir, $number);
21257 $dummyExitObj->ivPoke('destRoom', $realRoomObj->number);
21258 $dummyExitObj->ivPoke('oneWayFlag', TRUE);
21259 # NB If the exit is unallocatable, ->mapDir won't be set, so we'll use 'north' as an
21260 # emergency default value for ->mapDir
21261 if ($dummyExitObj->mapDir) {
21262  
21263 $dummyExitObj->ivPoke(
21264 'oneWayDir',
21265 $axmud::CLIENT->ivShow('constOppDirHash', $dummyExitObj->mapDir),
21266 );
21267  
21268 } else {
21269  
21270 # Emergency default
21271 $dummyExitObj->ivPoke('oneWayDir', 'north');
21272 }
21273  
21274 $dummyExitObj->ivPoke('parent', $dummyRoomObj->number);
21275  
21276 } else {
21277  
21278 # Dummy exit leading from the target room
21279 $realRoomObj->ivPush('sortedExitList', $dummyDir);
21280 $realRoomObj->ivAdd('exitNumHash', $dummyDir, $number);
21281 $dummyExitObj->ivPoke('destRoom', $dummyRoomObj->number);
21282 $dummyExitObj->ivPoke('oneWayFlag', TRUE);
21283 if ($dummyExitObj->mapDir) {
21284  
21285 $dummyExitObj->ivPoke(
21286 'oneWayDir',
21287 $axmud::CLIENT->ivShow('constOppDirHash', $dummyExitObj->mapDir),
21288 );
21289  
21290 } else {
21291  
21292 # Emergency default
21293 $dummyExitObj->ivPoke('oneWayDir', 'north');
21294 }
21295  
21296 $dummyExitObj->ivPoke('parent', $realRoomObj->number);
21297 }
21298  
21299 return ($dummyRoomObj, $dummyExitObj);
21300 }
21301  
21302 sub destroyDummyRoom {
21303  
21304 # Called by $self->findUniversalPath
21305 # Removes a dummy room and its dummy exit (created with a call to $self->createDummyRoom)
21306 # from the world model
21307 #
21308 # Expected arguments
21309 # $number - Set to -1 (for the exit node at the beginning of a path) or -2 (for
21310 # the exit node at the end of the path)
21311 #
21312 # Return values
21313 # 'undef' on improper arguments
21314 # 1 otherwise
21315  
21316 my ($self, $number, $check) = @_;
21317  
21318 # Local variables
21319 my (
21320 $dummyDir, $dummyExitObj, $realRoomObj,
21321 @dirList, @newDirList,
21322 );
21323  
21324 # Check for improper arguments
21325 if (! defined $number || defined $check) {
21326  
21327 return $axmud::CLIENT->writeImproper($self->_objClass . '->destroyDummyRoom', @_);
21328 }
21329  
21330 if ($number == -2) {
21331  
21332 # Dummy exit leading from the target room. Update the target room
21333 $dummyDir = 'dijkstra_dummy_exit';
21334 $dummyExitObj = $self->ivShow('exitModelHash', $number);
21335 $realRoomObj = $self->ivShow('modelHash', $dummyExitObj->parent);
21336  
21337 $realRoomObj->ivDelete('exitNumHash', $dummyDir);
21338 @dirList = $realRoomObj->sortedExitList;
21339 foreach my $dir (@dirList) {
21340  
21341 if ($dir ne $dummyDir) {
21342  
21343 push (@newDirList, $dir);
21344 }
21345 }
21346  
21347 $realRoomObj->ivPoke('sortedExitList', @newDirList);
21348 }
21349  
21350 # Remove the exit from the exit model
21351 $self->ivDelete('exitModelHash', $number);
21352 # Remove the room from the world model
21353 $self->ivDelete('modelHash', $number);
21354 $self->ivDelete('roomModelHash', $number);
21355  
21356 return 1;
21357 }
21358  
21359 # Dijkstra algorithm for GA::Obj::Route objects (used to find a path using pre-defined routes)
21360  
21361 sub findRoutePath {
21362  
21363 # Can be called by any function. Called by GA::Generic::Cmd->useRoute
21364 #
21365 # Dijkstra algorithm to find a path between two rooms using interlinked pre-defined routes,
21366 # each one stored in a GA::Obj::Route object (which are stored in route cages)
21367 # Based on AI::Pathfinding::AStar by Aaron Dalton
21368 #
21369 # Expected arguments
21370 # $session - The calling function's GA::Session
21371 # $initialRoomTag - The initial room's tag
21372 # $targetRoomTag - The target room's tag
21373 # $routeType - 'road', 'quick' or 'both'
21374 #
21375 # Return values
21376 # 'undef' on improper arguments or if no path can be found between the initial and target
21377 # rooms
21378 # Otherwise, returns a list reference containing a list of world commands to move between
21379 # the initial and target rooms
21380  
21381 my ($self, $session, $initialRoomTag, $targetRoomTag, $routeType, $check) = @_;
21382  
21383 # Local variables
21384 my (
21385 $openListObj, $nodeHashRef, $currentNode, $cmdListRef,
21386 @routeObjList,
21387 %routePathHash,
21388 );
21389  
21390 # Check for improper arguments
21391 if (
21392 ! defined $session || ! defined $initialRoomTag || ! defined $targetRoomTag
21393 || ! defined $routeType
21394 || ($routeType ne 'road' && $routeType ne 'quick' && $routeType ne 'both')
21395 || defined $check
21396 ) {
21397 return $axmud::CLIENT->writeImproper($self->_objClass . '->findRoutePath', @_);
21398 }
21399  
21400 # The first step is to compile a hash of routes available to us. Get a list of available
21401 # route GA::Obj::Route objects (ignore circuit routes altogether)
21402 if ($routeType eq 'both') {
21403 @routeObjList = $self->listAvailableRoutes($session, undef, 'road', 'quick');
21404 } else {
21405 @routeObjList = $self->listAvailableRoutes($session, undef, $routeType);
21406 }
21407  
21408 if (! @routeObjList) {
21409  
21410 # No routes with which to build a path
21411 return undef;
21412 }
21413  
21414 # Compile a hash in the form
21415 # $routeHash{start_tag} = hash_reference
21416 # where 'start_tag' is the room tag of the room at one end of the route
21417 # Each 'hash_reference' is in the form:
21418 # $hash_reference{stop_tag} = blessed_ref_of_route_object
21419 foreach my $routeObj (@routeObjList) {
21420  
21421 my $hashRef;
21422  
21423 # Use only hoppable route objects...
21424 if ($routeObj->hopFlag) {
21425  
21426 if (! exists $routePathHash{$routeObj->startRoom}) {
21427  
21428 $routePathHash{$routeObj->startRoom} = {};
21429 }
21430  
21431 $hashRef = $routePathHash{$routeObj->startRoom};
21432  
21433 # Add the RouteObj to the existing inner hash, or to the new inner hash
21434 $$hashRef{$routeObj->stopRoom} = $routeObj;
21435 }
21436 }
21437  
21438 # $routePathHashRef now contains a collection of interlinked routes, which we can search to
21439 # find the shortest route between the initial and target rooms (if they are linked by
21440 # route objects)
21441 # Now we run the Dijkstra algorithm for route objects (a modified A* algorithm in which the
21442 # h-score is always 0) to get the shortest path between the initial and target rooms
21443  
21444 # Create the open list, using a binomial heap
21445 $openListObj = Games::Axmud::Obj::Heap->new();
21446 # Create a reference to a hash of nodes, in the form
21447 # $hash{room_tag} = dijkstra_node
21448 $nodeHashRef = {};
21449  
21450 # Create a node for the initial room
21451 $currentNode = Games::Axmud::Node::Dijkstra->new(
21452 0, # Initial G score
21453 undef, # (Exit objects not used for pre-defined routes)
21454 $initialRoomTag, # Room tag of the first room object
21455 );
21456  
21457 # Add this node to the open list
21458 $currentNode->ivPoke('inOpenFlag', TRUE);
21459 $openListObj->add($currentNode);
21460  
21461 # Perform the Dijkstra algorithm, starting at the room tagged $initialRoomTag, and aiming
21462 # for the room tagged $targetRoomTag
21463 $self->doRouteDijkstra($targetRoomTag, $openListObj, $nodeHashRef, \%routePathHash);
21464  
21465 # We can now use the nodes stored in $openListObj to find the shortest route, by tracing the
21466 # path from the target room, and using the parent of each node in turn (in the standard
21467 # way)
21468 # Get a list reference, containing the list of world commands to move between the initial
21469 # and target rooms
21470 $cmdListRef = $self->fillPath_routeDijkstra(
21471 $session,
21472 $targetRoomTag,
21473 $openListObj,
21474 $nodeHashRef,
21475 \%routePathHash,
21476 );
21477  
21478 return $cmdListRef;
21479 }
21480  
21481 sub doRouteDijkstra {
21482  
21483 # Called by $self->findRoutePath
21484 # Performs the Dijkstra algorithm on two nodes, each corresponding to a room tag, in order
21485 # to find the shortest path between them, and therefore the shortest path between two
21486 # rooms (as described in the comments for the calling function)
21487 #
21488 # Expected arguments
21489 # $targetNode - The target node (a room tag)
21490 # $openListObj - The Dijkstra open list, stored in a binomial heap object
21491 # $nodeHashRef - The hash of nodes, in the form $hash{tag} = node
21492 # $routePathHashRef
21493 # - A hash of paths between the tagged rooms, each of which correspond to
21494 # a node. The hash tells us the cost of moving between two nodes
21495 #
21496 # Return values
21497 # 'undef' on improper arguments
21498 # 1 otherwise
21499  
21500 my ($self, $targetNode, $openListObj, $nodeHashRef, $routePathHashRef, $check) = @_;
21501  
21502 # Local variables
21503 my (
21504 $currentNode, $gScore, $nodeListRef,
21505 %twinNodeHash,
21506 );
21507  
21508 # Check for improper arguments
21509 if (
21510 ! defined $targetNode || ! defined $openListObj || ! defined $nodeHashRef
21511 || ! defined $routePathHashRef || defined $check
21512 ) {
21513 return $axmud::CLIENT->writeImproper($self->_objClass . '->doRouteDijkstra', @_);
21514 }
21515  
21516 # Perform the algorithm until we either find the shortest path to the target node or run out
21517 # of nodes
21518 OUTER: while(
21519 defined $openListObj->top()
21520 && ($openListObj->top()->roomTag ne $targetNode)
21521 ) {
21522 # Remove the first remaining node in the open list
21523 $currentNode = $openListObj->extract_top();
21524 $currentNode->ivPoke('inOpenFlag', FALSE);
21525  
21526 # Get the surrounding nodes. $nodeListRef is a list reference, which in turn contains a
21527 # number of list references, each representing a surrounding node (one linked to
21528 # $currentNode by a single GA::Obj::Route)
21529 # The contained list references are in the form
21530 # [room_tag, cost]
21531 $nodeListRef = $self->getSurrounding_routeDijkstra(
21532 $currentNode->roomTag,
21533 $routePathHashRef,
21534 );
21535  
21536 # Process each surrounding node
21537 INNER: foreach my $nodeRef (@$nodeListRef) {
21538  
21539 my (
21540 $surroundRoomTag, $surroundCost, $surroundNode, $currentGScore, $possibleGScore,
21541 );
21542  
21543 ($surroundRoomTag, $surroundCost) = @$nodeRef;
21544  
21545 # Skip this node if it's in the closed list
21546 if (
21547 exists $$nodeHashRef{$surroundRoomTag}
21548 && ! $$nodeHashRef{$surroundRoomTag}->inOpenFlag
21549 ) {
21550 next INNER;
21551 }
21552  
21553 # If the node isn't in the open list, add it to the open list
21554 if (! exists $$nodeHashRef{$surroundRoomTag}) {
21555  
21556 $surroundNode = Games::Axmud::Node::Dijkstra->new(
21557 $currentNode->gScore + $surroundCost, # G score
21558 undef, # Exits not used
21559 $surroundRoomTag, # Node
21560 );
21561  
21562 $surroundNode->ivPoke('parent', $currentNode);
21563 $surroundNode->ivPoke('cost', $surroundCost);
21564 $surroundNode->ivPoke('inOpenFlag', TRUE);
21565 $$nodeHashRef{$surroundRoomTag} = $surroundNode;
21566 $openListObj->add($surroundNode);
21567  
21568 } else {
21569  
21570 # Otherwise the node is already in the open list. Check to see if it's cheaper
21571 # to go through the current exit, compared to the previous path
21572 $surroundNode = $$nodeHashRef{$surroundRoomTag};
21573 $currentGScore = $surroundNode->gScore;
21574 $possibleGScore = $currentNode->gScore + $surroundCost;
21575  
21576 if ($possibleGScore < $currentGScore) {
21577  
21578 # Change the parent
21579 $surroundNode->ivPoke('parent', $currentNode);
21580 $surroundNode->ivPoke('gScore', $possibleGScore);
21581 $openListObj->decrease_key($surroundNode);
21582 }
21583 }
21584 }
21585 }
21586  
21587 # Dijkstra algorithm complete
21588 return 1;
21589 }
21590  
21591 sub fillPath_routeDijkstra {
21592  
21593 # Called by $self->findRoutePath, after a call to $self->doRouteDijkstra
21594 # The initial room and the target room are now linked, along the shortest path between them,
21595 # by a list of nodes, each corresponding to a room tag
21596 # Compile a list of world commands to travel along this path, from the initial room to the
21597 # target room
21598 #
21599 # Expected arguments
21600 # $session - The calling function's GA::Session
21601 # $targetNode - The target node (a room tag)
21602 # $openListRef - The Dijkstra open list, stored in a binomial heap object
21603 # $nodeHashRef - The hash of nodes, in the form $hash{exit} = node
21604 # $routePathHashRef
21605 # - A hash of paths between the room tags which correspond to nodes, which
21606 # tells us the cost of moving between them
21607 #
21608 # Return values
21609 # Returns an empty list on improper arguments
21610 # Otherwise returns a list reference, containing commands sequences to move between the
21611 # initial and target rooms. Each command sequence corresponds to a single route object
21612 # in the chain of route objects between the initial and target rooms, e.g.
21613 # 'north;east;north;enter cave'
21614  
21615 my (
21616 $self, $session, $targetNode, $openListObj, $nodeHashRef, $routePathHashRef, $check,
21617 ) = @_;
21618  
21619 # Local variables
21620 my (
21621 $currentNode,
21622 @emptyList, @nodeList, @cmdSequenceList,
21623 );
21624  
21625 # Check for improper arguments
21626 if (
21627 ! defined $session || ! defined $targetNode || ! defined $openListObj
21628 || ! defined $nodeHashRef || ! defined $routePathHashRef || defined $check
21629 ) {
21630 $axmud::CLIENT->writeImproper($self->_objClass . '->fillPath_routeDijkstra', @_);
21631 return @emptyList;
21632 }
21633  
21634 if (exists $$nodeHashRef{$targetNode}) {
21635 $currentNode = $$nodeHashRef{$targetNode};
21636 } else {
21637 $currentNode = $openListObj->top();
21638 }
21639  
21640 while (defined $currentNode) {
21641  
21642 unshift(@nodeList, $currentNode->roomTag);
21643 $currentNode = $currentNode->parent;
21644 }
21645  
21646 if (@nodeList) {
21647  
21648 # Everything in @nodeList is a room tag corresponding to the beginning or end of a route
21649 # object
21650 do {
21651  
21652 my ($roomTag, $hashRef, $routeObj);
21653  
21654 $roomTag = shift @nodeList;
21655  
21656 # Find the path between this node, and the next one
21657 if ($$routePathHashRef{$roomTag}) {
21658  
21659 $hashRef = $$routePathHashRef{$roomTag};
21660 $routeObj = $$hashRef{$nodeList[0]};
21661 if ($routeObj) {
21662  
21663 # If $routeObj->route is a speedwalk command, convert it into a chain of
21664 # world commands
21665 if (index($routeObj->route, $axmud::CLIENT->constSpeedSigil) == 0) {
21666  
21667 push (
21668 @cmdSequenceList,
21669 join(
21670 $axmud::CLIENT->cmdSep,
21671 $session->parseSpeedWalk($routeObj->route),
21672 ),
21673 );
21674  
21675 } else {
21676  
21677 # $routeObj->route is already a single world command or a chain of
21678 # world commands
21679 push (@cmdSequenceList, $routeObj->route);
21680 }
21681 }
21682 }
21683  
21684 } until (@nodeList < 2);
21685 }
21686  
21687 return \@cmdSequenceList;
21688 }
21689  
21690 sub getSurrounding_routeDijkstra {
21691  
21692 # Called by $self->doRouteDijkstra
21693 # Get a list of nodes surrounding the current one
21694 # In this function, the current node corresponds to a room tag. We look up this node in the
21695 # hash of GA::Obj::Route objects we created earlier to find all the connecting nodes
21696 #
21697 # Expected arguments
21698 # $currentNode
21699 # - The current node (a room tag)
21700 # $routePathHashRef
21701 # - A hash of hash references, in the form
21702 # $hash{start_tag} = hash_reference
21703 # ...where 'start_tag' is the tag of a room at one end of the route
21704 # - Each 'hash_reference' is in the form
21705 # $hash{stop_tag} = blessed_ref_of_route_object
21706 # - The GA::Obj::Route contains the path which connects the two nodes (tagged rooms)
21707 #
21708 # Return values
21709 # 'undef' on improper arguments
21710 # Otherwise returns a list reference, containing a series of list references, one for each
21711 # surrounding node. The inner list references are in the form
21712 # [surround_node_exit_object, surrounding_node_cost]
21713  
21714 my ($self, $currentNode, $routePathHashRef, $check) = @_;
21715  
21716 # Local variables
21717 my (
21718 $hashRef,
21719 @returnList,
21720 );
21721  
21722 # Check for improper arguments
21723 if (! defined $currentNode || ! defined $routePathHashRef || defined $check) {
21724  
21725 return $axmud::CLIENT->writeImproper(
21726 $self->_objClass . '->getSurrounding_routeDijkstra',
21727 @_,
21728 );
21729 }
21730  
21731 # Extract hash references from $routePathHashRef
21732 if ($$routePathHashRef{$currentNode}) {
21733  
21734 $hashRef = $$routePathHashRef{$currentNode};
21735  
21736 foreach my $routeObj (values %$hashRef) {
21737  
21738 push (@returnList, [
21739 $routeObj->stopRoom, # Surrounding node
21740 $routeObj->stepCount, # Cost
21741 ]);
21742 }
21743 }
21744  
21745 # Return a list reference, containing some list references
21746 return \@returnList;
21747 }
21748  
21749 sub listAvailableRoutes {
21750  
21751 # Called by $self->findRoutePath, GA::Cmd::ListRoute->do or by any another function
21752 # Returns a list of routes that are available from the current route cages (so, if there is
21753 # a 'centre' > 'shop' road route associated with the current world's route cage, and
21754 # another one associated with the current character's route cage, only the latter appears
21755 # in the returned list, because character cage always have priority over world cage)
21756 #
21757 # Expected arguments
21758 # $session - The calling function's GA::Session
21759 #
21760 # Optional arguments
21761 # $startRoom - When called by GA::Cmd::ListRoute->do, this function returns a list of
21762 # routes starting from the room with the tag $startroom. Set to
21763 # 'undef' when called by $self->findRoutePath
21764 # @typeList - Can comprise 0, 1, 2 or 3 of the strings 'road', 'quick' and 'circuit', in
21765 # any order. If the list is not empty, only those routes matching the
21766 # elements are returned. If it empty, all eligible routes are returned (so
21767 # an empty list is the same as the list ('road', 'quick', 'circuit')
21768 #
21769 # Return values
21770 # An empty list on improper arguments, if @typeList contains invalid route types, if no
21771 # route cages are found or if $startRoom is specified, but a route from that location
21772 # doesn't exist
21773 # Otherwise, returns a list of RouteObjs
21774  
21775 my ($self, $session, $startRoom, @typeList) = @_;
21776  
21777 # Local variables
21778 my (
21779 $match,
21780 @emptyList, @returnArray, @categoryList, @cageList,
21781 %typeHash, %startRoomHash, %roadRouteHash, %quickRouteHash, %circuitRouteHash,
21782 );
21783  
21784 # Check for improper arguments
21785 if (! defined $session) {
21786  
21787 $axmud::CLIENT->writeImproper($self->_objClass . '->listAvailableRoutes', @_);
21788 return @emptyList;
21789 }
21790  
21791 # Check the contents of @typeList, and compile a hash of types
21792 if (@typeList) {
21793  
21794 foreach my $item (@typeList) {
21795  
21796 if ($item ne 'road' && $item ne 'quick' && $item ne 'circuit') {
21797  
21798 $session->writeError(
21799 'Invalid route type \'' . $item . '\'',
21800 $self->_objClass . '->listAvailableRoutes',
21801 );
21802  
21803 return @emptyList;
21804  
21805 } else {
21806  
21807 $typeHash{$item} = undef;
21808 }
21809 }
21810  
21811 } else {
21812  
21813 # If @typeList is empty, the calling function requires road, quick AND circuit routes
21814 $typeHash{'road'} = undef;
21815 $typeHash{'quick'} = undef;
21816 $typeHash{'circuit'} = undef;
21817 }
21818  
21819 # Get a list of profile categories (each possessing one route cage) in reverse priority
21820 # order (i.e., a list starting with the lowest-priority world profile)
21821 @categoryList = reverse $session->profPriorityList;
21822 # Get a list of existing route cages in the same order
21823 foreach my $category (@categoryList) {
21824  
21825 # Find the current cage for this category, if there is one
21826 my $cageObj = $session->findCurrentCage('Route', $category);
21827 if ($cageObj) {
21828  
21829 push (@cageList, $cageObj);
21830 }
21831 }
21832  
21833 if (! @cageList) {
21834  
21835 # No route cages found (very unlikely)
21836 return @emptyList;
21837 }
21838  
21839 OUTER: foreach my $cageObj (@cageList) {
21840  
21841 my (@routeObjList, @newList);
21842  
21843 # Compile a list of GA::Obj::Route objects to process
21844 @routeObjList = $cageObj->ivValues('routeHash');
21845  
21846 # If a start room was specified, eliminate all route objects with the wrong start room
21847 if ($startRoom) {
21848  
21849 foreach my $routeObj (@routeObjList) {
21850  
21851 if ($routeObj->startRoom eq $startRoom) {
21852  
21853 push (@newList, $routeObj);
21854 }
21855 }
21856  
21857 @routeObjList = @newList;
21858 }
21859  
21860 # Now copy the route objects into three hashes, one for each type of route, in the form
21861 # $roadRouteHash{'start@@@stop'} = blessed_reference_to_route_object
21862 # $quickRouteHash{'start@@@stop'} = blessed_reference_to_route_object
21863 # $circuitRouteHash{'start@@@name'} = blessed_reference_to_route_object
21864 # ...where 'start' is the start room's tag, 'stop' the stop room's tag (for 'road' and
21865 # 'quick' routes) and 'name' is the circuit name (for 'circuit' routes)
21866 # Because @categoryList (and therefore @cageList) are in reverse priority order, at the
21867 # end of the OUTER loop, these three hashes will contain the highest-priority route
21868 # between two rooms (or the highest priority circuit with a given name)
21869 foreach my $routeObj (@routeObjList) {
21870  
21871 my $key;
21872  
21873 if ($routeObj->routeType eq 'road') {
21874  
21875 $key = $routeObj->startRoom . '@@@' . $routeObj->stopRoom;
21876 $roadRouteHash{$key} = $routeObj;
21877  
21878 } elsif ($routeObj->routeType eq 'quick') {
21879  
21880 $key = $routeObj->startRoom . '@@@' . $routeObj->stopRoom;
21881 $quickRouteHash{$key} = $routeObj;
21882  
21883 } elsif ($routeObj->routeType eq 'circuit') {
21884  
21885 $key = $routeObj->startRoom . '@@@' . $routeObj->circuitName;
21886 $circuitRouteHash{$key} = $routeObj;
21887 }
21888 }
21889 }
21890  
21891 # Only return the specified route types
21892 if (exists $typeHash{'road'}) {
21893  
21894 push (@returnArray, values %roadRouteHash);
21895 }
21896  
21897 if (exists $typeHash{'quick'}) {
21898  
21899 push (@returnArray, values %quickRouteHash);
21900 }
21901  
21902 if (exists $typeHash{'circuit'}) {
21903  
21904 push (@returnArray, values %circuitRouteHash);
21905 }
21906  
21907 return @returnArray;
21908 }
21909  
21910 # Other functions called by anything (not necessarily just GA::Obj::Map and GA::Win::Map )
21911  
21912 sub parseObj {
21913  
21914 # Can be called by anything, but called frequently by the Locator task
21915 # Parses a line (or lines) containing a list of things
21916 # e.g. 'A sword, a shield and a helmet are here.'
21917 # e.g. 'Two big evil guards, a troll and three small torches.'
21918 # Creates model objects for each of the things found
21919 # e.g. Creates 2 guard 'sentient' objects, a troll 'sentient' object and three torch
21920 # 'portable' objects
21921 #
21922 # Expected arguments
21923 # $session - The parent GA::Session object
21924 # $multipleFlag - If set to TRUE, treats '5 coins' as a single object, with its
21925 # ->multiple IV set to 5. If the flag is set to FALSE, treats
21926 # '5 coins' as 5 separate objects
21927 #
21928 # Expected arguments
21929 # @lineList - A line (or lines) containing the list(s) of things (may be an empty
21930 # list)
21931 #
21932 # Return values
21933 # An empty list on improper arguments
21934 # Otherwise, returns a list of blessed references to the newly-created objects (may be
21935 # an empty list if @lineList was empty, or if the lines can't be parsed)
21936  
21937 my ($self, $session, $multipleFlag, @lineList) = @_;
21938  
21939 # Local variables
21940 my (
21941 $worldObj, $dictObj, $regex, $thingCount, $numberFlag, $guessFlag,
21942 @tempList, @tempList2, @tempList3, @andOrList, @thingArray, @articleList, @columnList,
21943 @returnArray,
21944 %pseudoObjHash, %articleHash, %numberHash,
21945 );
21946  
21947 # Check for improper arguments
21948 if (! defined $session || ! defined $multipleFlag) {
21949  
21950 return $axmud::CLIENT->writeImproper($self->_objClass . '->parseObj', @_);
21951 }
21952  
21953 if ($axmud::CLIENT->debugParseObjFlag) {
21954  
21955 if ($multipleFlag) {
21956 $self->writeDebug('WORLD MODEL: Parsing objects multiple flag turned ON');
21957 } else {
21958 $self->writeDebug('WORLD MODEL: Parsing objects multiple flag turned OFF');
21959 }
21960 }
21961  
21962 # Import the current world profile and dictionary
21963 $worldObj = $session->currentWorld;
21964 $dictObj = $session->currentDict;
21965  
21966 # Import the hash of pseudo-objects
21967 %pseudoObjHash = $dictObj->pseudoObjHash;
21968 # Import a hash of number words
21969 %numberHash = $dictObj->numberHash;
21970 # Import a list of articles (in English, 'the', 'a' and 'an')
21971 @articleList = ($dictObj->definiteList, $dictObj->indefiniteList);
21972 # Convert to a hash for quick lookup
21973 foreach my $item (@articleList) {
21974  
21975 $articleHash{$item} = undef;
21976 }
21977  
21978 # Stage 1 - convert any capital letters into lower-case letters and remove the
21979 # characteristic room contents patterns (e.g. 'is here', 'are here' etc) from lines of
21980 # text in the list
21981 OUTER: foreach my $line (@lineList) {
21982  
21983 $line = lc($line);
21984 INNER: foreach my $pattern ($worldObj->contentPatternList) {
21985  
21986 $line =~ s/$pattern//gi;
21987 }
21988 }
21989  
21990 # Stage 2 - look for pseudo-objects (strings that will confuse the parser) and replace them
21991 # Test each pseudo-object against each line
21992 OUTER: foreach my $line (@lineList) {
21993  
21994 INNER: foreach my $pseudo (keys %pseudoObjHash) {
21995  
21996 my $replace = $pseudoObjHash{$pseudo};
21997 $line =~ s/$pseudo/$replace/g;
21998 }
21999 }
22000  
22001 # Stage 3 - remove multiples like '[ 5]' that tend to appear in worlds that use a single
22002 # object per line, optionally preceded by a multiplier. This multiplier is applied to
22003 # every object on that line
22004 $regex = '[\(\[\{\<]\s*(\d+)\s*[\)\]\}\>]';
22005 foreach my $line (@lineList) {
22006  
22007 my $num;
22008  
22009 if ($line =~ m/$regex/) {
22010  
22011 $num = $1;
22012 # Stage 5 will detect a simple integer, so replace the '[ 5]' with ' 5 '
22013 $line =~ s/$regex/$num /;
22014 }
22015 }
22016  
22017 # Stage 4 - split into a list of objects (or groups of objects)
22018 # e.g. 'Two big evil guards, a troll and three small torches.'
22019 #
22020 # @thingArray[0][n]
22021 #
22022 # [0] = two big evil guards
22023 # [1] = a troll
22024 # [2] = three small torches
22025  
22026 # Split the lines of @lineList by full stops and commas
22027 foreach my $line (@lineList) {
22028  
22029 push (@tempList, split("\\.", $line));
22030 }
22031  
22032 foreach my $item (@tempList) {
22033  
22034 push (@tempList2, split("\\,", $item));
22035 }
22036  
22037 # Further split the lines of @lineList by and/ors
22038 # Compile a list of and/or words from the current dictionary
22039 @andOrList = ($dictObj->andList, $dictObj->orList);
22040 # Surround each and/or word with whitespace, so that the word 'author' doesn't get split
22041 # into 'auth' and 'or'
22042 foreach my $andOr (@andOrList) {
22043  
22044 $andOr = ' ' . $andOr . ' ';
22045 }
22046  
22047 # Do the split
22048 foreach my $andOr (@andOrList) {
22049  
22050 foreach my $item (@tempList2) {
22051  
22052 push (@tempList3, split (/$andOr/ , $item));
22053 }
22054  
22055 # Reset the lists, ready for the next iteration of the loop (if any)
22056 @tempList2 = @tempList3;
22057 @tempList3 = ();
22058 }
22059  
22060 # Trim unnecessary whitespace from each object (or group of objects) in the list. The TRUE
22061 # argument tells the function to trim whitespace in the middle of the string, too
22062 foreach my $item (@tempList2) {
22063  
22064 $item = $axmud::CLIENT->trimWhitespace($item, TRUE);
22065 }
22066  
22067 # If a pseudo-object's replacement string is an empty string, one or more of the elements in
22068 # @tempList2 will be empty. Eliminate those lines
22069 # In addition, if a list of objects is spread over several lines, we might have artifacts
22070 # like 'the' and 'a' at the end of a line; they will now exist as items in @tempList2.
22071 # Eliminate those, too
22072 foreach my $item (@tempList2) {
22073  
22074 if ($item && (! exists $articleHash{$item})) {
22075  
22076 push (@tempList3, $item);
22077 }
22078 }
22079  
22080 # Insert the list of objects (or groups of objects) into the first column of a 2-dimensional
22081 # array
22082 # Use $thingCount to remember how many items there are
22083 $thingCount = scalar @tempList3;
22084 @thingArray = (\@tempList3);
22085  
22086 # Stage 5 - assign a number to everything in the list of objects (or group of objects)
22087 # The number might be 0, a decimal fraction, or -1 for 'unknown number greater than 1'
22088 # Remove the number word and any definite/indefinite articles
22089 #
22090 # e.g. 'Two big evil guards, a troll and three small torches.'
22091 #
22092 # @thingArray[0][n] [1][n] [2][n]
22093 #
22094 # [0] = two big evil guards [0] big evil guards [0] 2
22095 # [1] = a troll [1] troll [1] 1
22096 # [2] = three small torches [2] small torches [2] 3
22097 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22098  
22099 my (
22100 $pattern, $grpString, $string, $numberFlag,
22101 @wordList,
22102 );
22103  
22104 # Special case: if the string matches the current world's ->multiplePattern, use that as
22105 # the multiple (and remove it)
22106 $pattern = $worldObj->multiplePattern;
22107 if ($pattern && $thingArray[0][$count] =~ m/$pattern/) {
22108  
22109 $grpString = $1;
22110 if ($grpString && $grpString =~ m/^\d+$/ && $grpString > 0) {
22111  
22112 # Set the multiple
22113 $thingArray[2][$count] = $grpString;
22114 # Store the rest of the string, with the matching pattern substituted out
22115 $string = $thingArray[0][$count];
22116 $string =~ s/$pattern//;
22117 $thingArray[1][$count] = $string;
22118 next OUTER;
22119 }
22120 }
22121  
22122 # Split each thing into a list of word, e.g. ('two', 'evil', 'guards')
22123 @wordList = split(/\s+/, $thingArray[0][$count]);
22124  
22125 # If the first word is an article (and it's not the only word in the thing), remove the
22126 # article
22127 if (exists $articleHash{$wordList[0]} && scalar @wordList > 1) {
22128  
22129 # Remove the article
22130 shift @wordList;
22131 }
22132  
22133 # Remove any integer numbers from the beginning
22134 if ($axmud::CLIENT->intCheck($wordList[0])) {
22135  
22136 # Integer number found at beginning of $thing. Remove it and assign it to [2][n]
22137 $thingArray[2][$count] = $wordList[0];
22138  
22139 # Only remove the first number
22140 shift @wordList;
22141 $numberFlag = TRUE;
22142  
22143 # Remove any number words from the beginning, and convert it to a decimal number
22144 # e.g. 'two trolls' -> 2, 'half of the cake' -> 0.5, 'some cake' -> -1
22145 # (-1 represents an indeterminate number, the resulting of converting 'some')
22146 } elsif (exists $numberHash{$wordList[0]}) {
22147  
22148 # Number word found at beginning of $thing. Remove it, convert it to a decimal
22149 # number and assign it to [2][n]
22150 $thingArray[2][$count] = $numberHash{$wordList[0]};
22151  
22152 # Only remove one number word
22153 shift @wordList;
22154 $numberFlag = TRUE;
22155 }
22156  
22157 if (! $numberFlag) {
22158  
22159 # Treat this item as one thing
22160 $thingArray[2][$count] = 1;
22161 }
22162  
22163 # Recombine the word list into a string without articles or number words at
22164 # the beginning
22165 $thingArray[1][$count] = join(' ', @wordList);
22166 }
22167  
22168 # Stage 6 - extract pseudo-adjectives, because they mess everything up
22169 # Pseudo-adjectives are stored in a hash which translates them either into a simple one-word
22170 # adjective or marks them as something that should be removed completely
22171 # $hash{'slightly suspicious'} = 'suspicious'
22172 # - treat the adjective as 'suspicious'
22173 # $hash{'gruesome remains of'} = undef
22174 # - pretend this object doesn't have an adjective
22175 # The contents of [1][n] is moved to [3][n]; any pseudo-adjectives are removed from [3][n]
22176 # and the replacement is put in [4][n]
22177 #
22178 # e.g. 'A slightly suspicious cake and the gruesome remains of a corpse'
22179 #
22180 # @thingArray[0][n] [1][n] [2][n]
22181 #
22182 # [0] = a slightly suspicious cake [0] slightly suspicious cake [0] 1
22183 # [1] = the gruesome remains of a corpse [1] gruesome remains of a corpse [1] 1
22184 #
22185 # [3][n] [4][n]
22186 #
22187 # cake suspicious
22188 # a corpse undef
22189 #
22190 # e.g. 'Two big evil guards, a troll and three small torches.' (contains no
22191 # pseudo-adjectives)
22192 #
22193 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22194 #
22195 # [0] = two big evil guards [0] big evil guards [0] 2 [0] big evil guards [0] undef
22196 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22197 # [2] = three small torches [2] small torches [2] 3 [2] small torches [2] undef
22198  
22199 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22200  
22201 my $largest;
22202  
22203 # Find the largest pseudo-adjective that matches
22204 $largest = '';
22205  
22206 INNER: foreach my $pseudoAdj ($dictObj->ivKeys('pseudoAdjHash')) {
22207  
22208 if (
22209 $thingArray[1][$count] =~ m/$pseudoAdj/
22210 && length ($pseudoAdj) > length ($largest)
22211 ) {
22212 $largest = $pseudoAdj;
22213 }
22214 }
22215  
22216 if ($largest) {
22217  
22218 # Remove the largest pseudo-adjective from [1][n], and move its substitution to
22219 # [4][n]. (If the substitution is an empty string, don't put anything in [4][n])
22220 $thingArray[3][$count] = $thingArray[1][$count];
22221 $thingArray[3][$count] =~ s/$largest//;
22222 if ($dictObj->ivShow('pseudoAdjHash', $largest)) {
22223  
22224 $thingArray[4][$count] = $dictObj->ivShow('pseudoAdjHash', $largest);
22225 }
22226  
22227 } else {
22228  
22229 # No pseudo-adjective found
22230 $thingArray[3][$count] = $thingArray[1][$count];
22231 $thingArray[4][$count] = undef;
22232 }
22233 }
22234  
22235 # Stage 7 - extract pseudo-nouns from [3][n]
22236 # Pseudo-nouns are stored in a hash which translates them either into a simple one-word noun
22237 # $hash{'major general'} = 'major'
22238 # If a pseudo-noun is found, it is replaced with its substitution, and the substitution is
22239 # copied to [5][n] as the main noun
22240 #
22241 # e.g. 'An attractive major general'
22242 #
22243 # @thingArray[0][n] [1][n] [2][n]
22244 #
22245 # [0] = an attractive major general [0] attractive major general [0] 1
22246 #
22247 # [3][n] [4][n] [5][n]
22248 #
22249 # [0] attractive major [0] undef major
22250 #
22251 # e.g. 'Two big evil guards, a troll and three small torches.' (contains no pseudo-nouns)
22252 #
22253 # @thingArray[0][n] [1][n] [2][n] [3][n]
22254 #
22255 # [0] = two big evil guards [0] big evil guards [0] 2 [0] big evil guards
22256 # [1] = a troll [1] troll [1] 1 [1] troll
22257 # [2] = three small torches [2] small torches [2] 3 [2] small torches
22258 #
22259 # [4][n] [5][n]
22260 #
22261 # [0] undef [0] undef
22262 # [1] undef [1] undef
22263 # [2] undef [2] undef
22264  
22265 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22266  
22267 my ($largest, $substitution);
22268  
22269 # Find the largest pseudo-noun that matches
22270 $largest = '';
22271  
22272 INNER: foreach my $pseudoNoun ($dictObj->ivKeys('pseudoNounHash')) {
22273  
22274 if (
22275 $thingArray[3][$count] =~ m/$pseudoNoun/
22276 && length ($pseudoNoun) > length ($largest)
22277 ) {
22278 $largest = $pseudoNoun;
22279 }
22280 }
22281  
22282 if ($largest) {
22283  
22284 # Replace the largest pseudo-noun from [3][n] with its substitution
22285 $substitution = $dictObj->ivShow('pseudoNounHash', $largest);
22286 $thingArray[3][$count] =~ s/$largest/$substitution/;
22287 # Copy the substitution into [5][n] as the main noun
22288 $thingArray[5][$count] = $substitution;
22289 }
22290 }
22291  
22292 # Stage 8 - Try to separate nouns and adjectives, reducing plurals to singular forms and
22293 # declined adjectives to undeclined forms, where possible
22294 #
22295 # e.g. 'Two big evil guards, a troll and three small torches.'
22296 #
22297 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22298 #
22299 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22300 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22301 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22302 #
22303 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22304 #
22305 # [0] guards undef undef undef big evil undef undef
22306 # [1] troll undef undef undef undef undef undef
22307 # [2] torches undef undef undef undef small undef
22308 #
22309 # [5][n] contains the first word - working from right to left - that's a known noun (or
22310 # pseudo-noun)
22311 # [6][n] contains any other words which are known nouns
22312 # [7][n] contains the dictionary section the first noun was found in (e.g. 'weapon')
22313 # [8][n] contains the type of the first noun, if it's a portable or decoration (e.g.
22314 # 'torch')
22315 # [9][n] contains all words which are known adjectives
22316 # [10][n] contains all words which aren't known nouns or adjectives
22317 # [11][n] contains all declined adjectives
22318  
22319 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22320  
22321 my @wordList;
22322  
22323 # Split [3][n] into words
22324 @wordList = split(/\s+/, $thingArray[3][$count]);
22325 # If the noun is more likely to come at the end (i.e. English) than at the front (e.g.
22326 # French), reverse the order of the words
22327 if ($dictObj->nounPosn eq 'adj_noun') {
22328  
22329 @wordList = reverse (@wordList);
22330 }
22331  
22332 INNER: foreach my $word (@wordList) {
22333  
22334 my ($singular, $undeclined, $modFlag);
22335  
22336 # It's possible that $word may be an empty string, or 'undef', in an object like
22337 # 'a pair of dirty and smelly trousers', when 'pair of' is a pseudo-adjective,
22338 # 'dirty' & 'smelly' are adjectives, and 'trousers' is a noun - because the
22339 # parser will interpret this as two objects, 'a pair of dirty' and 'smelly
22340 # trousers', the former of which contains no nouns
22341 if (! $word) {
22342  
22343 next INNER;
22344 }
22345  
22346 if ($self->ivExists('knownCharHash', $word)) {
22347  
22348 # For characters, [5][n] should contain only one word, the character's name
22349 # If there's anything in [5][n] (main noun) already, move it to [6][n] (other
22350 # nouns)
22351 if (defined $thingArray[5][$count]) {
22352  
22353 if (! defined $thingArray[6][$count]) {
22354  
22355 # First word in [6][n]
22356 $thingArray[6][$count] = $thingArray[5][$count];
22357  
22358 } else {
22359  
22360 # Not first word in [6][n]
22361 $thingArray[6][$count]
22362 = $thingArray[5][$count] . ' ' . $thingArray[6][$count];
22363 }
22364 }
22365  
22366 # Character's name goes into [5][n]
22367 $thingArray[5][$count] = $word;
22368  
22369 # Remaining nouns go into [6][n]...
22370 if (! defined $thingArray[6][$count]) {
22371  
22372 # First word in [6][n]
22373 $thingArray[6][$count] = $word;
22374  
22375 } else {
22376  
22377 # Not first word in [6][n]
22378 $thingArray[6][$count] = $word . ' ' . $thingArray[6][$count];
22379 }
22380  
22381 # Mark the object as a character (in [7][n])
22382 $thingArray[7][$count] = 'char';
22383 next INNER;
22384 }
22385  
22386 # See if the word is already known, before trying to convert it to a singular (as
22387 # if it were a noun) or trying to undecline it (as if it were an adjective)
22388 if (
22389 # Word exists as a noun somewhere in the dictionary...
22390 $dictObj->ivExists('combNounHash', $word)
22391 # ...and it's not a special plural form, such as 'stadia' for stadium
22392 && (! $dictObj->ivExists('reversePluralNounHash', $word))
22393 ) {
22394 # This is a known noun. First noun goes into [5][n]
22395 if (! defined $thingArray[5][$count]) {
22396  
22397 $thingArray[5][$count] = $word;
22398  
22399 # Remaining nouns go into [6][n] (unless the same noun is already in [5][n]
22400 # after a pseudo-noun subsitution was placed there)
22401 } elsif ($word ne $thingArray[5][$count]) {
22402  
22403 if (! defined $thingArray[6][$count]) {
22404  
22405 # First word in [6][n]
22406 $thingArray[6][$count] = $word;
22407  
22408 } else {
22409  
22410 # Not first word in [6][n]
22411 $thingArray[6][$count] = $word . ' ' . $thingArray[6][$count];
22412 }
22413 }
22414  
22415 next INNER;
22416 }
22417  
22418 if (
22419 # Word exists as an adjective somewhere in the dictionary...
22420 $dictObj->ivExists('combAdjHash', $word)
22421 # ...and it's not a special declined form, e.g. 'heureuse' for heureux
22422 && (! $dictObj->ivExists('reverseDeclinedAdjHash', $word))
22423 ) {
22424 # This is a known adjective. Put it into [9][n]
22425 if (! defined $thingArray[9][$count]) {
22426  
22427 # First word in [9][n]
22428 $thingArray[9][$count] = $word;
22429  
22430 } else {
22431  
22432 # Not first word in [9][n]
22433 $thingArray[9][$count] = $word . ' ' . $thingArray[9][$count]
22434 }
22435  
22436 next INNER;
22437 }
22438  
22439 # Assume it's a plural noun, and try to reduce it to a singular noun
22440 $singular = $dictObj->convertToSingular($word);
22441 # For confirmed plurals, update the object's base string, so 'two big evil guards'
22442 # generates the base string 'big evil guard' rather 'big evil guards', as this is
22443 # useful for the Locator task window (and probably elsewhere, too)
22444 if ($thingArray[2][$count] > 1 && $singular ne $word) {
22445  
22446 $thingArray[1][$count] =~ s/$word/$singular/g;
22447 # (Only do this once per object)
22448 $modFlag = TRUE;
22449 }
22450  
22451 if ($dictObj->ivExists('combNounHash', $singular)) {
22452  
22453 # This is a known noun. First noun goes into [5][n]. If $word is in [5][n],
22454 # replace it by a singular
22455 if (! defined $thingArray[5][$count] || $thingArray[5][$count] eq $word) {
22456  
22457 $thingArray[5][$count] = $singular;
22458  
22459 # Remaining nouns go into [6][n] (unless the same noun is already in [5][n]
22460 # after a pseudo-noun subsitution was placed there)
22461 } elsif ($singular ne $thingArray[5][$count]) {
22462  
22463 if (! defined $thingArray[6][$count]) {
22464  
22465 # First word in [6][n]
22466 $thingArray[6][$count] = $singular;
22467  
22468 } else {
22469  
22470 # Not first word in [6][n]
22471 $thingArray[6][$count] = $singular . ' ' . $thingArray[6][$count];
22472 }
22473 }
22474  
22475 next INNER;
22476 }
22477  
22478 # Assume it's a declined adjective, and try to reduce it to an undeclined adjective
22479 $undeclined = $dictObj->convertToUndeclined($word);
22480 if ($dictObj->ivExists('combAdjHash', $undeclined)) {
22481  
22482 # This is a known adjective. Put it into [9][n]. If $word is in [9][n],
22483 # replace it by the undecliend form
22484 if (! defined $thingArray[9][$count] || $thingArray[9][$count] eq $word) {
22485  
22486 # First word in [9][n]
22487 $thingArray[9][$count] = $undeclined;
22488  
22489 } else {
22490  
22491 # Not first word in [9][n]
22492 $thingArray[9][$count] = $undeclined . ' ' . $thingArray[9][$count]
22493 }
22494  
22495 if ($word ne $undeclined) {
22496  
22497 # This is a known declinable adjective. Put the undeclined form into [11][n]
22498 if (! defined $thingArray[11][$count]) {
22499  
22500 # First word in [9][n]
22501 $thingArray[11][$count] = $word;
22502  
22503 } else {
22504  
22505 # Not first word in [9][n]
22506 $thingArray[11][$count] = $word . ' ' . $thingArray[11][$count]
22507 }
22508 }
22509  
22510 next INNER;
22511 }
22512  
22513 # Words which aren't known nouns or adjectives go into [10][n] (but don't add
22514 # ignorable words)
22515 if (! $dictObj->ivExists('ignoreWordHash', $word)) {
22516  
22517 if (! defined $thingArray[10][$count]) {
22518  
22519 # First word in [10][n]
22520 $thingArray[10][$count] = $word;
22521  
22522 } else {
22523  
22524 # Not first word in [10][n]
22525 $thingArray[10][$count] = $word.' '.$thingArray[10][$count]
22526 }
22527 }
22528 }
22529 }
22530  
22531 # Stage 9 - any words which aren't recognised nouns or adjectives should be added to the
22532 # dictionary's list of unknown words (if this is allowed); but words in the dictionary's
22533 # ignore list should not
22534 if ($worldObj->collectUnknownWordFlag) {
22535  
22536 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22537  
22538 if (defined $thingArray[10][$count]) {
22539  
22540 my @wordList;
22541  
22542 # Split [10][n] into words
22543 @wordList = split(/\s+/, $thingArray[10][$count]);
22544 # If the noun is more likely to come at the end (i.e. English) than at the front
22545 # (e.g. French), reverse the order of the words
22546 if ($dictObj->nounPosn eq 'adj_noun') {
22547  
22548 @wordList = reverse (@wordList);
22549 }
22550  
22551 # Empty [10][n] so it can be rebuilt, minus any ignorable words
22552 $thingArray[10][$count] = '';
22553  
22554 # Add each word to the dictionary's list of unknown words
22555 foreach my $word (@wordList) {
22556  
22557 $dictObj->ivAdd('unknownWordHash', $word, undef);
22558  
22559 if (! $thingArray[10][$count]) {
22560 $thingArray[10][$count] = $word;
22561 } else {
22562 $thingArray[10][$count] .= ' ' . $word;
22563 }
22564 }
22565 }
22566 }
22567 }
22568  
22569 # Stage 10 - if there's no recognised first noun in [5][n], we need to guess at one
22570 # Use the last (or the first) word in [10][n] (unrecognised words)
22571 # If there's nothing in [10][n], use the last (or the first) word in [9][n] (adjectives)
22572 # or [4][n] (pseudo-adjective replacement)
22573 # In either case, remove the selected word from [4][n], [9][n] or [10][n], and put it in
22574 # [5][n]
22575 #
22576 # e.g. 'Two big evil guards, a troll and three small torches.'
22577 #
22578 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22579 #
22580 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22581 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22582 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22583 #
22584 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22585 #
22586 # [0] guards undef undef undef big evil undef undef
22587 # [1] troll undef undef undef undef undef undef
22588 # [2] torches undef undef undef undef small undef
22589  
22590 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22591  
22592 my @wordList;
22593  
22594 if (! defined $thingArray[5][$count]) {
22595  
22596 # If there's anything in [10][n], use the first word (which would have been the last
22597 # word in 'three small torches', if 'torch' wasn't a recognised noun)
22598 if (defined $thingArray[10][$count]) {
22599  
22600 @wordList = split(/\s+/, $thingArray[10][$count]);
22601 # Reverse the order for French (and similar languages)
22602 if ($dictObj->nounPosn eq 'noun_adj') {
22603  
22604 @wordList = reverse (@wordList);
22605 }
22606  
22607 $thingArray[5][$count] = shift @wordList;
22608 $thingArray[10][$count] = join(' ', @wordList);
22609 $guessFlag = TRUE;
22610  
22611 } elsif (defined $thingArray[9][$count]) {
22612  
22613 @wordList = split(/\s+/, $thingArray[9][$count]);
22614 # Reverse the order for French (and similar languages)
22615 if ($dictObj->nounPosn eq 'noun_adj') {
22616  
22617 @wordList = reverse (@wordList);
22618 }
22619  
22620 $thingArray[5][$count] = shift @wordList;
22621 $thingArray[9][$count] = join(' ', @wordList);
22622 $guessFlag = TRUE;
22623  
22624 } elsif (defined $thingArray[4][$count]) {
22625  
22626 @wordList = split(/\s+/, $thingArray[4][$count]);
22627 # Reverse the order for French (and similar languages)
22628 if ($dictObj->nounPosn eq 'noun_adj') {
22629  
22630 @wordList = reverse (@wordList);
22631 }
22632  
22633 $thingArray[5][$count] = shift @wordList;
22634 $thingArray[4][$count] = join(' ', @wordList);
22635 $guessFlag = TRUE;
22636  
22637 } else {
22638  
22639 $self->writeWarning(
22640 '17056 Unable to parse object \'' . $thingArray[0][$count] . '\'',
22641 $self->_objClass . '->parseObj',
22642 );
22643  
22644 $thingArray[5][$count] = '(unparsed object)';
22645 }
22646 }
22647 }
22648  
22649 # Stage 11 - If [2][n] indicates a plural and we had to guess at the first noun, using an
22650 # unknown word (in [10][n]) or even an adjective (in [9][n]), we need to try to reduce
22651 # it to its singular form, in case it's a plural.
22652 #
22653 # e.g. 'Two big evil guards, a troll and three small torches.'
22654 #
22655 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22656 #
22657 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22658 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22659 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22660 #
22661 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22662 #
22663 # [0] guard undef undef undef big evil undef undef
22664 # [1] troll undef undef undef undef undef undef
22665 # [2] torch undef undef undef undef small undef
22666  
22667 if ($guessFlag) {
22668  
22669 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22670  
22671 my $standard;
22672  
22673 # If it's a known character, don't try to reduce it from plural to singular
22674 if (defined $thingArray[7][$count] && $thingArray[7][$count] eq 'char') {
22675  
22676 next OUTER;
22677  
22678 } elsif ($thingArray[2][$count] > 1) {
22679  
22680 $thingArray[5][$count]
22681 = $dictObj->convertToSingular($thingArray[5][$count]);
22682 }
22683 }
22684 }
22685  
22686 # Stage 12 - work out what kind of object everything is ('portable', 'creature', 'sentient',
22687 # etc). If the object is already known to be a character, skip this stage
22688 #
22689 # e.g. 'Two big evil guards, a troll and three small torches.'
22690 #
22691 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22692 #
22693 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22694 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22695 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22696 #
22697 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n]
22698 #
22699 # [0] guard undef sentient undef big evil undef undef
22700 # [1] troll undef race undef undef undef undef
22701 # [2] torch undef portable torch undef small undef
22702  
22703 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22704  
22705 # If it's a known character, don't need to work out what kind of thing it is
22706 if (defined $thingArray[7][$count] && $thingArray[7][$count] eq 'char') {
22707  
22708 next OUTER;
22709  
22710 } elsif ($dictObj->ivExists('combNounHash', $thingArray[5][$count])) {
22711  
22712 # It's a recognised noun. The parent dictionary goes into [7][n]...
22713 my $parentDict = $dictObj->ivShow(
22714 'combNounHash',
22715 $thingArray[5][$count],
22716 );
22717 $thingArray[7][$count] = $parentDict;
22718  
22719 # ...if it's a portable or decoration, the type goes into [8][n]
22720 if ($parentDict eq 'portable') {
22721  
22722 if ($dictObj->ivExists('portableTypeHash', $thingArray[5][$count])) {
22723  
22724 $thingArray[8][$count] = $dictObj->ivShow(
22725 'portableTypeHash',
22726 $thingArray[5][$count],
22727 );
22728  
22729 } else {
22730  
22731 $thingArray[8][$count] = 'other';
22732 }
22733  
22734 } elsif ($parentDict eq 'decoration') {
22735  
22736 if (
22737 $dictObj->ivExists(
22738 'decorationTypeHash',
22739 $thingArray[5][$count]),
22740 ) {
22741 $thingArray[8][$count] = $dictObj->ivShow(
22742 'decorationTypeHash',
22743 $thingArray[5][$count],
22744 );
22745  
22746 } else {
22747  
22748 $thingArray[8][$count] = 'other';
22749 }
22750  
22751 } else {
22752 $thingArray[8][$count] = undef;
22753 }
22754  
22755 } else {
22756  
22757 # It's not a recognised noun
22758 $thingArray[7][$count] = undef;
22759 $thingArray[8][$count] = undef;
22760 }
22761 }
22762  
22763 # Stage 13 - for objects marked 'sentient' or 'creature' (or temporarily as 'race' or
22764 # 'guild'), and for objects of unknown category (because they're not in the current
22765 # dictionary), we need to know whether they are known minions. $self->minionStringHash
22766 # contains a list of keys (e.g. 'Obelix', 'hairy orc') which represent a minion
22767 # object (stored as the corresponding value). If the object's base string (in [1][n])
22768 # contains one of these minion strings, it's a minion, and [7][n] must be changed; [12][n]
22769 # is set to the matching minion string ('Obelix', 'hairy orc') and [13][n] is set for
22770 # minions which belong to the user
22771 #
22772 # e.g. 'Two big evil guards, a troll and three small torches.'
22773 #
22774 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22775 #
22776 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22777 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22778 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22779 #
22780 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n] [12][n] [13][n]
22781 #
22782 # [0] guard undef sentient undef big evil undef undef undef undef
22783 # [1] troll undef minion undef undef undef undef troll undef
22784 # [2] torch undef portable torch undef small undef undef undef
22785  
22786 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22787  
22788 if (
22789 ! defined $thingArray[7][$count]
22790 || $thingArray[7][$count] eq 'sentient' || $thingArray[7][$count] eq 'creature'
22791 || $thingArray[7][$count] eq 'race' || $thingArray[7][$count] eq 'guild'
22792 ) {
22793 INNER: foreach my $minionString ($self->ivKeys('minionStringHash')) {
22794  
22795 my $minionObj;
22796  
22797 if ($thingArray[1][$count] =~ m/$minionString/i) {
22798  
22799 # It's a minion
22800 $thingArray[7][$count] = 'minion';
22801 $thingArray[12][$count] = $minionString;
22802  
22803 # Is it one of our own minions?
22804 $minionObj = $self->ivShow('minionStringHash', $minionString);
22805 if ($minionObj->ownMinionFlag) {
22806 $thingArray[13][$count] = TRUE;
22807 } else {
22808 $thingArray[13][$count] = FALSE;
22809 }
22810  
22811 next OUTER;
22812 }
22813 }
22814 }
22815 }
22816  
22817 # Stage 14 - for each separate object, create a new non-model object, and put its blessed
22818 # reference into @returnArray
22819 #
22820 # e.g. 'Two big evil guards, a troll and three small torches.'
22821 #
22822 # @thingArray[0][n] [1][n] [2][n] [3][n] [4][n]
22823 #
22824 # [0] = two big evil guards [0] big evil guard [0] 2 [0] big evil guards [0] undef
22825 # [1] = a troll [1] troll [1] 1 [1] troll [1] undef
22826 # [2] = three small torches [2] small torch [2] 3 [2] small torches [2] undef
22827 #
22828 # [5][n] [6][n] [7][n] [8][n] [9][n] [10][n] [11][n] [12][n] [13][n]
22829 #
22830 # [0] guard undef sentient undef big evil undef undef undef undef
22831 # [1] troll undef minion undef undef undef undef troll undef
22832 # [2] torch undef portable torch undef small undef undef undef
22833  
22834 # Trim unnecessary whitespace from every word (or group of words)
22835 OUTER: for (my $thing = 0; $thing < $thingCount; $thing++) {
22836  
22837 INNER: for (my $column = 0; $column < 11; $column++) {
22838  
22839 if (defined $thingArray[$column][$thing]) {
22840  
22841 $thingArray[$column][$thing]
22842 = $axmud::CLIENT->trimWhitespace($thingArray[$column][$thing]);
22843 }
22844 }
22845 }
22846  
22847 # Show debug information, if the global flag is set
22848 if ($axmud::CLIENT->debugParseObjFlag) {
22849  
22850 @columnList = (
22851 '(original)', # column 0
22852 '(base string)', # column 1
22853 '(multiple)', # column 2
22854 '(base string without pseudo noun/adjective)', # column 3
22855 '(pseudo adjective replacement)', # column 4
22856 '(1st noun)', # column 5
22857 '(other noun)', # column 6
22858 '(dictionary word type)', # column 7
22859 '(portable/decoration type)', # column 8
22860 '(1st adjective)', # column 9
22861 '(oth adjectives)', # column 10
22862 '(root adjective)', # column 11
22863 '(minion string)', # column 12
22864 '(own minion flag)', # column 13
22865 );
22866  
22867 $self->writeDebug('WORLD MODEL: Objects parsed: ' . $thingCount);
22868  
22869 OUTER: for (my $rowCount = 0; $rowCount < $thingCount; $rowCount++) {
22870  
22871 $self->writeDebug(' Object #' . ($rowCount + 1));
22872  
22873 INNER: for (my $columnCount = 0; $columnCount < 14; $columnCount++) {
22874  
22875 $self->writeDebug(
22876 ' Column ' . $columnCount . ' ' . $columnList[$columnCount],
22877 );
22878  
22879 if (defined $thingArray[$columnCount][$rowCount]) {
22880 $self->writeDebug(' ' . $thingArray[$columnCount][$rowCount]);
22881 } else {
22882 $self->writeDebug(' <undef>');
22883 }
22884 }
22885 }
22886  
22887 $self->writeDebug('WORLD MODEL: End of object parsing messages');
22888 }
22889  
22890 # Process each thing in $thingArray
22891 OUTER: for (my $count = 0; $count < $thingCount; $count++) {
22892  
22893 my ($total, $obj);
22894  
22895 # Don't create a non-model object for an unparsable thing
22896 if ($thingArray[5][$count] eq '(unparsed object)') {
22897  
22898 next OUTER;
22899 }
22900  
22901 # Each entry represents at least 1 object, even it its number is 0.5, 0.33 or -1
22902 $total = $thingArray[2][$count];
22903 if ($total < 2) {
22904  
22905 $total = 1;
22906 }
22907  
22908 # Sanity check - in case some idiot creates a room with "999999999 hobbits", limit
22909 # the number of world model objects to be created
22910 if ($total > $axmud::CLIENT->constParseObjMax) {
22911  
22912 $total = $axmud::CLIENT->constParseObjMax;
22913 }
22914  
22915 if ($total > 1 && $multipleFlag) {
22916  
22917 # Create a single object to represent '5 coins' or 'five coins'
22918 $obj = $self->createParsedObj($session, TRUE, \@thingArray, $count);
22919 if ($obj) {
22920  
22921 push (@returnArray, $obj);
22922 }
22923  
22924 } else {
22925  
22926 # If $total is 1, create a single object. Otherwise, create multiple objects,
22927 # e.g. create five objects for '5 axes'
22928 OUTER: for (my $number = 0; $number < $total; $number++) {
22929  
22930 $obj = $self->createParsedObj($session, FALSE, \@thingArray, $count);
22931 if ($obj) {
22932  
22933 push (@returnArray, $obj);
22934 }
22935 }
22936 }
22937 }
22938  
22939 # Parsing complete
22940 return @returnArray;
22941 }
22942  
22943 sub createParsedObj {
22944  
22945 # Called by $self->parseObj once for every non-model object to be created
22946 #
22947 # Expected arguments
22948 # $session - The parent GA::Session object
22949 # $multipleFlag - If flag is set to TRUE, treats '5 coins' as a single object, with its
22950 # ->multiple IV set to 5. If the flag is set to FALSE, treats '5
22951 # coins' as 5 seperate objects
22952 # $arrayRef - The 2D array containing information about objects in the world
22953 # collected during parsing
22954 # $count - The object in $arrayRef that's being processed. If $count = 3, then
22955 # we're processing the data in $$arrayRef[3][n]
22956 #
22957 # Return values
22958 # 'undef' on improper errors or if a non-model object isn't created
22959 # Otherwise returns the blessed reference of the object
22960  
22961 my ($self, $session, $multipleFlag, $arrayRef, $count, $check) = @_;
22962  
22963 # Local variables
22964 my (
22965 $dictObj, $obj, $deathFlag, $package,
22966 @wordList, @guildRaceList,
22967 %deathWordHash,
22968 );
22969  
22970 # Check for improper arguments
22971 if (
22972 ! defined $session || ! defined $multipleFlag || ! defined $arrayRef
22973 || ! defined $count || defined $check
22974 ) {
22975 return $axmud::CLIENT->writeImproper($self->_objClass . '->createParsedObj', @_);
22976 }
22977  
22978 # Import the current dictionary
22979 $dictObj = $session->currentDict;
22980  
22981 # For objects whose nouns are a known 'race' or 'guild' word, classify the object as a
22982 # 'sentient' (since 'sentient' has a higher priority, a word which is both a known
22983 # 'sentient' word and a known 'guild'/'race' word will already have been classified as a
22984 # 'sentient' object)
22985 # For known characters, if there's already a GA::ModelObj::Char, use that; otherwise, create
22986 # one
22987 if (defined $$arrayRef[7][$count] && $$arrayRef[7][$count] eq 'char') {
22988  
22989 if ($self->ivExists('knownCharHash', $$arrayRef[5][$count])) {
22990  
22991 # Use the existing object
22992 $obj = $self->ivShow('knownCharHash', $$arrayRef[5][$count])
22993  
22994 } else {
22995  
22996 # Create a new object temporarily, but don't save it in $self->knownCharHash
22997 $obj = Games::Axmud::ModelObj::Char->new(
22998 $session,
22999 $$arrayRef[5][$count], # Name
23000 FALSE, # Non-model object
23001 );
23002  
23003 if (! $obj) {
23004  
23005 # Couldn't create the non-model object
23006 return undef;
23007 }
23008 }
23009 }
23010  
23011 # For everything else...
23012 if (! $obj) {
23013  
23014 # Import the hash of death words
23015 %deathWordHash = $dictObj->deathWordHash;
23016  
23017 # Check all of the describing words (nouns, adjectives and unknowns); if any of them are
23018 # in the dictionary's deathlist, then this object is a corpse
23019 # Split [1][n] into words, so we can check each seperately
23020 @wordList = split(/\s+/, $$arrayRef[1][$count]);
23021 OUTER: foreach my $word (@wordList) {
23022  
23023 if (exists $deathWordHash{$word}) {
23024  
23025 # Death word found!
23026 $deathFlag = TRUE;
23027 last OUTER;
23028 }
23029 }
23030  
23031 # For dead things, classify it as a portable corpse
23032 if ($deathFlag) {
23033  
23034 # Dead minions are not GA::ModelObj::Minion objects!
23035 if (defined $$arrayRef[7][$count] && $$arrayRef[7][$count] eq 'minion') {
23036  
23037 $$arrayRef[12][$count] = undef;
23038 $$arrayRef[13][$count] = undef;
23039 }
23040  
23041 $$arrayRef[7][$count] = 'portable';
23042 $$arrayRef[8][$count] = 'corpse';
23043  
23044 # For unrecognised nouns (when [7][n] is 'undef'), classify them as 'decoration' for now
23045 } elsif (! defined $$arrayRef[7][$count] && ! $deathFlag) {
23046  
23047 $$arrayRef[7][$count] = 'decoration';
23048 $$arrayRef[8][$count] = 'other';
23049 }
23050  
23051 # Decide which package to use
23052 if ($$arrayRef[7][$count] eq 'guild' || $$arrayRef[7][$count] eq 'race') {
23053 $package = 'Games::Axmud::ModelObj::Sentient'; # Treat as a 'sentient'
23054 } else {
23055 $package = 'Games::Axmud::ModelObj::' . ucfirst($$arrayRef[7][$count]);
23056 }
23057  
23058 # Create the non-model object
23059 $obj = $package->new(
23060 $session,
23061 $$arrayRef[5][$count], # Name
23062 FALSE, # Non-model object
23063 );
23064  
23065 if (! $obj) {
23066  
23067 # Couldn't create the non-model object
23068 return undef;
23069 }
23070 }
23071  
23072 # Set the new object's IVs
23073  
23074 # Main noun
23075 $obj->ivPoke('noun', $$arrayRef[5][$count]);
23076 # (Default noun tag is the same as the main noun)
23077 $obj->ivPoke('nounTag', $$arrayRef[5][$count]);
23078  
23079 # Other nouns
23080 if (defined $$arrayRef[6][$count]) {
23081  
23082 @wordList = split(/\s+/, $$arrayRef[6][$count]);
23083 foreach my $word (@wordList) {
23084  
23085 $obj->ivPush('otherNounList', $word);
23086 }
23087 }
23088  
23089 # Adjective list
23090 if (defined $$arrayRef[9][$count]) {
23091  
23092 @wordList = split(/\s+/, $$arrayRef[9][$count]);
23093 foreach my $word (@wordList) {
23094  
23095 $obj->ivPush('adjList', $word);
23096 }
23097 }
23098  
23099 # Pseudo-adjective (modified)
23100 if (defined $$arrayRef[4][$count]) {
23101  
23102 $obj->ivPush('pseudoAdjList', $$arrayRef[4][$count]);
23103 }
23104  
23105 # Root adjective list
23106 if (defined $$arrayRef[11][$count]) {
23107  
23108 @wordList = split(/\s+/, $$arrayRef[11][$count]);
23109 foreach my $word (@wordList) {
23110  
23111 $obj->ivPush('rootAdjList', $word);
23112 }
23113 }
23114  
23115 # Unknown words
23116 if (defined $$arrayRef[10][$count]) {
23117  
23118 @wordList = split(/\s+/, $$arrayRef[10][$count]);
23119 foreach my $word (@wordList) {
23120  
23121 $obj->ivPush('unknownWordList', $word);
23122 }
23123 }
23124  
23125 # Minions
23126 if (defined $$arrayRef[12][$count]) {
23127  
23128 if ($$arrayRef[13][$count]) {
23129  
23130 $obj->ivPoke('ownMinionFlag', TRUE);
23131 }
23132 }
23133  
23134 # Set the multiple
23135 if ($multipleFlag) {
23136  
23137 # e.g. A single object represents '5 coins'
23138 $obj->ivPoke('multiple', $$arrayRef[2][$count]);
23139  
23140 } elsif ($$arrayRef[2][$count] > 1) {
23141  
23142 # e.g. One object is created for 'an axe', or five separate objects are created for
23143 # 'five axes'
23144 $obj->ivPoke('multiple', 1);
23145  
23146 } else {
23147  
23148 # When parsing 'half a cake', $$arrayRef[2][$count] is set to 0.5. Use that multiple
23149 # even though $multipleFlag isn't set
23150 $obj->ivPoke('multiple', $$arrayRef[2][$count]);
23151 }
23152  
23153 # Base string (e.g. 'big evil guards')
23154 $obj->ivPoke('baseString', $$arrayRef[1][$count]);
23155  
23156 # If it's a character, minion, sentient or creature object, we need to set those properties,
23157 # too
23158 if (
23159 $$arrayRef[7][$count] eq 'char' || $$arrayRef[7][$count] eq 'minion'
23160 || $$arrayRef[7][$count] eq 'sentient' || $$arrayRef[7][$count] eq 'creature'
23161 || $$arrayRef[7][$count] eq 'guild' # Treated as a 'sentient' object
23162 || $$arrayRef[7][$count] eq 'race' # Treated as a 'sentient' object
23163 ) {
23164 # Compile a list of words, any one of which might be a known guild or race word
23165  
23166 # Main noun
23167 @guildRaceList = ($$arrayRef[5][$count]);
23168  
23169 # Other nouns
23170 if (defined $$arrayRef[6][$count]) {
23171  
23172 push (@guildRaceList, split(/\s+/, $$arrayRef[6][$count]));
23173 }
23174  
23175 # Adjectives
23176 if (defined $$arrayRef[9][$count]) {
23177  
23178 push (@guildRaceList, split(/\s+/, $$arrayRef[9][$count]));
23179 }
23180  
23181 # Unknown words
23182 if (defined $$arrayRef[10][$count]) {
23183  
23184 push (@guildRaceList, split(/\s+/, $$arrayRef[10][$count]));
23185 }
23186  
23187 # Find the first word in @guildRaceList that's a known guild word, and use it
23188 OUTER: foreach my $word (@guildRaceList) {
23189  
23190 if ($dictObj->ivExists('guildHash', $word)) {
23191  
23192 $obj->ivPoke('guild', $word);
23193 last OUTER;
23194 }
23195 }
23196  
23197 # Find the first word in @guildRaceList that's a known race word, and use it
23198 OUTER: foreach my $word (@guildRaceList) {
23199  
23200 if ($dictObj->ivExists('raceHash', $word)) {
23201  
23202 $obj->ivPoke('race', $word);
23203 last OUTER;
23204 }
23205 }
23206 }
23207  
23208 # If it's a portable or decoration, we need to set its type
23209 if ($$arrayRef[7][$count] eq 'portable' || $$arrayRef[7][$count] eq 'decoration') {
23210  
23211 $obj->ivPoke('type', $$arrayRef[8][$count]);
23212 }
23213  
23214 # Object creation complete
23215 return $obj;
23216 }
23217  
23218 sub objCompare {
23219  
23220 # Can be called by anything to compare model objects (or non-model objects)
23221 #
23222 # Compares a $targetObj against a list of one or more possibly similar objects,
23223 # @compareList, to see whether $targetObj matches any of the objects in @compareList (i.e.
23224 # to see whether $targetObj seems to be the same object as an object in @compareList)
23225 # (If $targetObj is to be compared against a single object, then @compareList should contain
23226 # only one element)
23227 #
23228 # Assigns every object in @compareList a score from 0-100, with 0 representing totally
23229 # different objects and 100 representing absolutely identical objects
23230 # $sensitivity is also a number between 0-100. If anything in @compareList gets a score
23231 # equal to or greater than $sensitivity, we say that it matches $targetObj
23232 # We return the highest score of the first matching object, or 'undef' if no matching
23233 # objects are found
23234 # ->objCompare is very sensitive. If $targetObj has no adjectives, ->objCompare will assume
23235 # that a matching object also has no adjectives. For a less demanding comparison, use
23236 # $self->objMatch
23237 # Good values for $sensitivity are 70-80 (for a close match) or 90 (for a very close
23238 # match)
23239 #
23240 # Expected arguments
23241 # $sensitivity - A value between 0-100
23242 #
23243 # Optional arguments
23244 # $targetObj - Blessed reference of a model object (or non-model object). If 'undef',
23245 # no comparison takes place (but debug messages are displayed, if
23246 # allowed)
23247 # @compareList - List of objects against which to compare $targetObj. If an empty list,
23248 # no comparison takes place
23249 #
23250 # Return values
23251 # 'undef' on improper arguments or if nothing in @compareList matches $targetObj with a
23252 # high enough score
23253 # Otherwise, when the first match with a high enough score is found, returns the score
23254 # (which will be a value between 0-100, greater or equal to $sensitivity)
23255  
23256 my ($self, $sensitivity, $targetObj, @compareList) = @_;
23257  
23258 # Local variables
23259 my (@targetList, @otherList);
23260  
23261 # Check for improper arguments
23262 if (! defined $sensitivity) {
23263  
23264 return $axmud::CLIENT->writeImproper($self->_objClass . '->objCompare', @_);
23265 }
23266  
23267 # If no targets were specified, then there's nothing to compare
23268 if (! $targetObj || ! @compareList) {
23269  
23270 if ($axmud::CLIENT->debugCompareObjFlag) {
23271  
23272 $self->writeDebug('->objCompare');
23273 if (! $targetObj) {
23274 $self->writeDebug(' No target specified (code error?)');
23275 } elsif (! @compareList) {
23276 $self->writeDebug(' No comparison objects specified (code error?)');
23277 }
23278 }
23279  
23280 return undef;
23281 }
23282  
23283 OUTER: foreach my $compareObj (@compareList) {
23284  
23285 my $score;
23286  
23287 # Award points depending on matches between the two object's IVs
23288 $score = 0; # Points gained (out of 100)
23289  
23290 # Compare all possible nouns; if there are no nouns in common, the two objects can't
23291 # possibly be the same
23292 @targetList = ($targetObj->noun, $targetObj->otherNounList);
23293 @otherList = ($compareObj->noun, $compareObj->otherNounList);
23294 if (! $self->listCompare(\@targetList, \@otherList)) {
23295  
23296 # No nouns in common - objects must be different
23297 next OUTER;
23298 }
23299  
23300 # Check the main noun
23301 if ($targetObj->noun eq $compareObj->noun) {
23302  
23303 $score += 40;
23304 }
23305  
23306 # Check the other nouns
23307 @targetList = $targetObj->otherNounList;
23308 @otherList = $compareObj->otherNounList;
23309 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23310  
23311 # Check the adjectives
23312 @targetList = $targetObj->adjList;
23313 @otherList = $compareObj->adjList;
23314 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23315  
23316 # Check the pseudo-adjectives
23317 @targetList = $targetObj->pseudoAdjList;
23318 @otherList = $compareObj->pseudoAdjList;
23319 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23320  
23321 # Check the unknown word list
23322 @targetList = $targetObj->unknownWordList;
23323 @otherList = $compareObj->unknownWordList;
23324 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23325  
23326 # Don't need decimal places (and it ruins the confirmation message)
23327 $score = int($score);
23328  
23329 if ($axmud::CLIENT->debugCompareObjFlag) {
23330  
23331 $self->writeDebug('->objCompare');
23332 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23333 . $compareObj->noun . ', score ' . $score . ' (sensitivity ' . $sensitivity
23334 . ')',
23335 );
23336 }
23337  
23338 if ( $score >= $sensitivity) {
23339  
23340 # The two objects are close enough
23341 if ($axmud::CLIENT->debugCompareObjFlag) {
23342  
23343 $self->writeDebug(' Objects MATCH');
23344 }
23345  
23346 return $score;
23347 }
23348 }
23349  
23350 # None of the objects in @compareList match $targetObj at the specified sensitivity
23351 return undef;
23352 }
23353  
23354 sub objMatch {
23355  
23356 # Can be called by anything to compare model objects (or non-model objects)
23357 #
23358 # Compares a $targetObj against a list of one or more possibly similar objects,
23359 # @compareList, to see whether $targetObj matches any of the objects in @compareList (i.e.
23360 # to see whether $targetObj seems to be the same object as an object in @compareList)
23361 # (If $targetObj is to be compared against a single object, then @compareList should contain
23362 # only one element)
23363 #
23364 # Works much like $self->objCompare, except that this function is less demanding: it assumes
23365 # that objects in @compareList have incomplete IVs (e.g. perhaps having only their ->noun
23366 # IV set to something)
23367 # Only properties of objects in @compareList that have been set are checked against the IVs
23368 # in $targetObj
23369 # ->objCompare is more demanding - it expects that if $targetObj has no adjectives, the
23370 # things in @compareList will also have no adjectives
23371 #
23372 # Assigns every object in @compareList a score, which is then adjusted to create a
23373 # percentage score, with 0 representing totally different objects and 100 representing
23374 # objects that are complete matches
23375 # $sensitivity is also a number between 0-100. If anything in @compareList gets a score
23376 # equal to or greater than $sensitivity, we say that it matches $targetObj and return the
23377 # score. Otherwise, we return 'undef'
23378 # Good values for $sensitivity are 70-80 (for a close match) or 90 (for a very close
23379 # match).
23380 #
23381 # Expected arguments
23382 # $sensitivity - A value between 0-100
23383 # $targetObj - Blessed reference of a model object (or non-model object)
23384 #
23385 # Optional arguments
23386 # @compareList - List of objects against which to compare $targetObj (empty lists are
23387 # allowed)
23388 #
23389 # Return values
23390 # 'undef' on improper arguments or if nothing in @compareList matches $targetObj with a
23391 # high enough score
23392 # Otherwise, when the first match with a high enough score is found, returns the score
23393 # (which will be a value between 0-100, greater or equal to $sensitivity)
23394  
23395 my ($self, $sensitivity, $targetObj, @compareList) = @_;
23396  
23397 # Local variables
23398 my (@targetList, @otherList);
23399  
23400 # Check for improper arguments
23401 if (! defined $sensitivity || ! defined $targetObj) {
23402  
23403 return $axmud::CLIENT->writeImproper($self->_objClass . '->objMatch', @_);
23404 }
23405  
23406 # If @compareList is empty, then there's nothing to compare
23407 if (! @compareList) {
23408  
23409 return undef;
23410 }
23411  
23412 OUTER: foreach my $compareObj (@compareList) {
23413  
23414 my ($score, $maxScore, $percentage);
23415  
23416 # Award points depending on matches between the two object's IVs
23417 $score = 0; # Points gained
23418 $maxScore = 0; # Max points available (up to 100)
23419  
23420 # Compare all possible nouns; if there are no nouns in common, the two objects can't
23421 # possibly be the same
23422 @targetList = ($targetObj->noun, $targetObj->otherNounList);
23423 @otherList = ($compareObj->noun, $compareObj->otherNounList);
23424 if (! $self->listCompare(\@targetList, \@otherList)) {
23425  
23426 # No nouns in common - objects must be different
23427 next OUTER;
23428 }
23429  
23430 # Check the main noun (if $targetObj has one)
23431 if ($compareObj->noun && $targetObj->noun && $targetObj->noun eq $compareObj->noun) {
23432  
23433 $score += 40;
23434 $maxScore += 40;
23435 }
23436  
23437 # Check the other nouns (if $targetObj has any)
23438 if ($compareObj->otherNounList) {
23439  
23440 @targetList = $targetObj->otherNounList;
23441 @otherList = $compareObj->otherNounList;
23442 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23443 $maxScore += 15;
23444 }
23445  
23446 # Check the adjectives (if $targetObj has any)
23447 if ($compareObj->adjList) {
23448  
23449 @targetList = $targetObj->adjList;
23450 @otherList = $compareObj->adjList;
23451 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23452 $maxScore += 15;
23453 }
23454  
23455 # Check the pseudo-adjectives (if $targetObj has any)
23456 if ($compareObj->pseudoAdjList) {
23457  
23458 @targetList = $targetObj->pseudoAdjList;
23459 @otherList = $compareObj->pseudoAdjList;
23460 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23461 $maxScore += 15;
23462 }
23463  
23464 # Check the unknown word list (if $targetObj has any)
23465 if ($compareObj->unknownWordList) {
23466  
23467 @targetList = $targetObj->unknownWordList;
23468 @otherList = $compareObj->unknownWordList;
23469 $score += (15 * $self->listCompare(\@targetList, \@otherList));
23470 $maxScore += 15;
23471 }
23472  
23473 # We don't want to divide by zero...
23474 if (! $score) {
23475  
23476 if ($axmud::CLIENT->debugCompareObjFlag) {
23477  
23478 $self->writeDebug('->objMatch');
23479 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23480 . $compareObj->noun . ', score ' . $score . ' (sensitivity ' . $sensitivity
23481 . ')',
23482 );
23483 }
23484  
23485 next OUTER;
23486 }
23487  
23488 # Adjust $score so that it's a score out of 100
23489 $percentage = int(($score / $maxScore) * 100);
23490  
23491 if ($axmud::CLIENT->debugCompareObjFlag) {
23492  
23493 $self->writeDebug('->objMatch');
23494 $self->writeDebug(' Target: ' . $targetObj->noun . ', Comparison object: '
23495 . $compareObj->noun . ', score ' . $score . ', max score ' . $maxScore
23496 . ', percentage ' . $percentage . '% (sensitivity ' . $sensitivity . ')',
23497 );
23498 }
23499  
23500 if ( $percentage >= $sensitivity) {
23501  
23502 # The two objects are close enough
23503 if ($axmud::CLIENT->debugCompareObjFlag) {
23504  
23505 $self->writeDebug(' Objects MATCH');
23506 }
23507  
23508 return $percentage;
23509 }
23510 }
23511  
23512 # None of the objects in @compareList match $targetObj at the specified sensitivity
23513 return undef;
23514 }
23515  
23516 sub listCompare {
23517  
23518 # Called by $self->objCompare and $self->objMatch
23519 #
23520 # Calculates the intersection between two lists, and returns a value between 0 and 1
23521 # e.g. 0 means no common elements in the lists
23522 # e.g. 1 means the lists are identical
23523 # e.g. 0.5 would be the return value for the lists (fred, barney, wilma, betty) and
23524 # (fred, barney) (because 50% of the elements of the shorter list are present in the
23525 # longer one)
23526 # N.B. It doesn't matter which of the two lists is larger
23527 #
23528 # Expected arguments
23529 # targetListRef - Reference to an (anonymous) list, e.g. the adjectives describing a
23530 # non-model object
23531 # objectListRef - Reference to an (anonymous) list, e.g. the adjectives describing a
23532 # different non-model object
23533 #
23534 # Return values
23535 # 0 (not 'undef') on improper arguments
23536 # Otheriwse, retuns a decimal number between 0 and 1
23537  
23538 my ($self, $targetListRef, $objectListRef, $check) = @_;
23539  
23540 # Local variables
23541 my (
23542 @targetList, @objectList, @intersection,
23543 %grepHash,
23544 );
23545  
23546 # Check for improper arguments
23547 if (! defined $targetListRef || ! defined $objectListRef || defined $check) {
23548  
23549 $axmud::CLIENT->writeImproper($self->_objClass . '->listCompare', @_);
23550 return 0;
23551 }
23552  
23553 # De-reference the passed lists
23554 @targetList = @$targetListRef;
23555 @objectList = @$objectListRef;
23556  
23557 # Find the intersection between the two lists
23558 if (! @targetList && ! @objectList) {
23559  
23560 # Identical (empty) lists
23561 return 1;
23562  
23563 } elsif (@targetList && @objectList) {
23564  
23565 # Neither list is empty
23566 %grepHash = map{$_ =>1} @targetList;
23567 @intersection = grep( $grepHash{$_}, @objectList);
23568  
23569 if (@targetList > @objectList) {
23570  
23571 # Return percentage of elements in @objectList that also appear in @targetList
23572 return (scalar @intersection / @targetList);
23573  
23574 } else {
23575  
23576 # Return percentage of elements in @targetList that also appear in @objectList
23577 return (scalar @intersection / @objectList);
23578 }
23579  
23580 } else {
23581  
23582 # One of the lists is empty, so they are not at all alike
23583 return 0;
23584 }
23585 }
23586  
23587 sub compileRedrawRooms {
23588  
23589 # Called by several functions (e.g. called by ->moveRoomsLabels)
23590 # Given a list of rooms which must be redrawn, expand that list to include any connecting
23591 # rooms (which guarantees that the exits between them are redrawn correctly)
23592 # Returns a list in the form that GA::Win::Map->markObjs expects
23593 #
23594 # Expected arguments
23595 # (none besides $self)
23596 #
23597 # Optional arguments
23598 # @roomList - A list of room model objects (can be an empty list)
23599 #
23600 # Return values
23601 # An empty list on improper arguments or if @roomList is empty
23602 # Otherwise, returns the expanded list of rooms, in the form
23603 # (string, room_object, string, room_object...)
23604 # ...where 'string' is the literal string 'room', and 'room_object' is an affected room
23605 # object (GA::ModelObj::Room)
23606  
23607 my ($self, @roomList) = @_;
23608  
23609 # Local variables
23610 my (
23611 @returnList,
23612 %checkHash,
23613 );
23614  
23615 # (No improper arguments to check)
23616  
23617 # Compile a hash of specified rooms (to eliminate duplicates)
23618 foreach my $roomObj (@roomList) {
23619  
23620 $checkHash{$roomObj->number} = $roomObj;
23621 }
23622  
23623 # Add any connected rooms to that hash
23624 foreach my $roomObj (@roomList) {
23625  
23626 foreach my $exitNum (
23627 # Add rooms connected by outgoing exits
23628 $roomObj->ivValues('exitNumHash'),
23629 # Add rooms connected by incoming one-way, uncertain (etc) exits
23630 $roomObj->ivKeys('uncertainExitHash'),
23631 $roomObj->ivKeys('oneWayExitHash'),
23632 $roomObj->ivKeys('randomExitHash'),
23633 ) {
23634 my ($exitObj, $roomObj);
23635  
23636 $exitObj = $self->ivShow('exitModelHash', $exitNum);
23637 if ($exitObj) {
23638  
23639 $roomObj = $self->ivShow('modelHash', $exitObj->parent);
23640 if ($roomObj) {
23641  
23642 $checkHash{$roomObj->number} = $roomObj;
23643 }
23644 }
23645 }
23646  
23647 # Also add destination rooms for any involuntary/repulse exit patterns which specify a
23648 # destination
23649 foreach my $roomNum ($roomObj->ivKeys('invRepExitHash')) {
23650  
23651 my $roomObj = $self->ivShow('modelHash', $roomNum);
23652 if ($roomObj) {
23653  
23654 $checkHash{$roomObj->number} = $roomObj;
23655 }
23656 }
23657 }
23658  
23659 # Compose a list in the form (string, object, string, object...)
23660 foreach my $roomObj (values %checkHash) {
23661  
23662 push (@returnList, 'room', $roomObj);
23663 }
23664  
23665 # Operation complete
23666 return @returnList;
23667 }
23668  
23669 sub findObjNumber {
23670  
23671 # In a room filled with 'three hairy orcs, two ugly orcs and a dwarf', with corresponding
23672 # model objects stored in the Locator task's ->tempObjList IV as follows:
23673 #
23674 # object1 'hairy orc'
23675 # object2 'hairy orc'
23676 # object3 'hairy orc'
23677 # object4 'ugly orc'
23678 # object5 'ugly orc'
23679 # object6 'dwarf'
23680 #
23681 # ...this function works out the object's likely number on a world which numbers them
23682 # 'hairy orc 1', 'hairy orc2' or 'orc 1', ... 'orc 5'
23683 # This function is called with the blessed reference for one of these objects, $completeObj.
23684 # The function's task is to find how many of the objects occuring in the list up to and
23685 # including $completeObj match a partially-defined model object, $partialObj
23686 #
23687 # e.g. If $completeObj is object4, and if $partialObj is an 'orc', this function returns 4
23688 # If $completeObj is object4, and if $partialObj is an 'ugly orc', returns 1
23689 # If $completeObj does not appear in the Locator task's ->tempObjList, returns 'undef'
23690 #
23691 # Expected arguments
23692 # $session - The parent GA::Session
23693 # $completeObj - A real object in the Locator task's current room
23694 # $partialObj - A partially-defined matching object
23695 #
23696 # Return values
23697 # 'undef' on improper arguments, if $completeObj doesn't appear in the Locator task's
23698 # ->tempObjList or if the Locator task isn't running
23699 # Otherwise returns a number, 1 or above, matching the object's likely numbering on the
23700 # world
23701  
23702 my ($self, $session, $completeObj, $partialObj, $check) = @_;
23703  
23704 # Local variables
23705 my ($taskObj, $posn, $count, $number);
23706  
23707 # Check for improper arguments
23708 if (
23709 ! defined $session || ! defined $completeObj || ! defined $partialObj || defined $check
23710 ) {
23711 return $axmud::CLIENT->writeImproper($self->_objClass . '->findObjNumber', @_);
23712 }
23713  
23714 # Import the Locator task
23715 $taskObj = $session->locatorTask;
23716  
23717 # Check that there is a Locator task running and that $completeObj really is in the task's
23718 # current room
23719 if (! $taskObj || ! $taskObj->roomObj || ! $taskObj->roomObj->tempObjList) {
23720  
23721 return undef;
23722 }
23723  
23724 # Find $completeObj's position in the current room's object list
23725 $posn = $taskObj->roomObj->ivFind('tempObjList', $completeObj);
23726 if (! defined $posn) {
23727  
23728 # Not in the current room
23729 return undef;
23730  
23731 } elsif ($posn == 1) {
23732  
23733 # The world must number this object as #1
23734 return 1;
23735 }
23736  
23737 # Check every object in the list before $posn, to see how many match $partialObj
23738 $number = 1; # $completeObj matches $partialObj
23739 for (my $count = 0; $count < $posn; $count++) {
23740  
23741 if (
23742 $self->objMatch(
23743 100,
23744 $partialObj,
23745 $taskObj->roomObj->ivIndex('tempObjList', $count),
23746 )
23747 ) {
23748 $number++;
23749 }
23750 }
23751  
23752 return $number;
23753 }
23754  
23755 sub findRegionmap {
23756  
23757 # Can be called by anything
23758 # Given the ->number of a region model object (GA::ModelObj::Region), returns the equivalent
23759 # regionmap object (GA::Obj::Regionmap)
23760 #
23761 # Expected arguments
23762 # $number - The number of a region model object
23763 #
23764 # Return values
23765 # 'undef' on improper arguments or if no matching regionmap is found
23766 # Otherwise returns the matching GA::Obj::Regionmap
23767  
23768 my ($self, $number, $check) = @_;
23769  
23770 # Local variables
23771 my $regionObj;
23772  
23773 # Check for improper arguments
23774 if (! defined $number || defined $check) {
23775  
23776 return $axmud::CLIENT->writeImproper($self->_objClass . '->findRegionmap', @_);
23777 }
23778  
23779 $regionObj = $self->ivShow('regionModelHash', $number);
23780 if (! $regionObj) {
23781  
23782 return undef;
23783  
23784 } else {
23785  
23786 return $self->ivShow('regionmapHash', $regionObj->name);
23787 }
23788 }
23789  
23790 sub reversePath {
23791  
23792 # Attempts to convert a path, consisting of a list of directions, into the opposite path
23793 # To convert a single direction, pass a list containing just the direction
23794 # e.g. $pathList[0] = 'n' -> 's'
23795 # To convert a string consisting of several movement commands separated by the command
23796 # separator, pass a list containing just the string
23797 # e.g. $pathList[0] = 'n;nw;w;n;u' -> 'd;s;e;se;s'
23798 # To convert a list of directions, pass the list. The directions are converted into their
23799 # opposites and the list is returned in the opposite order
23800 # e.g. @pathList = ('n', 'nw', 'w') -> ('e', 'se', 's')
23801 # Only standard directions are converted into opposites. Other kinds of directions are left
23802 # alone, under the assumption that the same word is used for the exit in both directions
23803 # e.g. $pathList[0] = 'n;nw;closet;d' -> 'd;closet;se;s'
23804 # Standard secondary directions can have more than one opposite. Also, all the opposite
23805 # directions in the list can be converted to abbreviated forms, if required
23806 #
23807 # Expected arguments
23808 # $session - The calling GA::Session
23809 # $mode - 'no_abbrev' - do not abbreviate / if there is more than one opposite
23810 # direction, use the first one
23811 # - 'abbrev' - abbreviate / if there is more than one opposite direction, use
23812 # the first one
23813 # - 'no_abbrev_opp' - do not abbreviate / return all opposite directions
23814 # - 'abbrev_opp' - abbreviate / return all opposite directions
23815 # @pathList - a list of strings containing single directions or paths
23816 #
23817 # Notes
23818 # For $modes 'no_abbrev_opp' and 'abbrev_opp', the opposite directions are returned as a
23819 # string separated by a space, just as they occur in the dictionary
23820 # e.g. 'entrance' -> 'exit out'
23821 # In that case, it's up to the calling function to choose which direction to use
23822 #
23823 # Return values
23824 # An empty list on improper arguments (including if @pathList is empty or $mode isn't
23825 # a valid value)
23826 # Otherwise returns the reversed list of directions, as described above
23827  
23828 my ($self, $session, $mode, @pathList) = @_;
23829  
23830 # Local variables
23831 my (
23832 $cmdSep, $dictObj,
23833 @emptyList,
23834 );
23835  
23836 # Check for improper arguments
23837 if (
23838 ! defined $mode
23839 || (
23840 $mode ne 'no_abbrev' && $mode ne 'abbrev' && $mode ne 'no_abbrev_opp'
23841 && $mode ne 'abbrev_opp'
23842 )
23843 || ! @pathList
23844 ) {
23845 $axmud::CLIENT->writeImproper($self->_objClass . '->reversePath', @_);
23846 return @emptyList;
23847 }
23848  
23849 $cmdSep = $axmud::CLIENT->cmdSep;
23850 $dictObj = $session->currentDict;
23851  
23852 foreach my $path (@pathList) {
23853  
23854 my @dirList = split(/$cmdSep/, $path);
23855  
23856 foreach my $dir (@dirList) {
23857  
23858 # If it's a standard direction, convert it into the opposite standard direction. If
23859 # it's not a standard direction, don't change it
23860 if ($dictObj->ivExists('combDirHash', $dir)) {
23861  
23862 # Do not abbreviate
23863 if ($mode eq 'no_abbrev' || $mode eq 'no_abbrev_opp') {
23864  
23865 $dir = $dictObj->ivShow('combOppDirHash', $dir);
23866  
23867 # Abbreviate
23868 } elsif ($mode eq 'abbrev' || $mode eq 'abbrev_opp') {
23869  
23870 $dir = $dictObj->abbrevDir($dictObj->ivShow('combOppDirHash', $dir));
23871 }
23872  
23873 # If there is more than one opposite direction, use the first one
23874 if ($mode eq 'no_abbrev' || $mode eq 'abbrev') {
23875  
23876 my $position = index($dir, ' ');
23877 if ($position > -1) {
23878  
23879 $dir = substr($dir, ($position -1));
23880 }
23881 }
23882 }
23883 }
23884  
23885 @dirList = reverse @dirList;
23886 $path = join($cmdSep, @dirList);
23887 }
23888  
23889 @pathList = reverse @pathList;
23890 return (@pathList);
23891 }
23892  
23893 sub checkExitState {
23894  
23895 # Called by GA::Task::Locator->processExits (or by any other code)
23896 # On some worlds, the verbose list of exits indicates the state of an exit by surrounding
23897 # some (or all) exits with exit state strings, e.g. the brackets in
23898 # 'Obvious exits : north, (east), west'
23899 # Given a string containing a single exit (e.g. 'north' or '(east)'), this function removes
23900 # the exit state strings from the beginning, middle or end of each exit, if they occur,
23901 # and returns both the modified string and the corresponding exit state (one of the
23902 # possible values of GA::Obj::Exit->exitState, e.g. 'locked')
23903 #
23904 # Expected arguments
23905 # $profObj - The calling session's current world profile object
23906 # $exit - A string containing a single exit, optionally starting/ending or
23907 # containing exit state strings
23908 #
23909 # Return values
23910 # An empty list on improper arguments
23911 # Otherwise, returns a list in the form
23912 # (state, mod_exit)
23913 # ...where 'state' is one of the possible values of GA::Obj::Exit->exitState (e.g. 'open',
23914 # 'closed', impass'), and 'mod_exit' is the modified form of $exit, with all valid
23915 # exit state strings removed
23916  
23917 my ($self, $profObj, $exit, $check) = @_;
23918  
23919 # Local variables
23920 my (@emptyList, @stringList);
23921  
23922 # Check for improper arguments
23923 if (! defined $profObj || ! defined $exit || defined $check) {
23924  
23925 $axmud::CLIENT->writeImproper($self->_objClass . '->checkExitState', @_);
23926 return @emptyList,
23927 }
23928  
23929 @stringList = $profObj->exitStateStringList;
23930 if (@stringList) {
23931  
23932 do {
23933  
23934 my ($state, $start, $middle, $end, $result, $modExit);
23935  
23936 $state = shift @stringList;
23937 $start = shift @stringList;
23938 $middle = shift @stringList;
23939 $end = shift @stringList;
23940  
23941 # Test the exit for exit state strings, and remove them if found (e.g. remove the
23942 # brackets from '(east)'
23943 ($result, $modExit) = $self->testExitState(
23944 $exit,
23945 $start,
23946 $middle,
23947 $end,
23948 );
23949  
23950 if ($result) {
23951  
23952 return ($state, $modExit);
23953 }
23954  
23955 } until (! @stringList);
23956 }
23957  
23958 # Default exit state is 'normal' (exit is passable, or state not known)
23959 return ('normal', $exit);
23960 }
23961  
23962 sub testExitState {
23963  
23964 # Called by $self->checkExitState (only)
23965 # On some worlds, the verbose list of exits indicates the state of an exit by surrounding
23966 # some (or all) exits with exit state strings, e.g. the brackets in
23967 # 'Obvious exits : north, (east), west'
23968 # On some other worlds, the verbose list of exits indicates an exit state by surrounding
23969 # some characters at the beginning (usually just one character) with symbols, e.g.
23970 # 'Obvious exits : (n)orth, east, (w)est'
23971 # This function tests an exit string like 'north', '(north)' or '(n)orth' to see if it
23972 # contains a set of exit state strings, and then returns a list containing the result of
23973 # the test and a modified exit string, with the exit state strings removed if found
23974 #
23975 # Expected arguments
23976 # $exit - A string containing a single exit, optionally containing exit state
23977 # strings
23978 #
23979 # Optional arguments
23980 # $start - A string containing characters that should be found at the beginning of
23981 # $exit (an empty string, if nothing should be removed from the beginning)
23982 # $middle - A string containing characters that should be found in the middle of
23983 # $exit (or an empty string)
23984 # $end - A string containing characters that should be found at the end of $exit
23985 # (or an empty string)
23986 #
23987 # Return values
23988 # An empty list on improper arguments
23989 # Otherwise, returns a list in the form
23990 # (result, mod_exit)
23991 # ...where 'result' is TRUE if all the expected exit state strings are present (FALSE if
23992 # not) and where 'mod_exit' is the modified form of $exit, with all the exit state
23993 # strings removed
23994  
23995 my ($self, $exit, $start, $middle, $end, $check) = @_;
23996  
23997 # Local variables
23998 my (
23999 $modExit, $posn,
24000 @emptyList,
24001 );
24002  
24003 # Check for improper arguments
24004 if (
24005 ! defined $exit || ! defined $start || ! defined $middle || ! defined $end
24006 || defined $check
24007 ) {
24008 $axmud::CLIENT->writeImproper($self->_objClass . '->testExitState', @_);
24009 return @emptyList;
24010 }
24011  
24012 # Special case: if $start, $middle and $end are all empty strings, then no exit state is
24013 # detectable (and the exit's state will be set to 'normal'
24014 if (! $start && ! $middle && ! $end) {
24015  
24016 return (FALSE, $exit);
24017 }
24018  
24019 # $exit (e.g. 'north') has already been reduced to lower-case characters, so we must also
24020 # make sure that $start, $middle and $end are lower-case characters
24021 $start = lc($start);
24022 $middle = lc($middle);
24023 $end = lc($end);
24024  
24025 $modExit = $exit;
24026  
24027 if ($start) {
24028  
24029 if (index($modExit, $start) == 0) {
24030  
24031 # Remove the exit state string
24032 $modExit = substr($modExit, (length $start));
24033  
24034 } else {
24035  
24036 # Exit state strings not found. Return the exit string unmodified
24037 return (FALSE, $exit);
24038 }
24039 }
24040  
24041 # If $middle and $end are both non-empty strings, $middle must occur before $end. If only
24042 # $middle is set, it can occur in the middle or at the end. If only $end is set, it can
24043 # occur only at the end
24044 # Removing $middle before looking for $end accomplishes this
24045 if ($middle) {
24046  
24047 # (Second symbol can occur in middle or at end of $exit)
24048 $posn = index($modExit, $middle);
24049 if ($posn > -1) {
24050  
24051 substr($modExit, $posn, length($middle)) = '';
24052  
24053 } else {
24054  
24055 # Exit state strings not found. Return the exit string unmodified
24056 return (FALSE, $exit);
24057 }
24058 }
24059  
24060 if ($end) {
24061  
24062 $posn = index($modExit, $end);
24063 if ($posn > -1 && $posn == (length($modExit) - length($end))) {
24064  
24065 substr($modExit, $posn, length($end)) = '';
24066  
24067 } else {
24068  
24069 # Exit state strings not found. Return the exit string unmodified
24070 return (FALSE, $exit);
24071 }
24072 }
24073  
24074 # All expected exit state strings found
24075 return (TRUE, $modExit);
24076 }
24077  
24078 sub checkRoomAlignment {
24079  
24080 # Called by GA::Win::Map->moveSelectedObjects, $self->connectRegionBrokenExit and
24081 # $self->modifyIncomingExits
24082 # When an exit, which was formerly a region exit, is involved in a move operation, and when
24083 # that move places the exit's parent room and the destination room in the same regionmap,
24084 # it is probably now a broken exit
24085 # However, if (by chance) the two rooms are aligned along the direction of the exit, it's
24086 # not a broken exit but a normal one
24087 # In addition, we check whether there are any existing rooms in a direct line between the
24088 # two rooms. If any existing rooms are found, we consider that the two rooms aren't
24089 # aligned
24090 # NB Rooms are only considered to be aligned along the north-south, east-west,
24091 # northeast-southwest, northwest-southeast and up-down axes
24092 #
24093 # We also perform the same check in a 'connect to click' operation and when adding an exit
24094 # manually
24095 #
24096 # Expected arguments
24097 # $session - The calling function's GA::Session
24098 # $exitObj - The GA::Obj::Exit object to check
24099 #
24100 # Return values
24101 # 'undef' on improper arguments, if the exit is a retracing exit, if the two rooms aren't
24102 # aligned or if there are existing rooms between the exit's departure and arrival
24103 # rooms
24104 # 1 if the two rooms are aligned
24105  
24106 my ($self, $session, $exitObj, $check) = @_;
24107  
24108 # Local variables
24109 my (
24110 $departRoomObj, $arriveRoomObj, $regionmapObj, $mapDir, $listRef, $xPos, $yPos, $zPos,
24111 $xVector, $yVector, $zVector, $count,
24112 %vectorHash,
24113 );
24114  
24115 # Check for improper arguments
24116 if (! defined $session || ! defined $exitObj || defined $check) {
24117  
24118 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRoomAlignment', @_);
24119 }
24120  
24121 # Sanity check: we can't check for a room alignment if the exit's ->mapDir is not set (which
24122 # it won't be, if it's unallocatable)
24123 if (! $exitObj->mapDir) {
24124  
24125 return undef;
24126 }
24127  
24128 # Get a shortcut for the exit's ->mapDir
24129 $mapDir = $exitObj->mapDir;
24130 # We can check that ->mapDir isn't in a northnortheast direction (etc) by checking if its
24131 # length is greater than ten characters (e.g. northwest is only 9)
24132 if (length ($exitObj->mapDir) > 10) {
24133  
24134 # We don't consider that the rooms are aligned
24135 return undef;
24136 }
24137  
24138 # Get the blessed references of the exit's parent room and of the destination room
24139 $departRoomObj = $self->ivShow('modelHash', $exitObj->parent);
24140 $arriveRoomObj = $self->ivShow('modelHash', $exitObj->destRoom);
24141 # Get the regionmap to check
24142 $regionmapObj = $self->findRegionmap($departRoomObj->parent);
24143  
24144 # Import the vector hash, in the form
24145 # %vectorHash => {
24146 # north => [0, -1, 0],
24147 # northeast => [1, -1, 0],
24148 # east => [1, 0, 0],
24149 # southeast => [1, 1, 0],
24150 # south => [0, 1, 0],
24151 # southwest => [-1, 1, 0],
24152 # west => [-1, 0, 0],
24153 # northwest => [-1, -1, 0],
24154 # up => [0, 0, 1],
24155 # down => [0, 0, -1],
24156 # },
24157 # NB It also includes entries for northnorthwest, etc, but we're not using them
24158 %vectorHash = $session->mapWin->constVectorHash;
24159 $listRef = $vectorHash{$mapDir};
24160  
24161 # Check the general direction between the two rooms
24162 if (
24163 # Movement along x axis (west -> east)
24164 (($$listRef[0] == 0) && ($departRoomObj->xPosBlocks != $arriveRoomObj->xPosBlocks))
24165 || (($$listRef[0] == 1) && ($departRoomObj->xPosBlocks >= $arriveRoomObj->xPosBlocks))
24166 || (($$listRef[0] == -1) && ($departRoomObj->xPosBlocks <= $arriveRoomObj->xPosBlocks))
24167 # Movement along y axis (north -> south)
24168 || (($$listRef[1] == 0) && ($departRoomObj->yPosBlocks != $arriveRoomObj->yPosBlocks))
24169 || (($$listRef[1] == 1) && ($departRoomObj->yPosBlocks >= $arriveRoomObj->yPosBlocks))
24170 || (($$listRef[1] == -1) && ($departRoomObj->yPosBlocks <= $arriveRoomObj->yPosBlocks))
24171 # Movement along z axis (down > up)
24172 || (($$listRef[2] == 0) && ($departRoomObj->zPosBlocks != $arriveRoomObj->zPosBlocks))
24173 || (($$listRef[2] == 1) && ($departRoomObj->zPosBlocks >= $arriveRoomObj->zPosBlocks))
24174 || (($$listRef[2] == -1) && ($departRoomObj->zPosBlocks <= $arriveRoomObj->zPosBlocks))
24175 ) {
24176 # The rooms are not aligned
24177 return undef;
24178 }
24179  
24180 # Check that the path between the two rooms is in one of the ten primary directions checked
24181 # by this function
24182 $xVector = $arriveRoomObj->xPosBlocks - $departRoomObj->xPosBlocks;
24183 $yVector = $arriveRoomObj->yPosBlocks - $departRoomObj->yPosBlocks;
24184 $zVector = $arriveRoomObj->zPosBlocks - $departRoomObj->zPosBlocks;
24185  
24186 # Remove minus signs so we can test whether the magnitudes of $xVector and $yVector are
24187 # the same
24188 if ($xVector < 0) {$xVector *= -1};
24189 if ($yVector < 0) {$yVector *= -1};
24190  
24191 if (
24192 # ne, se, sw, nw
24193 ! (
24194 $$listRef[0] && $$listRef[1] && (! $$listRef[2])
24195 && $xVector && $yVector && (! $zVector) && $xVector == $yVector
24196 )
24197 # n, s
24198 && ! (
24199 (! $$listRef[0]) && $$listRef[1] && (! $$listRef[2])
24200 && (! $xVector) && $yVector && (! $zVector)
24201 )
24202 # w, e
24203 && ! (
24204 $$listRef[0] && (! $$listRef[1]) && (! $$listRef[2])
24205 && $xVector && (! $yVector) && (! $zVector)
24206 )
24207 # u, d
24208 && ! (
24209 (! $$listRef[0]) && (! $$listRef[1]) && $$listRef[2]
24210 && (! $xVector) && (! $yVector) && $zVector
24211 )
24212 ) {
24213 # The rooms are not aligned
24214 return undef;
24215 }
24216  
24217 # Check that there are no existing rooms in between $departRoomObj and $arriveRoomObj that
24218 # would clash with the drawn exit
24219 $xPos = $departRoomObj->xPosBlocks;
24220 $yPos = $departRoomObj->yPosBlocks;
24221 $zPos = $departRoomObj->zPosBlocks;
24222 $count = 0;
24223 do {
24224  
24225 $count++;
24226  
24227 # Check the next gridblock on the flightpath between $departRoomObj and
24228 # $arriveRoomObj
24229 $xPos += $$listRef[0];
24230 $yPos += $$listRef[1];
24231 $zPos += $$listRef[2];
24232  
24233 if (
24234 $xPos == $arriveRoomObj->xPosBlocks
24235 && $yPos == $arriveRoomObj->yPosBlocks
24236 && $zPos == $arriveRoomObj->zPosBlocks
24237 ) {
24238 # We've checked every gridblock between the two rooms, and found no existing
24239 # rooms on the way. In addition, the rooms are aligned in the direction
24240 # drawn as $mapDir
24241 return 1;
24242  
24243 } else {
24244  
24245 # If there's a room in this gridblock, return 0 to show that the exit can't
24246 # be drawn here, and that it must therefore be marked as a broken exit
24247 if ($regionmapObj->fetchRoom($xPos, $yPos, $zPos)) {
24248  
24249 return undef;
24250 }
24251 }
24252  
24253 # Don't bother looking beyond the maximum drawn exit size (currently 16)
24254 } until ($count >= $self->maxExitLengthBlocks);
24255  
24256 return 1;
24257 }
24258  
24259 ##################
24260 # Accessors - set
24261  
24262 # Definitely keep
24263  
24264 sub set_adjacentMode {
24265  
24266 my ($self, $mode, $count, $check) = @_;
24267  
24268 # Check for improper arguments
24269 if (! defined $mode || defined $check) {
24270  
24271 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_adjacentMode', @_);
24272 }
24273  
24274 # Update IVs
24275 $self->ivPoke('adjacentMode', $mode);
24276 if (defined $count) {
24277  
24278 $self->ivPoke('adjacentCount', $count);
24279 }
24280  
24281 return 1;
24282 }
24283  
24284 sub set_autoCompareMax {
24285  
24286 my ($self, $number, $check) = @_;
24287  
24288 # Check for improper arguments
24289 if (! defined $number || defined $check) {
24290  
24291 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoCompareMax', @_);
24292 }
24293  
24294 # Update IVs
24295 $self->ivPoke('autoCompareMax', $number);
24296  
24297 return 1;
24298 }
24299  
24300 sub set_autoSlideMax {
24301  
24302 my ($self, $number, $check) = @_;
24303  
24304 # Check for improper arguments
24305 if (! defined $number || defined $check) {
24306  
24307 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoSlideMax', @_);
24308 }
24309  
24310 # Update IVs
24311 $self->ivPoke('autoSlideMax', $number);
24312  
24313 return 1;
24314 }
24315  
24316 sub set_autoOpenWinFlag {
24317  
24318 # Called by GA::Cmd::ToggleAutomapper->do
24319  
24320 my ($self, $flag, $check) = @_;
24321  
24322 # Check for improper arguments
24323 if (! defined $flag || defined $check) {
24324  
24325 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_autoOpenWinFlag', @_);
24326 }
24327  
24328 if ($flag) {
24329 $self->ivPoke('autoOpenWinFlag', TRUE);
24330 } else {
24331 $self->ivPoke('autoOpenWinFlag', FALSE);
24332 }
24333  
24334 # Also need to update the check button in every Automapper window
24335 foreach my $mapWin ($self->collectMapWins()) {
24336  
24337 $self->worldModelObj->toggleFlag(
24338 'autoOpenWinFlag',
24339 $self->autoOpenWinFlag,
24340 FALSE, # Don't call $mapWin->drawRegion
24341 'auto_open_win',
24342 );
24343 }
24344  
24345 return 1;
24346 }
24347  
24348 sub add_buttonSet {
24349  
24350 # Called by GA::Win::Map->addToolbar
24351  
24352 my ($self, $set, $check) = @_;
24353  
24354 # Check for improper arguments
24355 if (! defined $set || defined $check) {
24356  
24357 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_buttonSet', @_);
24358 }
24359  
24360 $self->ivPush('buttonSetList', $set);
24361  
24362 return 1;
24363 }
24364  
24365 sub del_buttonSet {
24366  
24367 # Called by GA::Win::Map->removeToolbar
24368  
24369 my ($self, $set, $check) = @_;
24370  
24371 # Local variables
24372 my @list;
24373  
24374 # Check for improper arguments
24375 if (! defined $set || defined $check) {
24376  
24377 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_buttonSet', @_);
24378 }
24379  
24380 foreach my $item ($self->buttonSetList) {
24381  
24382 if ($item ne $set) {
24383  
24384 push (@list, $item);
24385 }
24386 }
24387  
24388 $self->ivPoke('buttonSetList', @list);
24389  
24390 return 1;
24391 }
24392  
24393 sub set_buttonSetList {
24394  
24395 # Called by GA::Win::Map->enableToolbar
24396  
24397 my ($self, @list) = @_;
24398  
24399 # (No improper arguments to check)
24400  
24401 $self->ivPoke('buttonSetList', @list);
24402  
24403 return 1;
24404 }
24405  
24406 sub set_exitAltDir {
24407  
24408 my ($self, $exitObj, $string, $check) = @_;
24409  
24410 # Check for improper arguments
24411 if (! defined $exitObj || defined $check) {
24412  
24413 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_exitAltDir', @_);
24414 }
24415  
24416 $exitObj->ivPoke('altDir', $string);
24417  
24418 return 1;
24419 }
24420  
24421 sub add_preferRoomFlag {
24422  
24423 # Called by GA::Win::Map->addRoomFlagButton
24424  
24425 my ($self, $roomFlag, $check) = @_;
24426  
24427 # Check for improper arguments
24428 if (! defined $roomFlag || defined $check) {
24429  
24430 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_preferRoomFlag', @_);
24431 }
24432  
24433 # Don't add duplicate room flags. The calling code should take care of this, but we'll
24434 # check anyway
24435 foreach my $item ($self->preferRoomFlagList) {
24436  
24437 if ($item eq $roomFlag) {
24438  
24439 return undef;
24440 }
24441 }
24442  
24443 # Update the list
24444 $self->ivPush('preferRoomFlagList', $roomFlag);
24445  
24446 return 1;
24447 }
24448  
24449 sub del_preferRoomFlag {
24450  
24451 # Called by GA::Win::Map->addRoomFlagButton
24452  
24453 my ($self, $roomFlag, $check) = @_;
24454  
24455 # Local variables
24456 my @list;
24457  
24458 # Check for improper arguments
24459 if (! defined $roomFlag || defined $check) {
24460  
24461 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_preferRoomFlag', @_);
24462 }
24463  
24464 foreach my $item ($self->preferRoomFlagList) {
24465  
24466 if ($item ne $roomFlag) {
24467  
24468 push (@list, $item);
24469 }
24470 }
24471  
24472 $self->ivPoke('preferRoomFlagList', @list);
24473  
24474 return 1;
24475 }
24476  
24477 sub reset_preferRoomFlagList {
24478  
24479 # Called by GA::Win::Map->removeRoomFlagButton
24480  
24481 my ($self, $check) = @_;
24482  
24483 # Check for improper arguments
24484 if (defined $check) {
24485  
24486 return $axmud::CLIENT->writeImproper(
24487 $self->_objClass . '->reset_preferRoomFlagList',
24488 @_,
24489 );
24490 }
24491  
24492 $self->ivEmpty('preferRoomFlagList');
24493  
24494 return 1;
24495 }
24496  
24497 sub add_preferBGColour {
24498  
24499 # Called by GA::Win::Map->addBGColourButton
24500  
24501 my ($self, $colour, $check) = @_;
24502  
24503 # Check for improper arguments
24504 if (! defined $colour || defined $check) {
24505  
24506 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_preferBGColour', @_);
24507 }
24508  
24509 # Don't add duplicate colours
24510 foreach my $item ($self->preferBGColourList) {
24511  
24512 if ($item eq $colour) {
24513  
24514 return undef;
24515 }
24516 }
24517  
24518 # Update the list
24519 $self->ivPush('preferBGColourList', $colour);
24520  
24521 return 1;
24522 }
24523  
24524 sub del_preferBGColour {
24525  
24526 # Called by GA::Win::Map->removeBGColourButton
24527  
24528 my ($self, $colour, $check) = @_;
24529  
24530 # Local variables
24531 my @list;
24532  
24533 # Check for improper arguments
24534 if (! defined $colour || defined $check) {
24535  
24536 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_preferBGColour', @_);
24537 }
24538  
24539 foreach my $item ($self->preferBGColourList) {
24540  
24541 if ($item ne $colour) {
24542  
24543 push (@list, $item);
24544 }
24545 }
24546  
24547 $self->ivPoke('preferBGColourList', @list);
24548  
24549 return 1;
24550 }
24551  
24552 sub reset_preferBGColourList {
24553  
24554 # Called by GA::Win::Map->removeBGColourButton
24555  
24556 my ($self, $check) = @_;
24557  
24558 # Check for improper arguments
24559 if (defined $check) {
24560  
24561 return $axmud::CLIENT->writeImproper(
24562 $self->_objClass . '->reset_preferBGColourList',
24563 @_,
24564 );
24565 }
24566  
24567 $self->ivEmpty('preferBGColourList');
24568  
24569 return 1;
24570 }
24571  
24572 sub toggle_componentFlag {
24573  
24574 # Called by GA::Cmd::ToggleAutomapper->do
24575  
24576 my ($self, $iv, $check) = @_;
24577  
24578 # Check for improper arguments
24579 if (! defined $iv || defined $check) {
24580  
24581 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggle_componentFlag', @_);
24582 }
24583  
24584 # Toggle the flag
24585 if ($self->$iv) {
24586 $self->ivPoke($iv, FALSE);
24587 } else {
24588 $self->ivPoke($iv, TRUE);
24589 }
24590  
24591 # Also need to update the check button in every Automapper window
24592 $self->toggleWinComponents($iv, $self->$iv);
24593  
24594 return 1;
24595 }
24596  
24597 sub set_exitLengthBlocks {
24598  
24599 my ($self, $type, $length, $check) = @_;
24600  
24601 # Check for improper arguments
24602 if (! defined $type || ! defined $length || defined $check) {
24603  
24604 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_exitLengthBlocks', @_);
24605 }
24606  
24607 if ($type eq 'vertical') {
24608 $self->ivPoke('verticalExitLengthBlocks', $length);
24609 } else {
24610 $self->ivPoke('horizontalExitLengthBlocks', $length);
24611 }
24612  
24613 return 1;
24614 }
24615  
24616 sub set_obscuredExitRadius {
24617  
24618 my ($self, $radius, $check) = @_;
24619  
24620 # Check for improper arguments
24621 if (! defined $radius || defined $check) {
24622  
24623 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_obscuredExitRadius', @_);
24624 }
24625  
24626 $self->ivPoke('obscuredExitRadius', $radius);
24627  
24628 return 1;
24629 }
24630  
24631 sub set_lightStatus {
24632  
24633 # Called by GA::Cmd::SetLightStatus->do
24634  
24635 my ($self, $status, $check) = @_;
24636  
24637 # Check for improper arguments
24638 if (! defined $status || defined $check) {
24639  
24640 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_lightStatus', @_);
24641 }
24642  
24643 $self->ivPoke('lightStatus', $status);
24644  
24645 return 1;
24646 }
24647  
24648 sub set_lightStatusList {
24649  
24650 # Called by GA::Cmd::SetLightList->do
24651  
24652 my ($self, @list) = @_;
24653  
24654 # Check for improper arguments
24655 if (! @list) {
24656  
24657 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_lightStatusList', @_);
24658 }
24659  
24660 $self->ivPoke('lightStatusList', @list);
24661  
24662 return 1;
24663 }
24664  
24665 sub set_mapLabelStyle {
24666  
24667 # Called by GA::Win::Map->addLabelAtBlockCallback, ->addLabelAtClickCallback and
24668 # ->setLabelCallback
24669  
24670 my ($self, $style, $check) = @_;
24671  
24672 # Check for improper arguments
24673 if (! defined $style || defined $check) {
24674  
24675 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_mapLabelStyle', @_);
24676 }
24677  
24678 $self->ivPoke('mapLabelStyle', $style);
24679  
24680 return 1;
24681 }
24682  
24683 sub set_matchDescripCharCount {
24684  
24685 my ($self, $number, $check) = @_;
24686  
24687 # Check for improper arguments
24688 if (! defined $number || defined $check) {
24689  
24690 return $axmud::CLIENT->writeImproper(
24691 $self->_objClass . '->set_matchDescripCharCount',
24692 @_,
24693 );
24694 }
24695  
24696 # Update IVs
24697 $self->ivPoke('matchDescripCharCount', $number);
24698  
24699 return 1;
24700 }
24701  
24702 sub set_minionStringHash {
24703  
24704 # Called by GA::Cmd::DeleteMinionString->do
24705  
24706 my ($self, %hash) = @_;
24707  
24708 # (No improper arguments to check)
24709  
24710 $self->ivPoke('minionStringHash', %hash);
24711  
24712 return 1;
24713 }
24714  
24715 sub set_paintAllRoomsFlag {
24716  
24717 my ($self, $flag, $check) = @_;
24718  
24719 # Check for improper arguments
24720 if (! defined $flag || defined $check) {
24721  
24722 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_paintAllRoomsFlag', @_);
24723 }
24724  
24725 if ($flag) {
24726 $self->ivPoke('paintAllRoomsFlag', TRUE);
24727 } else {
24728 $self->ivPoke('paintAllRoomsFlag', FALSE);
24729 }
24730  
24731 return 1;
24732 }
24733  
24734 sub set_preDrawMinRooms {
24735  
24736 my ($self, $number, $check) = @_;
24737  
24738 # Check for improper arguments
24739 if (! defined $number || defined $check) {
24740  
24741 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawMinRooms', @_);
24742 }
24743  
24744 # Update IVs
24745 $self->ivPoke('preDrawMinRooms', $number);
24746  
24747 return 1;
24748 }
24749  
24750 sub set_quickPaintMultiFlag {
24751  
24752 my ($self, $flag, $check) = @_;
24753  
24754 # Check for improper arguments
24755 if (! defined $flag || defined $check) {
24756  
24757 return $axmud::CLIENT->writeImproper(
24758 $self->_objClass . '->set_quickPaintMultiFlag',
24759 @_,
24760 );
24761 }
24762  
24763 if ($flag) {
24764 $self->ivPoke('quickPaintMultiFlag', TRUE);
24765 } else {
24766 $self->ivPoke('quickPaintMultiFlag', FALSE);
24767 }
24768  
24769 return 1;
24770 }
24771  
24772 sub set_preDrawAllocation {
24773  
24774 my ($self, $number, $check) = @_;
24775  
24776 # Check for improper arguments
24777 if (! defined $number || defined $check) {
24778  
24779 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawAllocation', @_);
24780 }
24781  
24782 # Update IVs
24783 $self->ivPoke('preDrawAllocation', $number);
24784  
24785 return 1;
24786 }
24787  
24788 sub set_preDrawRetainRooms {
24789  
24790 my ($self, $number, $check) = @_;
24791  
24792 # Check for improper arguments
24793 if (! defined $number || defined $check) {
24794  
24795 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_preDrawRetainRooms', @_);
24796 }
24797  
24798 # Update IVs
24799 $self->ivPoke('preDrawRetainRooms', $number);
24800  
24801 return 1;
24802 }
24803  
24804 sub set_roomFlagShowMode {
24805  
24806 my ($self, $mode, $check) = @_;
24807  
24808 # Check for improper arguments
24809 if (! defined $mode || defined $check) {
24810  
24811 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_roomFlagShowMode', @_);
24812 }
24813  
24814 # Update IVs
24815 $self->ivPoke('roomFlagShowMode', $mode);
24816  
24817 # Must redraw the menu in any automapper windows, so that the new room flag appears in them
24818 $self->updateMapMenuToolbars();
24819  
24820 return 1;
24821 }
24822  
24823 sub set_searchSelectRoomsFlag {
24824  
24825 my ($self, $flag, $check) = @_;
24826  
24827 # Check for improper arguments
24828 if (! defined $flag || defined $check) {
24829  
24830 return $axmud::CLIENT->writeImproper(
24831 $self->_objClass . '->set_searchSelectRoomsFlag',
24832 @_,
24833 );
24834 }
24835  
24836 if ($flag) {
24837 $self->ivPoke('searchSelectRoomsFlag', TRUE);
24838 } else {
24839 $self->ivPoke('searchSelectRoomsFlag', FALSE);
24840 }
24841  
24842 return 1;
24843 }
24844  
24845 sub set_showCanvasFlag {
24846  
24847 my ($self, $flag, $check) = @_;
24848  
24849 # Check for improper arguments
24850 if (! defined $flag || defined $check) {
24851  
24852 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showCanvasFlag', @_);
24853 }
24854  
24855 if ($flag) {
24856 $self->ivPoke('showCanvasFlag', TRUE);
24857 } else {
24858 $self->ivPoke('showCanvasFlag', FALSE);
24859 }
24860  
24861 return 1;
24862 }
24863  
24864 sub set_showMenuBarFlag {
24865  
24866 my ($self, $flag, $check) = @_;
24867  
24868 # Check for improper arguments
24869 if (! defined $flag || defined $check) {
24870  
24871 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showMenuBarFlag', @_);
24872 }
24873  
24874 if ($flag) {
24875 $self->ivPoke('showMenuBarFlag', TRUE);
24876 } else {
24877 $self->ivPoke('showMenuBarFlag', FALSE);
24878 }
24879  
24880 return 1;
24881 }
24882  
24883 sub set_showToolbarFlag {
24884  
24885 my ($self, $flag, $check) = @_;
24886  
24887 # Check for improper arguments
24888 if (! defined $flag || defined $check) {
24889  
24890 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showToolbarFlag', @_);
24891 }
24892  
24893 if ($flag) {
24894 $self->ivPoke('showToolbarFlag', TRUE);
24895 } else {
24896 $self->ivPoke('showToolbarFlag', FALSE);
24897 }
24898  
24899 return 1;
24900 }
24901  
24902 sub set_showTreeViewFlag {
24903  
24904 my ($self, $flag, $check) = @_;
24905  
24906 # Check for improper arguments
24907 if (! defined $flag || defined $check) {
24908  
24909 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_showTreeViewFlag', @_);
24910 }
24911  
24912 if ($flag) {
24913 $self->ivPoke('showTreeViewFlag', TRUE);
24914 } else {
24915 $self->ivPoke('showTreeViewFlag', FALSE);
24916 }
24917  
24918 return 1;
24919 }
24920  
24921 sub add_teleport {
24922  
24923 # Called by GA::Cmd::AddTeleport
24924  
24925 my ($self, $room, $cmd, $check) = @_;
24926  
24927 # Check for improper arguments
24928 if (! defined $room || ! defined $cmd || defined $check) {
24929  
24930 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_teleport', @_);
24931 }
24932  
24933 $self->ivAdd('teleportHash', $room, $cmd);
24934  
24935 return 1;
24936 }
24937  
24938 sub del_teleport {
24939  
24940 # Called by GA::Cmd::DeleteTeleport
24941  
24942 my ($self, $room, $check) = @_;
24943  
24944 # Check for improper arguments
24945 if (! defined $room || defined $check) {
24946  
24947 return $axmud::CLIENT->writeImproper($self->_objClass . '->del_teleport', @_);
24948 }
24949  
24950 $self->ivDelete('teleportHash', $room);
24951  
24952 return 1;
24953 }
24954  
24955 ##################
24956 # Accessors - get
24957  
24958 sub author
24959 { $_[0]->{author} }
24960 sub date
24961 { $_[0]->{date} }
24962 sub version
24963 { $_[0]->{version} }
24964 sub descripList
24965 { my $self = shift; return @{$self->{descripList}}; }
24966  
24967 sub modelCreationDate
24968 { $_[0]->{modelCreationDate} }
24969 sub modelCreationVersion
24970 { $_[0]->{modelCreationVersion} }
24971 sub modelConvertedFlag
24972 { $_[0]->{modelConvertedFlag} }
24973 sub modelConvertedVersion
24974 { $_[0]->{modelConvertedVersion} }
24975 sub modelSaveFileCount
24976 { $_[0]->{modelSaveFileCount} }
24977  
24978 sub modelHash
24979 { my $self = shift; return %{$self->{modelHash}}; }
24980 sub regionModelHash
24981 { my $self = shift; return %{$self->{regionModelHash}}; }
24982 sub roomModelHash
24983 { my $self = shift; return %{$self->{roomModelHash}}; }
24984 sub weaponModelHash
24985 { my $self = shift; return %{$self->{weaponModelHash}}; }
24986 sub armourModelHash
24987 { my $self = shift; return %{$self->{armourModelHash}}; }
24988 sub garmentModelHash
24989 { my $self = shift; return %{$self->{garmentModelHash}}; }
24990 sub charModelHash
24991 { my $self = shift; return %{$self->{charModelHash}}; }
24992 sub minionModelHash
24993 { my $self = shift; return %{$self->{minionModelHash}}; }
24994 sub sentientModelHash
24995 { my $self = shift; return %{$self->{sentientModelHash}}; }
24996 sub creatureModelHash
24997 { my $self = shift; return %{$self->{creatureModelHash}}; }
24998 sub portableModelHash
24999 { my $self = shift; return %{$self->{portableModelHash}}; }
25000 sub decorationModelHash
25001 { my $self = shift; return %{$self->{decorationModelHash}}; }
25002 sub customModelHash
25003 { my $self = shift; return %{$self->{customModelHash}}; }
25004  
25005 sub modelObjCount
25006 { $_[0]->{modelObjCount} }
25007 sub modelActualCount
25008 { $_[0]->{modelActualCount} }
25009 sub modelDeletedList
25010 { my $self = shift; return @{$self->{modelDeletedList}}; }
25011 sub modelBufferList
25012 { my $self = shift; return @{$self->{modelBufferList}}; }
25013 sub mostRecentNum
25014 { $_[0]->{mostRecentNum} }
25015  
25016 sub exitModelHash
25017 { my $self = shift; return %{$self->{exitModelHash}}; }
25018 sub exitObjCount
25019 { $_[0]->{exitObjCount} }
25020 sub exitActualCount
25021 { $_[0]->{exitActualCount} }
25022 sub exitDeletedList
25023 { my $self = shift; return @{$self->{exitDeletedList}}; }
25024 sub exitBufferList
25025 { my $self = shift; return @{$self->{exitBufferList}}; }
25026 sub mostRecentExitNum
25027 { $_[0]->{mostRecentExitNum} }
25028  
25029 sub regionmapHash
25030 { my $self = shift; return %{$self->{regionmapHash}}; }
25031 sub reverseRegionListFlag
25032 { $_[0]->{reverseRegionListFlag} }
25033 sub firstRegion
25034 { $_[0]->{firstRegion} }
25035  
25036 sub preDrawAllowFlag
25037 { $_[0]->{preDrawAllowFlag} }
25038 sub preDrawMinRooms
25039 { $_[0]->{preDrawMinRooms} }
25040 sub preDrawRetainRooms
25041 { $_[0]->{preDrawRetainRooms} }
25042 sub preDrawAllocation
25043 { $_[0]->{preDrawAllocation} }
25044  
25045 sub knownCharHash
25046 { my $self = shift; return %{$self->{knownCharHash}}; }
25047 sub minionStringHash
25048 { my $self = shift; return %{$self->{minionStringHash}}; }
25049  
25050 sub lightStatus
25051 { $_[0]->{lightStatus} }
25052 sub constLightStatusList
25053 { my $self = shift; return @{$self->{constLightStatusList}}; }
25054 sub lightStatusList
25055 { my $self = shift; return @{$self->{lightStatusList}}; }
25056  
25057 sub roomTagHash
25058 { my $self = shift; return %{$self->{roomTagHash}}; }
25059  
25060 sub teleportHash
25061 { my $self = shift; return %{$self->{teleportHash}}; }
25062  
25063 sub autoOpenWinFlag
25064 { $_[0]->{autoOpenWinFlag} }
25065 sub pseudoWinFlag
25066 { $_[0]->{pseudoWinFlag} }
25067 sub showMenuBarFlag
25068 { $_[0]->{showMenuBarFlag} }
25069 sub showToolbarFlag
25070 { $_[0]->{showToolbarFlag} }
25071 sub showTreeViewFlag
25072 { $_[0]->{showTreeViewFlag} }
25073 sub showCanvasFlag
25074 { $_[0]->{showCanvasFlag} }
25075 sub buttonSetList
25076 { my $self = shift; return @{$self->{buttonSetList}}; }
25077 sub preferRoomFlagList
25078 { my $self = shift; return @{$self->{preferRoomFlagList}}; }
25079 sub preferBGColourList
25080 { my $self = shift; return @{$self->{preferBGColourList}}; }
25081  
25082 sub defaultGridWidthBlocks
25083 { $_[0]->{defaultGridWidthBlocks} }
25084 sub defaultGridHeightBlocks
25085 { $_[0]->{defaultGridHeightBlocks} }
25086 sub defaultBlockWidthPixels
25087 { $_[0]->{defaultBlockWidthPixels} }
25088 sub defaultBlockHeightPixels
25089 { $_[0]->{defaultBlockHeightPixels} }
25090 sub defaultRoomWidthPixels
25091 { $_[0]->{defaultRoomWidthPixels} }
25092 sub defaultRoomHeightPixels
25093 { $_[0]->{defaultRoomHeightPixels} }
25094  
25095 sub maxGridWidthBlocks
25096 { $_[0]->{maxGridWidthBlocks} }
25097 sub maxGridHeightBlocks
25098 { $_[0]->{maxGridHeightBlocks} }
25099 sub maxBlockWidthPixels
25100 { $_[0]->{maxBlockWidthPixels} }
25101 sub maxBlockHeightPixels
25102 { $_[0]->{maxBlockHeightPixels} }
25103 sub maxRoomWidthPixels
25104 { $_[0]->{maxRoomWidthPixels} }
25105 sub maxRoomHeightPixels
25106 { $_[0]->{maxRoomHeightPixels} }
25107  
25108 sub defaultMapWidthPixels
25109 { $_[0]->{defaultMapWidthPixels} }
25110 sub defaultMapHeightPixels
25111 { $_[0]->{defaultMapHeightPixels} }
25112  
25113 sub regionSchemeHash
25114 { my $self = shift; return %{$self->{regionSchemeHash}}; }
25115 sub defaultSchemeObj
25116 { $_[0]->{defaultSchemeObj} }
25117  
25118 sub defaultBackgroundColour
25119 { $_[0]->{defaultBackgroundColour} }
25120 sub defaultNoBackgroundColour
25121 { $_[0]->{defaultNoBackgroundColour} }
25122 sub defaultRoomColour
25123 { $_[0]->{defaultRoomColour} }
25124 sub defaultRoomTextColour
25125 { $_[0]->{defaultRoomTextColour} }
25126 sub defaultSelectBoxColour
25127 { $_[0]->{defaultSelectBoxColour} }
25128 sub defaultBorderColour
25129 { $_[0]->{defaultBorderColour} }
25130 sub defaultCurrentBorderColour
25131 { $_[0]->{defaultCurrentBorderColour} }
25132 sub defaultCurrentFollowBorderColour
25133 { $_[0]->{defaultCurrentFollowBorderColour} }
25134 sub defaultCurrentWaitBorderColour
25135 { $_[0]->{defaultCurrentWaitBorderColour} }
25136 sub defaultCurrentSelectBorderColour
25137 { $_[0]->{defaultCurrentSelectBorderColour} }
25138 sub defaultLostBorderColour
25139 { $_[0]->{defaultLostBorderColour} }
25140 sub defaultLostSelectBorderColour
25141 { $_[0]->{defaultLostSelectBorderColour} }
25142 sub defaultGhostBorderColour
25143 { $_[0]->{defaultGhostBorderColour} }
25144 sub defaultGhostSelectBorderColour
25145 { $_[0]->{defaultGhostSelectBorderColour} }
25146 sub defaultSelectBorderColour
25147 { $_[0]->{defaultSelectBorderColour} }
25148 sub defaultRoomAboveColour
25149 { $_[0]->{defaultRoomAboveColour} }
25150 sub defaultRoomBelowColour
25151 { $_[0]->{defaultRoomBelowColour} }
25152 sub defaultRoomTagColour
25153 { $_[0]->{defaultRoomTagColour} }
25154 sub defaultSelectRoomTagColour
25155 { $_[0]->{defaultSelectRoomTagColour} }
25156 sub defaultRoomGuildColour
25157 { $_[0]->{defaultRoomGuildColour} }
25158 sub defaultSelectRoomGuildColour
25159 { $_[0]->{defaultSelectRoomGuildColour} }
25160 sub defaultExitColour
25161 { $_[0]->{defaultExitColour} }
25162 sub defaultSelectExitColour
25163 { $_[0]->{defaultSelectExitColour} }
25164 sub defaultSelectExitTwinColour
25165 { $_[0]->{defaultSelectExitTwinColour} }
25166 sub defaultSelectExitShadowColour
25167 { $_[0]->{defaultSelectExitShadowColour} }
25168 sub defaultRandomExitColour
25169 { $_[0]->{defaultRandomExitColour} }
25170 sub defaultImpassableExitColour
25171 { $_[0]->{defaultImpassableExitColour} }
25172 sub defaultMysteryExitColour
25173 { $_[0]->{defaultMysteryExitColour} }
25174 sub defaultCheckedDirColour
25175 { $_[0]->{defaultCheckedDirColour} }
25176 sub defaultDragExitColour
25177 { $_[0]->{defaultDragExitColour} }
25178 sub defaultExitTagColour
25179 { $_[0]->{defaultExitTagColour} }
25180 sub defaultSelectExitTagColour
25181 { $_[0]->{defaultSelectExitTagColour} }
25182 sub defaultMapLabelColour
25183 { $_[0]->{defaultMapLabelColour} }
25184 sub defaultSelectMapLabelColour
25185 { $_[0]->{defaultSelectMapLabelColour} }
25186  
25187 sub mapLabelStyleHash
25188 { my $self = shift; return %{$self->{mapLabelStyleHash}}; }
25189 sub mapLabelStyle
25190 { $_[0]->{mapLabelStyle} }
25191 sub mapLabelAlignXFlag
25192 { $_[0]->{mapLabelAlignXFlag} }
25193 sub mapLabelAlignYFlag
25194 { $_[0]->{mapLabelAlignYFlag} }
25195 sub mapLabelTextViewFlag
25196 { $_[0]->{mapLabelTextViewFlag} }
25197  
25198 sub roomFilterApplyHash
25199 { my $self = shift; return %{$self->{roomFilterApplyHash}}; }
25200 sub roomFlagHash
25201 { my $self = shift; return %{$self->{roomFlagHash}}; }
25202 sub roomFlagOrderedList
25203 { my $self = shift; return @{$self->{roomFlagOrderedList}}; }
25204 sub allRoomFiltersFlag
25205 { $_[0]->{allRoomFiltersFlag} }
25206 sub roomFlagShowMode
25207 { $_[0]->{roomFlagShowMode} }
25208 sub roomTerrainInitHash
25209 { my $self = shift; return %{$self->{roomTerrainInitHash}}; }
25210 sub roomTerrainHash
25211 { my $self = shift; return %{$self->{roomTerrainHash}}; }
25212  
25213 sub paintFromTitleHash
25214 { my $self = shift; return %{$self->{paintFromTitleHash}}; }
25215 sub paintFromDescripHash
25216 { my $self = shift; return %{$self->{paintFromDescripHash}}; }
25217 sub paintFromExitHash
25218 { my $self = shift; return %{$self->{paintFromExitHash}}; }
25219 sub paintFromObjHash
25220 { my $self = shift; return %{$self->{paintFromObjHash}}; }
25221 sub paintFromRoomCmdHash
25222 { my $self = shift; return %{$self->{paintFromRoomCmdHash}}; }
25223  
25224 sub currentRoomMode
25225 { $_[0]->{currentRoomMode} }
25226 sub roomInteriorMode
25227 { $_[0]->{roomInteriorMode} }
25228 sub roomInteriorXOffset
25229 { $_[0]->{roomInteriorXOffset} }
25230 sub roomInteriorYOffset
25231 { $_[0]->{roomInteriorYOffset} }
25232  
25233 sub drawExitMode
25234 { $_[0]->{drawExitMode} }
25235 sub obscuredExitFlag
25236 { $_[0]->{obscuredExitFlag} }
25237 sub obscuredExitRedrawFlag
25238 { $_[0]->{obscuredExitRedrawFlag} }
25239 sub obscuredExitRadius
25240 { $_[0]->{obscuredExitRadius} }
25241 sub maxObscuredExitRadius
25242 { $_[0]->{maxObscuredExitRadius} }
25243 sub drawOrnamentsFlag
25244 { $_[0]->{drawOrnamentsFlag} }
25245 sub horizontalExitLengthBlocks
25246 { $_[0]->{horizontalExitLengthBlocks} }
25247 sub verticalExitLengthBlocks
25248 { $_[0]->{verticalExitLengthBlocks} }
25249 sub maxExitLengthBlocks
25250 { $_[0]->{maxExitLengthBlocks} }
25251 sub drawBentExitsFlag
25252 { $_[0]->{drawBentExitsFlag} }
25253  
25254 sub matchTitleFlag
25255 { $_[0]->{matchTitleFlag} }
25256 sub matchDescripFlag
25257 { $_[0]->{matchDescripFlag} }
25258 sub matchDescripCharCount
25259 { $_[0]->{matchDescripCharCount} }
25260 sub matchExitFlag
25261 { $_[0]->{matchExitFlag} }
25262 sub analyseDescripFlag
25263 { $_[0]->{analyseDescripFlag} }
25264 sub matchSourceFlag
25265 { $_[0]->{matchSourceFlag} }
25266 sub matchVNumFlag
25267 { $_[0]->{matchVNumFlag} }
25268  
25269 sub updateTitleFlag
25270 { $_[0]->{updateTitleFlag} }
25271 sub updateDescripFlag
25272 { $_[0]->{updateDescripFlag} }
25273 sub updateExitFlag
25274 { $_[0]->{updateExitFlag} }
25275 sub updateSourceFlag
25276 { $_[0]->{updateSourceFlag} }
25277 sub updateVNumFlag
25278 { $_[0]->{updateVNumFlag} }
25279 sub updateRoomCmdFlag
25280 { $_[0]->{updateRoomCmdFlag} }
25281 sub updateOrnamentFlag
25282 { $_[0]->{updateOrnamentFlag} }
25283  
25284 sub assistedMovesFlag
25285 { $_[0]->{assistedMovesFlag} }
25286 sub assistedBreakFlag
25287 { $_[0]->{assistedBreakFlag} }
25288 sub assistedPickFlag
25289 { $_[0]->{assistedPickFlag} }
25290 sub assistedUnlockFlag
25291 { $_[0]->{assistedUnlockFlag} }
25292 sub assistedOpenFlag
25293 { $_[0]->{assistedOpenFlag} }
25294 sub assistedCloseFlag
25295 { $_[0]->{assistedCloseFlag} }
25296 sub assistedLockFlag
25297 { $_[0]->{assistedLockFlag} }
25298 sub protectedMovesFlag
25299 { $_[0]->{protectedMovesFlag} }
25300 sub superProtectedMovesFlag
25301 { $_[0]->{superProtectedMovesFlag} }
25302 sub craftyMovesFlag
25303 { $_[0]->{craftyMovesFlag} }
25304  
25305 sub setTwinOrnamentFlag
25306 { $_[0]->{setTwinOrnamentFlag} }
25307  
25308 sub newRoomScriptList
25309 { my $self = shift; return @{$self->{newRoomScriptList}}; }
25310 sub arriveScriptList
25311 { my $self = shift; return @{$self->{arriveScriptList}}; }
25312  
25313 sub countVisitsFlag
25314 { $_[0]->{countVisitsFlag} }
25315 sub allowModelScriptFlag
25316 { $_[0]->{allowModelScriptFlag} }
25317 sub allowRoomScriptFlag
25318 { $_[0]->{allowRoomScriptFlag} }
25319 sub intelligentExitsFlag
25320 { $_[0]->{intelligentExitsFlag} }
25321 sub followAnchorFlag
25322 { $_[0]->{followAnchorFlag} }
25323 sub capitalisedRoomTagFlag
25324 { $_[0]->{capitalisedRoomTagFlag} }
25325 sub showTooltipsFlag
25326 { $_[0]->{showTooltipsFlag} }
25327 sub showNotesFlag
25328 { $_[0]->{showNotesFlag} }
25329 sub explainGetLostFlag
25330 { $_[0]->{explainGetLostFlag} }
25331 sub disableUpdateModeFlag
25332 { $_[0]->{disableUpdateModeFlag} }
25333 sub updateExitTagFlag
25334 { $_[0]->{updateExitTagFlag} }
25335 sub drawRoomEchoFlag
25336 { $_[0]->{drawRoomEchoFlag} }
25337 sub allowTrackAloneFlag
25338 { $_[0]->{allowTrackAloneFlag} }
25339 sub showAllPrimaryFlag
25340 { $_[0]->{showAllPrimaryFlag} }
25341 sub allowCtrlCopyFlag
25342 { $_[0]->{allowCtrlCopyFlag} }
25343  
25344 sub autoCompareMode
25345 { $_[0]->{autoCompareMode} }
25346 sub autoCompareAllFlag
25347 { $_[0]->{autoCompareAllFlag} }
25348 sub autoCompareMax
25349 { $_[0]->{autoCompareMax} }
25350 sub autoSlideMode
25351 { $_[0]->{autoSlideMode} }
25352 sub autoSlideMax
25353 { $_[0]->{autoSlideMax} }
25354 sub autoRescueFlag
25355 { $_[0]->{autoRescueFlag} }
25356 sub autoRescueFirstFlag
25357 { $_[0]->{autoRescueFirstFlag} }
25358 sub autoRescuePromptFlag
25359 { $_[0]->{autoRescuePromptFlag} }
25360 sub autoRescueNoMoveFlag
25361 { $_[0]->{autoRescueNoMoveFlag} }
25362 sub autoRescueVisitsFlag
25363 { $_[0]->{autoRescueVisitsFlag} }
25364 sub autoRescueForceFlag
25365 { $_[0]->{autoRescueForceFlag} }
25366  
25367 sub lastFilePath
25368 { $_[0]->{lastFilePath} }
25369 sub lastVirtualAreaPath
25370 { $_[0]->{lastVirtualAreaPath} }
25371 sub trackPosnFlag
25372 { $_[0]->{trackPosnFlag} }
25373 sub trackingSensitivity
25374 { $_[0]->{trackingSensitivity} }
25375 sub avoidHazardsFlag
25376 { $_[0]->{avoidHazardsFlag} }
25377 sub postProcessingFlag
25378 { $_[0]->{postProcessingFlag} }
25379 sub quickPathFindFlag
25380 { $_[0]->{quickPathFindFlag} }
25381 sub autocompleteExitsFlag
25382 { $_[0]->{autocompleteExitsFlag} }
25383 sub collectCheckedDirsFlag
25384 { $_[0]->{collectCheckedDirsFlag} }
25385 sub drawCheckedDirsFlag
25386 { $_[0]->{drawCheckedDirsFlag} }
25387 sub checkableDirMode
25388 { $_[0]->{checkableDirMode} }
25389  
25390 sub adjacentMode
25391 { $_[0]->{adjacentMode} }
25392 sub adjacentCount
25393 { $_[0]->{adjacentCount} }
25394 sub updateBoundaryHash
25395 { my $self = shift; return %{$self->{updateBoundaryHash}}; }
25396 sub deleteBoundaryHash
25397 { my $self = shift; return %{$self->{deleteBoundaryHash}}; }
25398 sub updatePathHash
25399 { my $self = shift; return %{$self->{updatePathHash}}; }
25400 sub updateDelayFlag
25401 { $_[0]->{updateDelayFlag} }
25402 sub checkLevelsHash
25403 { my $self = shift; return %{$self->{checkLevelsHash}}; }
25404  
25405 sub mudlibPath
25406 { $_[0]->{mudlibPath} }
25407 sub mudlibExtension
25408 { $_[0]->{mudlibExtension} }
25409  
25410 sub painterObj
25411 { $_[0]->{painterObj} }
25412 sub constPainterIVList
25413 { my $self = shift; return @{$self->{constPainterIVList}}; }
25414 sub paintAllRoomsFlag
25415 { $_[0]->{paintAllRoomsFlag} }
25416 sub quickPaintMultiFlag
25417 { $_[0]->{quickPaintMultiFlag} }
25418  
25419 sub searchMaxMatches
25420 { $_[0]->{searchMaxMatches} }
25421 sub searchMaxObjects
25422 { $_[0]->{searchMaxObjects} }
25423 sub searchSelectRoomsFlag
25424 { $_[0]->{searchSelectRoomsFlag} }
25425 sub locateMaxObjects
25426 { $_[0]->{locateMaxObjects} }
25427 sub locateRandomInRegionFlag
25428 { $_[0]->{locateRandomInRegionFlag} }
25429 sub locateRandomAnywhereFlag
25430 { $_[0]->{locateRandomAnywhereFlag} }
25431  
25432 sub pathFindStepLimit
25433 { $_[0]->{pathFindStepLimit} }
25434  
25435 sub drawPauseNum
25436 { $_[0]->{drawPauseNum} }
25437 sub recalculatePauseNum
25438 { $_[0]->{recalculatePauseNum} }
25439  
25440 sub mapFont
25441 { $_[0]->{mapFont} }
25442 sub roomTagRatio
25443 { $_[0]->{roomTagRatio} }
25444 sub roomGuildRatio
25445 { $_[0]->{roomGuildRatio} }
25446 sub exitTagRatio
25447 { $_[0]->{exitTagRatio} }
25448 sub labelRatio
25449 { $_[0]->{labelRatio} }
25450 sub roomTextRatio
25451 { $_[0]->{roomTextRatio} }
25452  
25453 sub blockUnselectFlag
25454 { $_[0]->{blockUnselectFlag} }
25455 }
25456  
25457 # Package must return a true value
25458 1