Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++
4.2 KB
Raw Blame
#ifndef OPENMW_CELLCONTROLLER_HPP
#define OPENMW_CELLCONTROLLER_HPP

#include <set>

#include "Cell.hpp"
#include "ActorList.hpp"
#include "LocalActor.hpp"
#include "DedicatedActor.hpp"
#include "../mwworld/cellstore.hpp"

namespace mwmp
{
    class CellController
    {
    public:

        CellController();
        virtual ~CellController();

        void updateLocal(bool forceUpdate);
        void updateDedicated(float dt);

        void initializeCell(const ESM::Cell& cell);
        void uninitializeCell(const ESM::Cell& cell);
        void uninitializeCells();

        void readPositions(mwmp::ActorList& actorList);
        void readAnimFlags(mwmp::ActorList& actorList);
        void readAnimPlay(mwmp::ActorList& actorList);
        void readStatsDynamic(mwmp::ActorList& actorList);
        void readDeath(mwmp::ActorList& actorList);
        void readEquipment(mwmp::ActorList& actorList);
        void readSpeech(mwmp::ActorList& actorList);
        void readSpellsActive(mwmp::ActorList& actorList);
        void readAi(mwmp::ActorList& actorList);
        void readAttack(mwmp::ActorList& actorList);
        void readCast(mwmp::ActorList& actorList);
        void readCellChange(mwmp::ActorList& actorList);

        bool hasQueuedDeathState(MWWorld::Ptr ptr);
        unsigned int getQueuedDeathState(MWWorld::Ptr ptr);
        void clearQueuedDeathState(MWWorld::Ptr ptr);
        void setQueuedDeathState(MWWorld::Ptr ptr, unsigned int deathState);

        void setLocalActorRecord(std::string actorIndex, std::string cellIndex);
        void removeLocalActorRecord(std::string actorIndex);
        
        bool isLocalActor(MWWorld::Ptr ptr);
        bool isLocalActor(int refNum, int mpNum);
        virtual LocalActor *getLocalActor(MWWorld::Ptr ptr);
        virtual LocalActor *getLocalActor(int refNum, int mpNum);

        void setDedicatedActorRecord(std::string actorIndex, std::string cellIndex);
        void removeDedicatedActorRecord(std::string actorIndex);
        
        bool isDedicatedActor(MWWorld::Ptr ptr);
        bool isDedicatedActor(int refNum, int mpNum);
        virtual DedicatedActor *getDedicatedActor(MWWorld::Ptr ptr);
        virtual DedicatedActor *getDedicatedActor(int refNum, int mpNum);

        // Isowind MMO: actors this client runs itself whoever has authority over their cell, sending nothing about
        // them and ignoring what others send (a one-off event's people, each player's own: "isowind local" from the
        // server, see MechanicsHelper::runClientLocalCommand). They stay so for the session.
        void setClientLocalActor(int refNum, int mpNum);
        /// Run as any other again (a private follower sent back to its post)
        void unsetClientLocalActor(int refNum, int mpNum);
        /// No longer a LocalActor or DedicatedActor here (it's gone, or now run otherwise)
        void forgetActor(int refNum, int mpNum);
        bool isClientLocalActor(const MWWorld::Ptr& ptr);
        bool isClientLocalActor(int refNum, int mpNum);

        std::string generateMapIndex(int refNumindex, int mpNum);
        std::string generateMapIndex(MWWorld::Ptr ptr);
        std::string generateMapIndex(mwmp::BaseActor baseActor);

        bool hasLocalAuthority(const ESM::Cell& cell);
        bool isInitializedCell(const std::string& cellDescription);
        bool isInitializedCell(const ESM::Cell& cell);
        bool isActiveWorldCell(const ESM::Cell& cell);
        virtual Cell *getCell(const ESM::Cell& cell);

        virtual MWWorld::CellStore *getCellStore(const ESM::Cell& cell);

        bool isSameCell(const ESM::Cell& cell, const ESM::Cell& otherCell);

        // An object in an active cell, found by the numbers clients share (MWWorld::CellRef::getMpRefNum and getMpNum)
        MWWorld::Ptr searchPtrViaUniqueIndex(unsigned int refNum, unsigned int mpNum);

        int getCellSize() const;

    private:
        static std::map<std::string, mwmp::Cell *> cellsInitialized;
        static std::map<std::string, std::string> localActorsToCells;
        static std::map<std::string, std::string> dedicatedActorsToCells;
        static std::map<std::string, unsigned int> queuedDeathStates;
        static std::set<std::string> clientLocalActors;
    };
}

#endif //OPENMW_CELLCONTROLLER_HPP