00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00082 void surfaceSearch(UCList* itemlist, const uint8* loopscript,
00083 uint32 scriptsize, Item* item, bool above, bool below,
00084 bool recurse=false);
00085
00086
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
00093
00094
00095
00096
00097
00098
00099
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
00107
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
00114
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;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 sint32 hit_time;
00141 sint32 end_time;
00142
00143 bool touching;
00144 bool touching_floor;
00145
00146 bool blocking;
00147
00148
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
00175 const std::list<Item*>* getItemList (sint32 gx, sint32 gy)
00176 {
00177
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
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
00192 Item *traceTopItem(sint32 x, sint32 y, sint32 ztop, sint32 zbot, ObjId ignore, uint32 shflags);
00193
00194
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
00209
00210 std::list<Item*>** items;
00211
00212 ProcId egghatcher;
00213
00214
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