29 #include "common/memstream.h" 30 #include "saga2/fta.h" 31 #include "saga2/tileload.h" 32 #include "saga2/annoy.h" 33 #include "saga2/terrain.h" 34 #include "saga2/property.h" 35 #include "saga2/tcoords.h" 44 typedef TileBank *TileBankPtr;
47 inline TileID makeTileID(
int bank,
int num) {
48 return (TileID)((bank << 10) | num);
51 inline void TileID2Bank(TileID t, int16 &bank, int16 &num) {
52 bank = (int16)(t >> 10);
53 num = (int16)(t & 0x3ff);
63 inline int16 calcSubTileMask(
int u,
int v) {
64 return (int16)(1 << ((u << 2) + v));
96 uint8 cornerHeight[4];
106 int32 testTerrain(int16 mask) {
109 if (terrainMask & mask) terrain |= (1 << fgdTerrain);
110 if (~terrainMask & mask) terrain |= (1 << bgdTerrain);
117 kTileInGroup = (1 << 0),
121 kTileAutoGroup = (1 << 1),
124 kTileWalkSense = (1 << 2),
127 kTileModified = (1 << 3)
158 kTerrainNormal = (1 << kTerrNumNormal),
159 kTerrainEasy = (1 << kTerrNumEasy),
160 kTerrainRough = (1 << kTerrNumRough),
161 kTerrainStone = (1 << kTerrNumStone),
162 kTerrainWood = (1 << kTerrNumWood),
163 kTerrainHedge = (1 << kTerrNumHedge),
164 kTerrainTree = (1 << kTerrNumTree),
165 kTerrainWater = (1 << kTerrNumWater),
166 kTerrainFall = (1 << kTerrNumFall),
167 kTerrainRamp = (1 << kTerrNumRamp),
168 kTerrainStair = (1 << kTerrNumStair),
169 kTerrainLadder = (1 << kTerrNumLadder),
170 kTerrainObject = (1 << kTerrNumObject),
171 kTerrainActive = (1 << kTerrNumActive),
172 kTerrainSlash = (1 << kTerrNumSlash),
173 kTerrainBash = (1 << kTerrNumBash),
174 kTerrainIce = (1 << kTerrNumIce),
175 kTerrainCold = (1 << kTerrNumCold),
176 kTerrainHot = (1 << kTerrNumHot),
177 kTerrainFurniture = (1 << kTerrNumFurniture)
183 const int kTerrainSurface = kTerrainNormal
191 const int kTerrainSolidSurface
202 const int kTerrainRaised = kTerrainStone
208 const int kTerrainSupportingRaised = kTerrainStone
212 const int kTerrainImpassable = kTerrainStone
218 const int kTerrainSlow = kTerrainRough
222 const int kTerrainAverage = kTerrainNormal
226 const int kTerrainInsubstantial = kTerrainFall
231 const int kTerrainTransparent = kTerrainSurface
232 | kTerrainInsubstantial;
243 int32 combinedTerrainMask() {
244 return (1 << attrs.fgdTerrain) | (1 << attrs.bgdTerrain);
248 return tileProp.operator()(
this);
251 static TileInfo *tileAddress(TileID
id);
252 static TileInfo *tileAddress(TileID
id, uint8 **imageData);
266 _tileArray =
nullptr;
273 return &_tileArray[index];
290 kTrTileTAG = (1 << 0),
291 kTrTileHidden = (1 << 1),
292 kTrTileFlipped = (1 << 2),
293 kTrTileSensitive = (1 << 3)
298 void drawMainDisplay();
313 TileID _cycleList[16];
322 for (
int i = 0; i < 16; ++i)
330 const int kMaxCycleRanges = 128;
337 enum ActiveItemTypes {
338 kActiveTypeGroup = 0,
343 extern byte **stateArray;
349 #include "common/pack-start.h" 352 uint32 nextHashDummy;
353 uint16 scriptClassID;
354 uint16 associationOffset;
355 uint8 numAssociations;
386 #include "common/pack-end.h" 396 kActiveItemLocked = (1 << 8),
397 kActiveItemOpen = (1 << 9),
398 kActiveItemExclusive = (1 << 10)
417 assert(_data.itemType == kActiveTypeInstance);
418 return activeItemAddress(
ActiveItemID(getMapNum(), _data.instance.groupID));
421 enum BuiltInBehaviorType {
429 uint8 getInstanceState(int16 mapNum) {
430 return stateArray[mapNum][_data.instance.stateIndex];
434 void setInstanceState(int16 mapNum, uint8 state) {
435 stateArray[mapNum][_data.instance.stateIndex] = state;
438 uint8 builtInBehavior() {
439 return (uint8)(_data.instance.scriptFlags >> 13);
444 return (
bool)(_data.instance.scriptFlags & kActiveItemLocked);
446 void setLocked(
bool val) {
448 _data.instance.scriptFlags |= kActiveItemLocked;
450 _data.instance.scriptFlags &= ~kActiveItemLocked;
455 return (
bool)(_data.instance.scriptFlags & kActiveItemExclusive);
457 void setExclusive(
bool val) {
459 _data.instance.scriptFlags |= kActiveItemExclusive;
461 _data.instance.scriptFlags &= ~kActiveItemExclusive;
465 return (uint8)_data.instance.scriptFlags;
469 bool use(ObjectID enactor);
470 bool trigger(ObjectID enactor, ObjectID objID);
471 bool release(ObjectID enactor, ObjectID objID);
472 bool acceptLockToggle(ObjectID enactor, uint8 keyCode);
474 bool inRange(
const TilePoint &loc, int16 range);
478 bool trigger(
ActiveItem *ins, ObjectID enactor, ObjectID objID);
479 bool release(
ActiveItem *ins, ObjectID enactor, ObjectID objID);
480 bool acceptLockToggle(
ActiveItem *ins, ObjectID enactor, uint8 keyCode);
483 return loc.u >= ins->_data.instance.u - range
484 && loc.v >= ins->_data.instance.v - range
485 && loc.u < ins->_data.instance.u + _data.group.uSize + range
486 && loc.v < ins->_data.instance.v + _data.group.vSize + range;
489 ObjectID getInstanceContext();
492 static void playTAGNoise(
ActiveItem *ai, int16 tagNoiseID);
525 XArray<Point16> _vertexList;
528 return activeTypeHitZone;
537 return activeTypeObjectType;
543 TileGroupID _classID;
551 return activeTypeObject;
590 static void openDoor(
ActiveItem &activeInstance);
591 static void closeDoor(
ActiveItem &activeInstance);
592 static void doScript(
ActiveItem &activeInstance, uint8 finalState, ThreadID
id);
594 static void updateActiveItems();
596 static void initTileActivityTasks();
599 static bool setWait(
ActiveItem *tai, ThreadID script);
628 void moveActiveTerrain(int32 deltaTime);
636 ActiveItemPtr surfaceTAG;
645 const int kMaxPlatforms = 8;
651 TileRef tiles[kPlatformWidth][kPlatformWidth];
658 for (
int j = 0; j < kPlatformWidth; ++j) {
659 for (
int i = 0; i < kPlatformWidth; ++i) {
661 tiles[j][i].flags = stream->
readByte();
662 tiles[j][i].tileHeight = stream->
readByte();
668 return tiles[p.u][p.v];
671 TileRef &getTileRef(int16 u, int16 v) {
706 return (uint16)(flags & 0x0FFF);
714 kPlCutaway = (1 << 0),
718 kPlVisible = (1 << 15),
719 kPlModified = (1 << 14),
720 kPlCutUPos = (1 << 13),
721 kPlCutUNeg = (1 << 13),
722 kPlCutVPos = (1 << 13),
723 kPlCutVNeg = (1 << 13)
728 kPlCutaway = (1 << 0),
733 kPlCutUPos = (1 << 1),
734 kPlCutUNeg = (1 << 2),
735 kPlCutVPos = (1 << 3),
736 kPlCutVNeg = (1 << 4),
738 kPlVisible = (1 << 5),
739 kPlEnabled = (1 << 6)
754 kPlatformCacheSize = 256
764 typedef int16 RipTableID;
769 int16 zTable[kPlatformWidth][kPlatformWidth];
777 RipTable() : metaID(NoMetaTile), ripID(0), _index(-1) {
778 for (
int i = 0; i < kPlatformWidth; i++)
779 for (
int j = 0; j < kPlatformWidth; j++)
784 static RipTable *ripTableAddress(RipTableID
id);
791 typedef RipTableID *RipTableIDPtr,
794 typedef uint16 metaTileNoise;
806 uint16 _highestPixel;
808 uint16 _stack[kMaxPlatforms];
822 Platform *fetchPlatform(int16 mapNum, int16 index);
829 RipTableID &ripTableID(int16 mapNum);
831 metaTileNoise HeavyMetaMusic();
837 return metaTileProp(
this, mapNum, mCoords);
881 const uint16 kMetaTileVisited = (1 << 15);
888 TileRefPtr activeItemData;
891 RipTableIDPtr ripTableIDList;
902 MetaTilePtr lookupMeta(
TilePoint coords);
905 void buildInstanceHash();
926 _region.min.u = reg.min.u >> kPlatShift;
927 _region.max.u = (reg.max.u + kPlatMask) >> kPlatShift;
928 _region.min.v = reg.min.v >> kPlatShift;
929 _region.max.v = (reg.max.v + kPlatMask) >> kPlatShift;
930 _region.min.z = _region.max.z = 0;
959 _metaIter(mapNum, reg),
978 extern uint16 rippedRoofID;
990 void setCurrentMap(
int mapNum);
993 void initPlatformCache();
996 void initTileTasks();
1002 void cleanupTileTasks();
1006 void initActiveItemStates();
1009 void cleanupActiveItemStates();
1011 void initTileCyclingStates();
1014 void cleanupTileCyclingStates();
1019 inline void cleanupAutoMap() { }
1022 inline bool platformRipped(
Platform *pl) {
1023 if (rippedRoofID != 0)
1024 return pl->roofRipID() == rippedRoofID;
1035 int16 ptHeight(
const TilePoint &tp, uint8 *cornerHeight);
1068 ActiveItemPtr *pickTAI = NULL);
1076 bool offScreenOnly =
false);
uint16 readUint16LE()
Definition: stream.h:459
Definition: objproto.h:105
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: savefile.h:54
Definition: idtypes.h:124
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: tcoords.h:222
byte readByte()
Definition: stream.h:434
Definition: objects.h:118
Definition: tileload.h:41
Definition: property.h:45