CurrentMap.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2007 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 CURRENTMAP_H
00020 #define CURRENTMAP_H
00021 
00022 #include <list>
00023 #include "intrinsics.h"
00024 
00025 class Map;
00026 class Item;
00027 class UCList;
00028 class TeleportEgg;
00029 class EggHatcherProcess;
00030 class IDataSource;
00031 class ODataSource;
00032 
00033 #define MAP_NUM_CHUNKS  64
00034 
00035 class CurrentMap
00036 {
00037         friend class World;
00038 public:
00039         CurrentMap();
00040         ~CurrentMap();
00041 
00042         void clear();
00043         void writeback();
00044         void loadMap(Map* map);
00045 
00048         void setMap(Map* map) { current_map = map; }
00049 
00051         uint32 getNum() const;
00052 
00053         unsigned int getChunkSize() const { return mapChunkSize; }
00054 
00056         void addItem(Item* item);
00057 
00059         void addItemToEnd(Item* item);
00060 
00061         void removeItemFromList(Item* item, sint32 oldx, sint32 oldy);
00062         void removeItem(Item* item);
00063 
00065         void updateFastArea(sint32 from_x, sint32 from_y, sint32 from_z, sint32 to_x, sint32 to_y, sint32 to_z);
00066 
00077         void areaSearch(UCList* itemlist, const uint8* loopscript,
00078                                         uint32 scriptsize, Item* item, uint16 range, bool recurse,
00079                                         sint32 x=0, sint32 y=0);
00080 
00081         // Surface search: Search above and below an item.
00082         void surfaceSearch(UCList* itemlist, const uint8* loopscript,
00083                                         uint32 scriptsize, Item* item, bool above, bool below,
00084                                         bool recurse=false);
00085 
00086         // Surface search: Search above and below an item.
00087         void surfaceSearch(UCList* itemlist, const uint8* loopscript,
00088                                         uint32 scriptsize, ObjId id,
00089                                         sint32 origin[3], sint32 dims[2],
00090                                         bool above, bool below, bool recurse=false);
00091 
00092         // Collision detection. Returns true if the box [x,y,z]-[x-xd,y-yd,z+zd]
00093         // does not collide with any solid items.
00094         // Additionally, if support is not NULL, *support is set to the item
00095         // supporting the given box, or 0 if it isn't supported.
00096         // If under_roof is not NULL, *roof is set to the roof item with the lowest
00097         // z coordinate that's over the box, or 0 if there is no roof above box.
00098         // Ignores collisions which were already occurring at the start position.
00099         // NB: isValidPosition doesn't consider item 'item'.
00100         bool isValidPosition(sint32 x, sint32 y, sint32 z,
00101                                                  sint32 startx, sint32 starty, sint32 startz,
00102                                                  int xd, int yd, int zd, uint32 shapeflags,
00103                                                  ObjId item,
00104                                                  Item** support=0, ObjId* roof=0);
00105 
00106         // Note that this version of isValidPosition does not look for start
00107         // position collisions.
00108         bool isValidPosition(sint32 x, sint32 y, sint32 z,
00109                                                  int xd, int yd, int zd, uint32 shapeflags,
00110                                                  ObjId item,
00111                                                  Item** support=0, ObjId* roof=0);
00112 
00113         // Note that this version of isValidPosition can not take 'flipped'
00114         // into account!
00115         bool isValidPosition(sint32 x, sint32 y, sint32 z, uint32 shape,
00116                                                  ObjId item, Item** support=0, ObjId* roof=0);
00117 
00119         bool scanForValidPosition(sint32 x, sint32 y, sint32 z, Item* item,
00120                                                           int movedir, bool wantsupport,
00121                                                           sint32& tx, sint32& ty, sint32& tz);
00122 
00123         struct SweepItem {
00124                 SweepItem(ObjId it, sint32 ht, sint32 et, bool touch,
00125                                   bool touchfloor, bool block)
00126                         : item(it), hit_time(ht), end_time(et), touching(touch),
00127                           touching_floor(touchfloor), blocking(block) { }
00128 
00129                 ObjId   item;           // Item that was hit
00130 
00131                 //
00132                 // The time values here are 'normalized' fixed point values
00133                 // They range from 0 for the start of the move to 0x4000 for the end of
00134                 // The move.
00135                 //
00136                 // Linear interpolate between the start and end positions using
00137                 // hit_time to find where the moving item was when the hit occurs
00138                 //
00139 
00140                 sint32  hit_time;       // if -1, already hitting when sweep started. 
00141                 sint32  end_time;       // if 0x4000, still hitting when sweep finished
00142 
00143                 bool    touching;       // We are only touching (don't actually overlap)
00144                 bool    touching_floor; // touching and directly below the moving item
00145 
00146                 bool    blocking;       // This item blocks the moving item
00147 
00148                 // Use this func to get the interpolated location of the hit
00149                 void GetInterpolatedCoords(sint32 out[3], sint32 start[3], sint32 end[3])
00150                 {
00151                         for (int i = 0; i < 3; i++)
00152                                 out[i] = start[i] + ((end[i]-start[i])*(hit_time>=0?hit_time:0)+(end[i] > start[i] ? 0x2000 : -0x2000) )/0x4000;
00153                 }
00154         };
00155 
00168         bool sweepTest(const sint32 start[3], const sint32 end[3],
00169                                    const sint32 dims[3], uint32 shapeflags,
00170                                    ObjId item, bool solid_only, std::list<SweepItem> *hit);
00171 
00172         TeleportEgg* findDestination(uint16 id);
00173 
00174         // Not allowed to modify the list. Remember to use const_iterator
00175         const std::list<Item*>* getItemList (sint32 gx, sint32 gy)
00176         {
00177                 // CONSTANTS!
00178                 if (gx < 0 || gy < 0 || gx >= MAP_NUM_CHUNKS || gy >= MAP_NUM_CHUNKS) 
00179                         return 0;
00180                 return &items[gx][gy];
00181         }
00182 
00183         bool isChunkFast(sint32 cx, sint32 cy)
00184         {
00185                 // CONSTANTS!
00186                 if (cx < 0 || cy < 0 || cx >= MAP_NUM_CHUNKS || cy >= MAP_NUM_CHUNKS) 
00187                         return false;
00188                 return (fast[cy][cx/32]&(1<<(cx&31))) != 0;
00189         }
00190 
00191         // A simple trace to find the top item at a specific xy point
00192         Item *traceTopItem(sint32 x, sint32 y, sint32 ztop, sint32 zbot, ObjId ignore, uint32 shflags);
00193 
00194         // Set the entire map as being 'fast' 
00195         void setWholeMapFast();
00196 
00197         void save(ODataSource* ods);
00198         bool load(IDataSource* ids, uint32 version);
00199 
00200         INTRINSIC(I_canExistAt);
00201 
00202 private:
00203         void loadItems(std::list<Item*> itemlist, bool callCacheIn);
00204         void createEggHatcher();
00205 
00206         Map* current_map;
00207 
00208         // item lists. Lots of them :-)
00209         // items[x][y]
00210         std::list<Item*>** items;
00211 
00212         ProcId egghatcher;
00213 
00214         // Fast area bit masks -> fast[ry][rx/32]&(1<<(rx&31));
00215         uint32** fast;  
00216         sint32 fast_x_min, fast_y_min, fast_x_max, fast_y_max;
00217 
00218         int mapChunkSize;
00219 
00220         void setChunkFast(sint32 cx, sint32 cy);
00221         void unsetChunkFast(sint32 cx, sint32 cy);
00222 };
00223 
00224 #endif

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