world.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. enum // block types, order matters!
  2. {
  3. SOLID = 0, // entirely solid cube [only specifies wtex]
  4. CORNER, // half full corner of a wall
  5. FHF, // floor heightfield using neighbour vdelta values
  6. CHF, // idem ceiling
  7. SPACE, // entirely empty cube
  8. SEMISOLID, // generated by mipmapping
  9. MAXTYPE
  10. };
  11. struct sqr
  12. {
  13. uchar type; // one of the above
  14. char floor, ceil; // height, in cubes
  15. uchar wtex, ftex, ctex; // wall/floor/ceil texture ids
  16. uchar r, g, b; // light value at upper left vertex
  17. uchar vdelta; // vertex delta, used for heightfield cubes
  18. char defer; // used in mipmapping, when true this cube is not a perfect mip
  19. char occluded; // true when occluded
  20. uchar utex; // upper wall tex id
  21. uchar tag; // used by triggers
  22. uchar visible; // temporarily used to flag the visibility of a cube (INVISWTEX, INVISUTEX, INVISIBLE)
  23. uchar reserved;
  24. };
  25. struct servsqr // server variant of sqr
  26. {
  27. uchar type; // SOLID, etc. (also contains the two tagclip bits ORed in)
  28. char floor, ceil; // height, in cubes
  29. uchar vdelta; // vertex delta, used for heightfield cubes
  30. };
  31. enum // hardcoded texture numbers
  32. {
  33. DEFAULT_SKY = 0,
  34. DEFAULT_LIQUID,
  35. DEFAULT_WALL,
  36. DEFAULT_FLOOR,
  37. DEFAULT_CEIL
  38. };
  39. enum // stuff encoded in sqr.tag
  40. {
  41. TAGTRIGGERMASK = 0x3F, // room for old fashioned cube 1 triggers
  42. TAGCLIP = 0x40, // clips all objects
  43. TAGPLCLIP = 0x80 // clips only players
  44. };
  45. #define TAGANYCLIP (TAGCLIP|TAGPLCLIP)
  46. enum
  47. {
  48. INVISWTEX = 1<<0,
  49. INVISUTEX = 1<<1,
  50. INVISIBLE = 1<<2
  51. };
  52. enum
  53. {
  54. MHF_AUTOMAPCONFIG = 1<<0, // autogenerate map-config during map save
  55. MHF_DISABLEWATERREFLECT = 1 << 8, // force waterreflect to zero
  56. MHF_LIMITWATERWAVEHEIGHT = 1 << 9, // limit waveheight to 0.1
  57. MHF_DISABLESTENCILSHADOWS = 1 << 10 // force stencilshadow to 0
  58. };
  59. #define MAPVERSION 10 // default map format version to be written (bump if map format changes, see worldio.cpp)
  60. struct header // map file format header
  61. {
  62. char head[4]; // "CUBE"
  63. int version; // any >8bit quantity is little endian
  64. int headersize; // sizeof(header)
  65. int sfactor; // in bits
  66. int numents;
  67. char maptitle[128];
  68. uchar texlists[3][256];
  69. int waterlevel;
  70. uchar watercolor[4];
  71. int maprevision;
  72. int ambient;
  73. int flags; // MHF_*
  74. int timestamp; // UTC unixtime of time of save (yes, this will break in 2038)
  75. int reserved[10];
  76. //char mediareq[128]; // version 7 and 8 only.
  77. };
  78. struct mapsoundline { string name; int maxuses; };
  79. struct _mapconfigdata
  80. {
  81. string notexturename;
  82. vector<mapsoundline> mapsoundlines;
  83. void clear()
  84. {
  85. *notexturename = '\0';
  86. mapsoundlines.shrink(0);
  87. }
  88. };
  89. struct mapstats
  90. {
  91. struct header hdr;
  92. int entcnt[MAXENTTYPES];
  93. int cgzsize;
  94. uchar *enttypes;
  95. short *entposs;
  96. int spawns[3];
  97. int flags[2];
  98. int flagents[2];
  99. bool hasffaspawns;
  100. bool hasteamspawns;
  101. bool hasflags;
  102. };
  103. struct mapdim_s
  104. { // 0 2 1 3 6 7
  105. int x1, x2, y1, y2, minfloor, maxceil; // outer borders (points to last used cube)
  106. // 4 5
  107. int xspan, yspan; // size of area between x1|y1 and x2|y2
  108. float xm, ym; // middle of the map
  109. };
  110. #define MAS_VDELTA_QUANT 8
  111. #define MAS_VDELTA_TABSIZE 5 // (hardcoded maximum of 15!)
  112. #define MAS_VDELTA_THRES 3
  113. #define MAS_GRID 8
  114. #define MAS_GRID2 (MAS_GRID * MAS_GRID)
  115. #define MAS_RESOLUTION 32 // rays (32 * 8)
  116. struct mapareastats_s
  117. {
  118. int vdd[MAS_VDELTA_TABSIZE]; // vdelta-deltas (detect ugly steep heightfields)
  119. int vdds; // vdd table reduced to an easy to check bitmask
  120. int ppa[MAS_GRID2]; // area visible per probe point
  121. int ppv[MAS_GRID2]; // volume visible per probe point
  122. int total; // number of non-solid cubes on the map
  123. int rest; // area not visible from any probe point
  124. #ifndef STANDALONE
  125. int steepest; // location of steepest vdelta
  126. int ppp[MAS_GRID2]; // probe point position (client-only)
  127. #endif
  128. };
  129. #define SWS(w,x,y,s) (&(w)[((y)<<(s))+(x)])
  130. #define SW(w,x,y) SWS(w,x,y,sfactor)
  131. #define S(x,y) SW(world,x,y) // convenient lookup of a lowest mip cube
  132. #define SMALLEST_FACTOR 6 // determines number of mips there can be
  133. #define DEFAULT_FACTOR 8
  134. #define LARGEST_FACTOR 11 // 10 is already insane
  135. #define MAXENTITIES 65535
  136. #define MAXHEADEREXTRA (1<<20)
  137. #define SOLID(x) ((x)->type==SOLID)
  138. #define MINBORD 2 // 2 cubes from the edge of the world are always solid
  139. #define OUTBORD(x,y) ((x)<MINBORD || (y)<MINBORD || (x)>=ssize-MINBORD || (y)>=ssize-MINBORD)
  140. #define OUTBORDRAD(x,y,rad) (int(x-rad)<MINBORD || int(y-rad)<MINBORD || int(x+rad)>=ssize-MINBORD || (y+rad)>=ssize-MINBORD)
  141. #define WATERLEVELSCALING 10
  142. struct block { int x, y, xs, ys, h; short p[5]; };
  143. // vertex array format
  144. struct vertex { float u, v, x, y, z; uchar r, g, b, a; };
  145. // map statistics
  146. #define MINSPAWNS 5 // minimum number of spawns per team
  147. #define MINFLAGDISTANCE 42 // minimum flag entity distance (2D)
  148. struct entitystats_s
  149. {
  150. int entcnt[MAXENTTYPES]; // simple count for every basic ent type
  151. int spawns[3]; // number of spawns with valid attr2
  152. int flags[2]; // number of flags with valid attr2
  153. int flagents[2]; // entity indices of the flag ents
  154. int pickups; // total number of pickup entities
  155. int pickupdistance[LARGEST_FACTOR + 1]; // entity distance values grouped logarithmically
  156. int flagentdistance; // distance of the two flag entities, if existing
  157. int modes_possible; // bitmask of possible gamemodes, depending on flag and spawn entities
  158. bool hasffaspawns; // has enough ffa spawns
  159. bool hasteamspawns; // has enough team spawns
  160. bool hasflags; // has exactly 2 valid flags
  161. int unknownspawns, unknownflags; // attr2 is not valid
  162. int firstclip; // index of first clipped entity
  163. short first[MAXENTTYPES], last[MAXENTTYPES]; // first and last occurence of every basic ent type
  164. };
  165. // legacy
  166. #define MAXMHEIGHT 30
  167. #define MAXMAREA 10000
  168. #define MAXHHITS 50000 // was 6000, which denied my fav. maps - jamz, 2012-06-12; 15000 denies sane map too - lucas
  169. #define MINFF 2500