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

filter: Statementstmt 0.0% 0 / 548 Branchbran 0.0% 0 / 112 Conditioncond 0.0% 0 / 102 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 854 CC 57 SCAR 57.7
CC
57
Cov
0%
setupStandardZonemap
812.0
new
56.0
findZoneModel
56.0
CRAP 321.4
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::Zonemap
16 # A zonemap is a plan for arranging windows on a workspace grid which has been split into one or
17 # more zones
18  
19 { package Games::Axmud::Obj::Zonemap;
20  
21 use strict;
22 use warnings;
23 # use diagnostics;
24  
25 use Glib qw(TRUE FALSE);
26  
27 our @ISA = qw(Games::Axmud);
28  
29 ##################
30 # Constructors
31  
32 sub new {
33  
34 # Called by GA::Client->createStandardZonemaps or GA::Cmd::AddZonemap->new
35 # Creates a new zonemap which consists of a 60x60 grid (a size which is hard-coded and
36 # cannot be changed). The coordinates of the top-left corner of the grid are (0,0), and
37 # the coordinates of the bottom-right corner are (59,59)
38 # The grid is divided into GA::ZoneModel objects 'zone models', blueprints for real
39 # GA::Obj::Zone objects when they are created
40 # Because the blocks of a zonemap grid are an arbitrary size, the zonemap can be applied to
41 # a workspace of any size
42 #
43 # Expected arguments
44 # $name - A unique name for the zonemap (max 16 chars)
45 #
46 # Optional arguments
47 # $tempFlag - Set to TRUE if this is a temporary zonemap just for this $session,
48 # that isn't saved and can't be modified by the user. If set to FALSE
49 # (or 'undef'), a normal zonemap
50 # $tempSession - For temporary zonemaps, the parent GA::Session ('undef' for normal
51 # zonemaps)
52 #
53 # Notes
54 # GA::Client->constZonemapHash defines some standard zonemaps with names like 'single',
55 # 'basic', 'extended', 'widescreen', 'horizontal', 'vertical'
56 # Calling $self->new with $name set to one of the defined strings will fill the zonemap
57 # with zones; otherwise the zonemap remains empty until some other code fills it
58 #
59 # Return values
60 # 'undef' on improper arguments or if $name is invalid
61 # Blessed reference to the newly-created object on success
62  
63 my ($class, $name, $tempFlag, $tempSession, $check) = @_;
64  
65 # Check for improper arguments
66 if (! defined $class || ! defined $name || defined $check) {
67  
68 return $axmud::CLIENT->writeImproper($class . '->new', @_);
69 }
70  
71 # Check that the zonemap name is unique and isn't too long
72 if ($axmud::CLIENT->ivExists('zonemapHash', $name)) {
73  
74 return $axmud::CLIENT->writeError(
75 'Registry naming error: zonemap \'' . $name . '\' already exists',
76 $class . '->new',
77 );
78  
79 } elsif (! $axmud::CLIENT->nameCheck($name, 16)) {
80  
81 return $axmud::CLIENT->writeError(
82 'Registry naming error: illegal name \'' . $name . '\'',
83 $class . '->new',
84 );
85 }
86  
87 # Set default IV values
88 if (! defined $tempFlag) {
89  
90 $tempFlag = FALSE;
91 }
92  
93 # Setup
94 my $self = {
95 _objName => $name,
96 _parentFile => 'zonemaps',
97 _parentWorld => undef,
98 _objClass => $class,
99 _privFlag => TRUE, # All IVs are private
100  
101 # IVs
102 # ---
103  
104 # A unique name for the zonemap
105 name => $name,
106  
107 # The size of the zonemap grid (cannot be changed)
108 gridSize => 60,
109 # Hash of zone model objects associated with this map, in the form
110 # $modelHash{number} = blessed_reference_to_zone_model_object
111 modelHash => {},
112 # Number of zone models ever created for this zonemap (used to give every zone model
113 # object a number unique to the zonemap)
114 modelCount => 0,
115 # Flag set to TRUE when the zonemap becomes full
116 fullFlag => FALSE,
117  
118 # Some code (such as the MXP protocol) requires temporary zonemaps
119 # Temporary zonemaps are not saved by GA::Obj::File->saveDataFile, nor can they be
120 # modified by the user
121 tempFlag => $tempFlag,
122 # For temporary zonemaps, the GA::Session which created them is the only session which
123 # is allowed to use them, and is stored here. Set to 'undef' for non-temporary
124 # zonemaps (set below)
125 tempSession => $tempSession,
126 };
127  
128 # Bless the object into existence
129 bless $self, $class;
130  
131 # Set up the zonemap to its default (empty) state
132 $self->resetZonemap();
133  
134 # If this is a standard zonemap, auto-create some zone models within the zonemap
135 if ($axmud::CLIENT->ivExists('constZonemapHash', $name)) {
136  
137 if (! $self->setupStandardZonemap()) {
138  
139 return $axmud::CLIENT->writeError(
140 'Can\'t set up the standard zonemap \'' . $name . '\' - error creating zone'
141 . ' models',
142 $class . '->new',
143 );
144 }
145 }
146  
147 return $self;
148 }
149  
150 sub clone {
151  
152 # Called by GA::Cmd::CloneZonemap->do
153 # Create a clone of an existing zonemap
154 #
155 # Expected arguments
156 # $name - A name for the new zonemap (max 16 chars)
157 #
158 # Return values
159 # 'undef' on improper arguments, if $name is invalid or if this zonemap is a temporary
160 # zonemap (which can't be cloned)
161 # Blessed reference to the newly-created object on success
162  
163 my ($self, $name, $check) = @_;
164  
165 # Local variables
166 my ($count, $updateName);
167  
168 # Check for improper arguments
169 if (! defined $name || defined $check) {
170  
171 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
172 }
173  
174 # Check that the zonemap name is unique and isn't too long
175 if ($axmud::CLIENT->ivExists('zonemapHash', $name)) {
176  
177 return $axmud::CLIENT->writeError(
178 'Registry naming error: zonemap \'' . $name . '\' already exists',
179 $self . '->clone',
180 );
181  
182 } elsif (! $axmud::CLIENT->nameCheck($name, 16)) {
183  
184 return $axmud::CLIENT->writeError(
185 'Registry naming error: illegal name \'' . $name . '\'',
186 $self . '->clone',
187 );
188  
189 } elsif ($self->tempFlag) {
190  
191 return $axmud::CLIENT->writeError(
192 'Temporary zonemaps cannot be cloned',
193 $self . '->clone',
194 );
195 }
196  
197 # Setup
198 my $clone = {
199 _objName => $name,
200 _parentFile => 'zonemaps',
201 _parentWorld => undef,
202 _objClass => $self->_objClass,
203 _privFlag => TRUE, # All IVs are private
204  
205 name => $name,
206  
207 gridSize => $self->gridSize,
208 modelHash => {}, # Set below
209 modelCount => undef, # Set below
210 fullFlag => $self->fullFlag,
211  
212 tempFlag => undef,
213 tempSession => undef,
214 };
215  
216 # Bless the new zonemap into existence
217 bless $clone, $self->_objClass;
218  
219 # Clone the zone models, in order. For example, if the old zonemap had zone models numbered
220 # (0, 1, 4, 7), in the new zonemap the cloned zone models are numbered (0, 1, 2, 3)
221 $count = 0;
222 foreach my $oldModelObj (sort {$a->number <=> $b->number} ($self->ivValues('modelHash'))) {
223  
224 my $cloneModelObj;
225  
226 $cloneModelObj = $oldModelObj->clone($self, $count);
227 $clone->ivAdd('modelHash', $count, $cloneModelObj);
228  
229 $count++;
230 }
231  
232 $clone->ivPoke('modelCount', $count);
233  
234 # If the original and clone are both standard zonemaps, it's because the clone needs to
235 # have its zone models modified to allow multiple layers
236 $updateName = $axmud::CLIENT->ivShow('constZonemapHash', $self->name);
237 if ($updateName && $updateName eq $name) {
238  
239 $clone->modifyStandardZonemap();
240 }
241  
242 return $clone;
243 }
244  
245 ##################
246 # Methods
247  
248 sub setupStandardZonemap {
249  
250 # Called by $self->new whenever the specified name of the zonemap is one of the standard
251 # zonemaps defined by GA::Client->constZonemapHash
252 # (Could be called by any other function in order to reset a standard zonemap, probably
253 # after a call to $self->resetZonemap)
254 # Sets up some types of standard zonemap with their zone models; other types of standard
255 # zonemap are cloned from these ones
256 #
257 # Expected arguments
258 # (none besides $self)
259 #
260 # Return values
261 # 'undef' on improper arguments, if $name isn't one of the standard zonemap names or if
262 # any of the zone models can't be created
263 # 1 otherwise
264  
265 my ($self, $check) = @_;
266  
267 # Local variables
268 my (
269 $zone, $otherZone, $zoneLeft, $zoneRight, $zoneUpperLeft, $zoneLowerLeft,
270 $zoneUpperRight, $zoneCentreRight, $zoneLowerRight,
271 );
272  
273 # Check for improper arguments
274 if (defined $check) {
275  
276 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupStandardZonemap', @_);
277 }
278  
279 if ($self->name eq 'single') {
280  
281 # 'single' - The entire workspace is covered by a single zone. Windows (even 'main'
282 # windows) use their default sizes. Windows cannot be stacked above each other
283  
284 # 111111111111
285 # 111111111111
286 # 111111111111
287 # 111111111111
288 # 111111111111
289 # 111111111111
290 # 111111111111
291 # 111111111111
292 # 111111111111
293 # 111111111111
294 # 111111111111
295 # 111111111111
296  
297 $zone = Games::Axmud::Obj::ZoneModel->new($self);
298 if (! $zone) {
299  
300 # Zone model couldn't be created
301 return undef;
302 }
303  
304 $zone->{'left'} = 0;
305 $zone->{'right'} = 59;
306 $zone->{'top'} = 0;
307 $zone->{'bottom'} = 59;
308 $zone->{'width'} = 60;
309 $zone->{'height'} = 60;
310  
311 $zone->{'reservedFlag'} = FALSE;
312 $zone->{'multipleLayerFlag'} = FALSE;
313  
314 $zone->{'startCorner'} = 'top_left';
315 $zone->{'orientation'} = 'horizontal';
316  
317 $zone->{'areaMax'} = 0;
318 $zone->{'visibleAreaMax'} = 0;
319 $zone->{'defaultAreaWidth'} = 0;
320 $zone->{'defaultAreaHeight'} = 0;
321  
322 # Update this object's map, marking the area occupied by the zone model
323 $self->addZoneModel($zone);
324  
325 } elsif ($self->name eq 'basic') {
326  
327 # 'basic' - Intended for use when $self->shareMainWinFlag = TRUE. There are two zones.
328 # The first zone covers the left-hand 2/3 of the workspace and is reserved for a
329 # single 'main' window. The other zone covers the right-hand 1/3 of the workspace
330 # and is available for all 'grid' windows (and only those windows can be stacked
331 # above each other). The first 'main' window expands to fill the whole of its
332 # zone. Other windows use their default sizes
333  
334 # 111111112222
335 # 111111112222
336 # 111111112222
337 # 111111112222
338 # 111111112222
339 # 111111112222
340 # 111111112222
341 # 111111112222
342 # 111111112222
343 # 111111112222
344 # 111111112222
345 # 111111112222
346  
347 # Left-hand zone
348 # ==============
349  
350 $zoneLeft = Games::Axmud::Obj::ZoneModel->new($self);
351 if (! $zoneLeft) {
352  
353 # Zone model couldn't be created
354 return undef;
355 }
356  
357 $zoneLeft->{'left'} = 0;
358 $zoneLeft->{'right'} = 39;
359 $zoneLeft->{'top'} = 0;
360 $zoneLeft->{'bottom'} = 59;
361 $zoneLeft->{'width'} = 40;
362 $zoneLeft->{'height'} = 60;
363  
364 $zoneLeft->{'reservedFlag'} = TRUE;
365 $zoneLeft->ivAdd('reservedHash', 'main', 'main');
366 $zoneLeft->{'multipleLayerFlag'} = FALSE;
367  
368 $zoneLeft->{'startCorner'} = 'top_left';
369 $zoneLeft->{'orientation'} = 'vertical';
370  
371 $zoneLeft->{'areaMax'} = 1;
372 $zoneLeft->{'visibleAreaMax'} = 1;
373 $zoneLeft->{'defaultAreaWidth'} = 40;
374 $zoneLeft->{'defaultAreaHeight'} = 60;
375  
376 # Update this object's map, marking the area occupied by the zone model
377 $self->addZoneModel($zoneLeft);
378  
379 # Right-hand zone
380 # ===============
381  
382 $zoneRight = Games::Axmud::Obj::ZoneModel->new($self);
383 if (! $zoneRight) {
384  
385 # Zone model couldn't be created
386 return undef;
387 }
388  
389 $zoneRight->{'left'} = 40;
390 $zoneRight->{'right'} = 59;
391 $zoneRight->{'top'} = 0;
392 $zoneRight->{'bottom'} = 59;
393 $zoneRight->{'width'} = 20;
394 $zoneRight->{'height'} = 60;
395  
396 $zoneRight->{'reservedFlag'} = FALSE;
397 $zoneRight->{'multipleLayerFlag'} = TRUE;
398  
399 $zoneRight->{'startCorner'} = 'top_left';
400 $zoneRight->{'orientation'} = 'vertical';
401  
402 $zoneRight->{'areaMax'} = 0;
403 $zoneRight->{'visibleAreaMax'} = 3;
404 $zoneRight->{'defaultAreaWidth'} = 20;
405 $zoneRight->{'defaultAreaHeight'} = 20;
406  
407 # Update this object's map, marking the area occupied by the zone model
408 $self->addZoneModel($zoneRight);
409  
410 } elsif ($self->name eq 'extended') {
411  
412 # 'extended' - Intended for use when $self->shareMainWinFlag = TRUE. The left-hand 2/3
413 # of the workspace is reserved for a single 'main' window and the Status and
414 # Locator task windows. The task windows go above the first 'main' window; the
415 # Status window is to the left of the Locator window. The right-hand 1/3 of the
416 # workspace is reserved for a single 'map' window at the top half and any other
417 # 'grid' windows at the bottom half (and only those windows can be stacked above
418 # each other)
419  
420 # 222222223333
421 # 222222223333
422 # 222222223333
423 # 222222223333
424 # 111111113333
425 # 111111113333
426 # 111111114444
427 # 111111114444
428 # 111111114444
429 # 111111114444
430 # 111111114444
431 # 111111114444
432  
433 # Lower left-hand zone
434 # ====================
435  
436 $zoneLowerLeft = Games::Axmud::Obj::ZoneModel->new($self);
437 if (! $zoneLowerLeft) {
438  
439 # Zone model couldn't be created
440 return undef;
441 }
442  
443 $zoneLowerLeft->{'left'} = 0;
444 $zoneLowerLeft->{'right'} = 39;
445 $zoneLowerLeft->{'top'} = 20;
446 $zoneLowerLeft->{'bottom'} = 59;
447 $zoneLowerLeft->{'width'} = 40;
448 $zoneLowerLeft->{'height'} = 40;
449  
450 $zoneLowerLeft->{'reservedFlag'} = TRUE;
451 $zoneLowerLeft->ivAdd('reservedHash', 'main', 'main');
452 $zoneLowerLeft->{'multipleLayerFlag'} = FALSE;
453  
454 $zoneLowerLeft->{'startCorner'} = 'top_left';
455 $zoneLowerLeft->{'orientation'} = 'horizontal';
456  
457 $zoneLowerLeft->{'areaMax'} = 1;
458 $zoneLowerLeft->{'visibleAreaMax'} = 1;
459 $zoneLowerLeft->{'defaultAreaWidth'} = 40;
460 $zoneLowerLeft->{'defaultAreaHeight'} = 40;
461  
462 # Update this object's map, marking the area occupied by the zone model
463 $self->addZoneModel($zoneLowerLeft);
464  
465 # Upper left-hand zone
466 # ====================
467  
468 $zoneUpperLeft = Games::Axmud::Obj::ZoneModel->new($self);
469 if (! $zoneUpperLeft) {
470  
471 # Zone model couldn't be created
472 return undef;
473 }
474  
475 $zoneUpperLeft->{'left'} = 0;
476 $zoneUpperLeft->{'right'} = 39;
477 $zoneUpperLeft->{'top'} = 0;
478 $zoneUpperLeft->{'bottom'} = 19;
479 $zoneUpperLeft->{'width'} = 40;
480 $zoneUpperLeft->{'height'} = 20;
481  
482 $zoneUpperLeft->{'reservedFlag'} = TRUE;
483 $zoneUpperLeft->ivAdd('reservedHash', 'status_task', 'custom');
484 $zoneUpperLeft->ivAdd('reservedHash', 'locator_task', 'custom');
485 $zoneUpperLeft->{'multipleLayerFlag'} = FALSE;
486  
487 $zoneUpperLeft->{'startCorner'} = 'top_left';
488 $zoneUpperLeft->{'orientation'} = 'horizontal';
489  
490 $zoneUpperLeft->{'areaMax'} = 2;
491 $zoneUpperLeft->{'visibleAreaMax'} = 2;
492 $zoneUpperLeft->{'defaultAreaWidth'} = 20;
493 $zoneUpperLeft->{'defaultAreaHeight'} = 20;
494  
495 # Update this object's map, marking the area occupied by the zone model
496 $self->addZoneModel($zoneUpperLeft);
497  
498 # Upper right-hand zone
499 # =====================
500  
501 $zoneUpperRight = Games::Axmud::Obj::ZoneModel->new($self);
502 if (! $zoneUpperRight) {
503  
504 # Zone model couldn't be created
505 return undef;
506 }
507  
508 $zoneUpperRight->{'left'} = 40;
509 $zoneUpperRight->{'right'} = 59;
510 $zoneUpperRight->{'top'} = 0;
511 $zoneUpperRight->{'bottom'} = 29;
512 $zoneUpperRight->{'width'} = 20;
513 $zoneUpperRight->{'height'} = 30;
514  
515 $zoneUpperRight->{'reservedFlag'} = TRUE;
516 $zoneUpperRight->ivAdd('reservedHash', 'map', 'map');
517 $zoneUpperRight->{'multipleLayerFlag'} = FALSE;
518  
519 $zoneUpperRight->{'startCorner'} = 'top_left';
520 $zoneUpperRight->{'orientation'} = 'vertical';
521  
522 $zoneUpperRight->{'areaMax'} = 1;
523 $zoneUpperRight->{'visibleAreaMax'} = 1;
524 $zoneUpperRight->{'defaultAreaWidth'} = 20;
525 $zoneUpperRight->{'defaultAreaHeight'} = 30;
526  
527 # Update this object's map, marking the area occupied by the zone model
528 $self->addZoneModel($zoneUpperRight);
529  
530 # Lower right-hand zone
531 # =====================
532  
533 $zoneLowerRight = Games::Axmud::Obj::ZoneModel->new($self);
534 if (! $zoneLowerRight) {
535  
536 # Zone model couldn't be created
537 return undef;
538 }
539  
540 $zoneLowerRight->{'left'} = 40;
541 $zoneLowerRight->{'right'} = 59;
542 $zoneLowerRight->{'top'} = 30;
543 $zoneLowerRight->{'bottom'} = 59;
544 $zoneLowerRight->{'width'} = 20;
545 $zoneLowerRight->{'height'} = 30;
546  
547 $zoneLowerRight->{'reservedFlag'} = FALSE;
548 $zoneLowerRight->{'multipleLayerFlag'} = TRUE;
549  
550 $zoneLowerRight->{'startCorner'} = 'top_left';
551 $zoneLowerRight->{'orientation'} = 'vertical';
552  
553 $zoneLowerRight->{'areaMax'} = 0;
554 $zoneLowerRight->{'visibleAreaMax'} = 2;
555 $zoneLowerRight->{'defaultAreaWidth'} = 20;
556 $zoneLowerRight->{'defaultAreaHeight'} = 15;
557  
558 # Update this object's map, marking the area occupied by the zone model
559 $self->addZoneModel($zoneLowerRight);
560  
561 } elsif ($self->name eq 'widescreen') {
562  
563 # 'widescreen' - A modified version of 'extended' for widescreen monitors, with the
564 # the workspace divided into halves, rather than a 2/3 - 1/3 split
565  
566 # 222222333333
567 # 222222333333
568 # 222222333333
569 # 222222333333
570 # 111111333333
571 # 111111333333
572 # 111111444444
573 # 111111444444
574 # 111111444444
575 # 111111555555
576 # 111111555555
577 # 111111555555
578  
579 # Lower left-hand zone
580 # ====================
581  
582 $zoneLowerLeft = Games::Axmud::Obj::ZoneModel->new($self);
583 if (! $zoneLowerLeft) {
584  
585 # Zone model couldn't be created
586 return undef;
587 }
588  
589 $zoneLowerLeft->{'left'} = 0;
590 $zoneLowerLeft->{'right'} = 29;
591 $zoneLowerLeft->{'top'} = 20;
592 $zoneLowerLeft->{'bottom'} = 59;
593 $zoneLowerLeft->{'width'} = 30;
594 $zoneLowerLeft->{'height'} = 40;
595  
596 $zoneLowerLeft->{'reservedFlag'} = TRUE;
597 $zoneLowerLeft->ivAdd('reservedHash', 'main', 'main');
598 $zoneLowerLeft->{'multipleLayerFlag'} = FALSE;
599  
600 $zoneLowerLeft->{'startCorner'} = 'top_left';
601 $zoneLowerLeft->{'orientation'} = 'horizontal';
602  
603 $zoneLowerLeft->{'areaMax'} = 1;
604 $zoneLowerLeft->{'visibleAreaMax'} = 1;
605 $zoneLowerLeft->{'defaultAreaWidth'} = 30;
606 $zoneLowerLeft->{'defaultAreaHeight'} = 40;
607  
608 # Update this object's map, marking the area occupied by the zone model
609 $self->addZoneModel($zoneLowerLeft);
610  
611 # Upper left-hand zone
612 # ====================
613  
614 $zoneUpperLeft = Games::Axmud::Obj::ZoneModel->new($self);
615 if (! $zoneUpperLeft) {
616  
617 # Zone model couldn't be created
618 return undef;
619 }
620  
621 $zoneUpperLeft->{'left'} = 0;
622 $zoneUpperLeft->{'right'} = 29;
623 $zoneUpperLeft->{'top'} = 0;
624 $zoneUpperLeft->{'bottom'} = 19;
625 $zoneUpperLeft->{'width'} = 30;
626 $zoneUpperLeft->{'height'} = 20;
627  
628 $zoneUpperLeft->{'reservedFlag'} = TRUE;
629 $zoneUpperLeft->ivAdd('reservedHash', 'status_task', 'custom');
630 $zoneUpperLeft->ivAdd('reservedHash', 'locator_task', 'custom');
631 $zoneUpperLeft->{'multipleLayerFlag'} = FALSE;
632  
633 $zoneUpperLeft->{'startCorner'} = 'top_left';
634 $zoneUpperLeft->{'orientation'} = 'horizontal';
635  
636 $zoneUpperLeft->{'areaMax'} = 2;
637 $zoneUpperLeft->{'visibleAreaMax'} = 2;
638 $zoneUpperLeft->{'defaultAreaWidth'} = 15;
639 $zoneUpperLeft->{'defaultAreaHeight'} = 20;
640  
641 # Update this object's map, marking the area occupied by the zone model
642 $self->addZoneModel($zoneUpperLeft);
643  
644 # Upper right-hand zone
645 # =====================
646  
647 $zoneUpperRight = Games::Axmud::Obj::ZoneModel->new($self);
648 if (! $zoneUpperRight) {
649  
650 # Zone model couldn't be created
651 return undef;
652 }
653  
654 $zoneUpperRight->{'left'} = 30;
655 $zoneUpperRight->{'right'} = 59;
656 $zoneUpperRight->{'top'} = 0;
657 $zoneUpperRight->{'bottom'} = 29;
658 $zoneUpperRight->{'width'} = 30;
659 $zoneUpperRight->{'height'} = 30;
660  
661 $zoneUpperRight->{'reservedFlag'} = TRUE;
662 $zoneUpperRight->ivAdd('reservedHash', 'map', 'map');
663 $zoneUpperRight->{'multipleLayerFlag'} = FALSE;
664  
665 $zoneUpperRight->{'startCorner'} = 'top_left';
666 $zoneUpperRight->{'orientation'} = 'vertical';
667  
668 $zoneUpperRight->{'areaMax'} = 1;
669 $zoneUpperRight->{'visibleAreaMax'} = 1;
670 $zoneUpperRight->{'defaultAreaWidth'} = 30;
671 $zoneUpperRight->{'defaultAreaHeight'} = 30;
672  
673 # Update this object's map, marking the area occupied by the zone model
674 $self->addZoneModel($zoneUpperRight);
675  
676 # Centre right-hand zone 1
677 # ========================
678  
679 $zoneCentreRight = Games::Axmud::Obj::ZoneModel->new($self);
680 if (! $zoneCentreRight) {
681  
682 # Zone model couldn't be created
683 return undef;
684 }
685  
686 $zoneCentreRight->{'left'} = 30;
687 $zoneCentreRight->{'right'} = 59;
688 $zoneCentreRight->{'top'} = 30;
689 $zoneCentreRight->{'bottom'} = 44;
690 $zoneCentreRight->{'width'} = 30;
691 $zoneCentreRight->{'height'} = 15;
692  
693 $zoneCentreRight->{'reservedFlag'} = FALSE;
694 $zoneCentreRight->{'multipleLayerFlag'} = TRUE;
695  
696 $zoneCentreRight->{'startCorner'} = 'top_left';
697 $zoneCentreRight->{'orientation'} = 'horizontal';
698  
699 $zoneCentreRight->{'areaMax'} = 0;
700 $zoneCentreRight->{'visibleAreaMax'} = 2;
701 $zoneCentreRight->{'defaultAreaWidth'} = 15;
702 $zoneCentreRight->{'defaultAreaHeight'} = 15;
703  
704 # Update this object's map, marking the area occupied by the zone model
705 $self->addZoneModel($zoneCentreRight);
706  
707 # Lower right-hand zone
708 # =====================
709  
710 $zoneLowerRight = Games::Axmud::Obj::ZoneModel->new($self);
711 if (! $zoneLowerRight) {
712  
713 # Zone model couldn't be created
714 return undef;
715 }
716  
717 $zoneLowerRight->{'left'} = 30;
718 $zoneLowerRight->{'right'} = 59;
719 $zoneLowerRight->{'top'} = 45;
720 $zoneLowerRight->{'bottom'} = 59;
721 $zoneLowerRight->{'width'} = 30;
722 $zoneLowerRight->{'height'} = 15;
723  
724 $zoneLowerRight->{'reservedFlag'} = FALSE;
725 $zoneLowerRight->{'multipleLayerFlag'} = TRUE;
726  
727 $zoneLowerRight->{'startCorner'} = 'top_left';
728 $zoneLowerRight->{'orientation'} = 'horizontal';
729  
730 $zoneLowerRight->{'areaMax'} = 0;
731 $zoneLowerRight->{'visibleAreaMax'} = 2;
732 $zoneLowerRight->{'defaultAreaWidth'} = 15;
733 $zoneLowerRight->{'defaultAreaHeight'} = 15;
734  
735 # Update this object's map, marking the area occupied by the zone model
736 $self->addZoneModel($zoneLowerRight);
737  
738 } elsif ($self->name eq 'horizontal') {
739  
740 # 'horizontal' - Intended for use when $self->shareMainWinFlag = FALSE. The workspace
741 # is divided into two halves, left and right, with each half occupied by a single
742 # session's windows. Inside the half, the 'main' window is at the bottom, and
743 # other windows are at the top. Windows cannot be stacked above each other
744  
745 # 333333444444
746 # 333333444444
747 # 333333444444
748 # 333333444444
749 # 111111222222
750 # 111111222222
751 # 111111222222
752 # 111111222222
753 # 111111222222
754 # 111111222222
755 # 111111222222
756 # 111111222222
757  
758 # Lower left-hand zone
759 # ====================
760  
761 $zoneLowerLeft = Games::Axmud::Obj::ZoneModel->new($self);
762 if (! $zoneLowerLeft) {
763  
764 # Zone model couldn't be created
765 return undef;
766 }
767  
768 $zoneLowerLeft->{'left'} = 0;
769 $zoneLowerLeft->{'right'} = 29;
770 $zoneLowerLeft->{'top'} = 20;
771 $zoneLowerLeft->{'bottom'} = 59;
772 $zoneLowerLeft->{'width'} = 30;
773 $zoneLowerLeft->{'height'} = 40;
774  
775 $zoneLowerLeft->{'reservedFlag'} = TRUE;
776 $zoneLowerLeft->ivAdd('reservedHash', 'main', 'main');
777 $zoneLowerLeft->{'multipleLayerFlag'} = FALSE;
778  
779 $zoneLowerLeft->{'ownerString'} = '1';
780  
781 $zoneLowerLeft->{'startCorner'} = 'top_left';
782 $zoneLowerLeft->{'orientation'} = 'horizontal';
783  
784 $zoneLowerLeft->{'areaMax'} = 1;
785 $zoneLowerLeft->{'visibleAreaMax'} = 1;
786 $zoneLowerLeft->{'defaultAreaWidth'} = 30;
787 $zoneLowerLeft->{'defaultAreaHeight'} = 40;
788  
789 # Update this object's map, marking the area occupied by the zone model
790 $self->addZoneModel($zoneLowerLeft);
791  
792 # Lower right-hand zone
793 # =====================
794  
795 $zoneLowerRight = Games::Axmud::Obj::ZoneModel->new($self);
796 if (! $zoneLowerRight) {
797  
798 # Zone model couldn't be created
799 return undef;
800 }
801  
802 $zoneLowerRight->{'left'} = 30;
803 $zoneLowerRight->{'right'} = 59;
804 $zoneLowerRight->{'top'} = 20;
805 $zoneLowerRight->{'bottom'} = 59;
806 $zoneLowerRight->{'width'} = 30;
807 $zoneLowerRight->{'height'} = 40;
808  
809 $zoneLowerRight->{'reservedFlag'} = TRUE;
810 $zoneLowerRight->ivAdd('reservedHash', 'main', 'main');
811 $zoneLowerRight->{'multipleLayerFlag'} = FALSE;
812  
813 $zoneLowerRight->{'ownerString'} = '2';
814  
815 $zoneLowerRight->{'startCorner'} = 'top_left';
816 $zoneLowerRight->{'orientation'} = 'horizontal';
817  
818 $zoneLowerRight->{'areaMax'} = 1;
819 $zoneLowerRight->{'visibleAreaMax'} = 1;
820 $zoneLowerRight->{'defaultAreaWidth'} = 30;
821 $zoneLowerRight->{'defaultAreaHeight'} = 40;
822  
823 # Update this object's map, marking the area occupied by the zone model
824 $self->addZoneModel($zoneLowerRight);
825  
826 # Upper left-hand zone
827 # ====================
828  
829 $zoneUpperLeft = Games::Axmud::Obj::ZoneModel->new($self);
830 if (! $zoneUpperLeft) {
831  
832 # Zone model couldn't be created
833 return undef;
834 }
835  
836 $zoneUpperLeft->{'left'} = 0;
837 $zoneUpperLeft->{'right'} = 29;
838 $zoneUpperLeft->{'top'} = 0;
839 $zoneUpperLeft->{'bottom'} = 19;
840 $zoneUpperLeft->{'width'} = 30;
841 $zoneUpperLeft->{'height'} = 20;
842  
843 $zoneUpperLeft->{'reservedFlag'} = FALSE;
844 $zoneUpperLeft->{'multipleLayerFlag'} = FALSE;
845  
846 $zoneUpperLeft->{'ownerString'} = '1';
847  
848 $zoneUpperLeft->{'startCorner'} = 'top_left';
849 $zoneUpperLeft->{'orientation'} = 'horizontal';
850  
851 $zoneUpperLeft->{'areaMax'} = 0;
852 $zoneUpperLeft->{'visibleAreaMax'} = 2;
853 $zoneUpperLeft->{'defaultAreaWidth'} = 15;
854 $zoneUpperLeft->{'defaultAreaHeight'} = 20;
855  
856 # Update this object's map, marking the area occupied by the zone model
857 $self->addZoneModel($zoneUpperLeft);
858  
859 # Upper right-hand zone
860 # =====================
861  
862 $zoneUpperRight = Games::Axmud::Obj::ZoneModel->new($self);
863 if (! $zoneUpperRight) {
864  
865 # Zone model couldn't be created
866 return undef;
867 }
868  
869 $zoneUpperRight->{'left'} = 30;
870 $zoneUpperRight->{'right'} = 59;
871 $zoneUpperRight->{'top'} = 0;
872 $zoneUpperRight->{'bottom'} = 19;
873 $zoneUpperRight->{'width'} = 30;
874 $zoneUpperRight->{'height'} = 20;
875  
876 $zoneUpperRight->{'reservedFlag'} = FALSE;
877 $zoneUpperRight->{'multipleLayerFlag'} = FALSE;
878  
879 $zoneUpperRight->{'ownerString'} = '2';
880  
881 $zoneUpperRight->{'startCorner'} = 'top_left';
882 $zoneUpperRight->{'orientation'} = 'horizontal';
883  
884 $zoneUpperRight->{'areaMax'} = 0;
885 $zoneUpperRight->{'visibleAreaMax'} = 2;
886 $zoneUpperRight->{'defaultAreaWidth'} = 15;
887 $zoneUpperRight->{'defaultAreaHeight'} = 20;
888  
889 # Update this object's map, marking the area occupied by the zone model
890 $self->addZoneModel($zoneUpperRight);
891  
892 } elsif ($self->name eq 'vertical') {
893  
894 # 'vertical' - Intended for use when $self->shareMainWinFlag = FALSE. The workspace is
895 # divided into two halves, top and bottom, with each half occupied by a single
896 # session's windows. Inside the half, the 'main' window is on the left, and other
897 # windows are on the right. Windows cannot be stacked above each other
898  
899 # 111111113333
900 # 111111113333
901 # 111111113333
902 # 111111113333
903 # 111111113333
904 # 111111113333
905 # 222222224444
906 # 222222224444
907 # 222222224444
908 # 222222224444
909 # 222222224444
910 # 222222224444
911  
912 # Upper left-hand zone
913 # ====================
914  
915 $zoneUpperLeft = Games::Axmud::Obj::ZoneModel->new($self);
916 if (! $zoneUpperLeft) {
917  
918 # Zone model couldn't be created
919 return undef;
920 }
921  
922 $zoneUpperLeft->{'left'} = 0;
923 $zoneUpperLeft->{'right'} = 39;
924 $zoneUpperLeft->{'top'} = 0;
925 $zoneUpperLeft->{'bottom'} = 29;
926 $zoneUpperLeft->{'width'} = 40;
927 $zoneUpperLeft->{'height'} = 30;
928  
929 $zoneUpperLeft->{'reservedFlag'} = TRUE;
930 $zoneUpperLeft->ivAdd('reservedHash', 'main', 'main');
931 $zoneUpperLeft->{'multipleLayerFlag'} = FALSE;
932  
933 $zoneUpperLeft->{'ownerString'} = '1';
934  
935 $zoneUpperLeft->{'startCorner'} = 'top_left';
936 $zoneUpperLeft->{'orientation'} = 'vertical';
937  
938 $zoneUpperLeft->{'areaMax'} = 1;
939 $zoneUpperLeft->{'visibleAreaMax'} = 1;
940 $zoneUpperLeft->{'defaultAreaWidth'} = 40;
941 $zoneUpperLeft->{'defaultAreaHeight'} = 30;
942  
943 # Update this object's map, marking the area occupied by the zone model
944 $self->addZoneModel($zoneUpperLeft);
945  
946 # Lower left-hand zone
947 # ====================
948  
949 $zoneLowerLeft = Games::Axmud::Obj::ZoneModel->new($self);
950 if (! $zoneLowerLeft) {
951  
952 # Zone model couldn't be created
953 return undef;
954 }
955  
956 $zoneLowerLeft->{'left'} = 0;
957 $zoneLowerLeft->{'right'} = 39;
958 $zoneLowerLeft->{'top'} = 30;
959 $zoneLowerLeft->{'bottom'} = 59;
960 $zoneLowerLeft->{'width'} = 40;
961 $zoneLowerLeft->{'height'} = 30;
962  
963 $zoneLowerLeft->{'reservedFlag'} = TRUE;
964 $zoneLowerLeft->ivAdd('reservedHash', 'main', 'main');
965 $zoneLowerLeft->{'multipleLayerFlag'} = FALSE;
966  
967 $zoneLowerLeft->{'ownerString'} = '2';
968  
969 $zoneLowerLeft->{'startCorner'} = 'top_left';
970 $zoneLowerLeft->{'orientation'} = 'vertical';
971  
972 $zoneLowerLeft->{'areaMax'} = 1;
973 $zoneLowerLeft->{'visibleAreaMax'} = 1;
974 $zoneLowerLeft->{'defaultAreaWidth'} = 40;
975 $zoneLowerLeft->{'defaultAreaHeight'} = 30;
976  
977 # Update this object's map, marking the area occupied by the zone model
978 $self->addZoneModel($zoneLowerLeft);
979  
980 # Upper right-hand zone
981 # =====================
982  
983 $zoneUpperRight = Games::Axmud::Obj::ZoneModel->new($self);
984 if (! $zoneUpperRight) {
985  
986 # Zone model couldn't be created
987 return undef;
988 }
989  
990 $zoneUpperRight->{'left'} = 40;
991 $zoneUpperRight->{'right'} = 59;
992 $zoneUpperRight->{'top'} = 0;
993 $zoneUpperRight->{'bottom'} = 29;
994 $zoneUpperRight->{'width'} = 20;
995 $zoneUpperRight->{'height'} = 30;
996  
997 $zoneUpperRight->{'reservedFlag'} = FALSE;
998 $zoneUpperRight->{'multipleLayerFlag'} = FALSE;
999  
1000 $zoneUpperRight->{'ownerString'} = '1';
1001  
1002 $zoneUpperRight->{'startCorner'} = 'top_left';
1003 $zoneUpperRight->{'orientation'} = 'vertical';
1004  
1005 $zoneUpperRight->{'areaMax'} = 0;
1006 $zoneUpperRight->{'visibleAreaMax'} = 2;
1007 $zoneUpperRight->{'defaultAreaWidth'} = 20;
1008 $zoneUpperRight->{'defaultAreaHeight'} = 15;
1009  
1010 # Update this object's map, marking the area occupied by the zone model
1011 $self->addZoneModel($zoneUpperRight);
1012  
1013 # Lower right-hand zone
1014 # =====================
1015  
1016 $zoneLowerRight = Games::Axmud::Obj::ZoneModel->new($self);
1017 if (! $zoneLowerRight) {
1018  
1019 # Zone model couldn't be created
1020 return undef;
1021 }
1022  
1023 $zoneLowerRight->{'left'} = 40;
1024 $zoneLowerRight->{'right'} = 59;
1025 $zoneLowerRight->{'top'} = 30;
1026 $zoneLowerRight->{'bottom'} = 59;
1027 $zoneLowerRight->{'width'} = 20;
1028 $zoneLowerRight->{'height'} = 30;
1029  
1030 $zoneLowerRight->{'reservedFlag'} = FALSE;
1031 $zoneLowerRight->{'multipleLayerFlag'} = FALSE;
1032  
1033 $zoneLowerRight->{'ownerString'} = '2';
1034  
1035 $zoneLowerRight->{'startCorner'} = 'top_left';
1036 $zoneLowerRight->{'orientation'} = 'vertical';
1037  
1038 $zoneLowerRight->{'areaMax'} = 0;
1039 $zoneLowerRight->{'visibleAreaMax'} = 2;
1040 $zoneLowerRight->{'defaultAreaWidth'} = 20;
1041 $zoneLowerRight->{'defaultAreaHeight'} = 15;
1042  
1043 # Update this object's map, marking the area occupied by the zone model
1044 $self->addZoneModel($zoneLowerRight);
1045 }
1046  
1047 # Setup complete
1048 return 1;
1049 }
1050  
1051 sub modifyStandardZonemap {
1052  
1053 # Called by $self->clone to modify the cloned zonemap to allow its zone models to have
1054 # multiple layers (assuming that the original zonemap doesn't)
1055 # (Could be called by any other function in order to reset a standard zonemap, probably
1056 # after a call to $self->resetZonemap)
1057 #
1058 # Expected arguments
1059 # (none besides $self)
1060 #
1061 # Return values
1062 # 'undef' on improper arguments
1063 # 1 otherwise
1064  
1065 my ($self, $check) = @_;
1066  
1067 # Check for improper arguments
1068 if (defined $check) {
1069  
1070 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyStandardZonemap', @_);
1071 }
1072  
1073 # Only modify zone models not reserved for 'main' windows
1074 foreach my $zoneModelObj ($self->ivValues('modelHash')) {
1075  
1076 if (! $zoneModelObj->ivExists('reservedHash', 'main')) {
1077  
1078 $zoneModelObj->set_multipleLayerFlag(TRUE);
1079 }
1080 }
1081  
1082 return 1;
1083 }
1084  
1085 sub resetZonemap {
1086  
1087 # Called by $self->new, GA::Cmd::ResetZonemap->do or any other function to reset the zonemap
1088 #
1089 # Expected arguments
1090 # (none besides $self)
1091 #
1092 # Return values
1093 # 'undef' on improper arguments
1094 # 1 otherwise
1095  
1096 my ($self, $check) = @_;
1097  
1098 # Check for improper arguments
1099 if (defined $check) {
1100  
1101 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetZonemap', @_);
1102 }
1103  
1104 # Reset IVs
1105 $self->ivEmpty('modelHash');
1106 $self->ivPoke('modelCount', 0);
1107 $self->ivPoke('fullFlag', FALSE);
1108  
1109 return 1;
1110 }
1111  
1112 sub checkPosnInMap {
1113  
1114 # Called by $self->addZoneModel and GA::Cmd::ModifyZoneModel->do
1115 # Checks that the zonemap is unoccupied in a certain area
1116 #
1117 # Expected arguments
1118 # $xPosBlocks, $yPosBlocks
1119 # - Coordinates of the top-left corner of the search area
1120 # $widthBlocks, $heightBlocks
1121 # - The size of the search area
1122 #
1123 # Optional arguments
1124 # $ignoreObj
1125 # - A GA::Obj::ZoneModel object to ignore (used when resizing a zone model. Only
1126 # count the search area as occupied if it's occupied by another zone model)
1127 #
1128 # Return values
1129 # 'undef' on improper arguments, or if any part of the search area is occupied (except
1130 # for the specified zone model, where appropriate)
1131 # 1 if the whole search area is unoccupied
1132  
1133 my (
1134 $self, $xPosBlocks, $yPosBlocks, $widthBlocks, $heightBlocks, $ignoreObj, $check
1135 ) = @_;
1136  
1137 # Local variables
1138 my ($x1, $x2, $y1, $y2);
1139  
1140 # Check for improper arguments
1141 if (
1142 ! defined $xPosBlocks || ! defined $yPosBlocks || ! defined $widthBlocks
1143 || ! defined $heightBlocks || defined $check
1144 ) {
1145 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPosnInMap', @_);
1146 }
1147  
1148 $x1 = $xPosBlocks,
1149 $x2 = $x1 + $widthBlocks - 1;
1150 $y1 = $yPosBlocks,
1151 $y2 = $y1 + $heightBlocks - 1;
1152  
1153 foreach my $modelObj ($self->ivValues('modelHash')) {
1154  
1155 if (! defined $ignoreObj || $modelObj ne $ignoreObj) {
1156  
1157 if (
1158 (
1159 ($x1 >= $modelObj->left && $x1 <= $modelObj->right)
1160 || ($x2 >= $modelObj->left && $x2 <= $modelObj->right)
1161 ) && (
1162 ($y1 >= $modelObj->top && $y1 <= $modelObj->bottom)
1163 || ($y2 >= $modelObj->top && $y2 <= $modelObj->bottom)
1164 )
1165 ) {
1166 return undef;
1167 }
1168 }
1169 }
1170  
1171 # Whole search region is empty
1172 return 1;
1173 }
1174  
1175 sub addZoneModel {
1176  
1177 # Called by $self->setupStandardZonemap and GA::Cmd::AddZoneModel->do
1178 # Adds a zone model to the zonemap, first checking that the area specified by the zone
1179 # model's IVs is unoccupied
1180 #
1181 # Expected arguments
1182 # $modelObj - Blessed reference to the GA::Obj::ZoneModel object to add to the
1183 # zonemap
1184 #
1185 # Return values
1186 # 'undef' on improper arguments, if the new zone model's size variables are invalid or if
1187 # the specified area is occupied
1188 # 1 otherwise
1189  
1190 my ($self, $modelObj, $check) = @_;
1191  
1192 # Local variables
1193 my @grid;
1194  
1195 # Check for improper arguments
1196 if (! defined $modelObj || defined $check) {
1197  
1198 return $axmud::CLIENT->writeImproper($self->_objClass . '->addZoneModel', @_);
1199 }
1200  
1201 # Check that the zone model isn't bigger than the 60x60 zonemap
1202 if (
1203 $modelObj->left < 0 || $modelObj->right > ($self->gridSize - 1)
1204 || $modelObj->top < 0 || $modelObj->bottom > ($self->gridSize - 1)
1205 || ($modelObj->right - $modelObj->left + 1) != $modelObj->width
1206 || ($modelObj->bottom - $modelObj->top + 1) != $modelObj->height
1207 ) {
1208 return $self->writeError(
1209 'Illegal size/position variables specified for the zone model',
1210 $self->_objClass . '->addZoneModel',
1211 );
1212 }
1213  
1214 # Check that the area where the zone model wants to be placed isn't already allocated to
1215 # another zone model
1216 if (
1217 ! $self->checkPosnInMap(
1218 $modelObj->left,
1219 $modelObj->top,
1220 $modelObj->width,
1221 $modelObj->height,
1222 )
1223 ) {
1224 return $self->writeError(
1225 'Zonemap ' . $self->name . ' already occupied at x/y ' . $modelObj->left
1226 . '/' . $modelObj->top . ', cannot place new zone model there',
1227 $self->_objClass . '->addZoneModel',
1228 );
1229 }
1230  
1231 # Add the zone model to the zonemap
1232 $modelObj->set_number($self->modelCount);
1233 $self->ivAdd('modelHash', $modelObj->number, $modelObj);
1234 $self->ivIncrement('modelCount');
1235  
1236 # Check to see if there are any empty gridblocks and, if there are none, set a flag
1237 for (my $x = 0; $x < $self->gridSize; $x++) {
1238  
1239 for (my $y = 0; $y < $self->gridSize; $y++) {
1240  
1241 # Mark this gridblock unoccupied (for the moment)
1242 $grid[$x][$y] = undef;
1243 }
1244 }
1245  
1246 foreach my $otherObj ($self->ivValues('modelHash')) {
1247  
1248 for (my $x = $otherObj->left; $x <= $otherObj->right; $x++) {
1249  
1250 for (my $y = $otherObj->top; $y <= $otherObj->bottom; $y++) {
1251  
1252 # Mark this gridblock occupied
1253 $grid[$x][$y] = 1;
1254 }
1255 }
1256 }
1257  
1258 $self->ivPoke('fullFlag', TRUE);
1259 OUTER: for (my $x = 0; $x < $self->gridSize; $x++) {
1260  
1261 for (my $y = 0; $y < $self->gridSize; $y++) {
1262  
1263 if (! $grid[$x][$y]) {
1264  
1265 $self->ivPoke('fullFlag', FALSE);
1266 last OUTER;
1267 }
1268 }
1269 }
1270  
1271 return 1;
1272 }
1273  
1274 sub deleteZoneModel {
1275  
1276 # Called by GA::Cmd::DeleteZoneModel->do
1277 # Deletes a zone model from the zonemap
1278 #
1279 # Expected arguments
1280 # $number - The number of the zone model to delete
1281 #
1282 # Return values
1283 # 'undef' on improper arguments or if the zone model $number doesn't exist
1284 # 1 otherwise
1285  
1286 my ($self, $number, $check) = @_;
1287  
1288 # Local variables
1289 my $modelObj;
1290  
1291 # Check for improper arguments
1292 if (! defined $number || defined $check) {
1293  
1294 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteZoneModel', @_);
1295 }
1296  
1297 # Check that specified zone model exists
1298 $modelObj = $self->ivShow('modelHash', $number);
1299 if (! $modelObj) {
1300  
1301 return undef;
1302  
1303 } else {
1304  
1305 $self->ivDelete('modelHash', $number);
1306 $self->ivPoke('fullFlag', FALSE);
1307  
1308 return 1;
1309 }
1310 }
1311  
1312 sub findZoneModel {
1313  
1314 # Can be called by anything
1315 # Given an area of the zonemap that's at least partly occupied, go through the area block by
1316 # block and return the first zone model found
1317 #
1318 # Expected arguments
1319 # $left, $top, $width, $height
1320 # - The size of the area (in gridblocks) to search. The zonemap is 60x60, so if
1321 # any of these arguments are invalid (e.g. $right = 70), default values are
1322 # used (e.g. $right = 59)
1323 #
1324 # Return values
1325 # 'undef' on improper arguments or if the search area contains no zone models
1326 # Otherwise, returns the first GA::Obj::ZoneModel found
1327  
1328 my ($self, $left, $top, $width, $height, $check) = @_;
1329  
1330 # Local variables
1331 my ($x1, $x2, $y1, $y2);
1332  
1333 # Check for improper arguments
1334 if (
1335 ! defined $left || ! defined $top || ! defined $width || ! defined $height
1336 || defined $check
1337 ) {
1338 return $axmud::CLIENT->writeImproper($self->_objClass . '->findZoneModel', @_);
1339 }
1340  
1341 # Check that the arguments are valid and, if not, use default values
1342 if ($left < 0) {
1343  
1344 $left = 0;
1345 }
1346  
1347 if (($left + $width) > $self->gridSize) {
1348  
1349 $width = ($self->gridSize - $left);
1350 }
1351  
1352 if ($top < 0) {
1353  
1354 $top = 0;
1355 }
1356  
1357 if (($top + $height) > $self->gridSize) {
1358  
1359 $height = ($self->gridSize - $top);
1360 }
1361  
1362 # Check the search area
1363 $x1 = $left,
1364 $x2 = $x1 + $width - 1;
1365 $y1 = $top,
1366 $y2 = $y1 + $height - 1;
1367  
1368 foreach my $modelObj ($self->ivValues('modelHash')) {
1369  
1370 if (
1371 (
1372 ($x1 >= $modelObj->left && $x1 <= $modelObj->right)
1373 || ($x2 >= $modelObj->left && $x2 <= $modelObj->right)
1374 ) && (
1375 ($y1 >= $modelObj->top && $y1 <= $modelObj->bottom)
1376 || ($y2 >= $modelObj->top && $y2 <= $modelObj->bottom)
1377 )
1378 ) {
1379 return $modelObj;
1380 }
1381 }
1382  
1383 # No zone models found in the search area
1384 return undef;
1385 }
1386  
1387 ##################
1388 # Accessors - set
1389  
1390 ##################
1391 # Accessors - get
1392  
1393 sub name
1394 { $_[0]->{name} }
1395  
1396 sub gridSize
1397 { $_[0]->{gridSize} }
1398 sub modelHash
1399 { my $self = shift; return %{$self->{modelHash}}; }
1400 sub modelCount
1401 { $_[0]->{modelCount} }
1402 sub fullFlag
1403 { $_[0]->{fullFlag} }
1404  
1405 sub tempFlag
1406 { $_[0]->{tempFlag} }
1407 sub tempSession
1408 { $_[0]->{tempSession} }
1409 }
1410  
1411 # Package must return a true value
1412 1