Games-Axmud

 view release on metacpan or  search on metacpan

lib/Games/Axmud/Obj/WorldModel.pm  view on Meta::CPAN

                }

                # Available cardinal direction found
                return $cardinalDir;
            }
        }

         # All sixteen cardinal directions are unavailable
        return undef;
    }

    sub countRoomContents {

        # Called by GA::Obj::Map->updateRoom
        # Counts the number of living and non-living things in the Locator task's current room, and
        #   stores them in the regionmap in which a specified room model object is stored
        # As a result, it's possible for the Automapper window to display the number of things in a
        #   room the last time it was visited
        #
        # Expected arguments
        #   $session        - The calling function's GA::Session
        #   $modelRoomObj   - The room model object for which the counts are stored
        #
        # Return values
        #   'undef' on improper arguments, if there is no Locator task, if the Locator task doesn't
        #       know the current location or if $modelRoomObj's regionmap can't be found
        #   1 otherwise

        my ($self, $session, $modelRoomObj, $check) = @_;

        # Local variables
        my ($regionmapObj, $livingCount, $nonLivingCount);

        # Check for improper arguments
        if (! defined $session || ! defined $modelRoomObj || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->countRoomContents', @_);
        }

        # Shouldn't be possible for this function to be called when the Locator task isn't running
        #   or doesn't know the current location - but we'll check anyway
        if (! $session->locatorTask || ! $session->locatorTask->roomObj) {

            return undef;
        }

        # Get the room's regionmap
        $regionmapObj = $self->findRegionmap($modelRoomObj->parent);
        if (! $regionmapObj) {

            # Again, nothing we can do
            return undef;
        }

        # Count the number of living and non-living things in the Locator task's room
        $livingCount = 0;
        $nonLivingCount = 0;

        foreach my $obj ($session->locatorTask->roomObj->tempObjList) {

            if ($obj->aliveFlag) {
                $livingCount++;
            } else {
                $nonLivingCount++;
            }
        }

        # Now, if the count is 0, we remove an entry from the hash IV (if it exists); otherwise we
        #   add an entry (or replace the existing one)
        if ($livingCount) {
            $regionmapObj->storeLivingCount($modelRoomObj->number, $livingCount);
        } else {
            $regionmapObj->removeLivingCount($modelRoomObj->number);
        }

        if ($nonLivingCount) {
            $regionmapObj->storeNonLivingCount($modelRoomObj->number, $nonLivingCount);
        } else {
            $regionmapObj->removeNonLivingCount($modelRoomObj->number);
        }

        return 1;
    }

    sub setInteriorOffsets {

        # Called by GA::Obj::Map->setInteriorOffsetsCallback
        # Sets the offsets used when a room's grid coordinates are displayed as interior text inside
        #   the room box
        #
        # Expected arguments
        #   $xOffset, $yOffset  - The new values to set
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $xOffset, $yOffset, $check) = @_;

        # Check for improper arguments
        if (! defined $xOffset || ! defined $yOffset || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->setInteriorOffsets', @_);
        }

        # Update IVs
        $self->ivPoke('roomInteriorXOffset', $xOffset);
        $self->ivPoke('roomInteriorYOffset', $yOffset);

        return 1;
    }

    sub findPathCmds {

        # Called by GA::Win::Map->processPathCallback
        # Given a list of GA::ModelObj::Room objects along a continuous path - such as one
        #   generated by a call to $self->findPath or ->findUniversalPath - compiles a list of
        #   commands to get from the first room on the path to the last one
        # Uses assisted moves, if allowed; otherwise uses only exit nominal directions
        #
        # Expected arguments



( run in 2.935 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )