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

filter: Statementstmt 0.0% 0 / 237 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 144 MC/DCmcdc 0.0% 0 / 78 Subroutinesub 0.0% 0 / 25 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 590 CC 43 SCAR 44.0
CC
43
Cov
0%
setupStandardWinmap
272.0
findWinzone
56.0
new
42.0
CRAP 81.1
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::Winmap
16 # A winmap is a plan for arranging widgets in any 'grid' window except 'external' windows
17  
18 { package Games::Axmud::Obj::Winmap;
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::Client->createStandardWinmaps or GA::Cmd::AddWinmap->new
34 # Creates a new winmap, which is a plan for arranging widgets in any 'internal' window
35 # The winmap divides the window's client area into horizontal (by default) or vertical
36 # strips (conceptually, not using a specific Gtk3 widget)
37 # One (and only one) of the strips is occupied by a Gtk3::Grid, onto which any widget can be
38 # positioned. The other strips are placed above or below that strip, and typically contain
39 # things like a menu bar, a toolbar with clickable items or a Gtk3::Entry box. Besides the
40 # strips that Axmud provides, users can write their own strips and insert them via a
41 # plugin
42 # The winmap only affects the window, when it is first created (or when it is reset). The
43 # Axmud code is then free to add/remove strips, or add/remove widgets to the Gtk3::Grid,
44 # whenever it pleases
45 #
46 # Expected arguments
47 # $name - A unique name for the winmap (max 16 chars)
48 #
49 # Notes
50 # GA::Client->constWinmapNameHash defines some standard winmaps
51 #
52 # Return values
53 # 'undef' on improper arguments or if $name is invalid
54 # Blessed reference to the newly-created object on success
55  
56 my ($class, $name, $check) = @_;
57  
58 # Check for improper arguments
59 if (! defined $class || ! defined $name || defined $check) {
60  
61 return $axmud::CLIENT->writeImproper($class . '->new', @_);
62 }
63  
64 # Check that the winmap name is unique and isn't too long
65 if ($axmud::CLIENT->ivExists('winmapHash', $name)) {
66  
67 return $axmud::CLIENT->writeError(
68 'Registry naming error: winmap \'' . $name . '\' already exists',
69 $class . '->new',
70 );
71  
72 } elsif (! $axmud::CLIENT->nameCheck($name, 16)) {
73  
74 return $axmud::CLIENT->writeError(
75 'Registry naming error: illegal name \'' . $name . '\'',
76 $class . '->new',
77 );
78 }
79  
80 # Setup
81 my $self = {
82 _objName => $name,
83 _objClass => $class,
84 _parentFile => 'winmaps',
85 _parentWorld => undef,
86 _privFlag => TRUE, # All IVs are private
87  
88 # IVs
89 # ---
90  
91 # A unique name for the winmap
92 name => $name,
93  
94 # A hash of world profile names. Each specified world uses this winmap as its default
95 # winmap for its 'main' window (but only if GA::Client->shareMainWinFlag = FALSE,
96 # when all sessions have their own 'main' window)
97 # If plugins create winmaps tailored for a particular world, then ideally only one
98 # winmap should contain that world in this hash. Nevertheless, when creating 'main'
99 # windows, winmaps are tested in alphabetical order
100 # Hash in the form
101 # $worldHash{world_profile_name} = undef;
102 worldHash => {},
103  
104 # The order in which strip objects (inheriting from GA::Generic::Strip) are added to
105 # the window's client area
106 # 'top' - vertically, from top to bottom (default)
107 # 'bottom' - vertically, from bottom to top
108 # 'left' - horizontally, from left to right
109 # 'right' - horizontally, from right to left
110 orientation => 'top',
111 # List of package names for strip objects (inheriting from GA::Generic::Strip) with
112 # which to fill the window's client area and the initialisation settings for each
113 # object
114 # List in groups of two, in the form
115 # (package_name, hash_reference, package_name, hash_reference...)
116 # ...where 'package_name' is the class of the strip object (e.g. GA::Strip::GaugeBox)
117 # and 'hash_reference' is either 'undef', or is a reference to a hash containing
118 # arbitrary data to use as the strip object's initialisation settings. The strip
119 # object should use default initialisation settings unless it can succesfully
120 # interpret one or more of the key-value pairs in the hash, if there are any
121 # For strip objects that are 'jealous', only the first one of its kind is added;
122 # subsequent ones are ignored
123 # Must contain at least the strip object which implements the Gtk3::Grid,
124 # GA::Strip::Table; if not, when the window is created that strip object is added
125 # anyway, all the others have been added
126 stripInitList => [],
127  
128 # The size of the Gtk3::Grid (cannot be changed)
129 tableSize => 60,
130 # The winzone objects (GA::Obj::Winzone), each of which marks out an area of the
131 # Gtk3::Grid for a single widget. Hash in the form
132 # $zoneHash{number} = blessed_reference_to_winzone_object
133 # NB 'main' windows must have at last one pane object (GA::Table::Pane). The pane
134 # object with the lowest 'number' is used as the session's default pane object
135 # initially. If this hash contains no winzones that create a pane object, it can't be
136 # used with 'main' windows
137 zoneHash => {},
138 # Number of winzones ever created for this winmap (used to give every winzone object a
139 # number unique to the winmap)
140 zoneCount => 0,
141 # Flag set to TRUE when the winmap becomes full
142 fullFlag => FALSE,
143  
144 # A suggested size for new winzones, used when table objects are added after the window
145 # is created (for example, used in 'main' windows when tasks want to create their own
146 # pane objects (GA::Table::Pane) instead of using a task window)
147 # These sizes should fit neatly onto the 60x60 Gtk3::Grid; for example, 15x15, or
148 # 30x15, or 20x15, or 20x60.
149 # The process of choosing a size and position for 'grid' windows is quite flexible, and
150 # is capable of customising window sizes to suit local conditions and to fill small
151 # gaps. However, the process for table objects is much less sophisticated. The sizes
152 # specified here, if used, are used exactly, so the safest thing to do is to use a
153 # width and height that are factors of $self->tableSize. In practice, for a 60x60
154 # grid, that means using the values 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 or 60.
155 # In addition, the size should fit neatly with the sizes of of winzones in
156 # $self->zoneHash. For example, if $self->zoneHash specifies a single pane object
157 # sizes 40x40, then the size specified here should usually be a factor of that, for
158 # example 40x20 or 20x20 or 10x20
159 zoneWidth => 30,
160 zoneHeight => 30,
161 };
162  
163 # Bless the object into existence
164 bless $self, $class;
165  
166 # Set up the winmap to its default (empty) state (not really necessary, but kept for
167 # compatibility with GA::Obj::Zonemap's design)
168 $self->resetWinmap();
169  
170 # If this is a standard winmap, auto-create some winzones within the winmap
171 if ($axmud::CLIENT->ivExists('constWinmapNameHash', $name)) {
172  
173 if (! $self->setupStandardWinmap()) {
174  
175 return $axmud::CLIENT->writeError(
176 'Can\'t set up the standard winmap \'' . $name . '\'',
177 $class . '->new',
178 );
179 }
180 }
181  
182 return $self;
183 }
184  
185 sub clone {
186  
187 # Called by GA::Cmd::CloneWinmap->do
188 # Create a clone of an existing winmap
189 #
190 # Expected arguments
191 # $name - A name for the new winmap (max 16 chars)
192 #
193 # Return values
194 # 'undef' on improper arguments, if $name is invalid or if this winmap is a temporary
195 # winmap (which can't be cloned)
196 # Blessed reference to the newly-created object on success
197  
198 my ($self, $name, $check) = @_;
199  
200 # Local variables
201 my $count;
202  
203 # Check for improper arguments
204 if (! defined $name || defined $check) {
205  
206 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
207 }
208  
209 # Check that the winmap name is unique and isn't too long
210 if ($axmud::CLIENT->ivExists('winmapHash', $name)) {
211  
212 return $axmud::CLIENT->writeError(
213 'Registry naming error: winmap \'' . $name . '\' already exists',
214 $self . '->clone',
215 );
216  
217 } elsif (! $axmud::CLIENT->nameCheck($name, 16)) {
218  
219 return $axmud::CLIENT->writeError(
220 'Registry naming error: illegal name \'' . $name . '\'',
221 $self . '->clone',
222 );
223 }
224  
225 # Setup
226 my $clone = {
227 _objName => $name,
228 _objClass => $self->_objClass,
229 _parentFile => 'winmaps',
230 _parentWorld => undef,
231 _privFlag => TRUE, # All IVs are private
232  
233 name => $name,
234  
235 worldHash => {$self->worldHash},
236  
237 orientation => $self->orientation,
238 stripInitList => [$self->stripInitList],
239  
240 tableSize => $self->tableSize,
241 zoneHash => {}, # Set below
242 zoneCount => undef, # Set below
243 fullFlag => $self->fullFlag,
244  
245 zoneWidth => $self->zoneWidth,
246 zoneHeight => $self->zoneHeight,
247 };
248  
249 # Bless the new winmap into existence
250 bless $clone, $self->_objClass;
251  
252 # Clone the winzones, in order. For example, if the old winmap had winzones numbered
253 # (0, 1, 4, 7), in the new winmap the cloned winzones are numbered (0, 1, 2, 3)
254 $count = 0;
255 foreach my $oldZoneObj (sort {$a <=> $b} ($self->ivValues('zoneHash'))) {
256  
257 my $cloneZoneObj;
258  
259 $cloneZoneObj = $oldZoneObj->clone($self, $count);
260 $clone->ivAdd('zoneHash', $count, $cloneZoneObj);
261  
262 $count++;
263 }
264  
265 $clone->ivPoke('zoneCount', $count);
266  
267 return $clone;
268 }
269  
270 ##################
271 # Methods
272  
273 sub setupStandardWinmap {
274  
275 # Called by $self->new whenever the specified name of the winmap is one of the standard
276 # winmaps defined by GA::Client->constWinmapNameHash
277 # (Could be called by any other function in order to reset a standard winmap, probably
278 # after a call to $self->resetWinmap)
279 # Sets up the standard winmap with its winzones
280 #
281 # Return values
282 # 'undef' on improper arguments, if $name isn't one of the standard winmap names or if
283 # any of the winzones can't be created
284 # 1 otherwise
285  
286 my ($self, $check) = @_;
287  
288 # Local variables
289 my $zone;
290  
291 # Check for improper arguments
292 if (defined $check) {
293  
294 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupStandardWinmap', @_);
295 }
296  
297 # Check that this really is a standard winmap
298 if (! $axmud::CLIENT->ivExists('constWinmapNameHash', $self->name)) {
299  
300 return undef;
301 }
302  
303 # (These IVs the same for all standard winmaps)
304 $self->ivPoke('orientation', 'top');
305  
306 # Set up $self->stripInitList
307 if ($self->name eq 'main_wait') {
308  
309 # From top to bottom, the window will contain a menu bar, toolbar, Gtk3::Grid and an
310 # entry box
311 $self->ivPush(
312 'stripInitList',
313 'Games::Axmud::Strip::MenuBar',
314 undef,
315 'Games::Axmud::Strip::Toolbar',
316 undef,
317 'Games::Axmud::Strip::Table',
318 undef,
319 'Games::Axmud::Strip::Entry',
320 undef,
321 );
322  
323 } elsif ($self->name eq 'internal_wait') {
324  
325 # Contains only the Gtk3::Grid
326 $self->ivPush(
327 'stripInitList',
328 'Games::Axmud::Strip::Table',
329 undef,
330 );
331  
332 } elsif (
333 $self->name eq 'main_fill'
334 || $self->name eq 'main_part'
335 || $self->name eq 'main_empty'
336 ) {
337 # From top to bottom, the window will contain a menu bar, toolbar, Gtk3::Grid, a gauge
338 # box, an entry box and an info box
339 $self->ivPush(
340 'stripInitList',
341 'Games::Axmud::Strip::MenuBar',
342 undef,
343 'Games::Axmud::Strip::Toolbar',
344 undef,
345 'Games::Axmud::Strip::Table',
346 undef,
347 'Games::Axmud::Strip::GaugeBox',
348 undef,
349 'Games::Axmud::Strip::SearchBox',
350 undef,
351 'Games::Axmud::Strip::Entry',
352 {
353 'wipe_flag' => TRUE,
354 'add_flag' => TRUE,
355 'console_flag' => TRUE,
356 'input_flag' => TRUE,
357 'search_flag' => TRUE,
358 'cancel_flag' => TRUE,
359 'switch_flag' => TRUE,
360 'scroll_flag' => TRUE,
361 'split_flag' => TRUE,
362 },
363 'Games::Axmud::Strip::ConnectInfo',
364 undef,
365 );
366  
367 } elsif (
368 $self->name eq 'basic_fill'
369 || $self->name eq 'basic_part'
370 || $self->name eq 'basic_empty'
371 ) {
372 # Contains only a Gtk3::Grid
373 $self->ivPush(
374 'stripInitList',
375 'Games::Axmud::Strip::Table',
376 undef,
377 );
378  
379 } elsif (
380 $self->name eq 'entry_fill'
381 || $self->name eq 'entry_part'
382 || $self->name eq 'entry_empty'
383 ) {
384 # From top to bottom, contains a Gtk3::Grid and an entry box
385 $self->ivPush(
386 'stripInitList',
387 'Games::Axmud::Strip::Table',
388 undef,
389 'Games::Axmud::Strip::Entry',
390 undef,
391 );
392 }
393  
394 # Set up $self->zoneHash
395 if (
396 $self->name eq 'main_fill'
397 || $self->name eq 'basic_fill'
398 || $self->name eq 'entry_fill'
399 ) {
400 $zone = Games::Axmud::Obj::Winzone->new($self);
401 if (! $zone) {
402  
403 # Winzone couldn't be created
404 return undef;
405 }
406  
407 $zone->{'left'} = 0;
408 $zone->{'right'} = 59;
409 $zone->{'top'} = 0;
410 $zone->{'bottom'} = 59;
411 $zone->{'width'} = 60;
412 $zone->{'height'} = 60;
413 $zone->{'packageName'} = 'Games::Axmud::Table::Pane';
414  
415 if ($self->name eq 'main_fill') {
416  
417  
418 $zone->{'initHash'} = {
419 # A textview object that expects split screen mode to be set to 'split'
420 'split_mode' => 'hidden',
421 };
422  
423 } else {
424  
425 $zone->{'initHash'} = {
426 # A textview object that doesn't expect split screen mode to be set to 'split'
427 'split_mode' => 'single',
428 };
429 }
430  
431 # Update this object's map, marking the area occupied by the winzone
432 $self->addWinzone($zone);
433  
434 } elsif ($self->name eq 'main_part') {
435  
436 $zone = Games::Axmud::Obj::Winzone->new($self);
437 if (! $zone) {
438  
439 # Winzone couldn't be created
440 return undef;
441 }
442  
443 $zone->{'left'} = 0;
444 $zone->{'right'} = 39;
445 $zone->{'top'} = 0;
446 $zone->{'bottom'} = 59;
447 $zone->{'width'} = 40;
448 $zone->{'height'} = 60;
449 $zone->{'packageName'} = 'Games::Axmud::Table::Pane';
450  
451 $zone->{'initHash'} = {
452 'split_mode' => 'hidden',
453 };
454  
455 # Update this object's map, marking the area occupied by the winzone
456 $self->addWinzone($zone);
457  
458 } elsif (
459 $self->name eq 'basic_part'
460 || $self->name eq 'entry_part'
461 ) {
462 $zone = Games::Axmud::Obj::Winzone->new($self);
463 if (! $zone) {
464  
465 # Winzone couldn't be created
466 return undef;
467 }
468  
469 $zone->{'left'} = 0;
470 $zone->{'right'} = 29;
471 $zone->{'top'} = 30;
472 $zone->{'bottom'} = 59;
473 $zone->{'width'} = 30;
474 $zone->{'height'} = 30;
475 $zone->{'packageName'} = 'Games::Axmud::Table::Pane';
476  
477 $zone->{'initHash'} = {
478 'split_mode' => 'single',
479 };
480  
481 # Update this object's map, marking the area occupied by the winzone
482 $self->addWinzone($zone);
483 }
484  
485 # Set up $self->zoneWidth, etc
486 if ($self->name eq 'main_part') {
487  
488 # (The other standard winmaps can all use the default 30x30 size)
489 $self->ivPoke('zoneWidth', 20);
490 $self->ivPoke('zoneHeight', 20);
491 }
492  
493 # Setup complete
494 return 1;
495 }
496  
497 sub resetWinmap {
498  
499 # Called by $self->new, GA::Cmd::ResetWinmap->do or any other function to reset the winmap's
500 # winzones
501 #
502 # Expected arguments
503 # (none besides $self)
504 #
505 # Return values
506 # 'undef' on improper arguments
507 # 1 otherwise
508  
509 my ($self, $check) = @_;
510  
511 # Check for improper arguments
512 if (defined $check) {
513  
514 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWinmap', @_);
515 }
516  
517 # Reset IVs
518 $self->ivEmpty('zoneHash');
519 $self->ivPoke('zoneCount', 0);
520 $self->ivPoke('fullFlag', FALSE);
521  
522 return 1;
523 }
524  
525 sub checkPosnInMap {
526  
527 # Called by $self->addWinzone and GA::Cmd::ModifyWinzone->do
528 # Checks that the winzone is unoccupied in a certain area
529 #
530 # Expected arguments
531 # $xPosBlocks, $yPosBlocks
532 # - Coordinates of the top-left corner of the search area
533 # $widthBlocks, $heightBlocks
534 # - The size of the search area
535 #
536 # Optional arguments
537 # $ignoreObj
538 # - A GA::Obj::Winzone object to ignore (used when resizing a winzone. Only count
539 # the search area as occupied if it's occupied by another winzone)
540 #
541 # Return values
542 # 'undef' on improper arguments, or if any part of the search area is occupied (except
543 # for the specified winzone, where appropriate)
544 # 1 if the whole search area is unoccupied
545  
546 my (
547 $self, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $ignoreObj, $check
548 ) = @_;
549  
550 # Local variables
551 my ($x1, $x2, $y1, $y2);
552  
553 # Check for improper arguments
554 if (
555 ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $widthBlocks
556 || ! defined $heightBlocks || defined $check
557 ) {
558 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPosnInMap', @_);
559 }
560  
561 $x1 = $xPosBlocks,
562 $x2 = $x1 + $widthBlocks - 1;
563 $y1 = $yPosBlocks,
564 $y2 = $y1 + $heightBlocks - 1;
565  
566 foreach my $zoneObj ($self->ivValues('zoneHash')) {
567  
568 if (! defined $ignoreObj || $zoneObj ne $ignoreObj) {
569  
570 if (
571 (
572 ($x1 >= $zoneObj->left && $x1 <= $zoneObj->right)
573 || ($x2 >= $zoneObj->left && $x2 <= $zoneObj->right)
574 ) && (
575 ($y1 >= $zoneObj->top && $y1 <= $zoneObj->bottom)
576 || ($y2 >= $zoneObj->top && $y2 <= $zoneObj->bottom)
577 )
578 ) {
579 return undef;
580 }
581 }
582 }
583  
584 # Whole search region is empty
585 return 1;
586 }
587  
588 sub addWinzone {
589  
590 # Called by $self->setupStandardWinzone and GA::Cmd::AddWinzone->do
591 # Adds a winzone to the winmap, first checking that the area specified by the winzone's
592 # IVs is unoccupied
593 #
594 # Expected arguments
595 # $zoneObj - Blessed reference to the GA::Obj::Winzone object to add to the winmap
596 #
597 # Return values
598 # 'undef' on improper arguments, if the new winzone's size variables are invalid or if
599 # the specified area is occupied
600 # 1 otherwise
601  
602 my ($self, $zoneObj, $check) = @_;
603  
604 # Local variables
605 my @grid;
606  
607 # Check for improper arguments
608 if (! defined $zoneObj || defined $check) {
609  
610 return $axmud::CLIENT->writeImproper($self->_objClass . '->addWinzone', @_);
611 }
612  
613 # Check that the winzone isn't bigger than the winmap's Gtk3::Grid
614 if (
615 $zoneObj->left < 0 || $zoneObj->right > ($self->tableSize - 1)
616 || $zoneObj->top < 0 || $zoneObj->bottom > ($self->tableSize - 1)
617 || ($zoneObj->right - $zoneObj->left + 1) != $zoneObj->width
618 || ($zoneObj->bottom - $zoneObj->top + 1) != $zoneObj->height
619 ) {
620 return $axmud::CLIENT->writeError(
621 'Invalid size/position variables specified for the winzone',
622 $self->_objClass . '->addWinzone',
623 );
624 }
625  
626 # Check that the area where the winzone wants to be placed isn't already allocated to
627 # another winzone
628 if (
629 ! $self->checkPosnInMap(
630 $zoneObj->left,
631 $zoneObj->top,
632 $zoneObj->width,
633 $zoneObj->height,
634 )
635 ) {
636 return $axmud::CLIENT->writeError(
637 'Winmap ' . $self->name . ' already occupied at x/y ' . $zoneObj->left
638 . '/' . $zoneObj->top . ', cannot place new winzone there',
639 $self->_objClass . '->addWinzone',
640 );
641 }
642  
643 # Add the winzone to the winmap
644 $zoneObj->set_number($self->zoneCount);
645 $self->ivAdd('zoneHash', $zoneObj->number, $zoneObj);
646 $self->ivIncrement('zoneCount');
647  
648 # Check to see if there are any empty gridblocks and, if there are none, set a flag
649 for (my $x = 0; $x < $self->tableSize; $x++) {
650  
651 for (my $y = 0; $y < $self->tableSize; $y++) {
652  
653 # Mark this gridblock unoccupied (for the moment)
654 $grid[$x][$y] = undef;
655 }
656 }
657  
658 foreach my $otherObj ($self->ivValues('zoneHash')) {
659  
660 for (my $x = $otherObj->left; $x <= $otherObj->right; $x++) {
661  
662 for (my $y = $otherObj->top; $y <= $otherObj->bottom; $y++) {
663  
664 # Mark this gridblock occupied
665 $grid[$x][$y] = 1;
666 }
667 }
668 }
669  
670 $self->ivPoke('fullFlag', TRUE);
671 OUTER: for (my $x = 0; $x < 60; $x++) {
672  
673 for (my $y = 0; $y < 60; $y++) {
674  
675 if (! $grid[$x][$y]) {
676  
677 $self->ivPoke('fullFlag', FALSE);
678 last OUTER;
679 }
680 }
681 }
682  
683 return 1;
684 }
685  
686 sub deleteWinzone {
687  
688 # Called by GA::Cmd::DeleteWinzone->do
689 # Deletes a winzone from the winmap
690 #
691 # Expected arguments
692 # $number - The number of the winzone to delete
693 #
694 # Return values
695 # 'undef' on improper arguments or if the winzone $number doesn't exist
696 # 1 otherwise
697  
698 my ($self, $number, $check) = @_;
699  
700 # Local variables
701 my $zoneObj;
702  
703 # Check for improper arguments
704 if (! defined $number || defined $check) {
705  
706 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteWinzone', @_);
707 }
708  
709 # Check that specified winzone exists
710 $zoneObj = $self->ivShow('zoneHash', $number);
711 if (! $zoneObj) {
712  
713 return undef;
714  
715 } else {
716  
717 $self->ivDelete('zoneHash', $number);
718 $self->ivPoke('fullFlag', FALSE);
719  
720 return 1;
721 }
722 }
723  
724 sub findWinzone {
725  
726 # Can be called by anything
727 # Given an area of the winmap that's at least partly occupied, go through the area block by
728 # block and return the first winzone found
729 #
730 # Expected arguments
731 # $left, $top, $width, $height
732 # - The size of the area (in gridblocks) to search. The winmap is 60x60, so if any
733 # of these arguments are invalid (e.g. $right = 70), default values are used
734 # (e.g. $right = 59)
735 #
736 # Return values
737 # 'undef' on improper arguments or if the search area contains no winzones
738 # Otherwise, returns the first GA::Obj::Winzone found
739  
740 my ($self, $left, $top, $width, $height, $check) = @_;
741  
742 # Local variables
743 my ($x1, $x2, $y1, $y2);
744  
745 # Check for improper arguments
746 if (
747 ! defined $left || ! defined $top || ! defined $width || ! defined $height
748 || defined $check
749 ) {
750 return $axmud::CLIENT->writeImproper($self->_objClass . '->findWinzone', @_);
751 }
752  
753 # Check that the arguments are valid and, if not, use default values
754 if ($left < 0) {
755  
756 $left = 0;
757 }
758  
759 if (($left + $width) > $self->tableSize) {
760  
761 $width = ($self->tableSize - $left);
762 }
763  
764 if ($top < 0) {
765  
766 $top = 0;
767 }
768  
769 if (($top + $height) > $self->tableSize) {
770  
771 $height = ($self->tableSize - $top);
772 }
773  
774 # Check the search area
775 $x1 = $left,
776 $x2 = $x1 + $width - 1;
777 $y1 = $top,
778 $y2 = $y1 + $height - 1;
779  
780 foreach my $winzoneObj ($self->ivValues('zoneHash')) {
781  
782 if (
783 (
784 ($x1 >= $winzoneObj->left && $x1 <= $winzoneObj->right)
785 || ($x2 >= $winzoneObj->left && $x2 <= $winzoneObj->right)
786 ) && (
787 ($y1 >= $winzoneObj->top && $y1 <= $winzoneObj->bottom)
788 || ($y2 >= $winzoneObj->top && $y2 <= $winzoneObj->bottom)
789 )
790 ) {
791 return $winzoneObj;
792 }
793 }
794  
795 # No zone models found in the search area
796 return undef;
797 }
798  
799 ##################
800 # Accessors - set
801  
802 sub set_orientation {
803  
804 my ($self, $string, $check) = @_;
805  
806 # Check for improper arguments
807 if (! defined $string || defined $check) {
808  
809 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_orientation', @_);
810 }
811  
812 if ($string ne 'top' && $string ne 'bottom' && $string ne 'left' && $string ne 'right') {
813  
814 return undef;
815  
816 } else {
817  
818 $self->ivPoke('orientation', $string);
819  
820 return 1;
821 }
822 }
823  
824 sub set_stripInitList {
825  
826 my ($self, @list) = @_;
827  
828 # (No improper arguments to check)
829  
830 $self->ivPoke('stripInitList', @list);
831  
832 return 1;
833 }
834  
835 sub set_worldHash {
836  
837 my ($self, %hash) = @_;
838  
839 # (No improper arguments to check)
840  
841 $self->ivPoke('worldHash', %hash);
842  
843 return 1;
844 }
845  
846 sub set_zoneSize {
847  
848 my ($self, $width, $height, $check) = @_;
849  
850 # Check for improper arguments
851 if (! defined $width || ! defined $height || defined $check) {
852  
853 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_zoneSize', @_);
854 }
855  
856 $self->ivPoke('zoneWidth', $width);
857 $self->ivPoke('zoneHeight', $height);
858  
859 return 1;
860 }
861  
862 ##################
863 # Accessors - get
864  
865 sub name
866 { $_[0]->{name} }
867  
868 sub worldHash
869 { my $self = shift; return %{$self->{worldHash}}; }
870  
871 sub orientation
872 { $_[0]->{orientation} }
873 sub stripInitList
874 { my $self = shift; return @{$self->{stripInitList}}; }
875  
876 sub tableSize
877 { $_[0]->{tableSize} }
878 sub zoneHash
879 { my $self = shift; return %{$self->{zoneHash}}; }
880 sub zoneCount
881 { $_[0]->{zoneCount} }
882 sub fullFlag
883 { $_[0]->{fullFlag} }
884  
885 sub zoneWidth
886 { $_[0]->{zoneWidth} }
887 sub zoneHeight
888 { $_[0]->{zoneHeight} }
889 }
890  
891 # Package must return a true value
892 1