bg_local.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. // g_local.h -- local definitions for game module
  4. #pragma once
  5. #include "q_std.h"
  6. // define GAME_INCLUDE so that game.h does not define the
  7. // short, server-visible gclient_t and edict_t structures,
  8. // because we define the full size ones in this file
  9. #define GAME_INCLUDE
  10. #include "game.h"
  11. //
  12. // p_move.c
  13. //
  14. struct pm_config_t
  15. {
  16. int32_t airaccel = 0;
  17. bool n64_physics = false;
  18. };
  19. extern pm_config_t pm_config;
  20. void Pmove(pmove_t *pmove);
  21. using pm_trace_func_t = trace_t(const vec3_t &start, const vec3_t &mins, const vec3_t &maxs, const vec3_t &end);
  22. using pm_trace_t = std::function<pm_trace_func_t>;
  23. void PM_StepSlideMove_Generic(vec3_t &origin, vec3_t &velocity, float frametime, const vec3_t &mins, const vec3_t &maxs, touch_list_t &touch, bool has_time, pm_trace_t trace);
  24. enum class stuck_result_t
  25. {
  26. GOOD_POSITION,
  27. FIXED,
  28. NO_GOOD_POSITION
  29. };
  30. using stuck_object_trace_fn_t = trace_t(const vec3_t &, const vec3_t &, const vec3_t &, const vec3_t &);
  31. stuck_result_t G_FixStuckObject_Generic(vec3_t &origin, const vec3_t &own_mins, const vec3_t &own_maxs, std::function<stuck_object_trace_fn_t> trace);
  32. // state for coop respawning; used to select which
  33. // message to print for the player this is set on.
  34. enum coop_respawn_t
  35. {
  36. COOP_RESPAWN_NONE, // no messagee
  37. COOP_RESPAWN_IN_COMBAT, // player is in combat
  38. COOP_RESPAWN_BAD_AREA, // player not in a good spot
  39. COOP_RESPAWN_BLOCKED, // spawning was blocked by something
  40. COOP_RESPAWN_WAITING, // for players that are waiting to respawn
  41. COOP_RESPAWN_NO_LIVES, // out of lives, so need to wait until level switch
  42. COOP_RESPAWN_TOTAL
  43. };
  44. // reserved general CS ranges
  45. enum
  46. {
  47. CONFIG_CTF_MATCH = CS_GENERAL,
  48. CONFIG_CTF_TEAMINFO,
  49. CONFIG_CTF_PLAYER_NAME,
  50. CONFIG_CTF_PLAYER_NAME_END = CONFIG_CTF_PLAYER_NAME + MAX_CLIENTS,
  51. // nb: offset by 1 since NONE is zero
  52. CONFIG_COOP_RESPAWN_STRING,
  53. CONFIG_COOP_RESPAWN_STRING_END = CONFIG_COOP_RESPAWN_STRING + (COOP_RESPAWN_TOTAL - 1),
  54. // [Paril-KEX] if 1, n64 player physics apply
  55. CONFIG_N64_PHYSICS,
  56. CONFIG_HEALTH_BAR_NAME, // active health bar name
  57. CONFIG_STORY,
  58. CONFIG_LAST
  59. };
  60. static_assert(CONFIG_LAST <= CS_GENERAL + MAX_GENERAL);
  61. // ammo IDs
  62. enum ammo_t : uint8_t
  63. {
  64. AMMO_BULLETS,
  65. AMMO_SHELLS,
  66. AMMO_ROCKETS,
  67. AMMO_GRENADES,
  68. AMMO_CELLS,
  69. AMMO_SLUGS,
  70. // RAFAEL
  71. AMMO_MAGSLUG,
  72. AMMO_TRAP,
  73. // RAFAEL
  74. // ROGUE
  75. AMMO_FLECHETTES,
  76. AMMO_TESLA,
  77. AMMO_DISRUPTOR,
  78. AMMO_PROX,
  79. // ROGUE
  80. AMMO_MAX
  81. };
  82. // powerup IDs
  83. enum powerup_t : uint8_t
  84. {
  85. POWERUP_SCREEN,
  86. POWERUP_SHIELD,
  87. POWERUP_AM_BOMB,
  88. POWERUP_QUAD,
  89. POWERUP_QUADFIRE,
  90. POWERUP_INVULNERABILITY,
  91. POWERUP_INVISIBILITY,
  92. POWERUP_SILENCER,
  93. POWERUP_REBREATHER,
  94. POWERUP_ENVIROSUIT,
  95. POWERUP_ADRENALINE,
  96. POWERUP_IR_GOGGLES,
  97. POWERUP_DOUBLE,
  98. POWERUP_SPHERE_VENGEANCE,
  99. POWERUP_SPHERE_HUNTER,
  100. POWERUP_SPHERE_DEFENDER,
  101. POWERUP_DOPPELGANGER,
  102. POWERUP_FLASHLIGHT,
  103. POWERUP_COMPASS,
  104. POWERUP_TECH1,
  105. POWERUP_TECH2,
  106. POWERUP_TECH3,
  107. POWERUP_TECH4,
  108. POWERUP_MAX
  109. };
  110. // ammo stats compressed in 9 bits per entry
  111. // since the range is 0-300
  112. constexpr size_t BITS_PER_AMMO = 9;
  113. template<typename TI>
  114. constexpr size_t num_of_type_for_bits(size_t num_bits)
  115. {
  116. return (num_bits + (sizeof(TI) * 8) - 1) / ((sizeof(TI) * 8) + 1);
  117. }
  118. template<size_t bits_per_value>
  119. constexpr void set_compressed_integer(uint16_t *start, uint8_t id, uint16_t count)
  120. {
  121. uint16_t bit_offset = bits_per_value * id;
  122. uint16_t byte = bit_offset / 8;
  123. uint16_t bit_shift = bit_offset % 8;
  124. uint16_t mask = (bit_v<bits_per_value> - 1) << bit_shift;
  125. uint16_t *base = (uint16_t *) ((uint8_t *) start + byte);
  126. *base = (*base & ~mask) | ((count << bit_shift) & mask);
  127. }
  128. template<size_t bits_per_value>
  129. constexpr uint16_t get_compressed_integer(uint16_t *start, uint8_t id)
  130. {
  131. uint16_t bit_offset = bits_per_value * id;
  132. uint16_t byte = bit_offset / 8;
  133. uint16_t bit_shift = bit_offset % 8;
  134. uint16_t mask = (bit_v<bits_per_value> - 1) << bit_shift;
  135. uint16_t *base = (uint16_t *) ((uint8_t *) start + byte);
  136. return (*base & mask) >> bit_shift;
  137. }
  138. constexpr size_t NUM_BITS_FOR_AMMO = 9;
  139. constexpr size_t NUM_AMMO_STATS = num_of_type_for_bits<uint16_t>(NUM_BITS_FOR_AMMO * AMMO_MAX);
  140. // if this value is set on an STAT_AMMO_INFO_xxx, don't render ammo
  141. constexpr uint16_t AMMO_VALUE_INFINITE = bit_v<NUM_BITS_FOR_AMMO> - 1;
  142. constexpr void G_SetAmmoStat(uint16_t *start, uint8_t ammo_id, uint16_t count)
  143. {
  144. set_compressed_integer<NUM_BITS_FOR_AMMO>(start, ammo_id, count);
  145. }
  146. constexpr uint16_t G_GetAmmoStat(uint16_t *start, uint8_t ammo_id)
  147. {
  148. return get_compressed_integer<NUM_BITS_FOR_AMMO>(start, ammo_id);
  149. }
  150. // powerup stats compressed in 2 bits per entry;
  151. // 3 is the max you'll ever hold, and for some
  152. // (flashlight) it's to indicate on/off state
  153. constexpr size_t NUM_BITS_PER_POWERUP = 2;
  154. constexpr size_t NUM_POWERUP_STATS = num_of_type_for_bits<uint16_t>(NUM_BITS_PER_POWERUP * POWERUP_MAX);
  155. constexpr void G_SetPowerupStat(uint16_t *start, uint8_t powerup_id, uint16_t count)
  156. {
  157. set_compressed_integer<NUM_BITS_PER_POWERUP>(start, powerup_id, count);
  158. }
  159. constexpr uint16_t G_GetPowerupStat(uint16_t *start, uint8_t powerup_id)
  160. {
  161. return get_compressed_integer<NUM_BITS_PER_POWERUP>(start, powerup_id);
  162. }
  163. // player_state->stats[] indexes
  164. enum player_stat_t
  165. {
  166. STAT_HEALTH_ICON = 0,
  167. STAT_HEALTH = 1,
  168. STAT_AMMO_ICON = 2,
  169. STAT_AMMO = 3,
  170. STAT_ARMOR_ICON = 4,
  171. STAT_ARMOR = 5,
  172. STAT_SELECTED_ICON = 6,
  173. STAT_PICKUP_ICON = 7,
  174. STAT_PICKUP_STRING = 8,
  175. STAT_TIMER_ICON = 9,
  176. STAT_TIMER = 10,
  177. STAT_HELPICON = 11,
  178. STAT_SELECTED_ITEM = 12,
  179. STAT_LAYOUTS = 13,
  180. STAT_FRAGS = 14,
  181. STAT_FLASHES = 15, // cleared each frame, 1 = health, 2 = armor
  182. STAT_CHASE = 16,
  183. STAT_SPECTATOR = 17,
  184. STAT_CTF_TEAM1_PIC = 18,
  185. STAT_CTF_TEAM1_CAPS = 19,
  186. STAT_CTF_TEAM2_PIC = 20,
  187. STAT_CTF_TEAM2_CAPS = 21,
  188. STAT_CTF_FLAG_PIC = 22,
  189. STAT_CTF_JOINED_TEAM1_PIC = 23,
  190. STAT_CTF_JOINED_TEAM2_PIC = 24,
  191. STAT_CTF_TEAM1_HEADER = 25,
  192. STAT_CTF_TEAM2_HEADER = 26,
  193. STAT_CTF_TECH = 27,
  194. STAT_CTF_ID_VIEW = 28,
  195. STAT_CTF_MATCH = 29,
  196. STAT_CTF_ID_VIEW_COLOR = 30,
  197. STAT_CTF_TEAMINFO = 31,
  198. // [Kex] More stats for weapon wheel
  199. STAT_WEAPONS_OWNED_1 = 32,
  200. STAT_WEAPONS_OWNED_2 = 33,
  201. STAT_AMMO_INFO_START = 34,
  202. STAT_AMMO_INFO_END = STAT_AMMO_INFO_START + NUM_AMMO_STATS - 1,
  203. STAT_POWERUP_INFO_START,
  204. STAT_POWERUP_INFO_END = STAT_POWERUP_INFO_START + NUM_POWERUP_STATS - 1,
  205. // [Paril-KEX] Key display
  206. STAT_KEY_A,
  207. STAT_KEY_B,
  208. STAT_KEY_C,
  209. // [Paril-KEX] currently active wheel weapon (or one we're switching to)
  210. STAT_ACTIVE_WHEEL_WEAPON,
  211. // [Paril-KEX] top of screen coop respawn state
  212. STAT_COOP_RESPAWN,
  213. // [Paril-KEX] respawns remaining
  214. STAT_LIVES,
  215. // [Paril-KEX] hit marker; # of damage we successfully landed
  216. STAT_HIT_MARKER,
  217. // [Paril-KEX]
  218. STAT_SELECTED_ITEM_NAME,
  219. // [Paril-KEX]
  220. STAT_HEALTH_BARS, // two health bar values; 7 bits for value, 1 bit for active
  221. // [Paril-KEX]
  222. STAT_ACTIVE_WEAPON,
  223. // don't use; just for verification
  224. STAT_LAST
  225. };
  226. static_assert(STAT_LAST <= MAX_STATS + 1, "stats list overflow");