1 /* 2 ** p_terrain.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 1998-2006 Randy Heit 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 */ 33 34 #ifndef __P_TERRAIN_H__ 35 #define __P_TERRAIN_H__ 36 37 #include "s_sound.h" 38 #include "textures/textures.h" 39 40 struct PClass; 41 42 extern WORD DefaultTerrainType; 43 44 45 class FTerrainTypeArray 46 { 47 public: 48 TArray<WORD> Types; 49 50 WORD operator [](FTextureID tex) const 51 { 52 if ((unsigned)tex.GetIndex() >= Types.Size()) return DefaultTerrainType; 53 WORD type = Types[tex.GetIndex()]; 54 return type == 0xffff? DefaultTerrainType : type; 55 } 56 WORD operator [](int texnum) const 57 { 58 if ((unsigned)texnum >= Types.Size()) return DefaultTerrainType; 59 WORD type = Types[texnum]; 60 return type == 0xffff? DefaultTerrainType : type; 61 } Resize(unsigned newsize)62 void Resize(unsigned newsize) 63 { 64 Types.Resize(newsize); 65 } Clear()66 void Clear() 67 { 68 memset (&Types[0], 0xff, Types.Size()*sizeof(WORD)); 69 } Set(int index,int value)70 void Set(int index, int value) 71 { 72 if ((unsigned)index >= Types.Size()) 73 { 74 int oldsize = Types.Size(); 75 Resize(index + 1); 76 memset(&Types[oldsize], 0xff, (index + 1 - oldsize)*sizeof(WORD)); 77 } 78 Types[index] = value; 79 } 80 }; 81 82 extern FTerrainTypeArray TerrainTypes; 83 84 // at game start 85 void P_InitTerrainTypes (); 86 87 struct FSplashDef 88 { 89 FName Name; 90 FSoundID SmallSplashSound; 91 FSoundID NormalSplashSound; 92 const PClass *SmallSplash; 93 const PClass *SplashBase; 94 const PClass *SplashChunk; 95 BYTE ChunkXVelShift; 96 BYTE ChunkYVelShift; 97 BYTE ChunkZVelShift; 98 fixed_t ChunkBaseZVel; 99 fixed_t SmallSplashClip; 100 bool NoAlert; 101 }; 102 103 struct FTerrainDef 104 { 105 FName Name; 106 int Splash; 107 int DamageAmount; 108 FName DamageMOD; 109 int DamageTimeMask; 110 fixed_t FootClip; 111 float StepVolume; 112 int WalkStepTics; 113 int RunStepTics; 114 FSoundID LeftStepSound; 115 FSoundID RightStepSound; 116 bool IsLiquid; 117 bool AllowProtection; 118 fixed_t Friction; 119 fixed_t MoveFactor; 120 }; 121 122 extern TArray<FSplashDef> Splashes; 123 extern TArray<FTerrainDef> Terrains; 124 125 class FArchive; 126 int P_FindTerrain(FName name); 127 void P_SerializeTerrain(FArchive &arc, int &terrainnum); 128 129 #endif //__P_TERRAIN_H__ 130