World.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef WORLD_H
00020 #define WORLD_H
00021 
00022 // the main world class.
00023 
00024 // Current ideas on how to store the game world: (-wjp)
00025 
00026 // World contains Map objects. All Map objects are initialized when
00027 //  starting/loading a game.
00028 
00029 // Each Map permanently contains the nonfixed objects in that map,
00030 //  ( These objects don't have to be assigned object IDs here, I think )
00031 
00032 // When a Map is loaded, it loads the fixed objects from disk.
00033 // All objects in the active map will also have to be assigned object IDs.
00034 //  NB: This has to happen in such a way that when a game is loaded the IDs can
00035 //  be reproduced exactly. (Since running usecode scripts can contain objIDs)
00036 // The first N objIDs will probably be reserved from NPCs (and inventories?)
00037 // After that, for example, the fixed objects could be loaded (in disk-order),
00038 // followed by assigning IDs to the (already loaded) dynamic items.
00039 //  (in basic depth-first order, I would guess)
00040 
00041 // NPCs will also have to be stored somewhere. We could keep them in Map #0
00042 // like the original.
00043 // Q: Is the avatar's inventory stored in npcdata?
00044 // Q: Is the number of objIDs reserved for npcdata fixed?
00045 
00046 // World also has to have the necessary save/load functions. (Which will
00047 //  mostly consist of calls to the save/load functions of the Map objects.)
00048 
00049 // Fixed objects could be kept cached in for better performance, or
00050 // swapped out for memory.
00051 
00052 // A clear/reset function would also be useful. (All singletons that store
00053 //  game data need this, actually.)
00054 
00055 #include <vector>
00056 #include <list>
00057 
00058 class Map;
00059 class CurrentMap;
00060 class IDataSource;
00061 class ODataSource;
00062 class Actor;
00063 class MainActor;
00064 class Flex;
00065 class Item;
00066 
00067 class World
00068 {
00069 public:
00070         World();
00071         ~World();
00072 
00073         static World* get_instance() { return world; }
00074 
00076         void clear();
00077 
00079         void reset();
00080 
00082         void initMaps();
00083 
00085         void loadNonFixed(IDataSource* ds); // delete ds afterwards
00086 
00088         void loadItemCachNPCData(IDataSource* itemcach, IDataSource* npcdata);
00089 
00091         CurrentMap* getCurrentMap() const { return currentmap; }
00092 
00096         bool switchMap(uint32 newmap);
00097 
00099         void etherealPush(ObjId objid) { ethereal.push_front(objid); }
00100 
00102         bool etherealEmpty() { return ethereal.empty(); }
00103 
00105         ObjId etherealPeek() { return ethereal.front(); }
00106 
00108         void etherealRemove(ObjId objid) { ethereal.remove(objid); }
00109 
00111         void worldStats();
00112 
00114         void saveMaps(ODataSource* ods);
00115 
00117         bool loadMaps(IDataSource* ids, uint32 version);
00118 
00120         void save(ODataSource* ods);
00121 
00123         bool load(IDataSource* ids, uint32 version);
00124 
00125 private:
00126         static World *world;
00127 
00128         std::vector<Map*> maps;
00129         CurrentMap* currentmap;
00130 
00131         std::list<ObjId> ethereal;
00132 };
00133 
00134 #endif

Generated on Fri Jul 27 22:27:53 2007 for pentagram by  doxygen 1.4.7