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

filter: Statementstmt 0.0% 0 / 988 Branchbran 0.0% 0 / 310 Conditioncond 0.0% 0 / 213 MC/DCmcdc 0.0% 0 / 125 Subroutinesub 0.0% 0 / 100 Podpod 0.0% 0 / 97 totaltotal 0.0% 0 / 1833 CC 156 SCAR 39.3
CC
156
Cov
0%
sortExitObjs
210.0
sortExits
182.0
createCombNounHash
110.0
CRAP 50.7
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::Dict
16 # The code that handles an Axmud dictionary
17  
18 { package Games::Axmud::Obj::Dict;
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::Cmd::AddDictionary->do, SetDictionary->do, AddWorld->do,
34 # GA::Session->setupProfiles and by various 'edit' windows
35 # Creates a new instance of the dictionary object
36 #
37 # Expected arguments
38 # $session - The GA::Session which called this function (not stored as an IV)
39 # $name - A unique string name for this dictionary (max 16 chars, containing
40 # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable.
41 # Must not exist as a key in the global hash of reserved names,
42 # $axmud::CLIENT->constReservedHash)
43 #
44 # Optional arguments
45 # $language - Which language the dictionary will use. If specified, can be any string
46 # useful to the user, e.g. 'French', 'Francais', 'Franzoesisch'. If
47 # 'undef', the dictionary sets 'English' as its language)
48 # $tempFlag - If set to TRUE, this is a temporary dictionary created for use with an
49 # 'edit' window; $name and $language are not checked for validity.
50 # Otherwise set to FALSE (or 'undef')
51 #
52 # Return values
53 # 'undef' on improper arguments or if $name/$language are invalid
54 # Blessed reference to the newly-created object on success
55  
56 my ($class, $session, $name, $language, $tempFlag, $check) = @_;
57  
58 # Check for improper arguments
59 if (! defined $class || ! defined $session || ! defined $name || defined $check) {
60  
61 return $axmud::CLIENT->writeImproper($class . '->new', @_);
62 }
63  
64 if (! $tempFlag) {
65  
66 # Check that $name is valid and not already in use by another dictionary
67 if (! $axmud::CLIENT->nameCheck($name, 16)) {
68  
69 return $axmud::CLIENT->writeError(
70 'Registry naming error: invalid name \'' . $name . '\'',
71 $class . '->new',
72 );
73  
74 } elsif ($axmud::CLIENT->ivExists('dictHash', $name)) {
75  
76 return $axmud::CLIENT->writeError(
77 'Registry naming error: dictionary \'' . $name . '\' already exists',
78 $class . '->new',
79 );
80 }
81  
82 # If $language was specified, check it's not too long
83 if (defined $language) {
84  
85 if (! $axmud::CLIENT->nameCheck($language, 16)) {
86  
87 return $axmud::CLIENT->writeError(
88 'Registry naming error: invalid language name \'' . $language . '\'',
89 $class . '->new',
90 );
91 }
92 }
93 }
94  
95 # Set the language, if not specified
96 if (! defined $language) {
97  
98 $language = 'English';
99 }
100  
101 # Setup
102 my $self = {
103 _objName => $name,
104 _objClass => $class,
105 _parentFile => 'dicts',
106 _parentWorld => undef,
107 # Many IVs are interconnected, so we mark them all as 'private' to force use of the
108 # accessor methods set_, add_, del_ ...
109 _privFlag => TRUE,
110  
111 # Dictionary IVs
112 # --------------
113  
114 # A unique name for the dictionary
115 name => $name,
116 # The dictionary uses this language. Can be any string useful to the user, e.g.
117 # 'French', 'Francais', 'Franzoesisch'
118 language => $language,
119 # Noun position for this language:
120 # 'noun_adj' - typical order is noun-adjective (e.g. French)
121 # 'adj_noun' - typical order is adjective-noun (e.g. English)
122 nounPosn => 'adj_noun',
123  
124 # NB In this function, 'standard term' refers to a key in a hash that never changes,
125 # regardless of the dictionary's language.
126 # For example, the keys in $self->timeHash are always the standard terms second,
127 # minute, hour, day, week, month, year, decade, century, millennium;
128 # the corresponding values show the equivalent words in the dictionary's language
129 # In this function, standard terms are not enclosed by single quotes
130  
131 # Articles/conjunctions
132 # ---------------------
133  
134 # Definite articles used in the dictionary's language
135 definiteList => [
136 'the',
137 ],
138 # Indefinite articles used in the dictionary's language
139 indefiniteList => [
140 'a',
141 'an',
142 ],
143 # Words for 'and' in the dictionary's language
144 andList => [
145 'and',
146 'also',
147 ],
148 # Words for 'or' in the dictionary's language
149 orList => [
150 'or',
151 ],
152  
153 # Numbers / time
154 # --------------
155  
156 # Hash of numbers, transforming a word or phrase in the dictionary's language into a
157 # number. Hash in the form
158 # $numberHash{word_or_phrase} = number
159 # e.g. $numberHash{'two'} = 2
160 # e.g. $numberHash{'half of'} = 0.5
161 # Indeterminate words or phrases, like 'some of', are given the value -1
162 # e.g. $numberHash{'some of'} = -1
163 numberHash => {
164 # Zeroes
165 'no' => 0,
166 'zero' => 0,
167 'none' => 0,
168 'nil' => 0,
169 # Named numbers
170 'one' => 1,
171 'two' => 2,
172 'three' => 3,
173 'four' => 4,
174 'five' => 5,
175 'six' => 6,
176 'seven' => 7,
177 'eight' => 8,
178 'nine' => 9,
179 'ten' => 10,
180 'eleven' => 11,
181 'twelve' => 12,
182 'thirteen' => 13,
183 'fourteen' => 14,
184 'fifteen' => 15,
185 'sixteen' => 16,
186 'seventeen' => 17,
187 'eighteen' => 18,
188 'nineteen' => 19,
189 'twenty' => 20,
190 'thirty' => 30,
191 'forty' => 40,
192 'fifty' => 50,
193 'sixty' => 60,
194 'seventy' => 70,
195 'eighty' => 80,
196 'ninenty' => 90,
197 'hundred' => 100,
198 # Fractions
199 'half' => 0.5,
200 'half of' => 0.5,
201 'third' => 0.33,
202 'third of' => 0.33,
203 'quarter' => 0.25,
204 'quarter of' => 0.25,
205 # Indeterminate numbers
206 'fraction' => -1,
207 'fraction of' => -1,
208 'many' => -1,
209 'many of' => -1,
210 'number' => -1,
211 'number of' => -1,
212 'part' => -1,
213 'part of' => -1,
214 'several' => -1,
215 'several of' => -1,
216 'some' => -1,
217 'some of' => -1,
218 },
219  
220 # Hashes of time words, transforming a standard term into the equivalent. Hashes in the
221 # form
222 # $hash{standard_term} = word_in_language
223 # e.g. $timeHash{'hour'} = 'heure' # (French)
224 timeHash => {
225 'second' => 'second',
226 'minute' => 'minute',
227 'hour' => 'hour',
228 'day' => 'day',
229 'week' => 'week',
230 'month' => 'month',
231 'year' => 'year',
232 'decade' => 'decade',
233 'century' => 'century',
234 'millennium' => 'millennium',
235 },
236 timePluralHash => {
237 'second' => 'seconds',
238 'minute' => 'minutes',
239 'hour' => 'hours',
240 'day' => 'days',
241 'week' => 'weeks',
242 'month' => 'months',
243 'year' => 'years',
244 'decade' => 'decades',
245 'century' => 'centuries',
246 'millennium' => 'millennia',
247 },
248 # The same hashes, reversed
249 reverseTimeHash => {}, # Set below
250 reverseTimePluralHash => {}, # Set below
251  
252 # Hashes of time phrases, transforming a clock time in the dictionary's language
253 # (e.g. 'twenty past ten in the morning') into a digital time
254 # Hash transforming a phrase into 0 for a.m. and 1 for p.m., in the form
255 # $clockDayHash{phrase} = number
256 clockDayHash => {
257 'in the morning' => 0,
258 'in the afternoon' => 1,
259 'in the evening' => 1,
260 'at night' => 1,
261 },
262 # Hash transforming a phrase into an hour of the clock, in the form
263 # $clockHourHash{phrase} = number
264 clockHourHash => {
265 'midnight' => 0,
266 'one' => 1,
267 'two' => 2,
268 'three' => 3,
269 'four' => 4,
270 'five' => 5,
271 'six' => 6,
272 'seven' => 7,
273 'eight' => 8,
274 'nine' => 9,
275 'ten' => 10,
276 'eleven' => 11,
277 'twelve' => 12,
278 'midday' => 12,
279 'one o\'clock' => 1,
280 'two o\'clock' => 2,
281 'three o\'clock' => 3,
282 'four o\'clock' => 4,
283 'five o\'clock' => 5,
284 'six o\'clock' => 6,
285 'seven o\'clock' => 7,
286 'eight o\'clock' => 8,
287 'nine o\'clock' => 9,
288 'ten o\'clock' => 10,
289 'eleven o\'clock' => 11,
290 'twelve o\'clock' => 12,
291 },
292 # Hash transforming a phrase into an minute past the hour. Negative values establish
293 # minutes past the previous hour, so 'quarter to eleven' produces hour = 11,
294 # minutes = -45, so time = 10:45. Hash in the form
295 # $clockMinuteHash{phrase} = number
296 clockMinuteHash => {
297 'exactly' => 0,
298 'five past' => 5,
299 'five-past' => 5,
300 'ten past' => 10,
301 'ten-past' => 10,
302 'quarter past' => 15,
303 'quarter-past' => 15,
304 'twenty past' => 20,
305 'twenty-past' => 20,
306 'twenty five past' => 25,
307 'twenty-five past' => 25,
308 'twenty-five-past' => 25,
309 'half past' => 30,
310 'half-past' => 30,
311 'twenty five to' => -35,
312 'twenty-five to' => -35,
313 'twenty-five-to' => -35,
314 'twenty to' => -40,
315 'twenty-to' => -40,
316 'quarter to' => -45,
317 'quarter-to' => -45,
318 'ten to' => -50,
319 'ten-to' => -50,
320 'five to' => -55,
321 'five-to' => -55,
322 },
323  
324 # Portable object types
325 # ---------------------
326  
327 # Lists of portable model object types (things which can, in theory, be picked up)
328 # All portables are given a type, as a guide to what sort of object they might be
329 # Portable types used by Axmud are
330 # torch (anything that casts light with fire)
331 # lamp (anything that casts light by being turned on)
332 # match (anything that can light a torch or start a fire)
333 # key (anything that unlocks something)
334 # map (any kind of map)
335 # book (any readable object, with multiple pages)
336 # toy (any kind of toy or game)
337 # paper (any readable object, with a single page)
338 # corpse (any word for a dead thing)
339 # bodypart (any word for a piece of dead thing - arms, legs, etc)
340 # sack (any bag that can hold other things)
341 # box (any kind of box that can hold things)
342 # container (anything that's not a bag or a box, that can hold other things)
343 # coin (any monetary unit)
344 # treasure (anything which is just valuable, not including money)
345 # jewellery (valuable items that can be worn)
346 # tool (lockpicks, crowbars, etc)
347 # instrument (musical instruments)
348 # spade (anything for digging)
349 # food (anything that can be eaten)
350 # drink (anything non-alcoholic that can be drunk)
351 # alcohol (anything alcoholic than can be drunk)
352 # medicine (anything which can be eaten or drunk as a medicine)
353 # potion (any kind of potion)
354 # poison (the opposite of medicine)
355 # watch (any portable thing that tells the time)
356 # cup (any container which only holds liquids - cups, mugs, vials, etc)
357 # cutlery (any forks, plates, etc - but not cups)
358 # vehicle (a car, hoverpod - anything for transportation)
359 # boat (anything used for transportation on water - can't be picked up, but
360 # can be moved, so it's a portable)
361 # plane (anything used for transportation in the air)
362 # rope (any rope-like thing used for climbing)
363 # collectable (any collectable item)
364 # toy (any kind of toy)
365 # other (anything else)
366 #
367 # Custom types can also be created. ->constPortableTypeList contains the default list of
368 # types, and ->portableTypeList contains the actual list of types for this dictionary
369 constPortableTypeList => [
370 'torch',
371 'lamp',
372 'match',
373 'key',
374 'map',
375 'book',
376 'toy',
377 'paper',
378 'corpse',
379 'bodypart',
380 'sack',
381 'box',
382 'container',
383 'coin',
384 'treasure',
385 'jewellery',
386 'tool',
387 'instrument',
388 'spade',
389 'food',
390 'drink',
391 'alcohol',
392 'medicine',
393 'potion',
394 'poison',
395 'watch',
396 'cup',
397 'cutlery',
398 'vehicle',
399 'boat',
400 'plane',
401 'rope',
402 'collectable',
403 'toy',
404 'other',
405 ],
406 portableTypeList => [], # Set below
407  
408 # Decoration object types
409 # -----------------------
410  
411 # Lists of decoration model object types (things which can't, in theory, be picked up)
412 # All decorations are given a type, as a guide to what sort of object they might be
413 # Decoration types used by Axmud are
414 # door (anything which is openable, and is an exit)
415 # window (anything which might be openable, and might be an exit)
416 # wall (any fixed, immovable object resembling a wall, which might be
417 # climbable)
418 # portal (any kind of portal)
419 # sign (any fixed object that is readable)
420 # board (any fixed object that is interactively readable, e.g. a bulletin board)
421 # light (any fixed light source)
422 # furniture (tables, etc)
423 # seat (anything that can be sat on)
424 # bed (anything that can be lied on)
425 # fire (any fire object)
426 # bin (any container from which things don't return)
427 # container (any other kind of container)
428 # cart (any container which can be moved, usually by pushing it)
429 # ladder (any immovable, climable object)
430 # button (anything that can be pushed)
431 # lever (anything that can be pulled)
432 # clock (any decoration that tells the time)
433 # machine (any kind of static machine, e.g. a lottery machine)
434 # hook (any object to which things, like ropes, can be tied)
435 # tree (any kind of large plant, that could potentially be climbed)
436 # plant (any other kind of plant)
437 # fountain (any kind of water source)
438 # monument (any kind of monument or statue)
439 # other (any other object)
440 #
441 # Custom types can also be created. ->constDecorationTypeList contains the default list
442 # of types, and ->decorationTypeList contains the actual list of types for this
443 # dictionary
444 constDecorationTypeList => [
445 'door',
446 'window',
447 'wall',
448 'portal',
449 'sign',
450 'board',
451 'light',
452 'furniture',
453 'seat',
454 'bed',
455 'fire',
456 'bin',
457 'container',
458 'cart',
459 'ladder',
460 'button',
461 'lever',
462 'clock',
463 'machine',
464 'hook',
465 'tree',
466 'plant',
467 'fountain',
468 'monument',
469 'other',
470 ],
471 decorationTypeList => [], # Set below
472  
473 # Object classes
474 # --------------
475  
476 # Hashes of objects, transforming an object (e.g. 'spider') into a word which roughly
477 # corresponds to a class of model object (e.g. 'creature').
478 # Guilds, races and adjectives are treated as separate classes even though there is no
479 # 'guild' or 'race' model object, and certainly no 'adj' model object.
480 # Hashes in the form
481 # $hash{word} = world_model_category
482 guildHash => {
483 'adventurer' => 'guild',
484 'bard' => 'guild',
485 'cleric' => 'guild',
486 'fighter' => 'guild',
487 'thief' => 'guild',
488 'wizard' => 'guild',
489 },
490 raceHash => {
491 'centaur' => 'race',
492 'dwarf' => 'race',
493 'faery' => 'race',
494 'fairy' => 'race',
495 'giant' => 'race',
496 'goblin' => 'race',
497 'gnome' => 'race',
498 'halfling' => 'race',
499 'hobgoblin' => 'race',
500 'human' => 'race',
501 'kobold' => 'race',
502 'minotaur' => 'race',
503 'ogre' => 'race',
504 'orc' => 'race',
505 'troll' => 'race',
506 },
507 weaponHash => {
508 'sword' => 'weapon',
509 'axe' => 'weapon',
510 'club' => 'weapon',
511 'mace' => 'weapon',
512 'dagger' => 'weapon',
513 'knife' => 'weapon',
514 'wand' => 'weapon',
515 'staff' => 'weapon',
516 'stick' => 'weapon',
517 },
518 armourHash => {
519 'armour' => 'armour',
520 'chain-mail' => 'armour',
521 'gauntlet' => 'armour',
522 'helm' => 'armour',
523 'helmet' => 'armour',
524 'jacket' => 'armour',
525 'mail' => 'armour',
526 },
527 garmentHash => {
528 'hat' => 'garment',
529 'coat' => 'garment',
530 'scarf' => 'garment',
531 'shoe' => 'garment',
532 'boot' => 'garment',
533 'shirt' => 'garment',
534 'jumper' => 'garment',
535 'trousers' => 'garment',
536 'shorts' => 'garment',
537 'dress' => 'garment',
538 'pants' => 'garment',
539 'socks' => 'garment',
540 'cloak' => 'garment',
541 'veil' => 'garment',
542 },
543 sentientHash => {
544 'guard' => 'sentient',
545 'lookout' => 'sentient',
546 'sentry' => 'sentient',
547 'warrior' => 'sentient',
548 'man' => 'sentient',
549 'woman' => 'sentient',
550 'youth' => 'sentient',
551 'child' => 'sentient',
552 'baby' => 'sentient',
553 'priest' => 'sentient',
554 'farmer' => 'sentient',
555 'ghost' => 'sentient',
556 'beggar' => 'sentient',
557 },
558 creatureHash => {
559 'rabbit' => 'creature',
560 'rat' => 'creature',
561 'dog' => 'creature',
562 'cat' => 'creature',
563 'fish' => 'creature',
564 'chicken' => 'creature',
565 'hen' => 'creature',
566 'cow' => 'creature',
567 'bull' => 'creature',
568 'horse' => 'creature',
569 },
570 portableHash => {
571 'arm' => 'portable',
572 'backpack' => 'portable',
573 'bag' => 'portable',
574 'boat' => 'portable',
575 'book' => 'portable',
576 'box' => 'portable',
577 'coin' => 'portable',
578 'corpse' => 'portable',
579 'foot' => 'portable',
580 'game' => 'portable',
581 'guidebook' => 'portable',
582 'hand' => 'portable',
583 'head' => 'portable',
584 'key' => 'portable',
585 'lamp' => 'portable',
586 'leg' => 'portable',
587 'map' => 'portable',
588 'note' => 'portable',
589 'notebook' => 'portable',
590 'paper' => 'portable',
591 'parchment' => 'portable',
592 'potion' => 'portable',
593 'remains' => 'portable',
594 'rope' => 'portable',
595 'sack' => 'portable',
596 'shovel' => 'portable',
597 'spade' => 'portable',
598 'torch' => 'portable',
599 'toy' => 'portable',
600 'wagon' => 'portable',
601 },
602 decorationHash => {
603 'banner' => 'decoration',
604 'bed' => 'decoration',
605 'bench' => 'decoration',
606 'bin' => 'decoration',
607 'board' => 'decoration',
608 'box' => 'decoration',
609 'cart' => 'decoration',
610 'case' => 'decoration',
611 'chain' => 'decoration',
612 'chair' => 'decoration',
613 'chest' => 'decoration',
614 'container' => 'decoration',
615 'cupboard' => 'decoration',
616 'door' => 'decoration',
617 'doorway' => 'decoration',
618 'dustbin' => 'decoration',
619 'fence' => 'decoration',
620 'fire' => 'decoration',
621 'fireplace' => 'decoration',
622 'fountain' => 'decoration',
623 'furniture' => 'decoration',
624 'gate' => 'decoration',
625 'gateway' => 'decoration',
626 'hearth' => 'decoration',
627 'hook' => 'decoration',
628 'ladder' => 'decoration',
629 'light' => 'decoration',
630 'machine' => 'decoration',
631 'monument' => 'decoration',
632 'notice' => 'decoration',
633 'plant' => 'decoration',
634 'portal' => 'decoration',
635 'poster' => 'decoration',
636 'sign' => 'decoration',
637 'signpost' => 'decoration',
638 'staircase' => 'decoration',
639 'stairs' => 'decoration',
640 'statue' => 'decoration',
641 'steps' => 'decoration',
642 'stool' => 'decoration',
643 'table' => 'decoration',
644 'tree' => 'decoration',
645 'vortex' => 'decoration',
646 'window' => 'decoration',
647 'wall' => 'decoration',
648 'water' => 'decoration',
649 'wheelbarrow' => 'decoration',
650 },
651 adjHash => {
652 'big' => 'adj',
653 'huge' => 'adj',
654 'small' => 'adj',
655 'tiny' => 'adj',
656 'high' => 'adj',
657 'low' => 'adj',
658 'fat' => 'adj',
659 'thin' => 'adj',
660 'clean' => 'adj',
661 'dirty' => 'adj',
662 'hidden' => 'adj',
663 'open' => 'adj',
664 'closed' => 'adj',
665 'locked' => 'adj',
666 'unlocked' => 'adj',
667 'good' => 'adj',
668 'evil' => 'adj',
669 },
670  
671 # Portable/decoration types
672 # -------------------------
673  
674 # Hash of portable/decoration types, transforming every key in ->portableHash and
675 # ->decorationHash into its portable/decoration type (one of the values stored in
676 # ->portableTypeList or ->decorationTypeList).
677 # Hashes in the form
678 # $hash{word} = portable_or_decoration_type
679 portableTypeHash => {
680 'arm' => 'bodypart',
681 'backpack' => 'backpack',
682 'bag' => 'bag',
683 'beer' => 'beer',
684 'boat' => 'boat',
685 'book' => 'book',
686 'box' => 'box',
687 'coin' => 'coin',
688 'corpse' => 'corpse',
689 'foot' => 'bodypart',
690 'game' => 'toy',
691 'guidebook' => 'book',
692 'hand' => 'bodypart',
693 'head' => 'bodypart',
694 'key' => 'key',
695 'lamp' => 'lamp',
696 'leg' => 'bodypart',
697 'match' => 'match',
698 'map' => 'map',
699 'note' => 'paper',
700 'notebook' => 'book',
701 'paper' => 'paper',
702 'parchment' => 'paper',
703 'potion' => 'potion',
704 'remains' => 'corpse',
705 'rope' => 'rope',
706 'sack' => 'sack',
707 'shovel' => 'spade',
708 'spade' => 'spade',
709 'torch' => 'torch',
710 'toy' => 'toy',
711 'wagon' => 'vehicle',
712 },
713 decorationTypeHash => {
714 'banner' => 'sign',
715 'bed' => 'bed',
716 'bench' => 'seat',
717 'bin' => 'bin',
718 'board' => 'decoration',
719 'box' => 'container',
720 'cart' => 'cart',
721 'case' => 'container',
722 'chain' => 'ladder',
723 'chair' => 'seat',
724 'chest' => 'container',
725 'container' => 'container',
726 'cupboard' => 'container',
727 'door' => 'door',
728 'doorway' => 'door',
729 'dustbin' => 'bin',
730 'fence' => 'wall',
731 'fire' => 'fire',
732 'fireplace' => 'fire',
733 'fountain' => 'fountain',
734 'furniture' => 'furniture',
735 'gate' => 'door',
736 'gateway' => 'door',
737 'hearth' => 'fire',
738 'hook' => 'hook',
739 'ladder' => 'ladder',
740 'light' => 'light',
741 'machine' => 'machine',
742 'monument' => 'monument',
743 'notice' => 'sign',
744 'plant' => 'plant',
745 'portal' => 'portal',
746 'poster' => 'sign',
747 'sign' => 'sign',
748 'signpost' => 'sign',
749 'staircase' => 'ladder',
750 'stairs' => 'ladder',
751 'statue' => 'monument',
752 'steps' => 'ladder',
753 'stool' => 'seat',
754 'table' => 'furniture',
755 'tree' => 'tree',
756 'vortex' => 'window',
757 'wall' => 'wall',
758 'water' => 'other',
759 'wheelbarrow' => 'wheelbarrow',
760 'window' => 'window',
761 },
762  
763 # Plurals
764 # -------
765  
766 # Hash that transforms a plural ending commonly found in the dictionary's language into
767 # a singular ending. Hash in the form
768 # $pluralEndingHash{plural_ending_regex} = singular_ending_string
769 # e.g. $pluralEndingHash{'ies$'} = 'y'
770 # NB The key is a regex, because it's used in an s// substitution
771 # NB Endings are processed in order of length (longest key first)
772 pluralEndingHash => {
773 's$' => '',
774 'ies$' => 'y',
775 'ves$' => 'f',
776 'ches$' => 'ch',
777 'shes$' => 'sh',
778 'esses$', => 'ess',
779 },
780 # Hash that transforms a singular ending in the dictionary's language into a commonly
781 # found plural ending.
782 # When converting a singular word into a plural, if none of the keys in this hash match
783 # the singular word, the value corresponding to the key '' is added to the word,
784 # (e.g. 'orc' -> 'orcs')
785 # Hash in the form
786 # $pluralEndingHash{singular_ending_regex} = plural_ending_string
787 # e.g. $pluralEndingHash{'y$'} = 'ies'
788 # NB The key is a regex, because it's used in an s// substitution
789 # NB Endings are processed in order of length (longest key first)
790 reversePluralEndingHash => {
791 '' => 's',
792 'y$' => 'ies',
793 'f$' => 'ves',
794 'ch$' => 'ches',
795 'sh$' => 'shes',
796 'ess$', => 'esses',
797 },
798 # Hash that deals with exceptions to the above rules, transforming a singular word into
799 # its plural form. Hash in the form
800 # $pluralNounHash{singular} = plural
801 # e.g. $pluralNounHash{'knife'} = 'knives'
802 pluralNounHash => {
803 'knife' => 'knives',
804 'staff' => 'staves',
805 'man' => 'men',
806 'woman' => 'women',
807 'child' => 'children',
808 'remains' => 'remains',
809 },
810 # Hash that deals with exceptions to the above rules, transforming a plural word into
811 # its singular form. Hash in the form
812 # $pluralNounHash{singular} = plural
813 # e.g. $pluralNounHash{'knife'} = 'knives'
814 reversePluralNounHash => {
815 'knives' => 'knife',
816 'staves' => 'staff',
817 'men' => 'man',
818 'women' => 'woman',
819 'children' => 'child',
820 'remains' => 'remains',
821 },
822  
823 # Adjective declension
824 # --------------------
825  
826 # Hashes transforming an adjective into its declined form (might be useful in some
827 # languages, but not used in English. For languages that use declined plural
828 # adjectives, simply treat them as normal declined adjectives)
829 #
830 # Hash transforming a declined adjective ending commonly found in the dictionary's
831 # language into the equivalent non-declined ending. Hash in the form
832 # $adjEndingHash{declined_ending_regex} = replacement_ending_string
833 # e.g. $adjEndingHash{'en$'} = 'e' (from German)
834 # NB The key is a regex, because it's used in an s// substitution
835 # NB Endings are processed in order of length (longest key first)
836 adjEndingHash => {
837 # 'declined_ending$' => 'replacement_ending'
838 },
839 # Hash transforming a non-declined adjective ending commonly found in the dictionary's
840 # language into the equivalent declined ending. Hash in the form
841 # $reverseAdjEndingHash{non_declined_ending_regex} = replacement_ending_string
842 # e.g. $reverseAdjEndingHash{'e$'} = 'en' (from German)
843 reverseAdjEndingHash => {
844 # 'non_declined_ending$' => 'replacement_ending'
845 },
846 # Hash that deals with exceptions to the above rules, transforming a non-declined
847 # adjective into its declined form. Hash in the form
848 # $declinedAdjHash{non_declined_word_regex} = declined_word_string
849 # e.g. $declinedAdjHash{'beau'} = 'belle'
850 declinedAdjHash => {
851 # 'non_declined_adj' => 'declined adjective',
852 },
853 # Hash that deals with exceptions to the above rules, transforming a declined
854 # adjective into its non-declined form. Hash in the form
855 # $declinedAdjHash{declined_word_regex} = non_declined_word_string
856 # e.g. $declinedAdjHash{'belle'} = 'beau'
857 reverseDeclinedAdjHash => {
858 # 'non_declined_adj' => 'declined adjective',
859 },
860  
861 # Pseudo-nouns / pseudo-objects / pseudo-adjectives
862 # -------------------------------------------------
863  
864 # Hash of groups of words which represent a single noun (often used in constructions
865 # containing several nouns, e.g. 'wizard teacher' or grammatical constructions like
866 # 'conan the barbarian' or 'defender of honour'. These groups are called
867 # 'pseudo-nouns'. Pseudo-nouns are regexes.
868 # Hash in the form
869 # $pseudoNounHash{phrase_regex} = replacement_noun_string
870 pseudoNounHash => {
871 # 'regex' => 'replacement ',
872 },
873 # Hash of groups of words which represent a single adjective. These groups are called
874 # pseudo-adjectives. Pseudo-adjectives are regexes.
875 # Hash in the form
876 # $pseudoAdjHash{phrase_regex} = replacement_adjective_string
877 pseudoAdjHash => {
878 # 'regex' => 'replacement ',
879 },
880 # When Axmud tries to parse a line of text containing objects, the first thing it does
881 # is to search the line for 'pseudo-objects' - strings that should be reduced to
882 # something else, at the beginning of parsing
883 # For example, the line 'He-man, master of the universe is here' would normally be
884 # interpreted as two objects, because of the comma ('he-man' and 'master of the
885 # universe').
886 # You can prevent such lines of text from confusing the parser by defining the string
887 # 'He-man, master of the universe is here' as a pseudo-object, which is replaced by
888 # another string. Pseudo-objects are regexes.
889 #
890 # Hash in the form
891 # $pseudoObjHash{phrase_regex} = replacement_string
892 # e.g. $pseudoObjHash{'He-man, master of the universe'} = 'he-man'
893 # (In this example, the replacement string might be 'he-man', so the line of text would
894 # become 'He-man is here' BEFORE the parser does any serious work on it)
895 # e.g. $pseudoObjHash{'a big pile of nothing'} = ''
896 # (In this example, the replacement string is an empty string, so the parser ignores
897 # the text 'a big pile of nothing' altogether
898 #
899 # NB Pseudo-object replacement strings can be several words, perhaps 'cute little bunny'
900 # - but pseudo-noun replacement strings should be a single noun, perhaps 'bunny' and
901 # pseudo-adjective replacement strings should be a single adjective, perhaps 'cute'
902 pseudoObjHash => {
903 # 'regex' => 'replacement ',
904 },
905  
906 # Other words
907 # -----------
908  
909 # Hash of words (doesn't matter if they're recognised nouns/adjectives, or not) which
910 # mark an object as being 'dead'. The list must contain both singular and plural
911 # forms (e.g. 'corpses' as well as 'corpse')
912 # Hash in the form
913 # $deathWordHash{'word'} = undef
914 deathWordHash => {
915 'corpse' => undef,
916 'corpses' => undef,
917 'dead' => undef,
918 },
919 # Hash of unknown words - those which have been collected by the Locator task but which
920 # haven't been added to the dictionary yet. The words are stored in a hash for quick
921 # retrievel. Hash in the form
922 # $unknownWordHash{'word'} = undef
923 unknownWordHash => {
924 # 'unknown_word' => undef,
925 },
926 # Hash of unknown contents lines which have been collected by the Locator task,
927 # without (or as well as) splitting the lines into single objects. Hash in the form
928 # ->contentsLinesHash{'line_of_text'} = undef
929 contentsLinesHash => {
930 # 'line_of_text' => undef,
931 },
932 # Hash of ignorable words - words which are definitely not nouns or adjectives (nor
933 # pseudo-nouns or pseudo-adjectives) which should not be added to the unknown word
934 # list. This hash should contain commonly-used prepositions and adverbs in the
935 # dictionary's language
936 # Hash in the form
937 # $ignoreWordHash('word'} = 'ignore_word'
938 ignoreWordHash => {
939 'the' => 'ignore_word',
940 'a' => 'ignore_word',
941 'an' => 'ignore_word',
942 'of' => 'ignore_word',
943 'from' => 'ignore_word',
944 'in' => 'ignore_word',
945 'into' => 'ignore_word',
946 'on' => 'ignore_word',
947 'onto' => 'ignore_word',
948 'above' => 'ignore_word',
949 'under' => 'ignore_word',
950 'over' => 'ignore_word',
951 'underneath' => 'ignore_word',
952 'between' => 'ignore_word',
953 'besides' => 'ignore_word',
954 'in front of' => 'ignore_word',
955 'behind' => 'ignore_word',
956 'opposite' => 'ignore_word',
957 'quickly' => 'ignore_word',
958 'slowly' => 'ignore_word',
959 },
960  
961 # Directions
962 # ----------
963  
964 # Axmud divides all directions (and therefore exit names) into four groups
965 # Primary directions are the sixteen compass directions (including 'north', 'northeast'
966 # and 'northnortheast', etc) plus 'up' and 'down'. Axmud assumes that all worlds use
967 # these directions to organise rooms in three-dimensional space
968 # Secondary directions are a customisable list of directions commonly found in worlds
969 # using the dictionary's language (words such as 'entrance', 'exit', 'in', 'out', etc)
970 # Relative directions are those that change, depending on which way the character is
971 # facing (i.e., from which direction the character entered the room). For example,
972 # Discworld uses exits called 'forward', 'backward', 'left', 'forward-left' and so on;
973 # a single exit in a room might be described as 'forward' if the character entered
974 # from the north, or 'backward' if they entered from the south. Axmud translates
975 # relative directions into primary directions before using them
976 # Unrecognised directions are any direction not in the above three lists. Axmud treats
977 # any such direction as an unrecognised direction
978 #
979 # For example, in a room statement like this:
980 #
981 # You are in a boring room.
982 # Obvious exits: north, out, wibble
983 #
984 # ...we have a primary, secondary and unrecognised direction
985 #
986 # In a room statement like this:
987 #
988 # You are in an exciting room.
989 # Obvious exits: forward, forward-left, backward, out
990 #
991 # ...we have three relative directions and a secondary direction. If entering from the
992 # south, 'forward' is translated as 'north', 'forward-left' is translated as
993 # 'northwest' and 'backward' is translated as 'south'. 'out' is treated like any other
994 # secondary direction
995 #
996 # Axmud uses 'standard' primary directions internally:
997 # nort northnortheast northeast eastnortheast east eastsoutheast southeast
998 # southsoutheast south southsouthwest southwest westsouthwest west westnorthwest
999 # northwest northnorthwest up down
1000 # These scalar values never change and are available in GA::Client->constPrimaryDirList,
1001 # ->constShortPrimaryDirList and ->constShortPrimaryDirHash
1002 # Axmud uses the dictionary map these standard values onto custom primary directions in
1003 # whichever language the dictionary is using (e.g. mapping the standard 'north' onto
1004 # the Spanish 'norte'). If the dictionary's language is English, then the standard
1005 # and custom directions (probably) have the same value
1006 # For an exit, the world model stores both the exit's standard direction and the
1007 # corresponding custom direction. The automapper uses the standard direction to decide
1008 # how to draw the exit on the map, and uses the custom direction to respond to the
1009 # user's commands
1010 #
1011 # The dictionary stores both abbreviated and non-abbreviated forms of each primary
1012 # direction, but makes no distinction between abbreviated and non-abbreviated forms of
1013 # secondary and tertiary directions
1014 #
1015 # Primary direction hash - maps the standard primary directions onto the customised
1016 # forms for this dictionary's language. Hash in the form
1017 # $primaryDirHash{standard_primary_dir} = custom_primary_dir
1018 primaryDirHash => {
1019 north => 'north',
1020 northnortheast => 'northnortheast',
1021 northeast => 'northeast',
1022 eastnortheast => 'eastnortheast',
1023 east => 'east',
1024 eastsoutheast => 'eastsoutheast',
1025 southeast => 'southeast',
1026 southsoutheast => 'southsoutheast',
1027 south => 'south',
1028 southsouthwest => 'southsouthwest',
1029 southwest => 'southwest',
1030 westsouthwest => 'westsouthwest',
1031 west => 'west',
1032 westnorthwest => 'westnorthwest',
1033 northwest => 'northwest',
1034 northnorthwest => 'northnorthwest',
1035 up => 'up',
1036 down => 'down',
1037 },
1038 # Primary abbreviated direction hash - maps the standard primary directions onto the
1039 # customised abbreviated forms for this dictionary's language. Hash in the form
1040 # $primaryAbbrevHash{standard_primary_dir} = custom_primary_abbrev_dir
1041 primaryAbbrevHash => {
1042 north => 'n',
1043 northnortheast => 'nne',
1044 northeast => 'ne',
1045 eastnortheast => 'ene',
1046 east => 'e',
1047 eastsoutheast => 'ese',
1048 southeast => 'se',
1049 southsoutheast => 'sse',
1050 south => 's',
1051 southsouthwest => 'ssw',
1052 southwest => 'sw',
1053 westsouthwest => 'wsw',
1054 west => 'w',
1055 westnorthwest => 'wnw',
1056 northwest => 'nw',
1057 northnorthwest => 'nnw',
1058 up => 'u',
1059 down => 'd',
1060 },
1061 # Primary opposite hash - maps the standard primary directions onto the customised
1062 # form of the opposite direction. Hash in the form
1063 # $primaryOppHash{standard_primary_dir} = custom_primary_opposite_dir
1064 # NB If there is more than one possible opposite, separate them with a space,
1065 # e.g. 'south out'. If there is no opposite direction, use an empty string.
1066 primaryOppHash => {
1067 north => 'south',
1068 northnortheast => 'southsouthwest',
1069 northeast => 'southwest',
1070 eastnortheast => 'westsouthwest',
1071 east => 'west',
1072 eastsoutheast => 'westnorthwest',
1073 southeast => 'northwest',
1074 southsoutheast => 'northnorthwest',
1075 south => 'north',
1076 southsouthwest => 'northnortheast',
1077 southwest => 'northeast',
1078 westsouthwest => 'eastnortheast',
1079 west => 'east',
1080 westnorthwest => 'eastsoutheast',
1081 northwest => 'southeast',
1082 northnorthwest => 'southsoutheast',
1083 up => 'down',
1084 down => 'up',
1085 },
1086 # Primary opposite abbreviated hash - maps the standard primary directions onto the
1087 # customised form of the opposite direction. Hash in the form
1088 # $primaryOppHash{standard_primary_dir} = custom_primary_abbrev_opposite_dir
1089 # NB If there is more than one possible opposite, separate them with a space,
1090 # e.g. 's out'. If there is no abbreviated direction, use an empty string
1091 primaryOppAbbrevHash => {
1092 north => 's',
1093 northnortheast => 'ssw',
1094 northeast => 'sw',
1095 eastnortheast => 'wsw',
1096 east => 'w',
1097 eastsoutheast => 'wnw',
1098 southeast => 'nw',
1099 southsoutheast => 'nnw',
1100 south => 'n',
1101 southsouthwest => 'nne',
1102 southwest => 'ne',
1103 westsouthwest => 'ene',
1104 west => 'e',
1105 westnorthwest => 'ese',
1106 northwest => 'se',
1107 northnorthwest => 'sse',
1108 up => 'd',
1109 down => 'u',
1110 },
1111  
1112 # A customisable list of secondary directions, in an order defined by the user; the
1113 # equivalent of GA::Client->constPrimaryDirList, but this list can be modified
1114 # Any possible abbreviations are treated as distinct secondary directions
1115 secondaryDirList => [
1116 'in',
1117 'out',
1118 'entrance',
1119 'exit',
1120 'steps',
1121 'lift',
1122 'hole',
1123 'gap',
1124 'crack',
1125 'opening',
1126 'gate',
1127 'gateway',
1128 'door',
1129 'doorway',
1130 'portal',
1131 'vortex',
1132 ],
1133 # Secondary direction hash - a list of recognised secondary directions (including any
1134 # possible abbreviations). To be compatible with $self->primaryDirHash, the key and
1135 # corresponding value are the same
1136 # ->secondaryDirHash{secondary_dir} = secondary_dir
1137 secondaryDirHash => {
1138 'in' => 'in',
1139 'out' => 'out',
1140 'entrance' => 'entrance',
1141 'exit' => 'exit',
1142 'steps' => 'steps',
1143 'lift' => 'lift',
1144 'hole' => 'hole',
1145 'gap' => 'gap',
1146 'crack' => 'crack',
1147 'opening' => 'opening',
1148 'gate' => 'gate',
1149 'gateway' => 'gateway',
1150 'door' => 'door',
1151 'doorway' => 'doorway',
1152 'portal' => 'portal',
1153 'vortex' => 'vortex',
1154 },
1155 # Secondary abbreviated direction hash - maps the recognised secondary directions onto
1156 # customised abbreviated forms for this dictionary's language. If there's no
1157 # abbreviated form of the direction, the value of the key-value pair should be
1158 # 'undef'. Hash in the form
1159 # $primaryAbbrevHash{recongised_secondary_dir} = secondary_abbrev_dir
1160 # $primaryAbbrevHash{recongised_secondary_dir} = undef
1161 secondaryAbbrevHash => {
1162 'in' => undef, # Default, no abbreviated form
1163 'out' => undef,
1164 'entrance' => undef,
1165 'exit' => undef,
1166 'steps' => undef,
1167 'lift' => undef,
1168 'hole' => undef,
1169 'gap' => undef,
1170 'crack' => undef,
1171 'opening' => undef,
1172 'gate' => undef,
1173 'gateway' => undef,
1174 'door' => undef,
1175 'doorway' => undef,
1176 'portal' => undef,
1177 'vortex' => undef,
1178 },
1179 # Secondary opposite directions - maps the customised secondary directions onto its
1180 # assumed opposite direction, if any (or onto an empty string if not)
1181 # Hash in the form
1182 # $secondaryOppHash{custom_secondary_dir} = custom_secondary_opposite_dir
1183 # NB If there is more than one possible opposite, separate them with a space,
1184 # e.g. 'south out'. If there is no opposite direction, use an empty string.
1185 secondaryOppHash => {
1186 'in' => 'out',
1187 'out' => 'in',
1188 'entrance' => 'exit out',
1189 'exit' => 'entrance in',
1190 'steps' => 'steps',
1191 'lift' => 'lift',
1192 'gate' => 'gate',
1193 'gateway' => 'gateway',
1194 'door' => 'door',
1195 'doorway' => 'doorway',
1196 'hole' => 'hole out',
1197 'gap' => 'gap out',
1198 'crack' => 'crack out',
1199 'opening' => 'opening out',
1200 'portal' => 'portal out',
1201 'vortex' => 'vortex out',
1202 },
1203 # Secondary opposite abbreviated hash - maps the recognised secondary directions onto
1204 # the customised form of the opposite direction. Hash in the form
1205 # $primaryOppHash{standard_primary_dir} = custom_primary_abbrev_opposite_dir
1206 # NB If there is more than one possible opposite, separate them with a space,
1207 # e.g. 'south out'. If there is no abbreviated direction, use an empty string
1208 secondaryOppAbbrevHash => {
1209 'in' => '',
1210 'out' => '',
1211 'entrance' => '',
1212 'exit' => '',
1213 'steps' => '',
1214 'lift' => '',
1215 'gate' => '',
1216 'gateway' => '',
1217 'door' => '',
1218 'doorway' => '',
1219 'hole' => '',
1220 'gap' => '',
1221 'crack' => '',
1222 'opening' => '',
1223 'portal' => '',
1224 'vortex' => '',
1225 },
1226 # Secondary auto-allocatable directions. Maps a secondary direction onto a standard
1227 # primary direction, so that the automapper can automatically allocate it (e.g. if a
1228 # newly-encountered room contains a 'portal' exit, the automapper can automatically
1229 # allocate it to 'down', if that's what the user wants)
1230 # For each key-value pair, if the value is 'undef', the secondary direction in the key
1231 # is not auto-allocated
1232 secondaryAutoHash => {
1233 'in' => undef,
1234 'out' => undef,
1235 'entrance' => undef,
1236 'exit' => undef,
1237 'steps' => undef,
1238 'lift' => undef,
1239 'gate' => undef,
1240 'gateway' => undef,
1241 'door' => undef,
1242 'doorway' => undef,
1243 'hole' => undef,
1244 'gap' => undef,
1245 'crack' => undef,
1246 'opening' => undef,
1247 'portal' => undef,
1248 'vortex' => undef,
1249 },
1250  
1251 # Relative directions, which are translated into the eight cardinal directions,
1252 # depending on the direction of entry
1253 # One or more relative directions can be defined. For any relative direction that's
1254 # defined, the opposite should probably be defined too. If no relative directions are
1255 # defined, then Axmud doesn't use relative directions
1256 # If the direction of entry into a room is not known, Axmud uses the direction of the
1257 # first incoming exit that's not itself a relative direction; if that too fails, the
1258 # direction of entry is taken to be 'south'
1259 # Keys in the hash are integers in the range 0-7. Axmud help files describe them as
1260 # 'slots'. 0 represents 'forward', i.e. movement in the same direction as the
1261 # direction of entry. Then we move clockwise, so 1 represents 'forward-right',
1262 # 2 'right', 3 'backward-right', 4 'backward', 5 'backward-left', 6 'left',
1263 # 7 'forward-left'
1264 # A key's corresponding value is the relative direction, e.g.
1265 # $relativeDirHash{4} = 'backward'
1266 relativeDirHash => {},
1267 # Corresponding hash of abbreviated relative directions, for example
1268 # $relativeAbbrevHash{4] = 'bw'
1269 relativeAbbrevHash => {},
1270  
1271 # Speedwalk directions
1272 # --------------------
1273  
1274 # Hash of speedwalking characters (lower-case letters in range a-z, non-Latin alphabets
1275 # acceptable) and their corresponding movement commands, which can be standard primary
1276 # directions (one of the items in GA::Client->constPrimaryDirList) or any other type
1277 # of movement command
1278 # When interpreting speedwalk commands, GA::Session refers to this hash. If the key's
1279 # corresponding value is a standard primary direction, this dictionary is consulted to
1280 # provide the corresponding custom primary direction. Otherwise, GA::Session assumes
1281 # the key's corresponding value is a valid movement command (probably representing an
1282 # exit in the room), and processes it as such
1283 speedDirHash => {
1284 'n' => 'north',
1285 's' => 'south',
1286 'e' => 'east',
1287 'w' => 'west',
1288 'u' => 'up',
1289 'd' => 'down',
1290 'l' => 'look',
1291 't' => 'northwest',
1292 'y' => 'northeast',
1293 'g' => 'southwest',
1294 'h' => 'southeast',
1295 },
1296 # Hash of speedwalking modifier characters (upper-case letters in range A-Z, non-Latin
1297 # alphabets acceptable) and their corresponding standard commands (keys in
1298 # GA::Cage::Cmd->cmdHash, e.g. 'go', 'fly', 'sail', 'open_dir', 'unlock_dir' etc)
1299 # The cage specifies a replacement command for each standard command (the replacement
1300 # command can be modified by the user). The replacement is usually in the form
1301 # 'go direction', 'fly direction', 'sail direction'. There are also non-movement
1302 # standard commands like 'open_dir' and 'unlock_dir'; their replacements are usually
1303 # in the form 'open direction door' and 'unlock direction door'
1304 # In the speedwalk command, the modifier character must be followed by a speedwalking
1305 # character (e.g. 'Ue', representing 'unlock east door'). The GA::Session processes
1306 # the replacement command, substituting the word 'direction' for the speedwalking
1307 # character (e.g. standard command 'unlock direction door' becomes 'unlock east door')
1308 # If the standard command is a movement command (exists in GA::Cage::Cmd->moveCmdList),
1309 # GA::Session processes it as a movement command; otherwise it is processed as a
1310 # non-movement command
1311 speedModifierHash => {
1312 # Movement commands
1313 'G' => 'go_dir',
1314 'N' => 'run',
1315 'A' => 'walk',
1316 'F' => 'fly',
1317 'W' => 'swim',
1318 'V' => 'dive',
1319 'S' => 'sail',
1320 'I' => 'ride',
1321 'D' => 'drive',
1322 'R' => 'creep',
1323 'E' => 'sneak',
1324 'Q' => 'squeeze',
1325 # Non-movement commands
1326 'O' => 'open_dir',
1327 'C' => 'close_dir',
1328 'K' => 'unlock',
1329 'L' => 'lock',
1330 'P' => 'pick',
1331 'B' => 'break',
1332 },
1333  
1334 # Combined hashes
1335 # ---------------
1336  
1337 # Combined hash of recognised nouns, in the form
1338 # $combNounHash{noun} = type
1339 # ...where 'type' corresponds the name of the hash that stores it
1340 # e.g. $combNounHash{'hat'} = garment (corresponds to $self->garmentHash)
1341 combNounHash => {}, # Set below
1342 # Combined hash of recognised adjectives, in the form
1343 # $combAdjHash{adjective} = type
1344 # ...where 'type' corresponds the name of the hash that stores it
1345 # e.g. $combAdjHash{'big'} = 'adj' (corresponds to $self->adjHash)
1346 combAdjHash => {}, # Set below
1347 # Combined hash of customised directions, in the form
1348 # $combDirHash{custom_direction} = direction_type
1349 # ...where 'direction_type' is one of 'primaryDir', 'primaryAbbrev', 'secondaryDir',
1350 # 'secondaryAbbrev', 'relativeDir' or 'relativeAbbrev'
1351 combDirHash => {}, # Set below
1352 # Combined hash of customised opposite directions, in the form
1353 # $combOppDirHash{custom_direction} = custom_opposite_direction
1354 combOppDirHash => {}, # Set below
1355 # Combined hash of customised directions, converting the customised direction into the
1356 # standard (fixed) form of the primary or secondary direction (relative directions are
1357 # not included). Hash in the form
1358 # $combRevDirHash{custom_direction} = standard_direction
1359 combRevDirHash => {}, # Set below
1360 };
1361  
1362 # Bless the object into existence
1363 bless $self, $class;
1364  
1365 # Set up a few IVs based on other IVs
1366 $self->{'portableTypeList'} = [$self->constPortableTypeList];
1367 $self->{'decorationTypeList'} = [$self->constDecorationTypeList];
1368  
1369 # Create combined hashes (without marking the dictionary file object as having had its data
1370 # modified)
1371 $self->createCombHashes($session, FALSE);
1372  
1373 return $self;
1374 }
1375  
1376 sub clone {
1377  
1378 # Called by GA::Cmd::CloneWorld->do or CloneDictionary->do
1379 # Creates a clone of an existing dictionary
1380 #
1381 # Expected arguments
1382 # $session - The GA::Session which called this function (not stored as an IV)
1383 # $name - A unique string name for this dictionary (max 16 chars, containing
1384 # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable.
1385 # Must not exist as a key in the global hash of reserved names,
1386 # $axmud::CLIENT->constReservedHash)
1387 #
1388 # Return values
1389 # 'undef' on improper arguments or if $name is invalid
1390 # Blessed reference to the newly-created object on success
1391  
1392 my ($self, $session, $name, $check) = @_;
1393  
1394 # Check for improper arguments
1395 if (! defined $session || ! defined $name || defined $check) {
1396  
1397 return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
1398 }
1399  
1400 # Check that $name is valid and not already in use by another dictionary
1401 if (! $axmud::CLIENT->nameCheck($name, 16)) {
1402  
1403 return $axmud::CLIENT->writeError(
1404 'Registry naming error: invalid name \'' . $name . '\'',
1405 $self->_objClass . '->clone',
1406 );
1407  
1408 } elsif ($axmud::CLIENT->ivExists('dictHash', $name)) {
1409  
1410 return $axmud::CLIENT->writeError(
1411 'Registry naming error: dictionary \'' . $name . '\' already exists',
1412 $self->_objClass . '->clone',
1413 );
1414 }
1415  
1416 # Setup
1417 my $clone = {
1418 _objName => $name,
1419 _objClass => $self->_objClass,
1420 _parentFile => 'dicts',
1421 _parentWorld => undef,
1422 # Many IVs are interconnected, so we mark them all as 'private' to force use of the
1423 # accessor methods set_, add_, del_ ...
1424 _privFlag => TRUE,
1425  
1426 name => $name,
1427 language => $self->language,
1428 nounPosn => $self->nounPosn,
1429  
1430 definiteList => [$self->definiteList],
1431 indefiniteList => [$self->indefiniteList],
1432 andList => [$self->andList],
1433 orList => [$self->orList],
1434  
1435 numberHash => {$self->numberHash},
1436  
1437 timeHash => {$self->timeHash},
1438 timePluralHash => {$self->timePluralHash},
1439 reverseTimeHash => {$self->reverseTimeHash},
1440 reverseTimePluralHash => {$self->reverseTimePluralHash},
1441  
1442 clockDayHash => {$self->clockDayHash},
1443 clockHourHash => {$self->clockHourHash},
1444 clockMinuteHash => {$self->clockMinuteHash},
1445  
1446 constPortableTypeList => [$self->constPortableTypeList],
1447 portableTypeList => [$self->portableTypeList],
1448  
1449 constDecorationTypeList => [$self->constDecorationTypeList],
1450 decorationTypeList => [$self->decorationTypeList],
1451  
1452 guildHash => {$self->guildHash},
1453 raceHash => {$self->raceHash},
1454 weaponHash => {$self->weaponHash},
1455 armourHash => {$self->armourHash},
1456 garmentHash => {$self->garmentHash},
1457 sentientHash => {$self->sentientHash},
1458 creatureHash => {$self->creatureHash},
1459 portableHash => {$self->portableHash},
1460 decorationHash => {$self->decorationHash},
1461 adjHash => {$self->adjHash},
1462  
1463 portableTypeHash => {$self->portableTypeHash},
1464 decorationTypeHash => {$self->decorationTypeHash},
1465  
1466 pluralEndingHash => {$self->pluralEndingHash},
1467 reversePluralEndingHash => {$self->reversePluralEndingHash},
1468 pluralNounHash => {$self->pluralNounHash},
1469 reversePluralNounHash => {$self->reversePluralNounHash},
1470  
1471 adjEndingHash => {$self->adjEndingHash},
1472 reverseAdjEndingHash => {$self->reverseAdjEndingHash},
1473 declinedAdjHash => {$self->declinedAdjHash},
1474 reverseDeclinedAdjHash => {$self->reverseDeclinedAdjHash},
1475  
1476 pseudoNounHash => {$self->pseudoNounHash},
1477 pseudoAdjHash => {$self->pseudoAdjHash},
1478 pseudoObjHash => {$self->pseudoObjHash},
1479  
1480 deathWordHash => {$self->deathWordHash},
1481 unknownWordHash => {$self->unknownWordHash},
1482 contentsLinesHash => {$self->contentsLinesHash},
1483 ignoreWordHash => {$self->ignoreWordHash},
1484  
1485 primaryDirHash => {$self->primaryDirHash},
1486 primaryAbbrevHash => {$self->primaryAbbrevHash},
1487 primaryOppHash => {$self->primaryOppHash},
1488 primaryOppAbbrevHash => {$self->primaryOppAbbrevHash},
1489  
1490 secondaryDirList => [$self->secondaryDirList],
1491 secondaryDirHash => {$self->secondaryDirHash},
1492 secondaryAbbrevHash => {$self->secondaryAbbrevHash},
1493 secondaryOppHash => {$self->secondaryOppHash},
1494 secondaryOppAbbrevHash => {$self->secondaryOppAbbrevHash},
1495 secondaryAutoHash => {$self->secondaryAutoHash},
1496  
1497 relativeDirHash => {$self->relativeDirHash},
1498 relativeAbbrevHash => {$self->relativeAbbrevHash},
1499  
1500 speedDirHash => {$self->speedDirHash},
1501 speedModifierHash => {$self->speedModifierHash},
1502  
1503 combNounHash => {$self->combNounHash},
1504 combAdjHash => {$self->combAdjHash},
1505 combDirHash => {$self->combDirHash},
1506 combOppDirHash => {$self->combOppDirHash},
1507 combRevDirHash => {$self->combRevDirHash},
1508 };
1509  
1510 # Bless the cloned object into existence
1511 bless $clone, $self->_objClass;
1512 return $clone;
1513 }
1514  
1515 ##################
1516 # Methods
1517  
1518 sub createCombHashes {
1519  
1520 # Called by $self->new after the object has been blessed into existence, or by any other
1521 # function after they have modified the dictionary's IVs
1522 # Creates the hashes $self->combNounHash and $self->combAdjHash from scratch
1523 # Creates the combined direction hashes by calling ->createCombDirHash
1524 #
1525 # Expected arguments
1526 # $session - The GA::Session which called this function (perhaps indirectly)
1527 # $modifyFlag - Set to TRUE if the dictionary file object should be marked as having had
1528 # its data modified, FALSE otherwise. (Should be FALSE when called by
1529 # $self->new, TRUE when called by any other function)
1530 #
1531 # Return values
1532 # 'undef' on improper arguments
1533 # 1 otherwise
1534  
1535 my ($self, $session, $modifyFlag, $check) = @_;
1536  
1537 # Local variables
1538 my $fileObj;
1539  
1540 # Check for improper arguments
1541 if (! defined $session || ! defined $modifyFlag || defined $check) {
1542  
1543 return $axmud::CLIENT->writeImproper($self->_objClass . '->createCombHashes', @_);
1544 }
1545  
1546 # Create the combined noun hash, setting $self->combNounHash and ->overflowNounList
1547 $self->createCombNounHash($session);
1548  
1549 # Create the combined adjective hash
1550 $self->createCombAdjHash();
1551  
1552 # Create the combined standard direction hash and list
1553 $self->createCombDirHash();
1554  
1555 # Set the reversed time hashes
1556 if ($self->timeHash) {
1557 $self->{'reverseTimeHash'} = { reverse $self->timeHash };
1558 } else {
1559 $self->{'reverseTimeHash'} = {};
1560 }
1561  
1562 if ($self->timePluralHash) {
1563 $self->{'reverseTimePluralHash'} = { reverse $self->timePluralHash };
1564 } else {
1565 $self->{'reverseTimePluralHash'} = {};
1566 }
1567  
1568 # Set the dictionary file object's ->modifyFlag, if appropriate
1569 if ($modifyFlag) {
1570  
1571 $axmud::CLIENT->setModifyFlag(
1572 $self->_parentFile,
1573 TRUE,
1574 $self->_objClass . '->createCombHashes',
1575 );
1576 }
1577  
1578 return 1;
1579 }
1580  
1581 sub createCombNounHash {
1582  
1583 # Called by $self->createCombHashes
1584 # Creates the combined noun hash, the IV ->combNounHash
1585 #
1586 # Expected arguments
1587 # $session - The GA::Session which called $self->createCombHashes (perhaps
1588 # indirectly)
1589 #
1590 # Return values
1591 # 'undef' on improper arguments
1592 # 1 otherwise
1593  
1594 my ($self, $session, $check) = @_;
1595  
1596 # Local variables
1597 my (
1598 @typeList,
1599 %hash, %combHash,
1600 );
1601  
1602 # Check for improper arguments
1603 if (! defined $session || defined $check) {
1604  
1605 return $axmud::CLIENT->writeImproper($self->_objClass . '->createCombNounHash', @_);
1606 }
1607  
1608 # Nouns are stored in several hashes. $self->combNounHash attemps to combine them into
1609 # a single hash, preserving key-value pairs
1610 # e.g. $self->guildHash{'cleric'} = 'guild'
1611 # e.g. $self->combNounHash{'cleric'} = 'guild'
1612 #
1613 # Each key in $self->combNounHash is a noun; the corresponding value is its type. The
1614 # type is a string that's identical to the name of the IV, but with the 'Hash' portion
1615 # removed (so ->guildHash becomes 'guild')
1616 #
1617 # When a noun appears in multiple hashes, we use the one in the highest-priority hash. The
1618 # priority order is
1619 # pluralNoun > sentient > creature > portable > decoration > race > guild > weapon
1620 # > armour > garment > pseudoNoun
1621  
1622 # Deal with plural nouns...
1623 %hash = $self->reversePluralNounHash;
1624 foreach my $key (keys %hash) {
1625  
1626 my $value = $hash{$key};
1627  
1628 # If there's a singular noun that's identical, display a warning
1629 if (exists $combHash{$key}) {
1630  
1631 $session->writeWarning(
1632 'Found plural noun \''.$key.'\' with identical singular noun',
1633 $self->_objClass . '->createCombNounHash',
1634 );
1635  
1636 delete $combHash{$key};
1637  
1638 } else {
1639  
1640 # Temporarily mark this noun as being stored in $self->pluralNounHash
1641 $combHash{$key} = 'pluralNoun';
1642 }
1643 }
1644  
1645 # ...then deal with everything else
1646 @typeList = (
1647 'sentient', 'creature', 'portable', 'decoration', 'race', 'guild', 'weapon', 'armour',
1648 'garment', 'pseudoNoun',
1649 );
1650  
1651 foreach my $type (@typeList) {
1652  
1653 my $hashName = $type . 'Hash';
1654 my %thisHash = $self->$hashName;
1655  
1656 foreach my $key (keys %thisHash) {
1657  
1658 my $value = $thisHash{$key};
1659  
1660 if (! exists $combHash{$key}) {
1661  
1662 # Add to the combined hash
1663 $combHash{$key} = $value;
1664 }
1665 }
1666 }
1667  
1668 # Now go through the combined noun hash, dealing with everything that was marked as a
1669 # plural noun
1670 # Work out the singular form of the noun (if possible) and then change the value of the
1671 # key-value pair to the type matching that singular noun
1672 foreach my $key (keys %combHash) {
1673  
1674 if ($combHash{$key} eq 'pluralNoun') {
1675  
1676 # Find the equivalent singular word
1677 my $singular = $self->ivShow('reversePluralNounHash', $key);
1678 if (defined $singular) {
1679  
1680 if (! exists ($combHash{$singular} )) {
1681  
1682 # The singular form should be in the new combined hash, but it's missing
1683 $session->writeWarning(
1684 'Combined noun hash is missing the singular form \'' . $singular .
1685 '\' of the plural noun \''.$key.'\'',
1686 $self->_objClass . '->createCombNounHash',
1687 );
1688  
1689 # Remove this plural noun
1690 $self->ivDelete('reversePluralNounHash', $key);
1691  
1692 } else {
1693  
1694 # The singular form has already been added to the new combined hash
1695 if ($combHash{$key} ne $combHash{$singular}) {
1696  
1697 # Set the parent hash of the plural noun
1698 $combHash{$key} = $combHash{$singular};
1699  
1700 } else {
1701  
1702 # If plural and singular are the same word (e.g. sheep), we have a
1703 # problem: the value in the key-value pair is currently set to
1704 # 'plural', so it's not a simple matter to find the parent hash
1705 # Need to check every hash until we find the right singular word,
1706 # so we can set the right parent hash
1707 foreach my $type (@typeList) {
1708  
1709 my $hashName = $type . 'Hash';
1710  
1711 if ($self->ivExists($hashName, $key)) {
1712  
1713 $combHash{$key} = $type;
1714 }
1715 }
1716  
1717 # If the parent hash wasn't found, for some reason...
1718 if ($combHash{$key} eq 'pluralNoun') {
1719  
1720 # ...display a warning
1721 $session->writeWarning(
1722 'Found plural noun \'' . $key . '\' with identical singular'
1723 . ' form, but no parent hash',
1724 $self->_objClass . '->createCombNounHash',
1725 );
1726  
1727 # Remove this plural noun
1728 $self->ivDelete('reversePluralNounHash', $key);
1729 delete $combHash{$key};
1730 }
1731 }
1732 }
1733  
1734 } else {
1735  
1736 # The plural noun dictionary contains an unrecognised noun. Display a warning
1737 $session->writeWarning(
1738 'Found plural noun \''.$key.'\' with no parent hash',
1739 $self->_objClass . '->createCombNounHash',
1740 );
1741  
1742 # Remove this plural noun
1743 $self->ivDelete('reversePluralNounHash', $key);
1744 delete $combHash{$key};
1745 }
1746 }
1747 }
1748  
1749 # Combined noun hash complete. Update IVs
1750 $self->{'combNounHash'} = \%combHash;
1751  
1752 return 1;
1753 }
1754  
1755 sub createCombAdjHash {
1756  
1757 # Called by $self->createCombHashes
1758 # Creates the combined adjective hash, the IV ->combAdjHash
1759 #
1760 # Expected arguments
1761 # (none besides $self)
1762 #
1763 # Return values
1764 # 'undef' on improper arguments
1765 # 1 otherwise
1766  
1767 my ($self, $check) = @_;
1768  
1769 # Local variables
1770 my (
1771 @typeList,
1772 %hash, %combHash,
1773 );
1774  
1775 # Check for improper arguments
1776 if (defined $check) {
1777  
1778 return $axmud::CLIENT->writeImproper($self->_objClass . '->createCombAdjHash', @_);
1779 }
1780  
1781 # Adjectives are stored in three hashes. $self->combAdjHash attemps to combine them into
1782 # a single hash, preserving key-value pairs
1783 # e.g. $self->adjHash{'big'} = 'adj'
1784 # e.g. $self->combAdjHash{'big'} = 'adj'
1785 #
1786 # Each key in $self->combAdjHash is a noun; the corresponding value is its type. The
1787 # type is a string that's identical to the name of the IV, but with the 'Hash' portion
1788 # removed (so ->declinedAdjHash becomes 'declinedAdj')
1789 #
1790 # When a noun appears in multiple hashes, we use the one in the highest-priority hash. The
1791 # priority order is
1792 # declinedAdj > adjective > pseudoAdjective
1793 @typeList = ('declinedAdj', 'adj', 'pseudoAdj');
1794  
1795 foreach my $type (@typeList) {
1796  
1797 my $hashName = $type . 'Hash';
1798 my %thisHash = $self->$hashName;
1799  
1800 foreach my $key (keys %thisHash) {
1801  
1802 my $value = $thisHash{$key};
1803  
1804 if (! exists $combHash{$key}) {
1805  
1806 # Add to the combined hash
1807 $combHash{$key} = $value;
1808 }
1809 }
1810 }
1811  
1812 # Combined adjective hash complete. Update IVs
1813 $self->{'combAdjHash'} = \%combHash;
1814  
1815 return 1;
1816 }
1817  
1818 sub createCombDirHash {
1819  
1820 # Called by $self->createCombHashes and ->updateOppDirHash
1821 # Creates (or updates) the three combined direction hashes
1822 #
1823 # Expected arguments
1824 # (none besides $self)
1825 #
1826 # Return values
1827 # 'undef' on improper arguments
1828 # 1 otherwise
1829  
1830 my ($self, $check) = @_;
1831  
1832 # Local variables
1833 my (
1834 @typeList, @ivList,
1835 %combHash, %combOppHash, %combRevHash,
1836 );
1837  
1838 # Check for improper arguments
1839 if (defined $check) {
1840  
1841 return $axmud::CLIENT->writeImproper($self->_objClass . '->createCombDirHash', @_);
1842 }
1843  
1844 # The values stored in key-value pairs in six hashes are combined, creating three combined
1845 # hashes
1846  
1847 # A hash of customised directions, in the form
1848 # ->combDirHash{custom_direction} = direction_type
1849 # ...where 'direction_type' is one of these values:
1850 @typeList = (
1851 'primaryDir', 'primaryAbbrev', 'secondaryDir', 'secondaryAbbrev', 'relativeDir',
1852 'relativeAbbrev',
1853 );
1854  
1855 foreach my $type (@typeList) {
1856  
1857 my $hashName = $type . 'Hash';
1858 my %thisHash = $self->$hashName;
1859  
1860 foreach my $value (values %thisHash) {
1861  
1862 # ->secondaryAbbrevHash can have 'undef' values in its key-value pairs, so don't add
1863 # those to the combined hash
1864 # If the customised direction has already been added, don't replace it
1865 if (defined $value && ! exists $combHash{$value}) {
1866  
1867 $combHash{$value} = $type;
1868 }
1869 }
1870 }
1871  
1872 # A hash of opposite directions, in the form
1873 # ->combOppDirHash{custom_direction} = custom_opposite_direction
1874 @ivList = (
1875 'primaryDirHash', 'primaryOppHash',
1876 'primaryAbbrevHash', 'primaryOppAbbrevHash',
1877 'secondaryDirHash', 'secondaryOppHash',
1878 'secondaryAbbrevHash', 'secondaryOppAbbrevHash',
1879 );
1880  
1881 do {
1882  
1883 my (
1884 $thisHashName, $oppHashName,
1885 %thisHash, %oppHash,
1886 );
1887  
1888 $thisHashName = shift @ivList;
1889 %thisHash = $self->$thisHashName;
1890 $oppHashName = shift @ivList;
1891 %oppHash = $self->$oppHashName;
1892  
1893 foreach my $key (keys %thisHash) {
1894  
1895 my ($value, $oppValue);
1896  
1897 $value = $thisHash{$key};
1898 $oppValue = $oppHash{$key};
1899  
1900 # ->secondaryAbbrevHash can have 'undef' values in its key-value pairs, so don't add
1901 # those to the combined hash
1902 # ->secondaryOppAbbrevHash can have empty string values in its key-value pairs, so
1903 # don't add those either
1904 # If the customised direction has already been added, don't replace it
1905 if (defined $value && $value ne '' && ! exists $combOppHash{$value}) {
1906  
1907 $combOppHash{$value} = $oppValue;
1908 }
1909 }
1910  
1911 } until (! @ivList);
1912  
1913 # Need some special code to add relative directions to %combOppHash. The comments in ->new
1914 # recommend that if a relative direction is added to $self->relativeDirHash or
1915 # ->relativeAbbrevHash, the opposite relative direction is added too, but there's no way
1916 # to guarantee the user won't miss one out
1917 for (my $key = 0; $key < 8; $key++) {
1918  
1919 my ($oppKey, $dir, $oppDir);
1920  
1921 # (Keys in the hash are in the range 0-7, so the opposite of 0 is 4, the opposite of 7
1922 # is 3, etc)
1923 $oppKey = $key + 4;
1924 if ($oppKey > 7) {
1925  
1926 $oppKey -= 8;
1927 }
1928  
1929 foreach my $iv ('relativeDirHash', 'relativeAbbrevHash') {
1930  
1931 my ($value, $oppValue);
1932  
1933 $value = $self->ivShow($iv, $key);
1934 $oppValue = $self->ivShow($iv, $oppKey);
1935  
1936 if (defined $value && $value ne '' && defined $oppValue && $oppValue ne '') {
1937  
1938 $combOppHash{$value} = $oppValue;
1939 }
1940 }
1941 }
1942  
1943 # A hash of customised directions, in the form
1944 # ->combRevDirHash{custom_direction} = standard_direction (for primary directions)
1945 # ->combRevDirHash{recognised_direction} = recognised_direction (for secondary directions)
1946 @typeList = ('primaryDir', 'primaryAbbrev', 'secondaryDir', 'secondaryAbbrev');
1947 foreach my $type (@typeList) {
1948  
1949 my $hashName = $type . 'Hash';
1950 my %thisHash = $self->$hashName;
1951  
1952 foreach my $key (keys %thisHash) {
1953  
1954 my $value = $thisHash{$key};
1955  
1956 # ->secondaryAbbrevHash can have 'undef' values in its key-value pairs, so don't add
1957 # those to the combined hash
1958 # If the customised direction has already been added, don't replace it
1959 if ($value && (! exists $combRevHash{$value})) {
1960  
1961 $combRevHash{$value} = $key;
1962 }
1963 }
1964 }
1965  
1966 # Combined hashes complete. Update IVs
1967 $self->{'combDirHash'} = \%combHash;
1968 $self->{'combOppDirHash'} = \%combOppHash;
1969 $self->{'combRevDirHash'} = \%combRevHash;
1970  
1971 return 1;
1972 }
1973  
1974 sub updateCombNounHash {
1975  
1976 # Called by GA::Cmd::AddWord->do or DeleteWord->do
1977 # Updates the hash $self->combNounHash after one of the main noun hashes is modified
1978 # (this method is hopefully quicker than calling $self->createCombHashes every time a
1979 # single key-value pair is changed)
1980 #
1981 # Expected arguments
1982 # $nounType - Which type of noun has been changed ('pluralNoun', 'sentient', 'creature',
1983 # 'portable', 'decoration', 'race', 'guild', 'weapon', 'armour',
1984 # 'garment', 'pseudoNoun')
1985 # $addFlag - TRUE if the key-value pair is to be added to the combined hash; FALSE if
1986 # it is to be removed
1987 # $key - ($addFlag = TRUE) The new key; ($addFlag = FALSE) the key to be removed
1988 #
1989 # Optional arguments
1990 # $value - ($addFlag = TRUE) The new value ($addFlag = FALSE) 'undef'
1991 #
1992 # Return values
1993 # 'undef' on improper arguments or if the combined hash isn't modified
1994 # 1 otherwise
1995  
1996 my ($self, $nounType, $addFlag, $key, $value, $check) = @_;
1997  
1998 # Local variables
1999 my (
2000 $newPriority, $oldPriority,
2001 %priorityHash,
2002 );
2003  
2004 # Check for improper arguments
2005 if (! defined $nounType || ! defined $addFlag || ! defined $key || defined $check) {
2006  
2007 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateCombNounHash', @_);
2008 }
2009  
2010 # Create a hash of priorities, so we can quickly work out what to do with the new key-value
2011 # pair
2012 %priorityHash = (
2013 'pluralNoun' => 0,
2014 'sentient' => 1,
2015 'creature' => 2,
2016 'portable' => 3,
2017 'decoration' => 4,
2018 'race' => 5,
2019 'guild' => 6,
2020 'weapon' => 7,
2021 'armour' => 8,
2022 'garment' => 9,
2023 'pseudoNoun' => 10,
2024 );
2025  
2026 # Check that $nounType is valid
2027 if (! exists $priorityHash{$nounType} ) {
2028  
2029 # Treat this as an improper argument
2030 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateCombNounHash', @_);
2031 }
2032  
2033 # If the key-value pair is to be added to the combined hash...
2034 if ($addFlag) {
2035  
2036 # If it doesn't already exist in the hash, simply add it
2037 if (! $self->ivExists('combNounHash', $key)) {
2038  
2039 $self->ivAdd('combNounHash', $key, $value);
2040 return 1;
2041  
2042 # Otherwise work out which key-value pair has priority
2043 } else {
2044  
2045 $newPriority = $priorityHash{$value};
2046 $oldPriority = $priorityHash{$self->ivShow('combNounHash', $key)};
2047 if ($oldPriority < $newPriority) {
2048  
2049 # New key-value pair takes precedence
2050 $self->ivAdd('combNounHash', $key, $value);
2051 return 1;
2052  
2053 } else {
2054  
2055 # Old key-value pair takes precedence; don't change the combined hash
2056 return undef;
2057 }
2058 }
2059  
2060 # If the key-value pair is to be removed from the combined hash, need to check whether a
2061 # noun from a higher-priority hash should replace it
2062 #
2063 # If the key-value pair isn't in the combined hash, no changes to make
2064 } elsif (! $self->ivExists('combNounHash', $key)) {
2065  
2066 return undef;
2067  
2068 } else {
2069  
2070 # Remember the priority of the dictionary hash which contains the key-value pair to be
2071 # deleted
2072 $value = $self->ivShow('combNounHash', $key);
2073 $newPriority = $priorityHash{$value};
2074  
2075 # Delete the key
2076 $self->ivDelete('combNounHash', $key);
2077  
2078 # Check the lower-priority dictionary hashes to see if any of them use the same key
2079 # Reinstate the first key-value pair found
2080 if ($newPriority == 10) { # Axmud dictionaries use 11 noun hashes
2081  
2082 # No dictionary hashes with lower priority to check
2083 return 1;
2084  
2085 } else {
2086  
2087 for (my $count = 1; $count <= 10; $count++) {
2088  
2089 my $hashName = $nounType . 'Hash';
2090 if ($newPriority <= $count && $self->ivExists($hashName, $key)) {
2091  
2092 # The same key was found in this dictionary hash. Reinstate it into the
2093 # combined hash
2094 $value = $self->ivShow($hashName, $key);
2095 $self->ivAdd('combNounHash', $key, $value);
2096  
2097 return 1;
2098 }
2099 }
2100  
2101 # None of the lower-priority dictionary hashes use the same key
2102 return undef;
2103 }
2104 }
2105 }
2106  
2107 sub updateCombAdjHash {
2108  
2109 # Called by GA::Cmd::AddWord->do or DeleteWord->do
2110 # Updates the hash $self->combinedAdjHash after one of the main adjective hashes is modified
2111 # (this method is hopefully quicker than calling $self->createCombHashes every time a
2112 # single key-value pair is changed)
2113 #
2114 # Expected arguments
2115 # $adjType - Which type of adjective has been changed ('declinedAdj',
2116 # 'adj', 'pseudoAdj')
2117 # $addFlag - TRUE if the key-value pair is to be added to the combined hash; FALSE if
2118 # it is to be removed
2119 # $key - ($addFlag = TRUE) The new key; ($addFlag = FALSE) the key to be removed
2120 #
2121 # Optional arguments
2122 # $value - ($addFlag = TRUE) The new value ($addFlag = FALSE) 'undef'
2123 #
2124 # Return values
2125 # 'undef' on improper arguments or if the combined hash isn't modified
2126 # 1 otherwise
2127  
2128 my ($self, $adjType, $addFlag, $key, $value, $check) = @_;
2129  
2130 # Local variables
2131 my (
2132 $newPriority, $oldPriority,
2133 %priorityHash,
2134 );
2135  
2136 # Check for improper arguments
2137 if (! defined $adjType || ! defined $addFlag || ! defined $key || defined $check) {
2138  
2139 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateCombAdjHash', @_);
2140 }
2141  
2142 # Create a hash of priorities, so we can quickly work out what to do with the new key-value
2143 # pair
2144 %priorityHash = (
2145 'declinedAdj' => 0,
2146 'adj' => 1,
2147 'pseudoAdj' => 2,
2148 );
2149  
2150 # Check that $$adjType is valid
2151 if (! exists $priorityHash{$adjType} ) {
2152  
2153 # Treat this as an improper argument
2154 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateCombAdjHash', @_);
2155 }
2156  
2157 # If the key-value pair is to be added to the combined hash...
2158 if ($addFlag) {
2159  
2160 # If it doesn't already exist in the hash, simply add it
2161 if (! $self->ivExists('combAdjHash', $key)) {
2162  
2163 $self->ivAdd('combAdjHash', $key, $value);
2164 return 1;
2165  
2166 # Otherwise work out which key-value pair has priority
2167 } else {
2168  
2169 $newPriority = $priorityHash{$value};
2170 $oldPriority = $priorityHash{$self->ivShow('combAdjHash', $key)};
2171 if ($oldPriority < $newPriority) {
2172  
2173 # New key-value pair takes precedence
2174 $self->ivAdd('combAdjHash', $key, $value);
2175 return 1;
2176  
2177 } else {
2178  
2179 # Old key-value pair takes precedence; don't change the combined hash
2180 return undef;
2181 }
2182 }
2183  
2184 # If the key-value pair is to be removed from the combined hash, need to check whether an
2185 # adjective from a higher-priority hash should replace it
2186 #
2187 # If the key-value pair isn't in the combined hash, no changes to make
2188 } elsif (! $self->ivExists('combAdjHash', $key)) {
2189  
2190 return undef;
2191  
2192 } else {
2193  
2194 # Remember the priority of the dictionary hash which contains the key-value pair to be
2195 # deleted
2196 $value = $self->ivShow('combAdjHash', $key);
2197 $newPriority = $priorityHash{$value};
2198  
2199 # Delete the key
2200 $self->ivDelete('combAdjHash', $key);
2201  
2202 # Check the lower-priority dictionary hashes to see if any of them use the same key
2203 # Reinstate the first key-value pair found
2204 if ($newPriority == 2) { # Axmud dictionaries use 3 adjective hashes
2205  
2206 # No dictionary hashes with lower priority to check
2207 return 1;
2208  
2209 } else {
2210  
2211 for (my $count = 1; $count <= 2; $count++) {
2212  
2213 my $hashName = $adjType . 'Hash';
2214 if ($newPriority <= $count && $self->ivExists($hashName, $key)) {
2215  
2216 # The same key was found in this dictionary hash. Reinstate it into the
2217 # combined hash
2218 $value = $self->ivShow($hashName, $key);
2219 $self->ivAdd('combAdjHash', $key, $value);
2220  
2221 return 1;
2222 }
2223 }
2224  
2225 # None of the lower-priority dictionary hashes use the same key
2226 return undef;
2227 }
2228 }
2229 }
2230  
2231 sub updateOppDirHash {
2232  
2233 # Can be called by anything (for example, called by GA::WizWin::Locator->saveChanges)
2234 # When $self->primaryDirHash and/or $self->primaryAbbrevHash are modified, this function can
2235 # be called to update the contents of $self->primaryOppHash and ->primaryOppAbbrevHash
2236 #
2237 # Expected arguments
2238 # (none besides $self)
2239 #
2240 # Return values
2241 # 'undef' on improper arguments
2242 # 1 otherwise
2243  
2244 my ($self, $check) = @_;
2245  
2246 # Local variables
2247 my (%dirHash, %abbrevHash, %oppHash, %oppAbbrevHash);
2248  
2249 # Check for improper arguments
2250 if (defined $check) {
2251  
2252 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateOppDirHash', @_);
2253 }
2254  
2255 # Import IVs that we won't change (for simplicity)
2256 %dirHash = $self->primaryDirHash;
2257 %abbrevHash = $self->primaryAbbrevHash;
2258  
2259 # Use them to update these IVs
2260 foreach my $key ($axmud::CLIENT->constPrimaryDirList) {
2261  
2262 $oppHash{$key} = $dirHash{$axmud::CLIENT->ivShow('constOppDirHash', $key)};
2263 $oppAbbrevHash{$key} = $abbrevHash{$axmud::CLIENT->ivShow('constOppDirHash', $key)};
2264 }
2265  
2266 $self->ivPoke('primaryOppHash', %oppHash);
2267 $self->ivPoke('primaryOppAbbrevHash', %oppAbbrevHash);
2268  
2269 $self->createCombDirHash();
2270  
2271 return 1;
2272 }
2273  
2274 sub convertToPlural {
2275  
2276 # Called by anything
2277 # Converts any singular noun to its plural form, as best as it can
2278 #
2279 # Expected arguments
2280 # $word - The word to convert
2281 #
2282 # Return values
2283 # The plural form, if a plural form can be found
2284 # Otherwise returns $word unaltered (even on improper arguments)
2285  
2286 my ($self, $word, $check) = @_;
2287  
2288 # Local variables
2289 my @endingList;
2290  
2291 # Check for improper arguments
2292 if (! defined $word || defined $check) {
2293  
2294 $axmud::CLIENT->writeImproper($self->_objClass . '->convertToPlural', @_);
2295 return $word;
2296 }
2297  
2298 # If it's a word with a known plural form, use the plural form
2299 if ($self->ivExists('pluralNounHash', $word)) {
2300  
2301 return $self->ivShow('pluralNounHash', $word);
2302 }
2303  
2304 # Import the singular ending list, and sort them in descending order of size, so that (for
2305 # example) 'benches' is tested for the plural ending -es before it is tested for the
2306 # plural ending -s
2307 @endingList = sort {length $b <=> length $a} ($self->ivKeys('reversePluralEndingHash'));
2308  
2309 OUTER: foreach my $singularEnding (@endingList) {
2310  
2311 my $pluralEnding;
2312  
2313 # An empty string is the default ending. Instead of doing a substitution, we simply add
2314 # the plural ending
2315 if (! $singularEnding) {
2316  
2317 return $word . $self->ivShow('reversePluralEndingHash', $singularEnding);
2318 }
2319  
2320 # If the ending exists in this word...
2321 if ($word =~ m/$singularEnding/) {
2322  
2323 # ...convert the word to its plural form
2324 $pluralEnding = $self->ivShow('reversePluralEndingHash', $singularEnding);
2325 $word =~ s/$singularEnding/$pluralEnding/;
2326  
2327 return $word;
2328 }
2329 }
2330  
2331 # Failsafe - return the word unaltered
2332 return $word;
2333 }
2334  
2335 sub convertToSingular {
2336  
2337 # Called by anything
2338 # Converts any plural noun to its singular form, as best as it can
2339 #
2340 # Expected arguments
2341 # $word - The word to convert
2342 #
2343 # Return values
2344 # The singular form, if a singular form can be found
2345 # Otherwise returns $word unaltered (even on improper arguments)
2346  
2347 my ($self, $word, $check) = @_;
2348  
2349 # Local variables
2350 my @endingList;
2351  
2352 # Check for improper arguments
2353 if (! defined $word || defined $check) {
2354  
2355 $axmud::CLIENT->writeImproper($self->_objClass . '->convertToSingular', @_);
2356 return $word;
2357 }
2358  
2359 # If it's a known plural noun, convert to the corresponding singular form
2360 if ($self->ivExists('reversePluralNounHash', $word)) {
2361  
2362 return $self->ivShow('reversePluralNounHash', $word);
2363 }
2364  
2365 # Import the singular ending list, and sort them in descending order of size, so that (for
2366 # example) 'benches' is tested for the plural ending -es before it is tested for the
2367 # plural ending -s
2368 @endingList = sort {length $b <=> length $a} ($self->ivKeys('pluralEndingHash'));
2369  
2370 OUTER: foreach my $pluralEnding (@endingList) {
2371  
2372 my $singularEnding;
2373  
2374 # Ignore any empty strings
2375 if (! $pluralEnding) {
2376  
2377 next OUTER;
2378 }
2379  
2380 # If the ending exists in this word...
2381 if ($word =~ m/$pluralEnding/) {
2382  
2383 # ...convert the word to its singular form
2384 $singularEnding = $self->ivShow('pluralEndingHash', $pluralEnding);
2385 $word =~ s/$pluralEnding/$singularEnding/;
2386  
2387 return $word;
2388 }
2389 }
2390  
2391 # Otherwise, assume the specified $word wasn't a plural form, and simply
2392 # return it
2393 return $word;
2394 }
2395  
2396 sub convertToDeclined {
2397  
2398 # Called by anything
2399 # Converts any undeclined adjective to its declined form, as best as it can
2400 #
2401 # Expected arguments
2402 # $adj - The adjective to convert
2403 #
2404 # Return values
2405 # The declined form, if a declined form can be found
2406 # Otherwise returns $adj unaltered (even on improper arguments)
2407  
2408 my ($self, $adj, $check) = @_;
2409  
2410 # Local variables
2411 my @endingList;
2412  
2413 # Check for improper arguments
2414 if (! defined $adj || defined $check) {
2415  
2416 $axmud::CLIENT->writeImproper($self->_objClass . '->convertToDeclined', @_);
2417 return $adj;
2418 }
2419  
2420 # If it's a word with a known declined form, use the declined form
2421 if ($self->ivExists('declinedAdjHash', $adj)) {
2422  
2423 return $self->ivShow('declinedAdjHash', $adj);
2424 }
2425  
2426 # Import the adjective ending list, and sort them in descending order of size, so that (for
2427 # example) 'grandes' is tested for the declined ending -es before it is tested for the
2428 # undeclined ending -s
2429 @endingList = sort {length $b <=> length $a} ($self->ivKeys('reverseAdjEndingHash'));
2430  
2431 OUTER: foreach my $undeclinedEnding (@endingList) {
2432  
2433 my $declinedEnding;
2434  
2435 # An empty string is the default ending. Instead of doing a substitution, we simply add
2436 # the declined ending
2437 if (! $undeclinedEnding) {
2438  
2439 return $adj . $self->ivShow('reverseAdjEndingHash', $undeclinedEnding);
2440 }
2441  
2442 # If the ending exists in this word...
2443 if ($adj =~ m/$undeclinedEnding/) {
2444  
2445 # ...convert the word to its declined form
2446 $declinedEnding = $self->ivShow('reverseAdjEndingHash', $undeclinedEnding);
2447 $adj =~ s/$undeclinedEnding/$declinedEnding/;
2448  
2449 return $adj;
2450 }
2451 }
2452  
2453 # Failsafe - return the word unaltered
2454 return $adj;
2455 }
2456  
2457 sub convertToUndeclined {
2458  
2459 # Called by anything
2460 # Converts any declined adjective to its undeclined form, as best as it can
2461 #
2462 # Expected arguments
2463 # $adj - The adjective to convert
2464 #
2465 # Return values
2466 # The undeclined form, if an undeclined form can be found
2467 # Otherwise returns $adj unaltered (even on improper arguments)
2468  
2469 my ($self, $adj, $check) = @_;
2470  
2471 # Local variables
2472 my @endingList;
2473  
2474 # Check for improper arguments
2475 if (! defined $adj || defined $check) {
2476  
2477 $axmud::CLIENT->writeImproper($self->_objClass . '->convertToUndeclined', @_);
2478 return $adj;
2479 }
2480  
2481 # If it's a word with a known undeclined form, use the undeclined form
2482 if ($self->ivExists('reverseDeclinedAdjHash', $adj)) {
2483  
2484 return $self->ivShow('reverseDeclinedAdjHash', $adj);
2485 }
2486  
2487 # Import the adjective ending list, and sort them in descending order of size, so that (for
2488 # example) 'grandes' is tested for the declined ending -es before it is tested for the
2489 # undeclined ending -s
2490 @endingList = sort {length $b <=> length $a} ($self->ivKeys('adjEndingHash'));
2491  
2492 OUTER: foreach my $declinedEnding (@endingList) {
2493  
2494 my $undeclinedEnding;
2495  
2496 # Ignore any empty strings
2497 if (! $declinedEnding) {
2498  
2499 next OUTER;
2500 }
2501  
2502 # If the ending exists in this word...
2503 if ($adj =~ m/$declinedEnding/) {
2504  
2505 # ...reduce the word to its undeclined form
2506 $undeclinedEnding = $self->ivShow('adjEndingHash', $declinedEnding);
2507 $adj =~ s/$declinedEnding/$undeclinedEnding/;
2508  
2509 return $adj;
2510 }
2511 }
2512  
2513 # Otherwise, assume the specified $adj wasn't a declined form, and simply return it
2514 return $adj;
2515 }
2516  
2517 # Modify directions
2518  
2519 sub modifyPrimaryDir {
2520  
2521 # Called by GA::Cmd::ModifyPrimary->do or any other code
2522 # Modifies a primary direction and its abbreviation, updating others hashes as required
2523 #
2524 # NB So that a calling function can replace all directions in one go, it's the calling
2525 # function's responsibility to check that a custom direction doesn't already exist as a
2526 # custom primary, secondary or relative direction, before calling this function
2527 #
2528 # Expected arguments
2529 # $standardDir - The standard primary direction, a key in $self->primaryDirHash
2530 # $customDir - A custom primary direction, the corresponding value in
2531 # $self->primaryDirHash
2532 #
2533 # Optional arguments
2534 # $customAbbrev - The abbreviated custom primary direction, the corresponding value in
2535 # $self->primaryAbbrevHash. If 'undef' or an empty string, the custom
2536 # direction and its abbreviation are the same
2537 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2538 # times, in which case $self->updateOppDirHash is not called (it's up
2539 # to the calling function to do it, when ready). If FALSE (or
2540 # 'undef'), other hashes are updated as required
2541 #
2542 # Return values
2543 # 'undef' on improper arguments
2544 # 1 otherwise
2545  
2546 my ($self, $standardDir, $customDir, $customAbbrev, $noUpdateFlag, $check) = @_;
2547  
2548 # Check for improper arguments
2549 if (! defined $standardDir || ! defined $customDir || defined $check) {
2550  
2551 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifyPrimaryDir', @_);
2552 }
2553  
2554 if (! defined $customAbbrev || $customAbbrev eq '') {
2555  
2556 $customAbbrev = $customDir;
2557 }
2558  
2559 $self->ivAdd('primaryDirHash', $standardDir, $customDir);
2560 $self->ivAdd('primaryAbbrevHash', $standardDir, $customAbbrev);
2561  
2562 if (! $noUpdateFlag) {
2563  
2564 $self->updateOppDirHash();
2565 }
2566  
2567 # Operation complete
2568 return 1;
2569 }
2570  
2571 sub addSecondaryDir {
2572  
2573 # Called by GA::Cmd::AddSecondary->do or any other code
2574 # Adds a secondary direction and its abbreviation (if any), updating others hashes as
2575 # required
2576 #
2577 # NB So that a calling function can replace all directions in one go, it's the calling
2578 # function's responsibility to check that a custom direction doesn't already exist as a
2579 # custom primary, secondary or relative direction direction, before calling this function
2580 # NB Note that $self->secondaryDirList exists, but no $self->primaryDirList exists; also
2581 # abbreviated secondary directions are set to 'undef' by default; so this function behaves
2582 # slightly differently to $self->modifyPrimaryDir
2583 #
2584 # Expected arguments
2585 # $customDir - A custom secondary direction, stored as both a key and a value in
2586 # $self->secondaryDirHash
2587 #
2588 # Optional arguments
2589 # $customAbbrev - The abbreviated custom secondary direction. If 'undef' or an empty
2590 # string, the abbreviation is stored as 'undef'
2591 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2592 # times, in which case $self->updateOppDirHash is not called (it's up
2593 # to the calling function to do it, when ready). If FALSE (or
2594 # 'undef'), other hashes are updated as required
2595 #
2596 # Return values
2597 # 'undef' on improper arguments
2598 # 1 otherwise
2599  
2600 my ($self, $customDir, $customAbbrev, $noUpdateFlag, $check) = @_;
2601  
2602 # Check for improper arguments
2603 if (! defined $customDir || defined $check) {
2604  
2605 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSecondaryDir', @_);
2606 }
2607  
2608 if (defined $customAbbrev && $customAbbrev eq '') {
2609  
2610 $customAbbrev = undef;
2611 }
2612  
2613 $self->ivPush('secondaryDirList', $customDir);
2614 $self->ivAdd('secondaryDirHash', $customDir, $customDir);
2615 $self->ivAdd('secondaryAbbrevHash', $customDir, $customAbbrev);
2616 $self->ivAdd('secondaryOppHash', $customDir, '');
2617 $self->ivAdd('secondaryOppAbbrevHash', $customDir, '');
2618 $self->ivAdd('secondaryAutoHash', $customDir, undef);
2619  
2620 if (! $noUpdateFlag) {
2621  
2622 $self->updateOppDirHash();
2623 }
2624  
2625 # Operation complete
2626 return 1;
2627 }
2628  
2629 sub modifySecondaryDir {
2630  
2631 # Called by GA::Cmd::ModifySecondary->do or any other code
2632 # Sets the opposite direction of an existing custom secondary direction, updating others
2633 # hashes as required
2634 #
2635 # NB So that a calling function can replace all directions in one go, it's the calling
2636 # function's responsibility to check that a custom direction doesn't already exist as a
2637 # custom primary, secondary or relative direction, before calling this function
2638 #
2639 # Expected arguments
2640 # $customDir - A custom secondary direction, stored as both a key and a value in
2641 # $self->secondaryDirList
2642 #
2643 # Optional arguments
2644 # $oppDir - The opposite custom secondary direction. If 'undef' or an empty
2645 # string, $customDir has no opposite direction
2646 #
2647 # Optional arguments
2648 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2649 # times, in which case $self->updateOppDirHash is not called (it's up
2650 # to the calling function to do it, when ready). If FALSE (or
2651 # 'undef'), other hashes are updated as required
2652 #
2653 # Return values
2654 # 'undef' on improper arguments, if $customDir isn't a custom secondary direction, of if
2655 # $customAbbrev is specified and it, too, is not a custom secondary direction
2656 # 1 otherwise
2657  
2658 my ($self, $customDir, $oppDir, $noUpdateFlag, $check) = @_;
2659  
2660 # Check for improper arguments
2661 if (! defined $customDir || ! defined $oppDir || defined $check) {
2662  
2663 return $axmud::CLIENT->writeImproper($self->_objClass . '->modifySecondaryDir', @_);
2664 }
2665  
2666 if (! defined $oppDir) {
2667  
2668 $oppDir = '';
2669 }
2670  
2671 if (
2672 ! $self->ivExists('secondaryDirHash', $customDir)
2673 || ($oppDir ne '' && ! $self->ivExists('secondaryDirHash', $oppDir))
2674 ) {
2675 return undef;
2676 }
2677  
2678 $self->ivAdd('secondaryOppHash', $customDir, $oppDir);
2679 $self->ivAdd(
2680 'secondaryOppAbbrevHash',
2681 $customDir,
2682 $self->ivShow('secondaryAbbrevHash', $oppDir),
2683 );
2684  
2685 if (! $noUpdateFlag) {
2686  
2687 $self->updateOppDirHash();
2688 }
2689  
2690 # Operation complete
2691 return 1;
2692 }
2693  
2694 sub deleteSecondaryDir {
2695  
2696 # Called by GA::Cmd::DeleteSecondary->do or any other code
2697 # Deletes a secondary direction and its abbreviation (if any), updating others hashes as
2698 # required
2699 #
2700 # Expected arguments
2701 # $customDir - A custom secondary direction, stored as both a key and a value in
2702 # $self->secondaryDirHash
2703 #
2704 # Optional arguments
2705 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2706 # times, in which case $self->updateOppDirHash is not called (it's up
2707 # to the calling function to do it, when ready). If FALSE (or
2708 # 'undef'), other hashes are updated as required
2709 #
2710 # Return values
2711 # 'undef' on improper arguments or if the specified custom secondary direction doesn't
2712 # exist
2713 # 1 otherwise
2714  
2715 my ($self, $customDir, $noUpdateFlag, $check) = @_;
2716  
2717 # Check for improper arguments
2718 if (! defined $customDir || defined $check) {
2719  
2720 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteSecondaryDir', @_);
2721 }
2722  
2723 if (! $self->ivExists('secondaryDirHash', $customDir)) {
2724  
2725 return undef;
2726 }
2727  
2728 $self->ivSplice('secondaryDirList', $self->ivMatch('secondaryDirList', $customDir), 1);
2729 $self->ivDelete('secondaryDirHash', $customDir);
2730 $self->ivDelete('secondaryAbbrevHash', $customDir);
2731 $self->ivDelete('secondaryAutoHash', $customDir);
2732  
2733 if (! $noUpdateFlag) {
2734  
2735 $self->updateOppDirHash();
2736 }
2737  
2738 # Operation complete
2739 return 1;
2740 }
2741  
2742 sub addRelativeDir {
2743  
2744 # Called by GA::Cmd::AddRelative->do or any other code
2745 # Adds a relative direction and its abbreviation (if any), updating others hashes as
2746 # required
2747 #
2748 # NB So that a calling function can replace all directions in one go, it's the calling
2749 # function's responsibility to check that a relative direction doesn't already exist as a
2750 # custom primary, secondary or relative direction, before calling this function
2751 #
2752 # Expected arguments
2753 # $index - An integer in the range 0-7, matching the keys in
2754 # $self->relativeDirHash. 0 represents 'forward', 2 represents 'right'
2755 # and so on
2756 # $relativeDir - A relative direction, stored as both a key and a value in
2757 # $self->relativeDirHash
2758 #
2759 # Optional arguments
2760 # $relativeAbbrev - The abbreviated relative direction. If 'undef' or an empty
2761 # string, no key-value pair is added to $self->relativeAbbrevHash
2762 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2763 # times, in which case $self->updateOppDirHash is not called (it's up
2764 # to the calling function to do it, when ready). If FALSE (or
2765 # 'undef'), other hashes are updated as required
2766 #
2767 # Return values
2768 # 'undef' on improper arguments
2769 # 1 otherwise
2770  
2771 my ($self, $index, $relativeDir, $relativeAbbrev, $noUpdateFlag, $check) = @_;
2772  
2773 # Check for improper arguments
2774 if (
2775 ! defined $index
2776 || ! $axmud::CLIENT->intCheck($index, 0, 7)
2777 || ! defined $relativeDir || defined $check
2778 ) {
2779 return $axmud::CLIENT->writeImproper($self->_objClass . '->addRelativeDir', @_);
2780 }
2781  
2782 $self->ivAdd('relativeDirHash', $index, $relativeDir);
2783 if (defined $relativeAbbrev && $relativeAbbrev ne '') {
2784  
2785 $self->ivAdd('relativeAbbrevHash', $index, $relativeAbbrev);
2786 }
2787  
2788 if (! $noUpdateFlag) {
2789  
2790 $self->updateOppDirHash();
2791 }
2792  
2793 # Operation complete
2794 return 1;
2795 }
2796  
2797 sub deleteRelativeDir {
2798  
2799 # Called by GA::Cmd::DeleteRelative->do or any other code
2800 # Deletes a relative direction and its abbreviation (if any), updating others hashes as
2801 # required
2802 #
2803 # Expected arguments
2804 # (none besides $self)
2805 #
2806 # Optional arguments (one or both can be specified)
2807 # $index - An integer in the range 0-7, matching a key in $self->relativeDirHash
2808 # $relativeDir - A relative direction, matching a value in $self->relativeDirHash
2809 # $noUpdateFlag - If TRUE, the calling function expects to call this function several
2810 # times, in which case $self->updateOppDirHash is not called (it's up
2811 # to the calling function to do it, when ready). If FALSE (or
2812 # 'undef'), other hashes are updated as required
2813 #
2814 # Return values
2815 # 'undef' on improper arguments, if both $index and $relativeDir are undefined, or if the
2816 # specified index or relative direction doesn't exist
2817 # 1 otherwise
2818  
2819 my ($self, $index, $relativeDir, $noUpdateFlag, $check) = @_;
2820  
2821 # Local variables
2822 my %revHash;
2823  
2824 # Check for improper arguments
2825 if (defined $check) {
2826  
2827 return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteRelativeDir', @_);
2828 }
2829  
2830 # If neither $index nor $relativeDir are specified, then there's nothing to delete
2831 if (
2832 ! $axmud::CLIENT->intCheck($index, 0, 7)
2833 && (! defined $relativeDir || $relativeDir eq '')
2834 ) {
2835 return undef;
2836 }
2837  
2838 if (! defined $index) {
2839  
2840 %revHash = reverse $self->relativeDirHash;
2841 if (! exists $revHash{$relativeDir}) {
2842  
2843 return undef;
2844  
2845 } else {
2846  
2847 $index = $revHash{$relativeDir};
2848 }
2849 }
2850  
2851 $self->ivDelete('relativeDirHash', $index);
2852 $self->ivDelete('relativeAbbrevHash', $index);
2853  
2854 if (! $noUpdateFlag) {
2855  
2856 $self->updateOppDirHash();
2857 }
2858  
2859 # Operation complete
2860 return 1;
2861 }
2862  
2863 # Phrasebooks
2864  
2865 sub uploadPhrasebook {
2866  
2867 # A phrasebook object (GA::Obj::Phrasebook) stores basic vocabulary for a language -
2868 # primary directions (and their abbreviations), articles, conjunctions and number words.
2869 # The phrasebook object also stores equivalents to this object's ->language and ->nounPosn
2870 # IVs
2871 # Phrasebooks are loaded from text files in /items/phrasebooks, and can't be modified by the
2872 # user (although the text files could be edited, of course)
2873 # This function can be called by anything to upload the contents of the phrasebook to this
2874 # dictionary, replacing existing primary directions, articles, etc (but not modifying
2875 # secondary directions, nouns, time units, etc)
2876 #
2877 # Expected arguments
2878 # $pbObj - The Games::Axmud::Obj::Phrasebook object whose contents is to be uploaded
2879 #
2880 # Return values
2881 # 'undef' on improper arguments
2882 # 1 otherwise
2883  
2884 my ($self, $pbObj, $check) = @_;
2885  
2886 # Local variables
2887 my (
2888 @dirList, @abbrevList, @numberList,
2889 %dirHash, %abbrevHash,
2890 );
2891  
2892 # Check for improper arguments
2893 if (! defined $pbObj || defined $check) {
2894  
2895 return $axmud::CLIENT->writeImproper($self->_objClass . '->uploadPhrasebook', @_);
2896 }
2897  
2898 # (We'll assume the user hasn't been messing with the phrasebook text files, and that
2899 # thefore none of these values need to be checked)
2900 $self->ivPoke('language', $pbObj->targetName);
2901 $self->ivPoke('nounPosn', $pbObj->nounPosn);
2902  
2903 @dirList = $pbObj->primaryDirList;
2904 @abbrevList = $pbObj->primaryAbbrevDirList;
2905  
2906 foreach my $standard ($axmud::CLIENT->constPrimaryDirList) {
2907  
2908 $dirHash{$standard} = shift @dirList;
2909 $abbrevHash{$standard} = shift @abbrevList;
2910 }
2911  
2912 $self->ivPoke('primaryDirHash', %dirHash);
2913 $self->ivPoke('primaryAbbrevHash', %abbrevHash);
2914 $self->updateOppDirHash();
2915  
2916 $self->ivPoke('definiteList', $pbObj->definiteList);
2917 $self->ivPoke('indefiniteList', $pbObj->indefiniteList);
2918 $self->ivPoke('andList', $pbObj->andList);
2919 $self->ivPoke('orList', $pbObj->orList);
2920  
2921 @numberList = $pbObj->numberList;
2922 for (my $count = 1; $count <= 10; $count++) {
2923  
2924 $self->ivAdd('numberHash', shift @numberList, $count);
2925 }
2926  
2927 $self->createCombDirHash();
2928  
2929 # Operation complete
2930 return 1;
2931 }
2932  
2933 # Misc
2934  
2935 sub checkPrimaryDir {
2936  
2937 # Can be called by anything
2938 # Checks whether a specified direction is a primary direction. If so, returns the
2939 # unabbreviated form of the (custom) primary direction
2940 #
2941 # Expected arguments
2942 # $dir - The direction to check (full or abbreviated form)
2943 #
2944 # Return values
2945 # 'undef' on improper arguments or if $dir isn't a primary direction
2946 # Otherwise returns the unabbreviated primary direction
2947  
2948 my ($self, $dir, $check) = @_;
2949  
2950 # Local variables
2951 my ($type, $standard);
2952  
2953 # Check for improper arguments
2954 if (! defined $dir || defined $check) {
2955  
2956 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPrimaryDir', @_);
2957 }
2958  
2959 # Perform the check
2960 $type = $self->ivShow('combDirHash', $dir);
2961 if (defined $type) {
2962  
2963 if ($type eq 'primaryDir') {
2964  
2965 # $dir is already a primary direction
2966 return $dir;
2967  
2968 } elsif ($type eq 'primaryAbbrev') {
2969  
2970 # Get the standard direction
2971 $standard = $self->ivShow('combRevDirHash', $dir);
2972 return $self->ivShow('primaryDirHash', $standard);
2973 }
2974 }
2975  
2976 # Not a (custom) primary direction
2977 return undef;
2978 }
2979  
2980 sub checkSecondaryDir {
2981  
2982 # Can be called by anything
2983 # Checks whether a specified direction is a secondary direction. If so, returns the
2984 # unabbreviated form of the (recognised) secondary direction
2985 #
2986 # Expected arguments
2987 # $dir - The direction to check (full or abbreviated form)
2988 #
2989 # Return values
2990 # 'undef' on improper arguments or if $dir isn't a secondary direction
2991 # Otherwise returns the unabbreviated secondary direction
2992  
2993 my ($self, $dir, $check) = @_;
2994  
2995 # Local variables
2996 my ($type, $recognised);
2997  
2998 # Check for improper arguments
2999 if (! defined $dir || defined $check) {
3000  
3001 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkSecondaryDir', @_);
3002 }
3003  
3004 # Perform the check
3005 $type = $self->ivShow('combDirHash', $dir);
3006 if (defined $type) {
3007  
3008 if ($type eq 'secondaryDir') {
3009  
3010 # $dir is already a secondary direction
3011 return $dir;
3012  
3013 } elsif ($type eq 'secondaryAbbrev') {
3014  
3015 # Get the recognised direction
3016 $recognised = $self->ivShow('combRevDirHash', $dir);
3017 return $self->ivShow('secondaryDirHash', $recognised);
3018 }
3019 }
3020  
3021 # Not a (recognised) secondary direction
3022 return undef;
3023 }
3024  
3025 sub checkRelativeDir {
3026  
3027 # Can be called by anything
3028 # Checks whether a specified direction is a relative direction. If so, returns the
3029 # unabbreviated form of the (recognised) relative direction
3030 #
3031 # Expected arguments
3032 # $dir - The direction to check (full or abbreviated form)
3033 #
3034 # Return values
3035 # 'undef' on improper arguments or if $dir isn't a relative direction
3036 # Otherwise returns the unabbreviated relative direction
3037  
3038 my ($self, $dir, $check) = @_;
3039  
3040 # Local variables
3041 my (
3042 $type, $index,
3043 %revHash,
3044 );
3045  
3046 # Check for improper arguments
3047 if (! defined $dir || defined $check) {
3048  
3049 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkRelativeDir', @_);
3050 }
3051  
3052 # Perform the check
3053 $type = $self->ivShow('combDirHash', $dir);
3054 if (defined $type) {
3055  
3056 if ($type eq 'relativeDir') {
3057  
3058 # $dir is already a relative direction
3059 return $dir;
3060  
3061 } elsif ($type eq 'relativeAbbrev') {
3062  
3063 # $self->combRevDirHash doesn't contain relative directions
3064 %revHash = reverse $self->relativeAbbrevHash;
3065 if (! exists $revHash{$dir}) {
3066  
3067 return undef;
3068  
3069 } else {
3070  
3071 $index = $revHash{$dir};
3072 return $self->ivShow('relativeDirHash', $index);
3073 }
3074 }
3075 }
3076  
3077 # Not a (recognised) relative direction
3078 return undef;
3079 }
3080  
3081 sub checkOppDir {
3082  
3083 # Can be called by anything
3084 #
3085 # $self->combOppDirHash is in the form
3086 # ->combOppDirHash{custom_direction} = custom_opposite_direction
3087 # ...where 'custom_opposite_direction' is a string containing one or more directions, e.g.
3088 # 'out' or 'out door exit'
3089 #
3090 # This function takes two custom directions as arguments. If the first one is a key in
3091 # $self->combOppDirHash, and if the second one is one of the directions listed in the
3092 # key's corresponding value, this function returns TRUE; otherwise it returns 'undef'
3093 #
3094 # Expected arguments
3095 # $key - A custom direction
3096 # $dir - Another custom direction
3097 #
3098 # Return values
3099 # 'undef' on improper arguments
3100 # Otherwise returns TRUE or 'undef', as described above
3101  
3102 my ($self, $key, $dir, $check) = @_;
3103  
3104 # Local variables
3105 my (
3106 $string,
3107 @list,
3108 );
3109  
3110 # Check for improper arguments
3111 if (! defined $key || ! defined $dir || defined $check) {
3112  
3113 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkOppDir', @_);
3114 }
3115  
3116 # Perform the check
3117 $string = $self->ivShow('combOppDirHash', $key);
3118 if (! defined $string) {
3119  
3120 return undef;
3121 }
3122  
3123 # Split $string into a list of words (we presume that all secondary directions are single
3124 # words)
3125 @list = split(m/\s+/, $string);
3126 foreach my $item (@list) {
3127  
3128 if ($item eq $dir) {
3129  
3130 return TRUE;
3131 }
3132 }
3133  
3134 # $key and $dir are not opposite (custom) directions
3135 return undef;
3136 }
3137  
3138 sub convertStandardDir {
3139  
3140 # Can be called by anything, but often used for creating exit objects
3141 # Checks whether a specified direction is a primary direction. If so, returns the
3142 # equivalent standard direction (e.g. converts 'nord', 'n' to 'north')
3143 #
3144 # Expected arguments
3145 # $dir - The direction to check (full or abbreviated form)
3146 #
3147 # Return values
3148 # 'undef' on improper arguments or if $dir isn't a primary direction
3149 # Otherwise returns the standard primary direction
3150  
3151 my ($self, $dir, $check) = @_;
3152  
3153 # Local variables
3154 my $type;
3155  
3156 # Check for improper arguments
3157 if (! defined $dir || defined $check) {
3158  
3159 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertStandardDir', @_);
3160 }
3161  
3162 # Perform the check
3163 $type = $self->ivShow('combDirHash', $dir);
3164 if (defined $type && ($type eq 'primaryDir' || $type eq 'primaryAbbrev')) {
3165  
3166 # Return the standard direction
3167 return $self->ivShow('combRevDirHash', $dir);
3168  
3169 } else {
3170  
3171 # $dir is not a (custom) primary direction
3172 return undef;
3173 }
3174 }
3175  
3176 sub convertRelativeDir {
3177  
3178 # Can be called by anything
3179 # Checks whether a specified direction is a relative direction. If so, returns an integer
3180 # in the range 0-7 matching the keys in $self->relativeDirHash. 0 represents 'forward', 2
3181 # represents 'right' and so on
3182 #
3183 # Expected arguments
3184 # $dir - The direction to check (full or abbreviated form)
3185 #
3186 # Return values
3187 # 'undef' on improper arguments or if $dir isn't a relative direction
3188 # Otherwise returns the equivalent integer
3189  
3190 my ($self, $dir, $check) = @_;
3191  
3192 # Local variables
3193 my (
3194 $type,
3195 %revHash,
3196 );
3197  
3198 # Check for improper arguments
3199 if (! defined $dir || defined $check) {
3200  
3201 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertRelativeDir', @_);
3202 }
3203  
3204 # Perform the check
3205 $type = $self->ivShow('combDirHash', $dir);
3206 if (defined $type) {
3207  
3208 # (For other $types, %revHash remains empty, so the return value will be 'undef'
3209 if ($type eq 'relativeDir') {
3210 %revHash = reverse $self->relativeDirHash;
3211 } elsif ($type eq 'relativeAbbrev') {
3212 %revHash = reverse $self->relativeAbbrevHash;
3213 }
3214  
3215 return $revHash{$dir};
3216  
3217 } else {
3218  
3219 # Not a relative direction
3220 return undef;
3221 }
3222 }
3223  
3224 sub rotateRelativeDir {
3225  
3226 # Can be called by anything, usually after a call to $self->convertRelativeDir
3227 # Given one of the relative direction slots (an integer in the range 0-7 matching the keys
3228 # in $self->relativeDirHash. 0 represents 'forward', 2 represents 'right' and so on) and
3229 # the direction the character is currently facing, returns the equivalent standard primary
3230 # direction. For example:
3231 #
3232 # Character is facing Specified slot Returns
3233 # west 0 west
3234 # west 1 northwest
3235 # west 2 north
3236 #
3237 # southwest 0 southwest
3238 # southwest 4 northeast
3239 # southwest 7 south
3240 #
3241 # Expected arguments
3242 # $slot - An integer in the range 0-7
3243 #
3244 # Optional arguments
3245 # $facingDir - The direction the character is currently facing (must be one of the
3246 # following standard primary directions: north/northeast/east/southeast/
3247 # south/southwest/west/northwest). If it's a different direction, this
3248 # function returns 'undef'; but if $facingDir is not defined at all,
3249 # we'll assume the character is facing north
3250 #
3251 # Return values
3252 # 'undef' on improper arguments, if $slot is invalid or if $facingDir is specified and
3253 # invalid
3254 # Otherwise returns the equivalent standard primary direction
3255  
3256 my ($self, $slot, $facingDir, $check) = @_;
3257  
3258 # Local variables
3259 my $otherSlot;
3260  
3261 # Check for improper arguments
3262 if (! defined $slot || defined $check) {
3263  
3264 return $axmud::CLIENT->writeImproper($self->_objClass . '->rotateRelativeDir', @_);
3265 }
3266  
3267 # Check any arguments are valid
3268 if (
3269 ! $axmud::CLIENT->intCheck($slot, 0, 7)
3270 || (
3271 defined $facingDir
3272 && (
3273 ! $axmud::CLIENT->ivExists('constShortPrimaryDirHash', $facingDir)
3274 || $facingDir eq 'up'
3275 || $facingDir eq 'down'
3276 )
3277 )
3278 ) {
3279 return undef;
3280 }
3281  
3282 # If $facingDir is not defined, assume the character is facing north
3283 if (! defined $facingDir) {
3284  
3285 $facingDir = 'north';
3286 }
3287  
3288 # Find the slot number representing $facingDir. By good fortune, the first eight items in
3289 # GA::Client->constShortPrimaryDirList are in the correct order
3290 $otherSlot = $axmud::CLIENT->ivFind('constShortPrimaryDirList', $facingDir);
3291  
3292 # Rotate $slot to take into account the direction the character is facing
3293 $slot += $otherSlot;
3294 if ($slot > 7) {
3295  
3296 $slot -= 8;
3297 }
3298  
3299 return $axmud::CLIENT->ivIndex('constShortPrimaryDirList', $slot);
3300 }
3301  
3302 sub fetchRelativeDir {
3303  
3304 # Can be called by anything
3305 # Fetch the direction, relative to the direction in which the character is facing, of a
3306 # primary direction. For example:
3307 #
3308 # Character is facing Specified direction Returns
3309 # east east forward
3310 # east south right
3311 # east west backward
3312 # east north left
3313 #
3314 # Expected arguments
3315 # $dir - The specified direction (must be one of the following standard primary
3316 # directions: north/northeast/east/southeast/south/southwest/west/
3317 # northwest)
3318 #
3319 # Optional arguments
3320 # $facingDir - The direction the character is currently facing (must be one of the
3321 # following standard primary directions: north/northeast/east/southeast/
3322 # south/southwest/west/northwest)
3323 # - GA::Obj::Map->facingDir can be 'undef', so this function won't complain of
3324 # improper arguments if $facingDir is 'undef', but no relative direction
3325 # will be returned
3326 #
3327 # Return values
3328 # 'undef' on improper arguments, if either argument is an invalid direction, if
3329 # $facingDir is 'undef' or if the corresponding relative direction has not been
3330 # defined
3331 # Otherwise returns the equivalent relative direction
3332  
3333 my ($self, $dir, $facingDir, $check) = @_;
3334  
3335 # Local variables
3336 my ($slot, $otherSlot);
3337  
3338 # Check for improper arguments
3339 if (! defined $dir || defined $check) {
3340  
3341 return $axmud::CLIENT->writeImproper($self->_objClass . '->fetchRelativeDir', @_);
3342 }
3343  
3344 # Unlike other dictionary object functions, here we don't assume the character is facing
3345 # 'north' if $facingDir is not defined
3346 if (! $facingDir) {
3347  
3348 return undef;
3349 }
3350  
3351 # Check the directions are valid
3352 $slot = $axmud::CLIENT->ivFind('constShortPrimaryDirList', $dir);
3353 if (! $axmud::CLIENT->intCheck($slot, 0, 7)) {
3354  
3355 return undef;
3356 }
3357  
3358 $otherSlot = $axmud::CLIENT->ivFind('constShortPrimaryDirList', $facingDir);
3359 if (! $axmud::CLIENT->intCheck($otherSlot, 0, 7)) {
3360  
3361 return undef;
3362 }
3363  
3364 # Rotate $slot to take into account the direction the character is facing
3365 $slot += $otherSlot;
3366 if ($slot > 7) {
3367  
3368 $slot -= 8;
3369 }
3370  
3371 # Return the corresponding relative direction (or 'undef' if it's not defined)
3372 return $self->ivShow('relativeDirHash', $slot);
3373 }
3374  
3375 sub sortExits {
3376  
3377 # Can be called by anything (no longer called by GA::Task::Locator->processExits)
3378 # Sorts a list of exit strings (e.g. 'south', 'north', 'up) into a standard order (provided
3379 # by the current dictionary), and substitutes any abbreviated exits for the unabbreviated
3380 # forms (e.g. converts 'n' to 'north')
3381 #
3382 # Expected arguments
3383 # (none besides $self)
3384 #
3385 # Optional arguments
3386 # @exitList - List of exits (may be empty)
3387 #
3388 # Return values
3389 # An empty list on improper arguments
3390 # Otherwise, the sorted list
3391  
3392 my ($self, @exitList) = @_;
3393  
3394 # Local variables
3395 my (
3396 @primaryDirList, @secondaryDirList, @sortedList, @otherList,
3397 %exitHash, %primaryDirHash, %primaryAbbrevHash, %secondaryDirHash, %secondaryAbbrevHash,
3398 %relativeDirHash, %relativeAbbrevHash,
3399 );
3400  
3401 # (No improper arguments to check)
3402  
3403 # Copy the exits in @exitList into a hash, for quick lookup; but preserve duplicates. Hash
3404 # in the form
3405 # $exitHash{exit} = number_of_appearances
3406 foreach my $exit (@exitList) {
3407  
3408 if (! exists $exitHash{$exit}) {
3409  
3410 $exitHash{$exit} = 1;
3411  
3412 } else {
3413  
3414 $exitHash{$exit} = $exitHash{$exit} + 1;
3415 }
3416 }
3417  
3418 # Import IVs
3419 @primaryDirList = $axmud::CLIENT->constPrimaryDirList;
3420 %primaryDirHash = $self->primaryDirHash;
3421 %primaryAbbrevHash = $self->primaryAbbrevHash;
3422 @secondaryDirList = $self->secondaryDirList;
3423 %secondaryDirHash = $self->secondaryDirHash;
3424 %secondaryAbbrevHash = $self->secondaryAbbrevHash;
3425 %relativeDirHash = $self->relativeDirHash;
3426 %relativeAbbrevHash = $self->relativeAbbrevHash;
3427  
3428 # @sortedList is the list of exits, in the default order. Add primary directions
3429 foreach my $standard (@primaryDirList) {
3430  
3431 my ($match, $number);
3432  
3433 if (exists $exitHash{$primaryDirHash{$standard}}) {
3434  
3435 $match = $primaryDirHash{$standard};
3436 $number = $exitHash{$match};
3437 delete $exitHash{$match};
3438  
3439 } elsif (exists $exitHash{$primaryAbbrevHash{$standard}}) {
3440  
3441 $match = $primaryAbbrevHash{$standard};
3442 $number = $exitHash{$match};
3443 delete $exitHash{$match};
3444 }
3445  
3446 if ($match) {
3447  
3448 for (my $count = 0; $count < $number; $count++) {
3449  
3450 push (@sortedList, $match);
3451 }
3452 }
3453 }
3454  
3455 # Add secondary directions
3456 foreach my $recognised (@secondaryDirList) {
3457  
3458 my ($match, $number);
3459  
3460 if (
3461 defined $secondaryDirHash{$recognised}
3462 && exists $exitHash{$secondaryDirHash{$recognised}}
3463 ) {
3464 $match = $secondaryDirHash{$recognised};
3465 $number = $exitHash{$match};
3466 delete $exitHash{$match};
3467  
3468 } elsif (
3469 defined $secondaryAbbrevHash{$recognised}
3470 && exists $exitHash{$secondaryAbbrevHash{$recognised}}
3471 ) {
3472 $match = $secondaryAbbrevHash{$recognised};
3473 $number = $exitHash{$match};
3474 delete $exitHash{$match};
3475 }
3476  
3477 if ($match) {
3478  
3479 for (my $count = 0; $count < $number; $count++) {
3480  
3481 push (@sortedList, $match);
3482 }
3483 }
3484 }
3485  
3486 # Add relative directions
3487 for (my $count = 0; $count < 8; $count++) {
3488  
3489 my ($match, $number);
3490  
3491 if (
3492 exists $relativeDirHash{$count}
3493 && exists $exitHash{$relativeDirHash{$count}}
3494 ) {
3495 $match = $relativeDirHash{$count};
3496 $number = $exitHash{$match};
3497 delete $exitHash{$match};
3498  
3499 } elsif (
3500 exists $relativeAbbrevHash{$count}
3501 && exists $exitHash{$relativeAbbrevHash{$count}}
3502 ) {
3503 $match = $relativeAbbrevHash{$count};
3504 $number = $exitHash{$match};
3505 delete $exitHash{$match};
3506 }
3507  
3508 if ($match) {
3509  
3510 for (my $count = 0; $count < $number; $count++) {
3511  
3512 push (@sortedList, $match);
3513 }
3514 }
3515 }
3516  
3517 # Now, any exits in @exitList which aren't primary or secondary directions will still be
3518 # in %exitHash. Add them to @otherList in their original order
3519 foreach my $exit (@exitList) {
3520  
3521 if (exists $exitHash{$exit}) {
3522  
3523 for (my $count = 0; $count < $exitHash{$exit}; $count++) {
3524  
3525 push (@otherList, $exit);
3526 }
3527 }
3528 }
3529  
3530 # The final list consists of all primary/secondary directions in their default order,
3531 # followed by any other directions in alphabetical order
3532 if (@otherList) {
3533  
3534 push (@sortedList, sort {lc($a) cmp lc($b)} (@otherList));
3535 }
3536  
3537 # Sort complete
3538 return @sortedList;
3539 }
3540  
3541 sub sortExitObjs {
3542  
3543 # Called by GA::Task::Locator->processExits, or by any other code
3544 # Sorts a list of exit objects (e.g. 'south', 'north', 'up) into a standard order (provided
3545 # by the current dictionary), and substitutes any abbreviated exits for the unabbreviated
3546 # forms (e.g. converts 'n' to 'north')
3547 #
3548 # Expected arguments
3549 # (none besides $self)
3550 #
3551 # Optional arguments
3552 # @objList - List of exit objects (may be empty)
3553 #
3554 # Return values
3555 # An empty list on improper arguments
3556 # Otherwise, the sorted list
3557  
3558 my ($self, @objList) = @_;
3559  
3560 # Local variables
3561 my (
3562 @primaryDirList, @secondaryDirList, @sortedList, @otherList,
3563 %dirHash, %objHash, %primaryDirHash, %primaryAbbrevHash, %secondaryDirHash,
3564 %secondaryAbbrevHash, %relativeDirHash, %relativeAbbrevHash,
3565 );
3566  
3567 # (No improper arguments to check)
3568  
3569 # Copy the exit objects in @objList into a hash, for quick lookup; but preserve duplicates.
3570 # Hash in the form
3571 # $dirHash{exit_nominal_direction} = number_of_appearances
3572 foreach my $exitObj (@objList) {
3573  
3574 my $dir = $exitObj->dir;
3575  
3576 if (! exists $dirHash{$dir}) {
3577  
3578 $dirHash{$dir} = 1;
3579  
3580 } else {
3581  
3582 $dirHash{$dir} = $dirHash{$dir} + 1;
3583 }
3584  
3585 # Create a parallel hash, in the form
3586 # $objHash{exit_nominal_direction} = blessed_reference_to_exit_object
3587 # ...but, in this hash, duplicate nominal directions aren't added
3588 if (! exists $objHash{$dir}) {
3589  
3590 $objHash{$dir} = $exitObj;
3591 }
3592 }
3593  
3594 # Import IVs
3595 @primaryDirList = $axmud::CLIENT->constPrimaryDirList;
3596 %primaryDirHash = $self->primaryDirHash;
3597 %primaryAbbrevHash = $self->primaryAbbrevHash;
3598 @secondaryDirList = $self->secondaryDirList;
3599 %secondaryDirHash = $self->secondaryDirHash;
3600 %secondaryAbbrevHash = $self->secondaryAbbrevHash;
3601 %relativeDirHash = $self->relativeDirHash;
3602 %relativeAbbrevHash = $self->relativeAbbrevHash;
3603  
3604 # @sortedList is the list of exit objects, in the default order. Add primary directions
3605 foreach my $standard (@primaryDirList) {
3606  
3607 my ($match, $matchObj, $number);
3608  
3609 if (exists $dirHash{$primaryDirHash{$standard}}) {
3610  
3611 $match = $primaryDirHash{$standard};
3612 $matchObj = $objHash{$match};
3613 $number = $dirHash{$match};
3614  
3615 delete $dirHash{$match};
3616  
3617 } elsif (exists $dirHash{$primaryAbbrevHash{$standard}}) {
3618  
3619 $match = $primaryAbbrevHash{$standard};
3620 $matchObj = $objHash{$match};
3621 $number = $dirHash{$match};
3622  
3623 delete $dirHash{$match};
3624 }
3625  
3626 if ($match) {
3627  
3628 for (my $count = 0; $count < $number; $count++) {
3629  
3630 push (@sortedList, $matchObj);
3631 }
3632 }
3633 }
3634  
3635 # Add secondary directions
3636 foreach my $recognised (@secondaryDirList) {
3637  
3638 my ($match, $matchObj, $number);
3639  
3640 if (
3641 defined $secondaryDirHash{$recognised}
3642 && exists $dirHash{$secondaryDirHash{$recognised}}
3643 ) {
3644 $match = $secondaryDirHash{$recognised};
3645 $matchObj = $objHash{$match};
3646 $number = $dirHash{$match};
3647  
3648 delete $dirHash{$match};
3649  
3650 } elsif (
3651 defined $secondaryAbbrevHash{$recognised}
3652 && exists $dirHash{$secondaryAbbrevHash{$recognised}}
3653 ) {
3654 $match = $secondaryAbbrevHash{$recognised};
3655 $matchObj = $objHash{$match};
3656 $number = $dirHash{$match};
3657  
3658 delete $dirHash{$match};
3659 }
3660  
3661 if ($match) {
3662  
3663 for (my $count = 0; $count < $number; $count++) {
3664  
3665 push (@sortedList, $matchObj);
3666 }
3667 }
3668 }
3669  
3670 # Add relative directions
3671 for (my $count = 0; $count < 8; $count++) {
3672  
3673 my ($match, $matchObj, $number);
3674  
3675 if (
3676 exists $relativeDirHash{$count}
3677 && exists $dirHash{$relativeDirHash{$count}}
3678 ) {
3679 $match = $relativeDirHash{$count};
3680 $matchObj = $objHash{$match};
3681 $number = $dirHash{$match};
3682  
3683 delete $dirHash{$match};
3684  
3685 } elsif (
3686 exists $relativeAbbrevHash{$count}
3687 && exists $dirHash{$relativeAbbrevHash{$count}}
3688 ) {
3689 $match = $relativeAbbrevHash{$count};
3690 $matchObj = $objHash{$match};
3691 $number = $dirHash{$match};
3692  
3693 delete $dirHash{$match};
3694 }
3695  
3696 if ($match) {
3697  
3698 for (my $count = 0; $count < $number; $count++) {
3699  
3700 push (@sortedList, $matchObj);
3701 }
3702 }
3703 }
3704  
3705 # Now, any exits in @objList which aren't primary or secondary directions will still be
3706 # in %dirHash. Add them to @otherList in their original order
3707 foreach my $exitObj (@objList) {
3708  
3709 my $dir = $exitObj->dir;
3710  
3711 if (exists $dirHash{$dir}) {
3712  
3713 for (my $count = 0; $count < $dirHash{$dir}; $count++) {
3714  
3715 push (@otherList, $exitObj);
3716 }
3717 }
3718 }
3719  
3720 # The final list consists of all primary/secondary directions in their default order,
3721 # followed by any other directions in alphabetical order
3722 if (@otherList) {
3723  
3724 push (@sortedList, sort {lc($a->dir) cmp lc($b->dir)} (@otherList));
3725 }
3726  
3727 # Sort complete
3728 return @sortedList;
3729 }
3730  
3731 sub abbrevDir {
3732  
3733 # Can be called by anything
3734 #
3735 # Given a standard primary direction or a custom primary direction, returns the
3736 # corresponding custom abbreviated primary direction
3737 # (e.g. converts 'north' or 'nord' to 'n')
3738 #
3739 # Given a recognised secondary direction, returns the corresponding abbreviated direction
3740 # (e.g. converts 'out' to 'o')
3741 # If the recognised secondary direction doesn't have an abbreviation (which it doesn't, by
3742 # default), returns 'undef')
3743 #
3744 # Given a recognised relative direction, returns the corresponding abbreviated direction
3745 # (re.g. converts 'forward' to 'fw')
3746 # If the recognised relative direction doesn't have an abbreviation (which it doesn't, by
3747 # default), returns 'undef')
3748 #
3749 # Otherwise, returns the direction unmodified
3750 #
3751 # Expected arguments
3752 # $dir - The standard, custom primary/secondary or relative direction to abbreviate
3753 #
3754 # Return values
3755 # 'undef' on improper arguments or if $dir is a recognised secondary/relative direction
3756 # which has no abbreviation
3757 # The abbreviated (or original) direction, otherwise
3758  
3759 my ($self, $dir, $check) = @_;
3760  
3761 # Local variables
3762 my (
3763 $type, $standard, $recognised, $index,
3764 %revHash,
3765 );
3766  
3767 # Check for improper arguments
3768 if (! defined $dir || defined $check) {
3769  
3770 return $axmud::CLIENT->writeImproper($self->_objClass . '->abbrevDir', @_);
3771 }
3772  
3773 # If it's a standard primary direction...
3774 if ($self->ivExists('primaryAbbrevHash', $dir)) {
3775  
3776 # Return the abbreviated custom direction
3777 return $self->ivShow('primaryAbbrevHash', $dir);
3778 }
3779  
3780 $type = $self->ivShow('combDirHash', $dir);
3781 if (defined $type) {
3782  
3783 # If it's a custom primary direction...
3784 if ($type eq 'primaryDir') {
3785  
3786 # Find the standard primary direction
3787 $standard = $self->ivShow('combRevDirHash', $dir);
3788 # Convert that into the custom abbreviated direction
3789 return $self->ivShow('primaryAbbrevHash', $standard);
3790  
3791 # If it's a recognised secondary direction...
3792 } elsif ($type eq 'secondaryDir') {
3793  
3794 # Find the recognised secondary direction
3795 $recognised = $self->ivShow('combRevDirHash', $dir);
3796 # Convert that into the custom abbreviated direction
3797 return $self->ivShow('secondaryAbbrevHash', $recognised);
3798  
3799 # If it's a recognised relative direction...
3800 } elsif ($type eq 'relativeDir') {
3801  
3802 # $dir is a value in $self->relativeDirHash; find the corresponding key
3803 %revHash = reverse $self->relativeDirHash;
3804 $index = $revHash{$dir};
3805 if (defined $index) {
3806  
3807 # Convert it into the abbreviated relative direction
3808 return ($self->ivShow('relativeAbbrevHash', $index));
3809 }
3810 }
3811 }
3812  
3813 # Return the direction, unmodified
3814 return $dir;
3815 }
3816  
3817 sub unabbrevDir {
3818  
3819 # Can be called by anything
3820 #
3821 # Given an abbreviated custom primary direction, returns the corresponding unabbreviated
3822 # direction (e.g. converts 'n' to 'nord')
3823 #
3824 # Given a recognised abbreviated secondary direction, returns the corresponding
3825 # unabbreviated direction
3826 # (e.g. converts 'o' to 'out')
3827 #
3828 # Given a recognised abbreviated relative direction, returns the corresponding
3829 # unabbreviated direction
3830 # (e.g. converts 'forward' to 'fw')
3831 #
3832 # Otherwise, returns the direction unmodified
3833 #
3834 # Expected arguments
3835 # $dir - The standard, custom primary/secondary or relative direction to unabbreviate
3836 #
3837 # Return values
3838 # 'undef' on improper arguments
3839 # The unabbreviated (or original) direction, otherwise
3840  
3841 my ($self, $dir, $check) = @_;
3842  
3843 # Local variables
3844 my (
3845 $type, $standard, $recognised, $index,
3846 %revHash,
3847 );
3848  
3849 # Check for improper arguments
3850 if (! defined $dir || defined $check) {
3851  
3852 return $axmud::CLIENT->writeImproper($self->_objClass . '->unabbrevDir', @_);
3853 }
3854  
3855 $type = $self->ivShow('combDirHash', $dir);
3856 if (defined $type) {
3857  
3858 # If it's an abbreviated custom primary direction...
3859 if (defined $type && $type eq 'primaryAbbrev') {
3860  
3861 # Find the standard primary direction
3862 $standard = $self->ivShow('combRevDirHash', $dir);
3863 # Convert that into the custom unabbreviated direction
3864 return $self->ivShow('primaryDirHash', $standard);
3865  
3866 # If it's a recognised abbreviated secondary direction...
3867 } elsif (defined $type && $type eq 'secondaryAbbrev') {
3868  
3869 # Find the recognised secondary direction
3870 $recognised = $self->ivShow('combRevDirHash', $dir);
3871 # Convert that into the recognised unabbreviated direction
3872 return $self->ivShow('secondaryDirHash', $recognised);
3873  
3874 # If it's a recognised abbreviated relative direction...
3875 } elsif ($type eq 'relativeDir') {
3876  
3877 # $dir is a value in $self->relativeAbbrevHash; find the corresponding key
3878 %revHash = reverse $self->relativeAbbrevHash;
3879 $index = $revHash{$dir};
3880 if (defined $index) {
3881  
3882 # Convert it into the unabbreviated relative direction
3883 return ($self->ivShow('relativeDirHash', $index));
3884 }
3885 }
3886 }
3887  
3888 # Return the direction, unmodified
3889 return $dir;
3890 }
3891  
3892 ##################
3893 # Accessors - set
3894  
3895 ##################
3896 # Accessors - get
3897  
3898 sub name
3899 { $_[0]->{name} }
3900 sub language
3901 { $_[0]->{language} }
3902 sub nounPosn
3903 { $_[0]->{nounPosn} }
3904  
3905 sub definiteList
3906 { my $self = shift; return @{$self->{definiteList}}; }
3907 sub indefiniteList
3908 { my $self = shift; return @{$self->{indefiniteList}}; }
3909 sub andList
3910 { my $self = shift; return @{$self->{andList}}; }
3911 sub orList
3912 { my $self = shift; return @{$self->{orList}}; }
3913  
3914 sub numberHash
3915 { my $self = shift; return %{$self->{numberHash}}; }
3916  
3917 sub timeHash
3918 { my $self = shift; return %{$self->{timeHash}}; }
3919 sub timePluralHash
3920 { my $self = shift; return %{$self->{timePluralHash}}; }
3921 sub reverseTimeHash
3922 { my $self = shift; return %{$self->{reverseTimeHash}}; }
3923 sub reverseTimePluralHash
3924 { my $self = shift; return %{$self->{reverseTimePluralHash}}; }
3925  
3926 sub clockDayHash
3927 { my $self = shift; return %{$self->{clockDayHash}}; }
3928 sub clockHourHash
3929 { my $self = shift; return %{$self->{clockHourHash}}; }
3930 sub clockMinuteHash
3931 { my $self = shift; return %{$self->{clockMinuteHash}}; }
3932  
3933 sub constPortableTypeList
3934 { my $self = shift; return @{$self->{constPortableTypeList}}; }
3935 sub portableTypeList
3936 { my $self = shift; return @{$self->{portableTypeList}}; }
3937  
3938 sub constDecorationTypeList
3939 { my $self = shift; return @{$self->{constDecorationTypeList}}; }
3940 sub decorationTypeList
3941 { my $self = shift; return @{$self->{decorationTypeList}}; }
3942  
3943 sub guildHash
3944 { my $self = shift; return %{$self->{guildHash}}; }
3945 sub raceHash
3946 { my $self = shift; return %{$self->{raceHash}}; }
3947 sub weaponHash
3948 { my $self = shift; return %{$self->{weaponHash}}; }
3949 sub armourHash
3950 { my $self = shift; return %{$self->{armourHash}}; }
3951 sub garmentHash
3952 { my $self = shift; return %{$self->{garmentHash}}; }
3953 sub sentientHash
3954 { my $self = shift; return %{$self->{sentientHash}}; }
3955 sub creatureHash
3956 { my $self = shift; return %{$self->{creatureHash}}; }
3957 sub portableHash
3958 { my $self = shift; return %{$self->{portableHash}}; }
3959 sub decorationHash
3960 { my $self = shift; return %{$self->{decorationHash}}; }
3961 sub adjHash
3962 { my $self = shift; return %{$self->{adjHash}}; }
3963  
3964 sub portableTypeHash
3965 { my $self = shift; return %{$self->{portableTypeHash}}; }
3966 sub decorationTypeHash
3967 { my $self = shift; return %{$self->{decorationTypeHash}}; }
3968  
3969 sub pluralEndingHash
3970 { my $self = shift; return %{$self->{pluralEndingHash}}; }
3971 sub reversePluralEndingHash
3972 { my $self = shift; return %{$self->{reversePluralEndingHash}}; }
3973 sub pluralNounHash
3974 { my $self = shift; return %{$self->{pluralNounHash}}; }
3975 sub reversePluralNounHash
3976 { my $self = shift; return %{$self->{reversePluralNounHash}}; }
3977  
3978 sub adjEndingHash
3979 { my $self = shift; return %{$self->{adjEndingHash}}; }
3980 sub reverseAdjEndingHash
3981 { my $self = shift; return %{$self->{reverseAdjEndingHash}}; }
3982 sub declinedAdjHash
3983 { my $self = shift; return %{$self->{declinedAdjHash}}; }
3984 sub reverseDeclinedAdjHash
3985 { my $self = shift; return %{$self->{reverseDeclinedAdjHash}}; }
3986  
3987 sub pseudoNounHash
3988 { my $self = shift; return %{$self->{pseudoNounHash}}; }
3989 sub pseudoAdjHash
3990 { my $self = shift; return %{$self->{pseudoAdjHash}}; }
3991 sub pseudoObjHash
3992 { my $self = shift; return %{$self->{pseudoObjHash}}; }
3993  
3994 sub deathWordHash
3995 { my $self = shift; return %{$self->{deathWordHash}}; }
3996 sub unknownWordHash
3997 { my $self = shift; return %{$self->{unknownWordHash}}; }
3998 sub contentsLinesHash
3999 { my $self = shift; return %{$self->{contentsLinesHash}}; }
4000 sub ignoreWordHash
4001 { my $self = shift; return %{$self->{ignoreWordHash}}; }
4002  
4003 sub primaryDirHash
4004 { my $self = shift; return %{$self->{primaryDirHash}}; }
4005 sub primaryAbbrevHash
4006 { my $self = shift; return %{$self->{primaryAbbrevHash}}; }
4007 sub primaryOppHash
4008 { my $self = shift; return %{$self->{primaryOppHash}}; }
4009 sub primaryOppAbbrevHash
4010 { my $self = shift; return %{$self->{primaryOppAbbrevHash}}; }
4011  
4012 sub secondaryDirList
4013 { my $self = shift; return @{$self->{secondaryDirList}}; }
4014 sub secondaryDirHash
4015 { my $self = shift; return %{$self->{secondaryDirHash}}; }
4016 sub secondaryAbbrevHash
4017 { my $self = shift; return %{$self->{secondaryAbbrevHash}}; }
4018 sub secondaryOppHash
4019 { my $self = shift; return %{$self->{secondaryOppHash}}; }
4020 sub secondaryOppAbbrevHash
4021 { my $self = shift; return %{$self->{secondaryOppAbbrevHash}}; }
4022 sub secondaryAutoHash
4023 { my $self = shift; return %{$self->{secondaryAutoHash}}; }
4024  
4025 sub relativeDirHash
4026 { my $self = shift; return %{$self->{relativeDirHash}}; }
4027 sub relativeAbbrevHash
4028 { my $self = shift; return %{$self->{relativeAbbrevHash}}; }
4029  
4030 sub speedDirHash
4031 { my $self = shift; return %{$self->{speedDirHash}}; }
4032 sub speedModifierHash
4033 { my $self = shift; return %{$self->{speedModifierHash}}; }
4034  
4035 sub combNounHash
4036 { my $self = shift; return %{$self->{combNounHash}}; }
4037 sub combAdjHash
4038 { my $self = shift; return %{$self->{combAdjHash}}; }
4039 sub combDirHash
4040 { my $self = shift; return %{$self->{combDirHash}}; }
4041 sub combOppDirHash
4042 { my $self = shift; return %{$self->{combOppDirHash}}; }
4043 sub combRevDirHash
4044 { my $self = shift; return %{$self->{combRevDirHash}}; }
4045 }
4046  
4047 # Package must return a true value
4048 1