OpenMW
apps/openmw/mwworld/worldimp.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWWORLD_WORLDIMP_H
00002 #define GAME_MWWORLD_WORLDIMP_H
00003 
00004 #include "../mwrender/debugging.hpp"
00005 
00006 #include "ptr.hpp"
00007 #include "scene.hpp"
00008 #include "esmstore.hpp"
00009 #include "physicssystem.hpp"
00010 #include "cells.hpp"
00011 #include "localscripts.hpp"
00012 #include "timestamp.hpp"
00013 #include "fallback.hpp"
00014 
00015 #include "../mwbase/world.hpp"
00016 
00017 #include "contentloader.hpp"
00018 
00019 namespace Ogre
00020 {
00021     class Vector3;
00022 }
00023 
00024 namespace ESM
00025 {
00026     struct Position;
00027 }
00028 
00029 namespace Files
00030 {
00031     class Collections;
00032 }
00033 
00034 namespace Render
00035 {
00036     class OgreRenderer;
00037 }
00038 
00039 namespace MWRender
00040 {
00041     class SkyManager;
00042     class CellRender;
00043     class Animation;
00044 }
00045 
00046 struct ContentLoader;
00047 
00048 namespace MWWorld
00049 {
00050     class WeatherManager;
00051     class Player;
00052 
00054 
00055     class World : public MWBase::World
00056     {
00057             MWWorld::Fallback mFallback;
00058             MWRender::RenderingManager* mRendering;
00059 
00060             MWWorld::WeatherManager* mWeatherManager;
00061 
00062             MWWorld::Scene *mWorldScene;
00063             MWWorld::Player *mPlayer;
00064             std::vector<ESM::ESMReader> mEsm;
00065             MWWorld::ESMStore mStore;
00066             LocalScripts mLocalScripts;
00067             MWWorld::Globals *mGlobalVariables;
00068             MWWorld::PhysicsSystem *mPhysics;
00069             bool mSky;
00070 
00071             Cells mCells;
00072 
00073             OEngine::Physic::PhysicEngine* mPhysEngine;
00074 
00075             bool mGodMode;
00076 
00077             // not implemented
00078             World (const World&);
00079             World& operator= (const World&);
00080 
00081             Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore);
00082 
00083             int mActivationDistanceOverride;
00084             std::string mFacedHandle;
00085             float mFacedDistance;
00086 
00087             std::map<MWWorld::Ptr, int> mDoorStates;
00089 
00090             struct ProjectileState
00091             {
00092                 // Id of spell or enchantment to apply when it hits
00093                 std::string mId;
00094 
00095                 // Actor who casted this projectile
00096                 std::string mActorHandle;
00097 
00098                 // Name of item to display as effect source in magic menu (in case we casted an enchantment)
00099                 std::string mSourceName;
00100 
00101                 ESM::EffectList mEffects;
00102 
00103                 float mSpeed;
00104 
00105                 bool mStack;
00106             };
00107 
00108             std::map<MWWorld::Ptr, ProjectileState> mProjectiles;
00109             void updateWeather(float duration);
00110             int getDaysPerMonth (int month) const;
00111 
00112             void rotateObjectImp (const Ptr& ptr, Ogre::Vector3 rot, bool adjust);
00113 
00114             bool moveObjectImp (const Ptr& ptr, float x, float y, float z);
00116 
00117             Ptr copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos, bool adjustPos=true);
00118 
00119             void updateWindowManager ();
00120             void performUpdateSceneQueries ();
00121             void updateFacedHandle ();
00122 
00123             float getMaxActivationDistance ();
00124             float getNpcActivationDistance ();
00125             float getObjectActivationDistance ();
00126 
00127             void removeContainerScripts(const Ptr& reference);
00128             void addContainerScripts(const Ptr& reference, Ptr::CellStore* cell);
00129             void PCDropped (const Ptr& item);
00130 
00131             void processDoors(float duration);
00133 
00134             void moveProjectiles(float duration);
00135 
00136             void doPhysics(float duration);
00138 
00139             void ensureNeededRecords();
00140 
00147             void loadContentFiles(const Files::Collections& fileCollections,
00148                 const std::vector<std::string>& content, ContentLoader& contentLoader);
00149 
00150             int mPlayIntro;
00151 
00152             bool mTeleportEnabled;
00153             bool mLevitationEnabled;
00154 
00156             void objectLeftActiveCell (MWWorld::Ptr object, MWWorld::Ptr movedPtr);
00157 
00158             float feetToGameUnits(float feet);
00159 
00160         public:
00161 
00162             World (OEngine::Render::OgreRenderer& renderer,
00163                 const Files::Collections& fileCollections,
00164                 const std::vector<std::string>& contentFiles,
00165                 const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir,
00166                 ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap, int mActivationDistanceOverride);
00167 
00168             virtual ~World();
00169 
00170             virtual void startNewGame();
00171 
00172             virtual OEngine::Render::Fader* getFader();
00174 
00175             virtual CellStore *getExterior (int x, int y);
00176 
00177             virtual CellStore *getInterior (const std::string& name);
00178 
00179             virtual void setWaterHeight(const float height);
00180 
00181             virtual void toggleWater();
00182 
00183             virtual void adjustSky();
00184 
00185             virtual void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches);
00186 
00187             virtual const Fallback *getFallback() const;
00188 
00189             virtual Player& getPlayer();
00190 
00191             virtual const MWWorld::ESMStore& getStore() const;
00192 
00193             virtual std::vector<ESM::ESMReader>& getEsmReader();
00194 
00195             virtual LocalScripts& getLocalScripts();
00196 
00197             virtual bool hasCellChanged() const;
00199 
00200             virtual bool isCellExterior() const;
00201 
00202             virtual bool isCellQuasiExterior() const;
00203 
00204             virtual Ogre::Vector2 getNorthVector (CellStore* cell);
00206 
00207             virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out);
00209 
00210             virtual void getInteriorMapPosition (Ogre::Vector2 position, float& nX, float& nY, int &x, int& y);
00212 
00213             virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior);
00215 
00216             virtual Globals::Data& getGlobalVariable (const std::string& name);
00217 
00218             virtual Globals::Data getGlobalVariable (const std::string& name) const;
00219 
00220             virtual char getGlobalVariableType (const std::string& name) const;
00222 
00223             virtual std::vector<std::string> getGlobals () const;
00224 
00225             virtual std::string getCurrentCellName () const;
00226 
00227             virtual void removeRefScript (MWWorld::RefData *ref);
00228             //< Remove the script attached to ref from mLocalScripts
00229 
00230             virtual Ptr getPtr (const std::string& name, bool activeOnly);
00233 
00234             virtual Ptr getPtrViaHandle (const std::string& handle);
00236 
00237             virtual Ptr searchPtrViaHandle (const std::string& handle);
00239 
00240             virtual void adjustPosition (const Ptr& ptr);
00242 
00243             virtual void enable (const Ptr& ptr);
00244 
00245             virtual void disable (const Ptr& ptr);
00246 
00247             virtual void advanceTime (double hours);
00249 
00250             virtual void setHour (double hour);
00252 
00253             virtual void setMonth (int month);
00255 
00256             virtual void setDay (int day);
00258 
00259             virtual int getDay();
00260             virtual int getMonth();
00261 
00262             virtual TimeStamp getTimeStamp() const;
00264 
00265             virtual bool toggleSky();
00267 
00268             virtual void changeWeather (const std::string& region, unsigned int id);
00269 
00270             virtual int getCurrentWeather() const;
00271 
00272             virtual int getMasserPhase() const;
00273 
00274             virtual int getSecundaPhase() const;
00275 
00276             virtual void setMoonColour (bool red);
00277 
00278             virtual void modRegion(const std::string &regionid, const std::vector<char> &chances);
00279 
00280             virtual float getTimeScaleFactor() const;
00281 
00282             virtual void changeToInteriorCell (const std::string& cellName,
00283                 const ESM::Position& position);
00285 
00286             virtual void changeToExteriorCell (const ESM::Position& position);
00288 
00289             virtual const ESM::Cell *getExterior (const std::string& cellName) const;
00291 
00292             virtual void markCellAsUnchanged();
00293 
00294             virtual MWWorld::Ptr getFacedObject();
00296 
00300             virtual std::pair<MWWorld::Ptr,Ogre::Vector3> getHitContact(const MWWorld::Ptr &ptr, float distance);
00301 
00302             virtual void deleteObject (const Ptr& ptr);
00303 
00304             virtual void moveObject (const Ptr& ptr, float x, float y, float z);
00305             virtual void moveObject (const Ptr& ptr, CellStore &newCell, float x, float y, float z);
00306 
00307             virtual void scaleObject (const Ptr& ptr, float scale);
00308 
00311             virtual void rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust = false);
00312 
00313             virtual void localRotateObject (const Ptr& ptr, float x, float y, float z);
00314 
00315             virtual MWWorld::Ptr safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos);
00317 
00318             virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
00319                 const;
00321 
00322             virtual void positionToIndex (float x, float y, int &cellX, int &cellY) const;
00324 
00325             virtual void queueMovement(const Ptr &ptr, const Ogre::Vector3 &velocity);
00328 
00329             virtual bool castRay (float x1, float y1, float z1, float x2, float y2, float z2);
00331 
00332             virtual bool toggleCollisionMode();
00336 
00337             virtual bool toggleRenderMode (RenderMode mode);
00340 
00341             virtual const ESM::Potion *createRecord (const ESM::Potion& record);
00344 
00345             virtual const ESM::Spell *createRecord (const ESM::Spell& record);
00348 
00349             virtual const ESM::Class *createRecord (const ESM::Class& record);
00352 
00353             virtual const ESM::Cell *createRecord (const ESM::Cell& record);
00356 
00357             virtual const ESM::NPC *createRecord(const ESM::NPC &record);
00360 
00361             virtual const ESM::Armor *createRecord (const ESM::Armor& record);
00364 
00365             virtual const ESM::Weapon *createRecord (const ESM::Weapon& record);
00368 
00369             virtual const ESM::Clothing *createRecord (const ESM::Clothing& record);
00372 
00373             virtual const ESM::Enchantment *createRecord (const ESM::Enchantment& record);
00376 
00377             virtual const ESM::Book *createRecord (const ESM::Book& record);
00380 
00381             virtual void update (float duration, bool paused);
00382 
00383             virtual bool placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount);
00390 
00391             virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount);
00396 
00397             virtual bool canPlaceObject(float cursorX, float cursorY);
00399 
00400             virtual void processChangedSettings(const Settings::CategorySettingVector& settings);
00401 
00402             virtual bool isFlying(const MWWorld::Ptr &ptr) const;
00403             virtual bool isSlowFalling(const MWWorld::Ptr &ptr) const;
00405             virtual bool isSubmerged(const MWWorld::Ptr &object) const;
00406             virtual bool isSwimming(const MWWorld::Ptr &object) const;
00407             virtual bool isUnderwater(const MWWorld::Ptr::CellStore* cell, const Ogre::Vector3 &pos) const;
00408             virtual bool isOnGround(const MWWorld::Ptr &ptr) const;
00409 
00410             virtual void togglePOV() {
00411                 mRendering->togglePOV();
00412             }
00413 
00414             virtual void togglePreviewMode(bool enable) {
00415                 mRendering->togglePreviewMode(enable);
00416             }
00417 
00418             virtual bool toggleVanityMode(bool enable) {
00419                 return mRendering->toggleVanityMode(enable);
00420             }
00421 
00422             virtual void allowVanityMode(bool allow) {
00423                 mRendering->allowVanityMode(allow);
00424             }
00425 
00426             virtual void togglePlayerLooking(bool enable) {
00427                 mRendering->togglePlayerLooking(enable);
00428             }
00429 
00430             virtual void changeVanityModeScale(float factor) {
00431                 mRendering->changeVanityModeScale(factor);
00432             }
00433 
00434             virtual bool vanityRotateCamera(float * rot);
00435             virtual void setCameraDistance(float dist, bool adjust = false, bool override = true);
00436 
00437             virtual void setupPlayer();
00438             virtual void renderPlayer();
00439 
00440             virtual bool getOpenOrCloseDoor(const MWWorld::Ptr& door);
00442             virtual void activateDoor(const MWWorld::Ptr& door);
00444 
00445             virtual bool getPlayerStandingOn (const MWWorld::Ptr& object); 
00446             virtual bool getActorStandingOn (const MWWorld::Ptr& object); 
00447             virtual float getWindSpeed();
00448 
00449             virtual void getContainersOwnedBy (const MWWorld::Ptr& npc, std::vector<MWWorld::Ptr>& out);
00451             virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector<MWWorld::Ptr>& out);
00453 
00454             virtual bool getLOS(const MWWorld::Ptr& npc,const MWWorld::Ptr& targetNpc);
00456 
00457             virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable);
00458 
00459             virtual void setupExternalRendering (MWRender::ExternalRendering& rendering);
00460 
00461             virtual int canRest();
00467 
00469             virtual MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr);
00470 
00472             virtual void playVideo(const std::string& name, bool allowSkipping);
00473             virtual void stopVideo();
00474             virtual void frameStarted (float dt, bool paused);
00475 
00478             virtual bool findExteriorPosition(const std::string &name, ESM::Position &pos);
00479 
00482             virtual bool findInteriorPosition(const std::string &name, ESM::Position &pos);
00483 
00485             virtual void enableTeleporting(bool enable);
00486 
00488             virtual bool isTeleportingEnabled() const;
00489 
00491             virtual void enableLevitation(bool enable);
00492 
00494             virtual bool isLevitationEnabled() const;
00495 
00496             virtual void setWerewolf(const MWWorld::Ptr& actor, bool werewolf);
00497 
00498             virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor);
00499 
00500             virtual bool getGodModeState();
00501 
00502             virtual bool toggleGodMode();
00503 
00509             virtual bool startSpellCast (const MWWorld::Ptr& actor);
00510 
00515             virtual void castSpell (const MWWorld::Ptr& actor);
00516 
00517             virtual void launchProjectile (const std::string& id, bool stack, const ESM::EffectList& effects,
00518                                            const MWWorld::Ptr& actor, const std::string& sourceName);
00519 
00520             virtual void breakInvisibility (const MWWorld::Ptr& actor);
00521             // Are we in an exterior or pseudo-exterior cell and it's night?
00522             virtual bool isDark() const;
00523 
00524             virtual bool findInteriorPositionInWorldSpace(MWWorld::CellStore* cell, Ogre::Vector3& result);
00525 
00529             virtual void teleportToClosestMarker (const MWWorld::Ptr& ptr,
00530                                                   const std::string& id, Ogre::Vector3 worldPos);
00531 
00535             virtual void listDetectedReferences (const MWWorld::Ptr& ptr, std::vector<MWWorld::Ptr>& out,
00536                                                   DetectionType type);
00537     };
00538 }
00539 
00540 #endif