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

filter: Statementstmt 0.0% 0 / 412 Branchbran 0.0% 0 / 172 Conditioncond 0.0% 0 / 300 MC/DCmcdc 0.0% 0 / 155 Subroutinesub 0.0% 0 / 78 Podpod 0.0% 0 / 75 totaltotal 0.0% 0 / 1192 CC 87 SCAR 28.3
CC
87
Cov
0%
storeRect
56.0
storeRoom
42.0
fetchSquareInArea
42.0
CRAP 16.9
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::Regionmap
16 # Handles a single region with the world model
17  
18 { package Games::Axmud::Obj::Regionmap;
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 Games::Axmud::Obj::WorldModel->addRegion
34 #
35 # Create a new instance of the regionmap object, which contains the layout of a single
36 # region in the world. Each regionmap object corresponds to a GA::ModelObj::Region stored
37 # in the world model
38 #
39 # Expected arguments
40 # $session - The parent GA::Session (not stored as an IV)
41 # $name - A name for the regionmap (matches GA::ModelObj::Region->name)
42 #
43 # Return values
44 # 'undef' on improper arguments
45 # Blessed reference to the newly-created object on success
46  
47 my ($class, $session, $name, $check) = @_;
48  
49 # Check for improper arguments
50 if (! defined $class || ! defined $session || ! defined $name || defined $check) {
51  
52 return $axmud::CLIENT->writeImproper($class . '->new', @_);
53 }
54  
55 # Setup
56 my $self = {
57 _objName => $name,
58 _objClass => $class,
59 _parentFile => 'worldmodel',
60 _parentWorld => $session->currentWorld->name,
61 # All IVs are private, but should usually be set with calls to the GA::Obj::WorldModel
62 # object
63 _privFlag => TRUE, # All IVs are private
64  
65 # Object IVs
66 # ----------
67  
68 # The region's name (max 32 chars)
69 name => $name,
70 # The model number of the corresponding GA::ModelObj::Region (set later by
71 # GA::Obj::WorldModel->addRegion)
72 number => undef,
73  
74 # Current magnification - 1 is the standard size
75 magnification => 1,
76 # Position of the scrollbars (values between 0 and 1), the last time this region was
77 # removed from display - stored here so that, the next time it is displayed, the
78 # scrollbars can be moved to the same position
79 scrollXPos => 0.5, # Middle of the map
80 scrollYPos => 0.5,
81 # They are also stored when the user zooms out fully, so that there are no scrollbars
82 # visible - so that, the next time the user zooms in, the map is in the same position.
83 # (Gtk3::Canvas conveniently forgets, so we have to remember ourselves.)
84 # When that happens, this flag is set to TRUE. Whenever the user zooms in or out,
85 # ->zoomCallback checks this flag. If it has been set to TRUE, ->zoomCallback knows
86 # that the previous zoom was maximum, and that therefore the scrollbars are in the
87 # wrong place. They are moved, and the flag is reset back to FALSE.
88 # One of the horizontal and vertical scrollbars may be fully zoomed out before the
89 # other, so we have two flags, one for each scrollbar
90 maxZoomOutXFlag => FALSE,
91 maxZoomOutYFlag => FALSE,
92  
93 # Current block/room sizes (which depend on the magnification)
94 gridWidthBlocks => undef, # Set below
95 gridHeightBlocks => undef,
96 blockWidthPixels => undef,
97 blockHeightPixels => undef,
98 roomWidthPixels => undef,
99 roomHeightPixels => undef,
100 # Current map (canvas) sizes (which depend on the magnification)
101 mapWidthPixels => undef, # Set below
102 mapHeightPixels => undef,
103  
104 # Name of the region scheme (GA::Obj::RegionScheme) that specifies colours for this
105 # region. If 'undef', or if the named scheme doesn't exist, colours specified by the
106 # 'default' region scheme are used
107 regionScheme => undef,
108  
109 # How exits are drawn for this region; the range of values matches those used in
110 # GA::Obj::WorldModel->drawExitMode. If that IV is set to 'ask_regionmap', this IV is
111 # consulted
112 # The acceptable values are:
113 # 'no_exit' - Draw no exits (only the rooms themselves are drawn)
114 # 'simple_exit' - Draw simple exits (all exists are simple lines, with arrows for
115 # one-way exits)
116 # 'complex_exit' - Draw complex exits (there are four kinds of exits drawn -
117 # incomplete, uncertain, one-way and two-way)
118 drawExitMode => 'simple_exit',
119 # Flag set to TRUE if the automapper should obscure (i.e. filter out) some exits in this
120 # region, drawing only those exits for rooms near the current room, or for selected
121 # rooms (and selected exits), and for rooms whose rooms flags match those in
122 # GA::Client->constRoomNoObscuredHash (e.g. 'main_route')
123 obscuredExitFlag => FALSE,
124 # Flag set to TRUE if the automapper should re-obscure exits as the character moves
125 # around (so that only exits around the character's location are visible), and
126 # when other conditions change
127 obscuredExitRedrawFlag => FALSE,
128 # Radius (in gridblocks) of a square area, with the current room in the middle. When
129 # obscuring exits is enabled for this region, exits are drawn for all rooms in this
130 # area (including the current room), but not necessarily for any rooms outside the
131 # area
132 # Use 1 to draw only the current room, 2 to draw exits for rooms in a 3x3 area, 3 for a
133 # 5x5 area, and so on
134 # The maximum value is that specified by GA::Obj::WorldModel->maxObscuredExitRadius
135 obscuredExitRadius => 3,
136 # When this flag is set to TRUE, exit ornaments are drawn in this region. If set to
137 # FALSE, ornaments aren't drawn
138 drawOrnamentsFlag => TRUE,
139  
140 # The current level (i.e., the z-coordinate currently displayed). The initial level is
141 # 0, the level in the middle
142 currentLevel => 0,
143 # The highest level occupied by a room or label (set to 'undef' when the regionmap has
144 # no rooms or labels)
145 highestLevel => undef,
146 # The lowest level occupied by a room (set to 'undef' when the regionmap has no rooms or
147 # labels)
148 lowestLevel => undef,
149  
150 # The region's layout is stored in the following IVs as a collection of
151 # GA::ModelObj::Room, GA::Obj::Exit and GA::Obj::MapLabel objects
152 # Only one room is allowed per gridblock, but exits and labels can be drawn freely
153 # Hash of rooms in this regionmap, in the form
154 # $gridRoomHash{'x_y_z'} = model_number_of_room_at_these_coordinates
155 # ...where 'x_y_z' are the room's coordinates in the regionmap
156 gridRoomHash => {},
157 # Hash of rooms with room tags in this regionmap, in the form
158 # $gridRoomTagHash{'x_y_z'} = model_number_of_room_at_these_coordinates
159 gridRoomTagHash => {},
160 # Hash of rooms with room guilds in this regionmap, in the form
161 # $gridRoomGuildHash{'x_y_z'} = model_number_of_room_at_these_coordinates
162 gridRoomGuildHash => {},
163 # Hash of exits that have been drawn in this regionmap (not necessarily all the exits in
164 # all the rooms - the Automapper window often needs to know which exits have been
165 # drawn, and which therefore need to be re-drawn, and for that it uses this hash)
166 # Hash in the form
167 # $gridExitHash{exit_model_number} = undef
168 gridExitHash => {},
169 # Hash of (all) exits with exit tags in this regionmap, in the form
170 # $gridExitTagHash{exit_model_number} = undef
171 gridExitTagHash => {},
172 # Hash of (all) labels that exist in this regionmap, in the form
173 # $gridLabelHash{label_number} = blessed_reference_to_map_label_object
174 gridLabelHash => {},
175  
176 # As GA::Obj::MapLabel objects are added to this regionmap they are given a unique
177 # ->labelNumber. This IV records the ->labelNumber given to the last created label.
178 # The first label gets the number #1
179 # (The number is set by $self->storeLabel)
180 labelCount => 0,
181  
182 # Gridblocks in the map's background can be coloured in (useful for representing map
183 # features that aren't actually accessible to the player, such as rivers and mountain
184 # ranges)
185 # The user can colour in a single gridblock, or a group of gridblocks in a rectangle
186 # shape
187 # The rules for drawing are these:
188 # 1. Coloured rectangles can overlap each other. The coloured rectangle that was added
189 # first is drawn first (so will be obscured by later rectangles)
190 # 2. Coloured rectangles cannot overlap a single coloured block. Adding a coloured
191 # rectangle destroys any single coloured block in the same space
192 # 3. Single coloured blocks cannot overlap other coloured blacks or other coloured
193 # rectangles. Adding a single coloured block destroys any existing single coloured
194 # block or coloured rectangle occupying the same gridblock
195 #
196 # Single gridblock colours are stored in this hash, a hash in the form
197 # $gridColourBlockHash{'x_y_z'} = rgb_colour_tag
198 # $gridColourBlockHash{'x_y'} = rgb_colour_tag
199 # ...where 'x_y_z' are the block's coordinates in the regionmap (for coloured blocks
200 # displayed on only one level), 'x_y' are the block's coordinates (for coloured
201 # blocks that are displayed on every level), and 'rgb_colour_tag' is in the form
202 # #ABCDEF (case-insensitive)
203 gridColourBlockHash => {},
204 # Multiple gridblock colours are stored as GA::Obj::GridColour objects. Hash in the form
205 # $gridColourObjHash{unique_number} = blessed_reference_to_grid_colour_object
206 gridColourObjHash => {},
207 # Number of grid colour objects ever created in this regionmap (used to give each
208 # object a unique number)
209 colourObjCount => 0,
210  
211 # Hash of exits that lead to another region, in the form
212 # $regionExitHash{exit_number} = model_number_of_other_region
213 regionExitHash => {},
214 # Hash of paths between all the exits in ->regionExitHash, in the form
215 # $regionPathHash{exit_string} = blessed_ref_of_region_path_object
216 # ...where 'exit_string' is in the form 'a_b', where 'a' is the exit model number of the
217 # region exit at the start of the path, and 'b' is the exit model number of the exit
218 # at the end of the path
219 regionPathHash => {},
220 # Hash of paths between all the exits in ->regionExitHash, but avoiding rooms with
221 # hazardous room flags. The actual paths are not necessarily the same as those in
222 # ->regionPathHash. When there is no safe path between two boundary exits, there will
223 # be an entry in ->regionPathHash but not a corresponding one in ->safeRegionPathHash
224 safeRegionPathHash => {},
225  
226 # When the Locator task has a current room, it copies the room's contents into
227 # GA::ModelObj::Room->tempObjList
228 # Now, when GA::Win::Map->countRoomContents is called, the automapper makes a note of
229 # how many living and non-living things there are in the Locator's current room, and
230 # stores them in the equivalent room object
231 # Hence, each room object has a record of the number of living and non-living things in
232 # it, the last time the room was visited
233 # We can use this record to display the counts (when the appropriate flag is set) and,
234 # more importantly, it's quick and easy to empty the record when the user wants a
235 # reset
236 # These two hashes are in the form
237 # $hash{room_object_model_number} = number_of_things
238 # If there is no entry for a room in this region, then the number of things in it (on
239 # the last visit) is 0
240 livingCountHash => {},
241 nonLivingCountHash => {},
242 };
243  
244 # Bless the object into existence
245 bless $self, $class;
246  
247 # Set the initial values of the size IVs
248 $self->{gridWidthBlocks} = $session->worldModelObj->defaultGridWidthBlocks;
249 $self->{gridHeightBlocks} = $session->worldModelObj->defaultGridHeightBlocks;
250 # NB ->blockWidthPixels, ->blockHeightPixels, ->roomWidthPixels and
251 # ->roomHeightPixels are set again every time the map is redrawn
252 $self->{blockWidthPixels} = $session->worldModelObj->defaultBlockWidthPixels;
253 $self->{blockHeightPixels} = $session->worldModelObj->defaultBlockHeightPixels;
254 $self->{roomWidthPixels} = $session->worldModelObj->defaultRoomWidthPixels;
255 $self->{roomHeightPixels} = $session->worldModelObj->defaultRoomHeightPixels;
256 # NB ->mapWidthPixels and ->mapHeightPixels are set again every time the map
257 # is redrawn
258 $self->{mapWidthPixels} = $self->gridWidthBlocks * $self->blockWidthPixels;
259 $self->{mapHeightPixels} = $self->gridHeightBlocks * $self->blockHeightPixels;
260  
261 return $self;
262 }
263  
264 ##################
265 # Methods
266  
267 sub emptyGrid {
268  
269 # Called by GA::Obj::WorldModel->emptyRegion
270 # Resets this object's IVs after a region is emptied
271 #
272 # Expected arguments
273 # (none besides $self)
274 #
275 # Return values
276 # 'undef' on improper arguments
277 # 1 otherwise
278  
279 my ($self, $check) = @_;
280  
281 # Check for improper arguments
282 if (defined $check) {
283  
284 return $axmud::CLIENT->writeImproper($self->_objClass . '->emptyGrid', @_);
285 }
286  
287 # Reset the highest/lowest occupied levels
288 $self->ivUndef('highestLevel');
289 $self->ivUndef('lowestLevel');
290  
291 # Empty the hashes of drawn objects
292 $self->ivEmpty('gridRoomHash');
293 $self->ivEmpty('gridRoomTagHash');
294 $self->ivEmpty('gridRoomGuildHash');
295 $self->ivEmpty('gridExitHash');
296 $self->ivEmpty('gridLabelHash');
297 $self->ivPoke('labelCount', 0);
298  
299 # Empty the hashes of grid colours
300 $self->ivEmpty('gridColourBlockHash');
301 $self->ivEmpty('gridColourObjHash');
302 $self->ivPoke('colourObjCount', 0);
303  
304 # Empty the hashes of region paths
305 $self->ivEmpty('regionExitHash');
306 $self->ivEmpty('regionPathHash');
307 $self->ivEmpty('safeRegionPathHash');
308  
309 # Reset the living/non-living object counts
310 $self->ivEmpty('livingCountHash');
311 $self->ivEmpty('nonLivingCountHash');
312  
313 return 1;
314 }
315  
316 # Functions for $self->gridRoomHash, ->gridRoomTagHash, ->gridRoomGuildHash, ->gridExitHash,
317 # ->gridLabelHash
318  
319 sub checkGridBlock {
320  
321 # Can be called by anything
322 # Checks that a gridblock actually exists - for example, before creating a new room, check
323 # that its proposed location actually fits on the map
324 #
325 # Expected arguments
326 # $xPosBlocks, $yPosBlocks, $zPosBlocks
327 # - Coordinates of the gridblock in this regionmap to check
328 #
329 # Return values
330 # 'undef' on improper arguments or if the gridblock doesn't actually exist
331 # 1 if the gridblock exists (regardless of whether it contains a room, or not)
332  
333 my ($self, $xPosBlocks, $yPosBlocks, $zPosBlocks, $check) = @_;
334  
335 # Check for improper arguments
336 if (
337 ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $zPosBlocks
338 || defined $check
339 ) {
340 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkGridBlock', @_);
341 }
342  
343 if (
344 ! $axmud::CLIENT->intCheck($xPosBlocks, 0)
345 || ! $axmud::CLIENT->intCheck($yPosBlocks, 0)
346 || ! $axmud::CLIENT->intCheck($zPosBlocks) # Can be negative
347 || $xPosBlocks >= $self->gridWidthBlocks
348 || $yPosBlocks >= $self->gridHeightBlocks
349 ) {
350 # Specified gridblock doesn't exist
351 return undef;
352  
353 } else {
354  
355 # Specified gridblock exists
356 return 1;
357 }
358 }
359  
360 sub fetchRoom {
361  
362 # Can be called by anything
363 # Finds the GA::ModelObj::Room in the gridblock at the specified coordinates in the grid
364 #
365 # Expected arguments
366 # $xPosBlocks, $yPosBlocks, $zPosBlocks
367 # - The grid coordinates of the room object to get
368 #
369 # Return values
370 # 'undef' on improper arguments, or if the specified gridblock doesn't exits or doesn't
371 # contain a room
372 # Otherwise, returns the model number of the GA::ModelObj::Room occupying the gridblock
373  
374 my ($self, $xPosBlocks, $yPosBlocks, $zPosBlocks, $check) = @_;
375  
376 # Local variables
377 my ($posn, $number);
378  
379 # Check for improper arguments
380 if (
381 ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $zPosBlocks
382 || defined $check
383 ) {
384 return $axmud::CLIENT->writeImproper($self->_objClass . '->fetchRoom', @_);
385 }
386  
387 # Need to check that $xPosBlocks, $yPosBlocks and $zPosBlocks are valid grid coordinates
388 if (! $self->checkGridBlock($xPosBlocks, $yPosBlocks, $zPosBlocks)) {
389  
390 # The specified gridblock doesn't exist
391 return undef;
392 }
393  
394 # Keys in $self->gridRoomHash are strings in the form 'x_y_z'
395 $posn = $xPosBlocks . '_' . $yPosBlocks . '_' . $zPosBlocks;
396  
397 # Fetch the room, returning either the model number (if there is a room in this gridblock),
398 # or 'undef' (if there isn't)
399 return $self->ivShow('gridRoomHash', $posn);
400 }
401  
402 sub storeRoom {
403  
404 # Called by GA::Obj::WorldModel->addRoom and ->moveRoomsLabels when the world model adds a
405 # room object to this region
406 # Update this object's IVs
407 #
408 # Expected arguments
409 # $roomObj - The GA::ModelObj::Room to store
410 #
411 # Return values
412 # 'undef' on improper arguments or if the room's proposed location on the grid is invalid
413 # 1 otherwise
414  
415 my ($self, $roomObj, $check) = @_;
416  
417 # Local variables
418 my ($posn, $roomNum);
419  
420 # Check for improper arguments
421 if (! defined $roomObj || defined $check) {
422  
423 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeRoom', @_);
424 }
425  
426 # Need to check that room's proposed location are at valid grid coordinates and that there
427 # isn't already a room at the location
428 if (
429 ! $self->checkGridBlock(
430 $roomObj->xPosBlocks,
431 $roomObj->yPosBlocks,
432 $roomObj->zPosBlocks,
433 )
434 ) {
435 # The specified gridblock doesn't exist
436 return undef;
437 }
438  
439 # Keys in $self->gridRoomHash are strings in the form 'x_y_z'
440 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
441  
442 # If there is already a room at this position, return an error
443 # (also update ->gridRoomTagHash and ->gridRoomGuildHash)
444 if ($self->ivExists('gridRoomHash', $posn)) {
445  
446 return undef;
447 }
448  
449 # Store the room by updating ->gridRoomHash
450 $self->ivAdd('gridRoomHash', $posn, $roomObj->number);
451 # Also update ->gridRoomTagHash and ->gridRoomGuildHash
452 if ($roomObj->roomTag) {
453  
454 $self->storeRoomTag($roomObj, $posn);
455 }
456  
457 if ($roomObj->roomGuild) {
458  
459 $self->storeRoomGuild($roomObj, $posn);
460 }
461  
462 return 1;
463 }
464  
465 sub removeRoom {
466  
467 # Called by GA::Obj::WorldModel->deleteRooms and ->moveRoomsLabels when the world model
468 # removes a room object from this region
469 # Update this object's IVs
470 #
471 # Expected arguments
472 # $roomObj - The GA::ModelObj::Room to remove
473 #
474 # Return values
475 # 'undef' on improper arguments or if the room object isn't stored in this regionmap
476 # 1 otherwise
477  
478 my ($self, $roomObj, $check) = @_;
479  
480 # Local variables
481 my $posn;
482  
483 # Check for improper arguments
484 if (! defined $roomObj || defined $check) {
485  
486 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRoom', @_);
487 }
488  
489 # Keys in $self->gridRoomHash are strings in the form 'x_y_z'
490 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
491  
492 # Check the room exists in this region
493 if (! $self->ivExists('gridRoomHash', $posn)) {
494  
495 return undef;
496  
497 } else {
498  
499 # Remove the room
500 $self->ivDelete('gridRoomHash', $posn);
501  
502 # If the room has a room tag or room guild, update those IVs, too
503 if ($roomObj->roomTag) {
504  
505 $self->removeRoomTag($roomObj, $posn);
506 }
507  
508 if ($roomObj->roomGuild) {
509  
510 $self->removeRoomGuild($roomObj, $posn);
511 }
512  
513 return 1;
514 }
515 }
516  
517 sub storeRoomTag {
518  
519 # Called by GA::Obj::WorldModel->setRoomTag and $self->storeRoom when the world model adds
520 # a room tag to this region
521 # Update this object's IVs
522 #
523 # Expected arguments
524 # $roomObj - The GA::ModelObj::Room (which has a room tag) to store
525 #
526 # Optional arguments
527 # $posn - The room's position in the grid, in the form 'x_y_z' (used as a key in
528 # $self->gridRoomTagHash). If 'undef', this function works out the
529 # position
530 #
531 # Return values
532 # 'undef' on improper arguments
533 # 1 otherwise
534  
535 my ($self, $roomObj, $posn, $check) = @_;
536  
537 # Check for improper arguments
538 if (! defined $roomObj || defined $check) {
539  
540 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeRoomTag', @_);
541 }
542  
543 if (! $posn) {
544  
545 # Keys in $self->gridRoomTagHash are strings in the form 'x_y_z'
546 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
547 }
548  
549 # Store the room tag, replacing any existing entry
550 $self->ivAdd('gridRoomTagHash', $posn, $roomObj->number);
551  
552 return 1;
553 }
554  
555 sub removeRoomTag {
556  
557 # Called by GA::Obj::WorldModel->resetRoomTag and $self->removeRoom when the world model
558 # removes a room tag from this region
559 # Update this object's IVs
560 #
561 # Expected arguments
562 # $roomObj - The GA::ModelObj::Room (which has a room tag) to remove
563 #
564 # Optional arguments
565 # $posn - The room's position in the grid, in the form 'x_y_z' (used as a key in
566 # $self->gridRoomTagHash). If 'undef', this function works out the
567 # position
568 #
569 # Return values
570 # 'undef' on improper arguments or if the tagged room isn't stored in this regionmap
571 # 1 otherwise
572  
573 my ($self, $roomObj, $posn, $check) = @_;
574  
575 # Check for improper arguments
576 if (! defined $roomObj || defined $check) {
577  
578 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRoomTag', @_);
579 }
580  
581 if (! $posn) {
582  
583 # Keys in $self->gridRoomHash are strings in the form 'x_y_z'
584 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
585 }
586  
587 # Check the tagged room exists in this region
588 if (! $self->ivExists('gridRoomTagHash', $posn)) {
589  
590 return undef;
591  
592 } else {
593  
594 # Remove the tagged room
595 $self->ivDelete('gridRoomTagHash', $posn);
596  
597 return 1;
598 }
599 }
600  
601 sub storeRoomGuild {
602  
603 # Called by GA::Obj::WorldModel->setRoomGuild and $self->storeRoom when the world model
604 # adds a room guild to this region
605 # Update this object's IVs
606 #
607 # Expected arguments
608 # $roomObj - The GA::ModelObj::Room (which has a room guild) to store
609 #
610 # Optional arguments
611 # $posn - The room's position in the grid, in the form 'x_y_z' (used as a key in
612 # $self->gridRoomGuildHash). If 'undef', this function works out the
613 # position
614 #
615 # Return values
616 # 'undef' on improper arguments
617 # 1 otherwise
618  
619 my ($self, $roomObj, $posn, $check) = @_;
620  
621 # Check for improper arguments
622 if (! defined $roomObj || defined $check) {
623  
624 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeRoomGuild', @_);
625 }
626  
627 if (! $posn) {
628  
629 # Keys in $self->gridRoomGuildHash are strings in the form 'x_y_z'
630 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
631 }
632  
633 # Store the room guild, replacing any existing entry
634 $self->ivAdd('gridRoomGuildHash', $posn, $roomObj->number);
635  
636 return 1;
637 }
638  
639 sub removeRoomGuild {
640  
641 # Called by GA::Obj::WorldModel->setRoomGuild and $self->removeRoom when the world model
642 # removes a room guild from this region
643 # Update this object's IVs
644 #
645 # Expected arguments
646 # $roomObj - The GA::ModelObj::Room (which has a room guild) to remove
647 #
648 # Optional arguments
649 # $posn - The room's position in the grid, in the form 'x_y_z' (used as a key in
650 # $self->gridRoomGuildHash). If 'undef', this function works out the
651 # position
652 #
653 # Return values
654 # 'undef' on improper arguments or if the room with a guild isn't stored in this regionmap
655 # 1 otherwise
656  
657 my ($self, $roomObj, $posn, $check) = @_;
658  
659 # Check for improper arguments
660 if (! defined $roomObj || defined $check) {
661  
662 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRoomGuild', @_);
663 }
664  
665 if (! $posn) {
666  
667 # Keys in $self->gridRoomGuildHash are strings in the form 'x_y_z'
668 $posn = $roomObj->xPosBlocks . '_' . $roomObj->yPosBlocks . '_' . $roomObj->zPosBlocks;
669 }
670  
671 # Check the room with a guild exists in this region
672 if (! $self->ivExists('gridRoomGuildHash', $posn)) {
673  
674 return undef;
675  
676 } else {
677  
678 # Remove the room with a gu ild
679 $self->ivDelete('gridRoomGuildHash', $posn);
680  
681 return 1;
682 }
683 }
684  
685 sub storeExit {
686  
687 # Called by GA::Win::Map->drawExit to store any exit that has been drawn (not necesssarily
688 # every exit belonging to every room in this regionmap). Gets called every time the
689 # exit is drawn. Also called by GA::Obj::WorldModel->moveRoomsLabels
690 # Updates this object's IVs
691 #
692 # Expected arguments
693 # $exitObj - The GA::Obj::Exit that has been drawn on the map
694 #
695 # Return values
696 # 'undef' on improper arguments
697 # 1 otherwise
698  
699 my ($self, $exitObj, $check) = @_;
700  
701 # Check for improper arguments
702 if (! defined $exitObj || defined $check) {
703  
704 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeExit', @_);
705 }
706  
707 # Store the drawn exit
708 $self->ivAdd('gridExitHash', $exitObj->number, undef);
709  
710 return 1;
711 }
712  
713 sub removeExit {
714  
715 # Called by GA::Obj::WorldModel->deleteExits when the world model removes an exit object
716 # from this region
717 # Update this object's IVs
718 #
719 # Expected arguments
720 # $exitObj - The GA::Obj::Exit to remove
721 #
722 # Return values
723 # 'undef' on improper arguments
724 # 1 otherwise
725  
726 my ($self, $exitObj, $check) = @_;
727  
728 # Check for improper arguments
729 if (! defined $exitObj || defined $check) {
730  
731 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeExit', @_);
732 }
733  
734 # Remove the exit (if the exit hasn't been drawn, there won't be an entry in
735 # ->gridExitHash)
736 $self->ivDelete('gridExitHash', $exitObj->number);
737  
738 # If the exit has an exit tag, update that IV, too
739 if ($exitObj->exitTag) {
740  
741 $self->removeExitTag($exitObj);
742 }
743  
744 # If it's a region exit, remove its entry from ->regionExitHash
745 if ($self->ivExists('regionExitHash', $exitObj->number)) {
746  
747 $self->ivDelete('regionExitHash', $exitObj->number);
748 }
749  
750 return 1;
751 }
752  
753 sub resetExit {
754  
755 # Called by GA::Obj::WorldModel->deleteExits when the world model removes an exit object
756 # whose twin exit is in this region
757 # If the twin is to be deleted, it hasn't been deleted yet. The calling function makes the
758 # twin an incomplete exit; this function updates this object's IVs to reflect the fact
759 # that the still-existing twin is no longer a region exit
760 #
761 # Expected arguments
762 # $exitObj - The still-existing twin GA::Obj::Exit
763 #
764 # Return values
765 # 'undef' on improper arguments
766 # 1 otherwise
767  
768 my ($self, $exitObj, $check) = @_;
769  
770 # Check for improper arguments
771 if (! defined $exitObj || defined $check) {
772  
773 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetExit', @_);
774 }
775  
776 # If the exit has an exit tag, update that IV, too
777 if ($exitObj->exitTag) {
778  
779 $self->removeExitTag($exitObj);
780 }
781  
782 # If it's a region exit, remove its entry from ->regionExitHash
783 if ($self->ivExists('regionExitHash', $exitObj->number)) {
784  
785 $self->ivDelete('regionExitHash', $exitObj->number);
786 }
787  
788 return 1;
789 }
790  
791 sub storeExitTag {
792  
793 # Called by GA::Obj::WorldModel->moveRoomsLabels and ->applyExitTag when the world model
794 # adds an exit tag to this region
795 # Updates this object's IVs
796 #
797 # Expected arguments
798 # $exitObj - The GA::Obj::Exit (which has an exit tag) to store
799 #
800 # Return values
801 # 'undef' on improper arguments
802 # 1 otherwise
803  
804 my ($self, $exitObj, $check) = @_;
805  
806 # Check for improper arguments
807 if (! defined $exitObj || defined $check) {
808  
809 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeExitTag', @_);
810 }
811  
812 # Store the exit tag
813 $self->ivAdd('gridExitTagHash', $exitObj->number, undef);
814  
815 return 1;
816 }
817  
818 sub removeExitTag {
819  
820 # Called by $self->removeExit and GA::Obj::WorldModel->cancelExitTag when the world model
821 # removes an exit tag from this region
822 # Update this object's IVs
823 #
824 # Expected arguments
825 # $exitObj - The GA::Obj::Exit (which has an exit tag) to remove
826 #
827 # Return values
828 # 'undef' on improper arguments
829 # 1 otherwise
830  
831 my ($self, $exitObj, $check) = @_;
832  
833 # Check for improper arguments
834 if (! defined $exitObj || defined $check) {
835  
836 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeExit', @_);
837 }
838  
839 # Remove the exit tag
840 $self->ivDelete('gridExitTagHash', $exitObj->number);
841  
842 return 1;
843 }
844  
845 sub storeLabel {
846  
847 # Called by GA::Obj::WorldModel->addLabel and ->moveRoomsLabels when the world model adds a
848 # label to this region
849 # Assigns the new label a unique number within this regionmap, and adds the label to
850 # $self->gridLabelHash
851 #
852 # Expected arguments
853 # $labelObj - The GA::Obj::MapLabel to store
854 #
855 # Return values
856 # 'undef' on improper arguments
857 # 1 otherwise
858  
859 my ($self, $labelObj, $check) = @_;
860  
861 # Check for improper arguments
862 if (! defined $labelObj || defined $check) {
863  
864 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeLabel', @_);
865 }
866  
867 # Allocate the label a unique number
868 $self->ivIncrement('labelCount');
869 $labelObj->ivPoke('number', $self->labelCount);
870 # (->id is in the form 'region-name_label_number', e.g. 'town_42')
871 $labelObj->ivPoke('id', $labelObj->region . '_' . $self->labelCount);
872  
873 # Store the drawn exit
874 $self->ivAdd('gridLabelHash', $labelObj->number, $labelObj);
875  
876 return 1;
877 }
878  
879 sub removeLabel {
880  
881 # Called by GA::Obj::WorldModel->deleteLabels and ->moveRoomsLabels when the world model
882 # removes a label from this region
883 # Update this object's IVs
884 #
885 # Expected arguments
886 # $labelObj - The GA::Obj::MapLabel to remove
887 #
888 # Return values
889 # 'undef' on improper arguments or if the label object isn't stored in this regionmap
890 # 1 otherwise
891  
892 my ($self, $labelObj, $check) = @_;
893  
894 # Check for improper arguments
895 if (! defined $labelObj || defined $check) {
896  
897 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeLabel', @_);
898 }
899  
900 # Check the label exists in this region
901 if (! $self->ivExists('gridLabelHash', $labelObj->number)) {
902  
903 return undef;
904  
905 } else {
906  
907 # Remove the label
908 $self->ivDelete('gridLabelHash', $labelObj->number);
909  
910 return 1;
911 }
912 }
913  
914 # Functions for $self->gridColourBlockHash, ->gridColourObjHash
915  
916 sub fetchSquareInSquare {
917  
918 # Called by GA::Win::Map->setColouredSquare
919 # Given a single gridblock, return a list of coloured squares that occupy the block
920 # (possible on differently levels)
921 #
922 # Expected arguments
923 # $xBlocks, $yBlocks
924 # - Grid coordinates of the block to check
925 #
926 # Optional arguments
927 # $level - The z-coordinate, matching $self->currentLevel. If not defined, coloured
928 # blocks/rectangles on all levels are counted
929 #
930 # Return values
931 # An empty list on improper arguments or if the specified block's position on the grid is
932 # invalid
933 # Otherwise returns a list of keys from $self->gridColourBlockHash, one for each matching
934 # square (the keys are strings in the form 'x_y_z' or 'x_y')
935  
936 my ($self, $xBlocks, $yBlocks, $level, $check) = @_;
937  
938 # Local variables
939 my (@emptyList, @returnList);
940  
941 # Check for improper arguments
942 if (! defined $xBlocks || ! defined $yBlocks || defined $check) {
943  
944 $axmud::CLIENT->writeImproper($self->_objClass . '->fetchSquareInSquare', @_);
945 return @emptyList;
946 }
947  
948 # Check that the coordinates are valid grid coordinates
949 if (! $self->checkGridBlock($xBlocks, $yBlocks, $self->currentLevel)) {
950  
951 # The specified gridblock doesn't exist
952 return undef;
953 }
954  
955 # Count coloured blocks on the specified gridblock, across all levels
956 foreach my $coord ($self->ivKeys('gridColourBlockHash')) {
957  
958 # $coord is in the form 'x_y_z' or 'x_y', for coloured blocks shown on every level
959 my ($thisX, $thisY, $thisZ) = split(/_/, $coord);
960  
961 if (
962 $thisX == $xBlocks
963 && $thisY == $yBlocks
964 && (
965 ! defined $thisZ
966 || ! defined $level
967 || $thisZ == $level
968 )
969 ) {
970 push (@returnList, $coord);
971 }
972 }
973  
974 return @returnList;
975 }
976  
977 sub fetchSquareInArea {
978  
979 # Called by GA::Win::Map->setColouredRect
980 # Given a rectangular area of the grid (which can be as small as a single gridblock),
981 # return a list of coloured squares that occupy a block within the area
982 #
983 # Expected arguments
984 # $x1, $y1, $x2, $y2
985 # - Grid coordinates of opposite corners (top-left, then bottom-right) of the
986 # rectangular area. $x1 and $x2 can be the same, and $y1 and $y2 can
987 # be the same. If both pairs are the same, it's a single gridblock (this
988 # should never happen, but is not forbidden)
989 #
990 # Optional arguments
991 # $level - The z-coordinate, matching $self->currentLevel. If not defined, coloured
992 # blocks/rectangles on all levels are counted
993 #
994 # Return values
995 # An empty list on improper arguments or if the rectangular area's position on the grid is
996 # invalid
997 # Otherwise returns a list of keys from $self->gridColourBlockHash, one for each matching
998 # square (the keys are strings in the form 'x_y_z' or 'x_y')
999  
1000 my ($self, $x1, $y1, $x2, $y2, $level, $check) = @_;
1001  
1002 # Local variables
1003 my (@emptyList, @returnList);
1004  
1005 # Check for improper arguments
1006 if (! defined $x1 || ! defined $y1 || ! defined $x2 || ! defined $y2 || defined $check) {
1007  
1008 $axmud::CLIENT->writeImproper($self->_objClass . '->fetchSquareInArea', @_);
1009 return @emptyList;
1010 }
1011  
1012 # Check that both corners of the rectangle are valid grid coordinates
1013 if (
1014 ! $self->checkGridBlock($x1, $y1, $self->currentLevel)
1015 || ! $self->checkGridBlock($x2, $y2, $self->currentLevel)
1016 ) {
1017 # The specified gridblock(s) don't exist
1018 return @emptyList;
1019 }
1020  
1021 # If the two corners are the wrong way around, swap them
1022 if ($x1 > $x2) {
1023  
1024 ($x1, $x2) = ($x2, $x1);
1025 }
1026  
1027 if ($y1 > $y2) {
1028  
1029 ($y1, $y2) = ($y2, $y1);
1030 }
1031  
1032 # Count coloured blocks in the rectangular area
1033 foreach my $coord ($self->ivKeys('gridColourBlockHash')) {
1034  
1035 # $coord is in the form 'x_y_z' or 'x_y', for coloured blocks shown on every level
1036 my ($thisX, $thisY, $thisZ) = split(/_/, $coord);
1037  
1038 if (
1039 $thisX >= $x1
1040 && $thisX <= $x2
1041 && $thisY >= $y1
1042 && $thisY <= $y2
1043 && (
1044 ! defined $thisZ
1045 || ! defined $level
1046 || $thisZ == $level
1047 )
1048 ) {
1049 push (@returnList, $coord);
1050 }
1051 }
1052  
1053 return @returnList;
1054 }
1055  
1056 sub storeSquare {
1057  
1058 # Called by GA::Win::Map->setColouredSquare
1059 # Update this object's IVs
1060 #
1061 # Expected arguments
1062 # $colour - The block's colour
1063 # $xBlocks, $yBlocks
1064 # - The block's grid coordinates
1065 #
1066 # Optional arguments
1067 # $level - The z-coordinate, matching $self->currentLevel. If not defined, the
1068 # coloured block is visible on every level
1069 #
1070 # Return values
1071 # 'undef' on improper arguments or if the block's proposed location on the grid is invalid
1072 # 1 otherwise
1073  
1074 my ($self, $colour, $xBlocks, $yBlocks, $level, $check) = @_;
1075  
1076 # Local variables
1077 my $coord;
1078  
1079 # Check for improper arguments
1080 if (! defined $colour || ! defined $xBlocks || ! defined $yBlocks || defined $check) {
1081  
1082 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeSquare', @_);
1083 }
1084  
1085 # Check that the coordinates are valid grid coordinates
1086 if (! $self->checkGridBlock($xBlocks, $yBlocks, $self->currentLevel)) {
1087  
1088 # The specified gridblock doesn't exist
1089 return undef;
1090 }
1091  
1092 # Store the block by updating the IV
1093 $coord = $xBlocks . '_' . $yBlocks;
1094 if (defined $level) {
1095  
1096 $coord .= '_' . $level;
1097 }
1098  
1099 $self->ivAdd('gridColourBlockHash', $coord, $colour);
1100  
1101 return 1;
1102 }
1103  
1104 sub removeSquare {
1105  
1106 # Called by GA::Win::Map->setColouredSquare and ->setColouredRect
1107 # Updates this object's IVs
1108 #
1109 # Expected arguments
1110 # $coord - A string representing the coloured block's coordinates, matching a key in
1111 # $self->gridColourBlockHash
1112 #
1113 # Return values
1114 # 'undef' on improper arguments
1115 # 1 otherwise
1116  
1117 my ($self, $coord, $check) = @_;
1118  
1119 # Check for improper arguments
1120 if (! defined $coord || defined $check) {
1121  
1122 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeSquare', @_);
1123 }
1124  
1125 $self->ivDelete('gridColourBlockHash', $coord);
1126  
1127 return 1;
1128 }
1129  
1130 sub fetchRectInSquare {
1131  
1132 # Called by GA::Win::Map->setColouredSquare
1133 # Given a single gridblock, return a list of coloured rectangles that occupy the block
1134 # (possible on differently levels)
1135 #
1136 # Expected arguments
1137 # $xBlocks, $yBlocks
1138 # - Grid coordinates of the block to check
1139 #
1140 # Optional arguments
1141 # $level - The z-coordinate, matching $self->currentLevel. If not defined, coloured
1142 # blocks/rectangles on all levels are counted
1143 #
1144 # Return values
1145 # An empty list on improper arguments or if the specified block's position on the grid is
1146 # invalid
1147 # Otherwise returns a list of GA::Obj::GridColour objects, one for each rectangle
1148 # occupying the specified block (may be an empty list)
1149  
1150 my ($self, $xBlocks, $yBlocks, $level, $check) = @_;
1151  
1152 # Local variables
1153 my (@emptyList, @returnList);
1154  
1155 # Check for improper arguments
1156 if (! defined $xBlocks || ! defined $yBlocks || defined $check) {
1157  
1158 $axmud::CLIENT->writeImproper($self->_objClass . '->fetchRectInSquare', @_);
1159 return @emptyList;
1160 }
1161  
1162 # Check that the coordinates are valid grid coordinates
1163 if (! $self->checkGridBlock($xBlocks, $yBlocks, $self->currentLevel)) {
1164  
1165 # The specified gridblock doesn't exist
1166 return undef;
1167 }
1168  
1169 # Count coloured rectangles in the rectangular area
1170 foreach my $obj ($self->ivValues('gridColourObjHash')) {
1171  
1172 if (
1173 $xBlocks >= $obj->x1
1174 && $xBlocks <= $obj->x2
1175 && $yBlocks >= $obj->y1
1176 && $yBlocks <= $obj->y2
1177 && (
1178 ! defined $level
1179 || ! defined $obj->level
1180 || $level == $obj->level
1181 )
1182 ) {
1183 push (@returnList, $obj);
1184 }
1185 }
1186  
1187 return @returnList;
1188 }
1189  
1190 sub fetchRectInArea {
1191  
1192 # Called by GA::Win::Map->setColouredRect
1193 # Given a rectangular area of the grid (which can be as small as a single gridblock),
1194 # return a list of coloured rectangles that occupy the same area, wholly or partially
1195 #
1196 # Expected arguments
1197 # $x1, $y1, $x2, $y2
1198 # - Grid coordinates of opposite corners (top-left, then bottom-right) of the
1199 # rectangular area. $x1 and $x2 can be the same, and $y1 and $y2 can
1200 # be the same. If both pairs are the same, it's a single gridblock (this
1201 # should never happen, but is not forbidden)
1202 #
1203 # Optional arguments
1204 # $level - The z-coordinate, matching $self->currentLevel. If not defined, coloured
1205 # blocks/rectangles on all levels are counted
1206 #
1207 # Return values
1208 # An empty list on improper arguments or if the rectangular area's position on the grid is
1209 # invalid
1210 # Otherwise returns a list of GA::Obj::GridColour objects, one for each rectangle
1211 # occupying part of the rectangular area (may be an empty list)
1212  
1213 my ($self, $x1, $y1, $x2, $y2, $level, $check) = @_;
1214  
1215 # Local variables
1216 my (@emptyList, @returnList);
1217  
1218 # Check for improper arguments
1219 if (! defined $x1 || ! defined $y1 || ! defined $x2 || ! defined $y2 || defined $check) {
1220  
1221 $axmud::CLIENT->writeImproper($self->_objClass . '->fetchRect', @_);
1222 return @emptyList;
1223 }
1224  
1225 # Check that both corners of the rectangle are valid grid coordinates
1226 if (
1227 ! $self->checkGridBlock($x1, $y1, $self->currentLevel)
1228 || ! $self->checkGridBlock($x2, $y2, $self->currentLevel)
1229 ) {
1230 # The specified gridblock(s) don't exist
1231 return @emptyList;
1232 }
1233  
1234 # If the two corners are the wrong way around, swap them
1235 if ($x1 > $x2) {
1236  
1237 ($x1, $x2) = ($x2, $x1);
1238 }
1239  
1240 if ($y1 > $y2) {
1241  
1242 ($y1, $y2) = ($y2, $y1);
1243 }
1244  
1245 # Count coloured rectangles in the rectangular area
1246 foreach my $obj ($self->ivValues('gridColourObjHash')) {
1247  
1248 if (
1249 (
1250 # Occupy the same 2-dimensional space
1251 ($x1 >= $obj->x1 && $x1 <= $obj->x2)
1252 || ($x2 >= $obj->x1 && $x2 <= $obj->x2)
1253 ) && (
1254 ($y1 >= $obj->y1 && $y1 <= $obj->y2)
1255 || ($y2 >= $obj->y1 && $y2 <= $obj->y2)
1256 ) && (
1257 # Occupy the same level
1258 ! defined $level
1259 || ! defined $obj->level
1260 || $level == $obj->level
1261 )
1262 ) {
1263 push (@returnList, $obj);
1264 }
1265 }
1266  
1267 return @returnList;
1268 }
1269  
1270 sub storeRect {
1271  
1272 # Called by GA::Win::Map->setColouredRect
1273 # Update this object's IVs
1274 #
1275 # Expected arguments
1276 # $session - The calling function's GA::Session
1277 # $colour - The rectangle's colour
1278 # $x1, $y1, $x2, $y2
1279 # - Grid coordinates of opposite corners (top-left, then bottom-right) of the
1280 # coloured rectangle. $x1 and $x2 can be the same, and $y1 and $y2 can
1281 # be the same. If both pairs are the same, it's a single gridblock (this
1282 # should never happen, but is not forbidden)
1283 #
1284 # Optional arguments
1285 # $level - The z-coordinate, matching $self->currentLevel. If not defined, the
1286 # coloured rectangle is visible on every level
1287 #
1288 # Return values
1289 # 'undef' on improper arguments or if the rectangles's proposed location on the grid is
1290 # invalid
1291 # Otherwise returns the GA::Obj::GridColour object created
1292  
1293 my ($self, $session, $colour, $x1, $y1, $x2, $y2, $level, $check) = @_;
1294  
1295 # Local variables
1296 my $colourObj;
1297  
1298 # Check for improper arguments
1299 if (
1300 ! defined $session || ! defined $colour || ! defined $x1 || ! defined $y1
1301 || ! defined $x2 || ! defined $y2 || defined $check
1302 ) {
1303 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeRect', @_);
1304 }
1305  
1306 # Check that both corners of the rectangle are valid grid coordinates
1307 if (
1308 ! $self->checkGridBlock($x1, $y1, $self->currentLevel)
1309 || ! $self->checkGridBlock($x2, $y2, $self->currentLevel)
1310 ) {
1311 # The specified gridblock(s) don't exist
1312 return undef;
1313 }
1314  
1315 # If the two corners are the wrong way around, swap them
1316 if ($x1 > $x2) {
1317  
1318 ($x1, $x2) = ($x2, $x1);
1319 }
1320  
1321 if ($y1 > $y2) {
1322  
1323 ($y1, $y2) = ($y2, $y1);
1324 }
1325  
1326 # Coloured rectangles can be drawn on top of each other, but coloured blocks cannot
1327 # Import the IV (for speed) and check every coloured square
1328 foreach my $coord ($self->ivKeys('gridColourBlockHash')) {
1329  
1330 # $coord is in the form 'x_y_z' or 'x_y', for coloured blocks shown on every level
1331 my ($thisX, $thisY, $thisZ) = split(/_/, $coord);
1332  
1333 if (
1334 $thisX >= $x1
1335 && $thisX <= $x2
1336 && $thisY >= $y1
1337 && $thisY <= $y2
1338 && (
1339 ! defined $thisZ
1340 || ! defined $level
1341 || $thisZ == $level
1342 )
1343 ) {
1344 # This coloured block occupies part of the space that the rectangle wants, so don't
1345 # draw the rectangle
1346 return undef;
1347 }
1348 }
1349  
1350 # Create a new grid colour object
1351 $colourObj = Games::Axmud::Obj::GridColour->new(
1352 $session,
1353 $self->ivIncrement('colourObjCount'),
1354 $colour,
1355 $x1, $y1,
1356 $x2, $y2,
1357 $level,
1358 );
1359  
1360 if (! $colourObj) {
1361  
1362 return undef;
1363 }
1364  
1365 # Store the rectangle by updating the IV
1366 $self->ivAdd('gridColourObjHash', $colourObj->number, $colourObj);
1367  
1368 return $colourObj;
1369 }
1370  
1371 sub removeRect {
1372  
1373 # Called by GA::Win::Map->setColouredSquare and ->setColouredRect
1374 # Updates this object's IVs
1375 #
1376 # Expected arguments
1377 # $obj - The GA::Obj::GridColour to remove
1378 #
1379 # Return values
1380 # 'undef' on improper arguments
1381 # 1 otherwise
1382  
1383 my ($self, $obj, $check) = @_;
1384  
1385 # Check for improper arguments
1386 if (! defined $obj || defined $check) {
1387  
1388 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRect', @_);
1389 }
1390  
1391 $self->ivDelete('gridColourObjHash', $obj->number);
1392  
1393 return 1;
1394 }
1395  
1396 # Functions for $self->regionExitHash, ->regionPathHash, ->safeRegionPathHash
1397  
1398 sub storeRegionExit {
1399  
1400 # Called by GA::Obj::WorldModel->updateRegionPaths to store a region exit
1401 #
1402 # Expected arguments
1403 # $session - The calling function's GA::Session
1404 # $exitObj - The GA::Obj::Exit to store (a region exit)
1405 #
1406 # Return values
1407 # 'undef' on improper arguments or if $exitObj is not a region exit with a destination
1408 # room set
1409 # 1 otherwise
1410  
1411 my ($self, $session, $exitObj, $check) = @_;
1412  
1413 # Local variables
1414 my $destRoomObj;
1415  
1416 # Check for improper arguments
1417 if (! defined $session || ! defined $exitObj || defined $check) {
1418  
1419 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeRegionExit', @_);
1420 }
1421  
1422 # Check that it's really a region exit with a destination room set
1423 if (! $exitObj->regionFlag || ! $exitObj->destRoom || $exitObj->randomType ne 'none') {
1424  
1425 return undef;
1426 }
1427  
1428 # Get the exit's destination region
1429 $destRoomObj = $session->worldModelObj->ivShow('modelHash', $exitObj->destRoom);
1430  
1431 # Store the drawn exit
1432 $self->ivAdd('regionExitHash', $exitObj->number, $destRoomObj->parent);
1433  
1434 return 1;
1435 }
1436  
1437 sub removeRegionExit {
1438  
1439 # Called by GA::Obj::WorldModel->updateRegionPaths to remove a stored region exit
1440 #
1441 # Expected arguments
1442 # $exitObj - The GA::Obj::Exit to remove
1443 #
1444 # Return values
1445 # 'undef' on improper arguments
1446 # 1 otherwise
1447  
1448 my ($self, $exitObj, $check) = @_;
1449  
1450 # Check for improper arguments
1451 if (! defined $exitObj || defined $check) {
1452  
1453 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeRegionExit', @_);
1454 }
1455  
1456 # Remove the exit, if it is stored
1457 $self->ivDelete('regionExitHash', $exitObj->number);
1458  
1459 return 1;
1460 }
1461  
1462 sub storePath {
1463  
1464 # Called by GA::Obj::WorldModel->connectRegionExits and ->replaceRegionPath to add a region
1465 # path to one (but not both) of the IVs ->regionPathHash and ->safeRegionPathHash
1466 #
1467 # Expected arguments
1468 # $iv - Which hash IV should be used to store the region path:
1469 # 'regionPathHash' or 'safeRegionPathHash'
1470 # $exitObj, $exitObj2 - The exit objects at each end of the path
1471 # $pathObj - The GA::Obj::RegionPath object which connects the two exits
1472 #
1473 # Return values
1474 # 'undef' on improper arguments
1475 # 1 otherwise
1476  
1477 my ($self, $iv, $exitObj, $exitObj2, $pathObj, $check) = @_;
1478  
1479 # Check for improper arguments
1480 if (
1481 ! defined $iv || ! defined $exitObj || ! defined $exitObj2 || ! defined $pathObj
1482 || defined $check
1483 ) {
1484 return $axmud::CLIENT->writeImproper($self->_objClass . '->storePath', @_);
1485 }
1486  
1487 # Store the path objects
1488 $self->ivAdd(
1489 $iv,
1490 $exitObj->number . '_' . $exitObj2->number,
1491 $pathObj,
1492 );
1493  
1494 return 1;
1495 }
1496  
1497 sub removePaths {
1498  
1499 # Called by GA::Obj::WorldModel->updateRegionPaths and ->replaceRegionPath to remove a
1500 # region path from one or both of the IVs ->regionPathHash and ->safeRegionPathHash
1501 #
1502 # Expected arguments
1503 # $exitString - A string describing the region path to remove (a key in one of the
1504 # hash IVs ->regionPathHash and ->safeRegionPathHash)
1505 #
1506 # Optional arguments
1507 # $iv - If specified, set to 'regionPathHash' or 'safeRegionPathHash'. If
1508 # not specified, the region path is removed from both hash IVs
1509 #
1510 # Return values
1511 # 'undef' on improper arguments
1512 # 1 otherwise
1513  
1514 my ($self, $exitString, $iv, $check) = @_;
1515  
1516 # Check for improper arguments
1517 if (! defined $exitString || defined $check) {
1518  
1519 return $axmud::CLIENT->writeImproper($self->_objClass . '->removePaths', @_);
1520 }
1521  
1522 # Remove the region path from one or both hash IVs
1523 if (! $iv || $iv eq 'regionPathHash') {
1524  
1525 $self->ivDelete('regionPathHash', $exitString);
1526 }
1527  
1528 if (! $iv || $iv eq 'safeRegionPathHash') {
1529  
1530 $self->ivDelete('safeRegionPathHash', $exitString);
1531 }
1532  
1533 return 1;
1534 }
1535  
1536 sub resetPaths {
1537  
1538 # Called by GA::Obj::WorldModel->recalculateRegionPaths
1539 # Empties the regionmap's list of region paths, so that new ones can be calculated
1540 #
1541 # Expected arguments
1542 # (none besides $self)
1543 #
1544 # Return values
1545 # 'undef' on improper arguments
1546 # 1 otherwise
1547  
1548 my ($self, $check) = @_;
1549  
1550 # Check for improper arguments
1551 if (defined $check) {
1552  
1553 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetPaths', @_);
1554 }
1555  
1556 # Empty the region path hash IVs
1557 $self->ivEmpty('regionPathHash');
1558 $self->ivEmpty('safeRegionPathHash');
1559  
1560 return 1;
1561 }
1562  
1563 # Functions for $self->livingCountHash, ->nonLivingCountHash
1564  
1565 sub resetCounts {
1566  
1567 # Called by GA::Obj::WorldModel->resetRegionCounts
1568 # Empties the ->livingCountHash and ->nonLivingCountHash IVs (for compatibility with
1569 # other functions modifying these IVs, we'll provide a separate function for doing it)
1570 #
1571 # Expected arguments
1572 # (none besides $self)
1573 #
1574 # Return values
1575 # 'undef' on improper arguments
1576 # 1 otherwise
1577  
1578 my ($self, $check) = @_;
1579  
1580 # Check for improper arguments
1581 if (defined $check) {
1582  
1583 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCounts', @_);
1584 }
1585  
1586 # Update the IVs
1587 $self->ivEmpty('livingCountHash');
1588 $self->ivEmpty('nonLivingCountHash');
1589  
1590 return 1;
1591 }
1592  
1593 sub storeLivingCount {
1594  
1595 # Called by GA::Obj::WorldModel->moveRoomsLabels and ->countRoomContents and to update this
1596 # region's count of living beings
1597 #
1598 # Expected arguments
1599 # $roomNum - The number of the model room whose count of living beings is being updated
1600 #
1601 # Optional arguments
1602 # $count - The number of living beings in this room. If zero or 'undef', no entry is
1603 # added (we don't need to track rooms with no living beings)
1604 #
1605 # Return values
1606 # 'undef' on improper arguments
1607 # 1 otherwise
1608  
1609 my ($self, $roomNum, $count, $check) = @_;
1610  
1611 # Check for improper arguments
1612 if (! defined $roomNum || defined $check) {
1613  
1614 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeLivingCount', @_);
1615 }
1616  
1617 # Update the IV
1618 if ($count) {
1619  
1620 $self->ivAdd('livingCountHash', $roomNum, $count);
1621 }
1622  
1623 return 1;
1624 }
1625  
1626 sub removeLivingCount {
1627  
1628 # Called by GA::Obj::WorldModel->deleteRooms, moveRoomsLabels and ->countRoomContents to
1629 # update this region's count of living beings
1630 #
1631 # Expected arguments
1632 # $roomNum - The number of the model room whose count of living beings is being updated
1633 #
1634 # Return values
1635 # 'undef' on improper arguments
1636 # Otherwise, returns the current number of living beings stored for this room (may be
1637 # zero)
1638  
1639 my ($self, $roomNum, $check) = @_;
1640  
1641 # Local variables
1642 my $count;
1643  
1644 # Check for improper arguments
1645 if (! defined $roomNum || defined $check) {
1646  
1647 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeLivingCount', @_);
1648 }
1649  
1650 # Get the current number of living beings stored
1651 if ($self->ivExists('livingCountHash', $roomNum)) {
1652  
1653 $count = $self->ivShow('livingCountHash', $roomNum);
1654  
1655 # If there are no living beings in the room, there will be no entry in ->livingCountHash
1656 # but we still need to return an explicit zero
1657 if (! $count) {
1658  
1659 $count = 0;
1660 }
1661 }
1662  
1663 # Update the IV
1664 if ($count) {
1665  
1666 $self->ivDelete('livingCountHash', $roomNum);
1667 }
1668  
1669 return $count;
1670 }
1671  
1672 sub storeNonLivingCount {
1673  
1674 # Called by GA::Obj::WorldModel->moveRoomsLabels and ->countRoomContents to update this
1675 # region's count of non-living beings
1676 #
1677 # Expected arguments
1678 # $roomNum - The number of the model room whose count of non-living beings is being
1679 # updated
1680 #
1681 # Optional arguments
1682 # $count - The number of non-living beings in this room. If zero or 'undef', no entry
1683 # is added (we don't need to track rooms with no non-living beings)
1684 #
1685 # Return values
1686 # 'undef' on improper arguments
1687 # 1 otherwise
1688  
1689 my ($self, $roomNum, $count, $check) = @_;
1690  
1691 # Check for improper arguments
1692 if (! defined $roomNum || defined $check) {
1693  
1694 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeNonLivingCount', @_);
1695 }
1696  
1697 # Update the IV
1698 if ($count) {
1699  
1700 $self->ivAdd('nonLivingCountHash', $roomNum, $count);
1701 }
1702  
1703 return 1;
1704 }
1705  
1706 sub removeNonLivingCount {
1707  
1708 # Called by GA::Obj::WorldModel->deleteRooms, ->moveRoomsLabels and ->countRoomContents to
1709 # update this region's count of non-living beings
1710 #
1711 # Expected arguments
1712 # $roomNum - The number of the model room whose count of non-living beings is being
1713 # updated
1714 #
1715 # Return values
1716 # 'undef' on improper arguments
1717 # Otherwise, returns the current number of non-living beings stored for this room (may be
1718 # zero)
1719  
1720 my ($self, $roomNum, $check) = @_;
1721  
1722 # Local variables
1723 my $count;
1724  
1725 # Check for improper arguments
1726 if (! defined $roomNum || defined $check) {
1727  
1728 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeNonLivingCount', @_);
1729 }
1730  
1731 # Get the current number of non-living beings stored
1732 if ($self->ivExists('nonLivingCountHash', $roomNum)) {
1733  
1734 $count = $self->ivShow('nonLivingCountHash', $roomNum);
1735  
1736 # If there are no non-living beings in the room, there will be no entry in
1737 # ->livingCountHash, but we still need to return an explicit zero
1738 if (! $count) {
1739  
1740 $count = 0;
1741 }
1742 }
1743  
1744 # Update the IV
1745 if ($count) {
1746  
1747 $self->ivDelete('nonLivingCountHash', $roomNum);
1748 }
1749  
1750 return $count;
1751 }
1752  
1753 # Other functions
1754  
1755 sub getGridCentre {
1756  
1757 # Can be called by anything
1758 # Finds the grid coordinates of the centre of the regionmap's grid
1759 #
1760 # Expected arguments
1761 # (none besides $self)
1762 #
1763 # Return values
1764 # The list (0, 0, 0) on improper arguments
1765 # Otherwise, returns a list containing the coordinates of the centre of the grid, in the
1766 # form (x, y, z)
1767  
1768 my ($self, $check) = @_;
1769  
1770 # Local variables
1771 my ($xPosBlocks, $yPosBlocks, $zPosBlocks);
1772  
1773 # Check for improper arguments
1774 if (defined $check) {
1775  
1776 $axmud::CLIENT->writeImproper($self->_objClass . '->getGridCentre', @_);
1777 return (0, 0, 0);
1778 }
1779  
1780 $xPosBlocks = int (($self->gridWidthBlocks) / 2);
1781 $yPosBlocks = int (($self->gridHeightBlocks) / 2);
1782 $zPosBlocks = 0; # 'Ground' level
1783  
1784 return ($xPosBlocks, $yPosBlocks, $zPosBlocks);
1785 }
1786  
1787 ##################
1788 # Accessors - set
1789  
1790 ##################
1791 # Accessors - get
1792  
1793 sub name
1794 { $_[0]->{name} }
1795 sub number
1796 { $_[0]->{number} }
1797  
1798 sub magnification
1799 { $_[0]->{magnification} }
1800 sub scrollXPos
1801 { $_[0]->{scrollXPos} }
1802 sub scrollYPos
1803 { $_[0]->{scrollYPos} }
1804 sub maxZoomOutXFlag
1805 { $_[0]->{maxZoomOutXFlag} }
1806 sub maxZoomOutYFlag
1807 { $_[0]->{maxZoomOutYFlag} }
1808  
1809 sub gridWidthBlocks
1810 { $_[0]->{gridWidthBlocks} }
1811 sub gridHeightBlocks
1812 { $_[0]->{gridHeightBlocks} }
1813 sub blockWidthPixels
1814 { $_[0]->{blockWidthPixels} }
1815 sub blockHeightPixels
1816 { $_[0]->{blockHeightPixels} }
1817 sub roomWidthPixels
1818 { $_[0]->{roomWidthPixels} }
1819 sub roomHeightPixels
1820 { $_[0]->{roomHeightPixels} }
1821 sub mapWidthPixels
1822 { $_[0]->{mapWidthPixels} }
1823 sub mapHeightPixels
1824 { $_[0]->{mapHeightPixels} }
1825  
1826 sub regionScheme
1827 { $_[0]->{regionScheme} }
1828  
1829 sub drawExitMode
1830 { $_[0]->{drawExitMode} }
1831 sub obscuredExitFlag
1832 { $_[0]->{obscuredExitFlag} }
1833 sub obscuredExitRedrawFlag
1834 { $_[0]->{obscuredExitRedrawFlag} }
1835 sub obscuredExitRadius
1836 { $_[0]->{obscuredExitRadius} }
1837 sub drawOrnamentsFlag
1838 { $_[0]->{drawOrnamentsFlag} }
1839  
1840 sub currentLevel
1841 { $_[0]->{currentLevel} }
1842 sub highestLevel
1843 { $_[0]->{highestLevel} }
1844 sub lowestLevel
1845 { $_[0]->{lowestLevel} }
1846  
1847 sub gridRoomHash
1848 { my $self = shift; return %{$self->{gridRoomHash}}; }
1849 sub gridRoomTagHash
1850 { my $self = shift; return %{$self->{gridRoomTagHash}}; }
1851 sub gridRoomGuildHash
1852 { my $self = shift; return %{$self->{gridRoomGuildHash}}; }
1853 sub gridExitHash
1854 { my $self = shift; return %{$self->{gridExitHash}}; }
1855 sub gridExitTagHash
1856 { my $self = shift; return %{$self->{gridExitTagHash}}; }
1857 sub gridLabelHash
1858 { my $self = shift; return %{$self->{gridLabelHash}}; }
1859  
1860 sub labelCount
1861 { $_[0]->{labelCount} }
1862  
1863 sub gridColourBlockHash
1864 { my $self = shift; return %{$self->{gridColourBlockHash}}; }
1865 sub gridColourObjHash
1866 { my $self = shift; return %{$self->{gridColourObjHash}}; }
1867 sub colourObjCount
1868 { $_[0]->{colourObjCount} }
1869  
1870 sub regionExitHash
1871 { my $self = shift; return %{$self->{regionExitHash}}; }
1872 sub regionPathHash
1873 { my $self = shift; return %{$self->{regionPathHash}}; }
1874 sub safeRegionPathHash
1875 { my $self = shift; return %{$self->{safeRegionPathHash}}; }
1876  
1877 sub livingCountHash
1878 { my $self = shift; return %{$self->{livingCountHash}}; }
1879 sub nonLivingCountHash
1880 { my $self = shift; return %{$self->{nonLivingCountHash}}; }
1881 }
1882  
1883 # Package must return a true value
1884 1