PageRenderTime 32ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/nazghul/src/common.h

#
C Header | 343 lines | 226 code | 52 blank | 65 comment | 3 complexity | ea1f01c8f6d9f06c06070ff3e887c03d MD5 | raw file
Possible License(s): GPL-3.0
  1. //
  2. // nazghul - an old-school RPG engine
  3. // Copyright (C) 2002, 2003 Gordon McNutt
  4. //
  5. // This program is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU General Public License as published by the Free
  7. // Software Foundation; either version 2 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful, but WITHOUT
  11. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. // more details.
  14. //
  15. // You should have received a copy of the GNU General Public License along with
  16. // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
  17. // Suite 330, Boston, MA 02111-1307 USA
  18. //
  19. // Gordon McNutt
  20. // gmcnutt@users.sourceforge.net
  21. //
  22. #ifndef common_h
  23. #define common_h
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include "list.h"
  28. #include "debug.h"
  29. #include "los.h"
  30. #include "dup_constants.h"
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <SDL.h>
  34. /* Constants *****************************************************************/
  35. /*
  36. * Experimental code that let's NPC parties move around the wilderness while
  37. * the player is in a temporary combat map.
  38. */
  39. #define CONFIG_CONCURRENT_WILDERNESS 1
  40. /* Directions */
  41. #define DIRECTION_NONE -1
  42. #define NORTHWEST 0
  43. #define NORTH 1
  44. #define NORTHEAST 2
  45. #define WEST 3
  46. #define HERE 4
  47. #define EAST 5
  48. #define SOUTHWEST 6
  49. #define SOUTH 7
  50. #define SOUTHEAST 8
  51. #define UP 9
  52. #define DOWN 10
  53. #define NUM_DIRECTIONS 11
  54. #define NUM_PLANAR_DIRECTIONS 9
  55. #define NUM_WIND_DIRECTIONS 9
  56. #define IS_LEGAL_DIRECTION(dir) ((dir)>=0 && (dir)<NUM_DIRECTIONS)
  57. #define CANCEL SDLK_ESCAPE
  58. /* Time -- In future, these likely come from GhulScript */
  59. #define TURNS_PER_MINUTE 20
  60. #define MINUTES_PER_HOUR 60
  61. #define HOURS_PER_DAY 24
  62. #define TURNS_PER_HOUR (TURNS_PER_MINUTE * MINUTES_PER_HOUR)
  63. #define TURNS_PER_DAY (TURNS_PER_HOUR * HOURS_PER_DAY)
  64. #define MINUTES_PER_DAY (MINUTES_PER_HOUR * HOURS_PER_DAY)
  65. #define MINUTES_PER_WEEK (MINUTES_PER_DAY * DAYS_PER_WEEK)
  66. #define MINUTES_PER_MONTH (MINUTES_PER_WEEK * WEEKS_PER_MONTH)
  67. #define MINUTES_PER_YEAR (MINUTES_PER_MONTH * MONTHS_PER_YEAR)
  68. #define DAYS_PER_WEEK 7
  69. #define WEEKS_PER_MONTH 4
  70. #define MONTHS_PER_YEAR 13
  71. #define DAYS_PER_MONTH (DAYS_PER_WEEK * WEEKS_PER_MONTH)
  72. #define DAYS_PER_YEAR (DAYS_PER_MONTH * MONTHS_PER_YEAR)
  73. #define TURNS_PER_WEEK (DAYS_PER_WEEK * TURNS_PER_DAY)
  74. #define TURNS_PER_MONTH (DAYS_PER_MONTH * TURNS_PER_DAY)
  75. #define TURNS_PER_YEAR (DAYS_PER_YEAR * TURNS_PER_DAY)
  76. #define HOURS_OF_NIGHT 8
  77. #define HOURS_OF_SUNLIGHT (HOURS_PER_DAY - HOURS_OF_NIGHT)
  78. #define SUNRISE_HOUR 4
  79. #define SUNSET_HOUR (SUNRISE_HOUR + HOURS_OF_SUNLIGHT)
  80. #define NOON_HOUR 12
  81. #define MIDNIGHT_HOUR_LATE 24
  82. #define MIDNIGHT_HOUR_EARLY 0
  83. #define DEGREES_PER_HOUR (360 / HOURS_PER_DAY)
  84. #define DEGREES_PER_MINUTE (360 / MINUTES_PER_DAY)
  85. #define MINUTES_PER_DEGREE (MINUTES_PER_DAY / 360)
  86. #define SUNRISE_DEGREE (SUNRISE_HOUR * DEGREES_PER_HOUR)
  87. #define SUNSET_DEGREE (SUNSET_HOUR * DEGREES_PER_HOUR)
  88. #define NOON_DEGREE (NOON_HOUR * DEGREES_PER_HOUR)
  89. #define MIDNIGHT_DEGREE_LATE (MIDNIGHT_HOUR_LATE * DEGREES_PER_HOUR)
  90. #define MIDNIGHT_DEGREE_EARLY (MIDNIGHT_HOUR_EARLY * DEGREES_PER_HOUR)
  91. /* Moons */
  92. #define NUM_MOONS 0 /*2*/
  93. #define MOON_WINDOW_DEGREES (HOURS_OF_SUNLIGHT * DEGREES_PER_HOUR)
  94. #define MOON_WINDOW_PIXELS_PER_DEGREE 1 /* needs to be an integer */
  95. #define MOON_WINDOW_W (MOON_WINDOW_PIXELS_PER_DEGREE * \
  96. MOON_WINDOW_DEGREES)
  97. #define MOON_HOURS_PER_REVOLUTION (HOURS_PER_DAY - 1)
  98. #define MOON_DEGREES_PER_HOUR (360 / MOON_HOURS_PER_REVOLUTION)
  99. #define MOON_DEGREES_PER_MINUTE (MOON_DEGREES_PER_HOUR * 60)
  100. #define MOON_MINUTES_PER_DEGREE ((MOON_HOURS_PER_REVOLUTION * 60) / 360)
  101. #define MOON_PIXELS_PER_HOUR (MOON_DEGREES_PER_HOUR * \
  102. MOON_WINDOW_PIXELS_PER_DEGREE)
  103. #define TURNS_PER_MOON_CYCLE (TURNS_PER_DAY * 30)
  104. #define MOON_TURNS_PER_DEGREE (TURNS_PER_HOUR / \
  105. MOON_DEGREES_PER_HOUR)
  106. #define SUN_DEGREES_PER_HOUR (360 / 24)
  107. #define SUN_TURNS_PER_DEGREE (TURNS_PER_HOUR / \
  108. SUN_DEGREES_PER_HOUR)
  109. /* Font info */
  110. #define FONT_FILENAME "fonts/cour.ttf"
  111. #define FONT_PTSIZE 14
  112. #define FONT_STYLE TTF_STYLE_NORMAL
  113. /* Timing */
  114. #define ANIMATION_TICKS 10 /* Ticks between animation frame changes */
  115. #define MS_PER_TICK 100
  116. /* Misc */
  117. #define TURNS_TO_FIRE_VEHICLE_WEAPON 2
  118. #define APPLICATION_NAME "Nazghul"
  119. #define WIND_CHANGE_PROBABILITY 5
  120. #define PLAYER_MAX_PROGRESS 100
  121. #define STAT_TEXT_LEN ((STAT_W - TILE_W) / ASCII_W)
  122. #define MAX_NAME_LEN STAT_TEXT_LEN
  123. #define MIN_VISION_RADIUS 1
  124. #define HP_PER_LVL 30
  125. #define MAX_ATTRIBUTE_VALUE 999
  126. // MAX_VISION_RADIUS must be <= MAX_SIGHT in angband.c, but it cannot be
  127. // greater than the map viewer. The reason it can't be greater than the map
  128. // viewer is because we set our visibility mask to be the same dimensions as
  129. // the map viewer, and if we let the LOS alg exceed these dimensions it will
  130. // produce artifacts on the vmask.
  131. //#define MAX_VISION_RADIUS (MAP_TILE_W / 2)
  132. #define MAX_VISION_RADIUS (MAP_TILE_W)
  133. #define MAX_VIEWPORT_RANGE (MAX_VISION_RADIUS + (MAX_VISION_RADIUS / 2))
  134. #define FRAME_IMAGE "images/frame.bmp"
  135. #define SPLASH_IMAGE "images/splash.bmp"
  136. #define MAX_WORDS_IN_SPELL_NAME 4
  137. /* The maximum intensity of ambient sunlight. No point making it more than 255
  138. * because the lightmap only allows tiles to have a max value of 255.*/
  139. #define MAX_AMBIENT_LIGHT 255
  140. #define MAX_SUNLIGHT 255
  141. #define MAX_MOONLIGHT 128
  142. /* The minimum amount of light the player generates. This is so that the user
  143. * can at least see the player icon in total darkness. */
  144. #define MIN_PLAYER_LIGHT 8 /*128*/
  145. // The sun sprite is SKY_SPRITE_W pixels wide, and it advances
  146. // MOON_WINDOW_PIXELS_PER_DEGREE every time it moves, and I want its luminence
  147. // to drop to zero by the time it passes out of sight of the sky window.
  148. #define DELTA_SUNLIGHT (MAX_SUNLIGHT / \
  149. (SKY_SPRITE_W * MOON_WINDOW_PIXELS_PER_DEGREE))
  150. #define TURNS_PER_FOOD (TURNS_PER_DAY/3)
  151. #define MAX_SPEED 100
  152. #define WILDERNESS_SCALE 32
  153. #define NON_WILDERNESS_SCALE 1
  154. #define MAX_N_REAGENTS 32
  155. /* Resting */
  156. #define HP_RECOVERED_PER_HOUR_OF_REST 3
  157. #define MANA_RECOVERED_PER_HOUR_OF_REST 10
  158. #define PROB_AWAKEN 25
  159. /* My events */
  160. #define TICK_EVENT 1
  161. /* Damages */
  162. #define DAMAGE_FIRE 10
  163. #define DAMAGE_POISON 1
  164. #define DAMAGE_STARVATION 1
  165. #define DAMAGE_ACID 10
  166. #define DAMAGE_BOMB 25
  167. /* Targets */
  168. #define TARG_NONE 0
  169. #define TARG_SELF 1
  170. #define TARG_FRIEND 2
  171. /* Type ID's (TIDs) */
  172. #define OBJECT_ID 1
  173. #define VEHICLE_ID (OBJECT_ID + 1)
  174. #define CHARACTER_ID (OBJECT_ID + 2)
  175. #define MOONGATE_ID (OBJECT_ID + 3)
  176. #define PORTAL_ID (OBJECT_ID + 4)
  177. #define PARTY_ID (OBJECT_ID + 5)
  178. #define SPRITE_ID (OBJECT_ID + 7)
  179. #define OBJECT_TYPE_ID 100
  180. #define ARMS_TYPE_ID 101
  181. #define ITEM_TYPE_ID 102
  182. #define VEHICLE_TYPE_ID 103
  183. #define ORDNANCE_TYPE_ID 104
  184. #define CHARACTER_TYPE_ID 105
  185. #define ENTITY_TYPE_ID 106
  186. #define MOONGATE_TYPE_ID 107
  187. #define REAGENT_TYPE_ID 108
  188. #define SPELL_TYPE_ID 109
  189. #define MISSILE_TYPE_ID 110 //repurposed from unused AMMO_TYPE_ID
  190. #define FIELD_TYPE_ID 111
  191. #define FOOD_TYPE_ID 112
  192. #define TRAP_TYPE_ID 113
  193. #define PARTY_TYPE_ID 114
  194. #define RESPONSE_TYPE_ID 116
  195. #define CONVERSATION_TYPE_ID 117
  196. #define OCC_ID 118
  197. #define SPECIES_ID 119
  198. #define SCHEDULE_ID 120
  199. #define PLACE_ID 121
  200. #define MAP_ID 122
  201. #define TERRAIN_PALETTE_ID 124
  202. #define TERRAIN_ID 125
  203. #define MECH_TYPE_ID 126
  204. #define MECH_ID 127
  205. #define IMAGES_ID 128
  206. #define FORMATION_TYPE_ID 129
  207. /* Services (loadfile must match) */
  208. #define SRV_HEAL 1
  209. #define SRV_CURE 2
  210. #define SRV_RESURRECT 3
  211. #define SRV_MIN SRV_HEAL
  212. #define SRV_MAX SRV_RESURRECT
  213. /* Contexts */
  214. #define CONTEXT_WILDERNESS 1
  215. #define CONTEXT_TOWN 2
  216. /* Spells (loadfile must match) */
  217. #define SPELL_TARGET_NONE 0
  218. #define SPELL_TARGET_CHARACTER 1
  219. #define SPELL_TARGET_MECH 2
  220. #define SPELL_TARGET_DIRECTION 3
  221. #define SPELL_TARGET_LOCATION 4
  222. #define SPELL_TARGET_UP 5
  223. #define SPELL_TARGET_DOWN 6
  224. #define SPELL_TARGET_ALL_PARTY_MEMBERS 7
  225. #define SPELL_TARGET_CASTER_LOCATION 8
  226. #define SPELL_TARGET_PARTY_MEMBER 9
  227. // Compile-time configuration parameters
  228. #define CONFIG_MOVEMENT_COST_FOR_CHARACTERS false
  229. /* Action point values (temporary - should be moved to the load file) */
  230. // #define NAZGHUL_BASE_ACTION_POINTS 50 // SAM: should be obsolete now, with the use of kern_intvar_get()
  231. /* Hard-coded experience point values */
  232. #define COMBAT_VICTORY_XP 5
  233. /* Hard-coded drop probabilities */
  234. #define ITEM_DROP_PROB 25 /* 25% chance to drop readied items */
  235. #define CHEST_DROP_PROB 25 /* 25% chance to drop container */
  236. /* Macros ********************************************************************/
  237. #define perror_sdl(msg) err("%s: %s\n", (msg), SDL_GetError())
  238. // #define perror_sdl(msg) fprintf(stderr, "%s:%s\n", (msg), SDL_GetError())
  239. #define max(a,b) ((a) > (b) ? (a) : (b))
  240. #define min(a,b) ((a) < (b) ? (a) : (b))
  241. #define clamp(v,a,b) ((v) = (v) < (a) ? (a) : ((v) > (b) ? (b) : (v)))
  242. #define array_sz(a) (int)(sizeof((a))/sizeof((a)[0]))
  243. #define outcast(ptr,type,field) \
  244. ((type*)((char*)(ptr)-(unsigned long)(&((type *)0)->field)))
  245. #define CREATE(ptr,type,err) \
  246. (ptr) = (type*)malloc(sizeof(type)); \
  247. if (!(ptr)) \
  248. return (err); \
  249. memset((ptr), 0, sizeof(type));
  250. #define distance(dx,dy) (((dx)>(dy)) ? ((dx)+((dy)>>1)) : ((dy)+ (dx)>>1)))
  251. // SAM: The below are used by palette_print(), terrain_map_print(), etc.
  252. #define INITIAL_INDENTATION 0
  253. #define INDENTATION_FACTOR 2
  254. #define INDENT fprintf(fp, "%*s", indent, "")
  255. /* Enums *********************************************************************/
  256. typedef enum {
  257. UI_SIZE_NORMAL = 0,
  258. UI_SIZE_SMALL = 1
  259. } ui_size_t;
  260. /* Structures ****************************************************************/
  261. /* Global Functions **********************************************************/
  262. char * version_as_string(void); // From nazghul.c
  263. extern int commonInit(void);
  264. extern const char *get_dir_str(int dx, int dy);
  265. extern void turnAdvance(int turns);
  266. extern int vector_to_dir(int dx, int dy);
  267. extern int vector_to_facing(int dx, int dy);
  268. extern int vector_to_rotation(int dx, int dy);
  269. extern int vector_to_8facing(int dx, int dy);
  270. extern int stringToDirection(char *str);
  271. extern int keyToDirection(int key);
  272. extern int directionToDx(int dir);
  273. extern int directionToDy(int dir);
  274. extern const char *directionToString(int dir);
  275. extern int isvowel(char c);
  276. extern int point_in_rect(int x, int y, SDL_Rect *rect);
  277. extern int directionToOpposite(int dir);
  278. #define keyIsDirection(key) ((key) >= KEY_SOUTHWEST && (key) <= KEY_NORTHEAST)
  279. /* Global Variables **********************************************************/
  280. extern int Turn;
  281. extern int AnimationTicks;
  282. extern int Tick;
  283. extern int TickMilliseconds;
  284. extern int Quit;
  285. extern struct los *LosEngine;
  286. extern int ShowAllTerrain;
  287. extern int logBase2(int val);
  288. #ifdef __cplusplus
  289. }
  290. #endif
  291. #endif