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

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 73 CC 2 SCAR 10.3
CC
2
Cov
0%
new
6.0
startExit
2.0
stopExit
2.0
CRAP 2.8
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::RegionPath
16 # Contains a path between two region exits in the same region
17  
18 { package Games::Axmud::Obj::RegionPath;
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::Obj::WorldModel->connectRegionExits, ->replaceRegionPath and
34 # ->findUniversalPath
35 #
36 # Create a new instance of the region path object, which stores the shortest path between
37 # two exits in a region, both of which are region exits (which lead to a room in a
38 # different region). The path is used for quick pathfinding between two rooms in
39 # different regions
40 #
41 # Expected arguments
42 # $session - The parent GA::Session (not stored as an IV)
43 # $startExit - The number of the GA::Obj::Exit at the start of the path, whose
44 # destination room is in a different region
45 # $stopExit - The number of the GA::Obj::Exit at the end of the path, whose
46 # destination room is in a different region (possibly the same region
47 # as $startExit's destination room)
48 # $roomListRef - Reference to a list of numbers of room objects along the path
49 # $exitListRef - Reference to a list of numbers of exit objects which connect them.
50 # The list will contain one less item than $roomListRef
51 #
52 # Return values
53 # 'undef' on improper arguments
54 # Blessed reference to the newly-created object on success
55  
56 my ($class, $session, $startExit, $stopExit, $roomListRef, $exitListRef, $check) = @_;
57  
58 # Local variables
59 my (@roomList, @exitList);
60  
61 # Check for improper arguments
62 if (
63 ! defined $class || ! defined $session || ! defined $startExit || ! defined $stopExit
64 || ! defined $roomListRef || ! defined $exitListRef || defined $check
65 ) {
66 return $axmud::CLIENT->writeImproper($class . '->new', @_);
67 }
68  
69 # Convert $roomListRef, a reference to a list of room objects, into @roomList, a list of
70 # model object numbers
71 foreach my $obj (@$roomListRef) {
72  
73 push (@roomList, $obj->number);
74 }
75  
76 # Convert $exitListRef, a reference to a list of exit objects, into @exitList, a list of
77 # exit model numbers
78 foreach my $obj (@$exitListRef) {
79  
80 push (@exitList, $obj->number);
81 }
82  
83 # Setup
84 my $self = {
85 _objName => 'region_path',
86 _objClass => $class,
87 _parentFile => 'worldmodel',
88 _parentWorld => $session->currentWorld->name,
89 # All IVs are private, but should usually be set with calls to the GA::Obj::WorldModel
90 # object
91 _privFlag => TRUE,
92  
93 # Object IVs
94 # ----------
95  
96 # The number of the GA::Obj::Exit at the start of the path, whose destination room is
97 # in a different region
98 startExit => $startExit,
99 # The number of the GA::Obj::Exit at the end of the path, whose destination room is in
100 # a different region (possibly the same region as $startExit's destination room)
101 stopExit => $stopExit,
102 # List of numbers of room objects along the path
103 roomList => \@roomList,
104 # List of numbers of exit objects which connect the rooms in $self->roomList. This list
105 # will contain one less item than $self->roomList
106 exitList => \@exitList,
107 # Shortcut to the number of rooms in ->roomList
108 roomCount => scalar @roomList,
109 };
110  
111 # Bless the object into existence
112 bless $self, $class;
113 return $self;
114 }
115  
116 ##################
117 # Methods
118  
119 ##################
120 # Accessors - set
121  
122 ##################
123 # Accessors - get
124  
125 sub startExit
126 { $_[0]->{startExit} }
127 sub stopExit
128 { $_[0]->{stopExit} }
129 sub roomList
130 { my $self = shift; return @{$self->{roomList}}; }
131 sub exitList
132 { my $self = shift; return @{$self->{exitList}}; }
133 sub roomCount
134 { $_[0]->{roomCount} }
135 }
136  
137 # Package must return a true value
138 1