1 /***************************************************************************
2 constants.h - Global constants and utility functions
3 -------------------
4 begin : Sun Oct 12 2003
5 copyright : (C) 2003 by Gabor Torok
6 email : cctorok@yahoo.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #ifndef CONSTANTS_H
19 #define CONSTANTS_H
20 #pragma once
21
22 // autopackage's binary relocation lib
23 #include "binreloc.h"
24
25 // from tuxracer
26 #if defined ( __MWERKS__ ) || defined( _MSC_VER ) || defined( WIN32 )
27 # define NATIVE_WIN32_COMPILER 1
28 #else
29 /* Assume UNIX compatible by default */
30 # define COMPILER_IS_UNIX_COMPATIBLE 1
31 #endif
32
33 // -=K=- since it was most popular header i made most porting here
34 #ifdef _MSC_VER // i only checked for MSVC 8 portability
35 // turn numeric types conversion warnings OFF; like size_t <-> int;
36 # pragma warning(disable : 4267 4244) //4800) but not odd usage of bool
37 // to be sure that these are included *before* following defines
38 # include <string.h>
39 # include <stdio.h>
40 # include <cstdio>
41 // some common string ops have different names under MSVC 8
42 # define strcasecmp _stricmp
43 # if _MSC_VER < 1400
44 # define snprintf _snprintf
45 # define vsnprintf _vsnprintf
46 # else
47 # define snprintf _sprintf_p
48 // just to avoid using sprintf
49 # define sprintf please_use_snprintf
50 # endif
51 # define strdup _strdup
52 // somewhere was error: unknown identifier "time"
53 # include <time.h>
54 // MSVC 8 has no rint so i improvise one
55 template<class T>
rint(T v)56 T rint( T v ) {
57 T f = floor( v ); // v >= f
58 T c = ceil( v ); // c >= v
59 return ( v -f > c - v ) ? c : f; //what's closer is rint(v)
60 }
61 // MS Visual C++ related debug stuff
62 # include <assert.h>
63 // The following macros set and clear, given bits of debug flag.
64 # if defined(_DEBUG)
65 # define SET_CRT_DEBUG_FIELD(a) \
66 _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
67 # define CLEAR_CRT_DEBUG_FIELD(a) \
68 _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
69 # define DEBUG_NEW new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
70 # else
71 # define SET_CRT_DEBUG_FIELD(a) ((void) 0)
72 # define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
73 # endif
74 // MSVC asserts with POSIX style LC_MESSAGES
75 // most simple workaround is to use LC_CTYPE as LC_MESSAGES
76 # include <locale.h>
77 # ifndef LC_MESSAGES
78 # define LC_MESSAGES LC_CTYPE
79 # endif
80 #endif // MSVC 8 portability
81
82 #include <stdlib.h>
83 #include <math.h>
84 #include <vector>
85 #include <queue>
86 #include <map>
87 #include <iostream>
88 #include <errno.h>
89 #include <string>
90
91 // include sdl, opengl and glut
92 #include <SDL.h>
93 #include <SDL_opengl.h>
94 #include <SDL_endian.h>
95 #include <SDL_ttf.h>
96 #include <SDL_image.h>
97
98 // include some gl noise
99 #include "glnoise.h"
100
101 #ifdef HAVE_SDL_NET
102 #include <SDL_net.h>
103 #include <SDL_thread.h>
104 #endif
105
106 #ifdef HAVE_SDL_MIXER
107 #include <SDL_mixer.h>
108 #endif
109
110 #if defined(__APPLE__) || defined(__MACH_O__)
111 // *** #include <GLUT/glut.h>
112 #else
113 // *** #include <GL/glut.h>
114 #ifndef WIN32
115 // Could not get these to include on my Mandrake9 box...
116 #ifndef APIENTRY
117 #define APIENTRY
118 #endif
119 typedef void ( APIENTRY * PFNGLACTIVETEXTUREARBPROC ) ( GLenum texture );
120 typedef void ( APIENTRY * PFNGLMULTITEXCOORD2FARBPROC ) ( GLenum target, GLfloat s, GLfloat t );
121 typedef void ( APIENTRY * PFNGLMULTITEXCOORD2IARBPROC ) ( GLenum target, GLint s, GLint t );
122 #endif
123 #endif
124
125 #if defined( COMPILER_IS_UNIX_COMPATIBLE )
126 # include <unistd.h>
127 # include <pwd.h>
128 # include <dirent.h>
129 # include <sys/time.h>
130 # include <sys/types.h>
131 # include <dirent.h>
132 # include <sys/stat.h>
133 #endif
134
135 // Couldn't figure out gettext for the macos x. :-(
136 #ifdef NO_GETTEXT
137 #define _(String) String
138 #define gettext_noop(String) String
139 #define N_(String) gettext_noop (String)
140 #else
141 #include <libintl.h>
142 #define _(String) gettext (String)
143 #define gettext_noop(String) String
144 #define N_(String) gettext_noop (String)
145 #endif
146
147 #ifdef WIN32
148 #define SEPARATOR '\\'
149 #else
150 #define SEPARATOR '/'
151 #endif
152
153 /*
154 Data and config dirs. Shamelessly borrowed from tuxracer.
155 */
156 #if defined( WIN32 )
157 # define CONFIG_DIR "."
158 # define CONFIG_FILE "options.txt"
159 #else
160 # define CONFIG_DIR ".scourge"
161 # define CONFIG_FILE "options"
162 #endif /* defined( WIN32 ) */
163
164 #define DATA_DIR_NAME "scourge_data"
165
166 #ifndef DATA_DIR
167 # if defined( WIN32 )
168 # define DATA_DIR "./"DATA_DIR_NAME
169 # else
170 # define DATA_DIR "/usr/local/share/scourge"
171 # endif /* defined( WIN32 ) */
172 #endif
173
174 #ifndef assert
175 #define assert(x) x;
176 #endif
177
178 #define SCOURGE_VERSION "0.21"
179 #define MAX_PARTY_SIZE 4
180
181 // Max level depth per mission
182 #define MAX_MISSION_DEPTH 10
183
184 #define toint(x) (int)(x<0 ? (x - 0.5f) : (x + 0.5f))
185
186 extern std::string rootDir;
187 extern std::string localeDir;
188 extern std::string configDir;
189 extern std::string get_config_dir_name();
190 extern std::string get_config_file_name();
191 extern std::string get_file_name( const std::string fileName );
192
193 // opengl extension function ptrs for SDL (set in sdlhandler.cpp)
194 extern PFNGLACTIVETEXTUREARBPROC glSDLActiveTextureARB;
195 extern PFNGLMULTITEXCOORD2FARBPROC glSDLMultiTexCoord2fARB;
196 extern PFNGLMULTITEXCOORD2IARBPROC glSDLMultiTexCoord2iARB;
197
198 // some windows versions of opengl don't have this
199 #define GL_BGR 0x80E0
200 #define GL_BGRA 0x80E1
201
202
203 /*
204 Float swapping code by:http://sourceforge.net/project/stats/?group_id=98006&ugn=scourge
205 Ramin Firoozye' -- rp&A Inc.
206 1995/06/30 found on Google groups
207 */
208
209
210 /** Helpful macros in swapping bytes etc...
211 * This union lets us map just about any common datatype onto the
212 * specified value, so we can use direct array access to do byte, word,
213 * or long swapping.
214 */
215 union NetValue {
216 short s; /* Straight 2-byte short */
217 unsigned short sU; /* unsigned short */
218 unsigned char sC[2]; /* short as bytes */
219
220 long l; /* Straight 4-byte long */
221 unsigned long lU; /* unsigned long */
222 unsigned char lC[4]; /* long as bytes */
223 unsigned short lS[2]; /* long as short */
224
225 float f; /* Straight (presumed) 4-byte single */
226 unsigned char fC[4]; /* single as bytes */
227 unsigned short fS[2]; /* single as short */
228
229 double g; /* Straight (presumed) 8-byte double */
230 unsigned char gC[8]; /* double as bytes */
231 unsigned short gS[4]; /* double as short */
232 unsigned long gL[2]; /* double as long */
233 };
234 typedef union NetValue NetValue;
235
236 /*
237 * We define macros as mSWAPn where m is one of B=Byte, W=word and L=long
238 * and n is one of B=byte, W=word, L=long, F=single float,
239 * and G=double float. We are swapping n in chunks of m. So WSWAPL is
240 * a word-swap of a longword (i.e. we swap the first and second words).
241 * and BSWAPG is a byte-swap of a double (i.e. total reversal of byte order
242 * across all 8 bytes). For float and double values, we don't do bit
243 * swapping of any sort (just B, W, and L). So if the network format of
244 * the floating value is too damn obscure, something more complicated
245 * has to be done...
246 */
247
248 #define BSWAPW(src, dst) { NetValue _t; _t.s = src; \
249 ((char *)&dst)[0] = _t.sC[1]; ((char *)&dst)[1] = _t.sC[0]; \
250 }
251 #define BSWAPL(src, dst) { NetValue _t; _t.lU = src; \
252 ((char *)&dst)[0] = _t.lC[3]; ((char *)&dst)[1] = _t.lC[2]; \
253 ((char *)&dst)[2] = _t.lC[1]; ((char *)&dst)[3] = _t.lC[0]; \
254 }
255 #define WSWAPL(src, dst) { NetValue _t; _t.lU = src; \
256 ((short *)&dst)[0] = _t.lS[1]; ((short *)&dst)[1] = _t.lS[0]; \
257 }
258 #define BSWAPF(src, dst) { NetValue _t; _t.f = src; \
259 ((char *)&dst)[0] = _t.fC[3]; ((char *)&dst)[1] = _t.fC[2]; \
260 ((char *)&dst)[2] = _t.fC[1]; ((char *)&dst)[3] = _t.fC[0]; \
261 }
262 #define WSWAPF(src, dst) { NetValue _t; _t.f = src; \
263 ((short *)&dst)[0] = _t.fS[1]; ((short *)&dst)[1] = _t.fS[0]; \
264 }
265 #define BSWAPG(src, dst) { NetValue _t; _t.g = src; \
266 ((char *)&dst)[0] = _t.gC[7]; ((char *)&dst)[1] = _t.gC[6]; \
267 ((char *)&dst)[2] = _t.gC[5]; ((char *)&dst)[3] = _t.gC[4]; \
268 ((char *)&dst)[4] = _t.gC[3]; ((char *)&dst)[5] = _t.gC[2]; \
269 ((char *)&dst)[6] = _t.gC[1]; ((char *)&dst)[7] = _t.gC[0]; \
270 }
271 #define WSWAPG(src, dst) { NetValue _t; _t.g = src; \
272 ((short *)&dst)[0] = _t.gS[3]; ((short *)&dst)[1] = _t.gS[2]; \
273 ((short *)&dst)[2] = _t.gS[1]; ((short *)&dst)[3] = _t.gS[0]; \
274 }
275 #define LSWAPG(src, dst) { NetValue _t; _t.g = src; \
276 ((long *)&dst)[0] = _t.gL[1]; ((long *)&dst)[1] = _t.gL[0]; \
277 }
278
279 /// GL color in float
280
281 class Color {
282 public:
283 float r, g, b, a;
284
Color()285 Color(): r( 0 ), g( 0 ), b( 0 ), a( 0 ) {}
286
287 Color( float r, float g, float b, float a = 1.0f ) {
288 this->set( r, g, b, a );
289 }
290
~Color()291 ~Color() {
292 }
293
294 inline void set( float r, float g, float b, float a = 1.0f ) {
295 this->r = r;
296 this->g = g;
297 this->b = b;
298 this->a = a;
299 }
300
Clear()301 void Clear() {
302 *this = Color();
303 }
304 };
305
306 /**
307 *@author Gabor Torok
308 */
309
310 /// A particle.
311 struct ParticleStruct {
312 GLfloat x, y, z, startZ;
313 GLint height;
314 int life;
315 GLfloat moveDelta;
316 int maxLife;
317 int trail;
318 float rotate;
319 float zoom;
320 bool tail;
321 bool untilGround;
322 Color tailColor;
323 };
324
325 #define SINGLE_TARGET 0
326 #define GROUP_TARGET 1
327
328 #define MAX_BACKPACK_SIZE 200
329 #define MAX_CONTAINED_ITEMS 100
330
331 #define MAX_LEVEL 50
332
333 #define MIN_DISTANCE 1.0f
334
335 // The radius in map tiles in which a fighting creature searches for a target.
336 #define CREATURE_SIGHT_RADIUS 32
337
338 // Maximum length of a random loitering path.
339 #define CREATURE_LOITERING_RADIUS 16
340
341 /// A progress display.
342
343 class StatusReport {
344 public:
StatusReport()345 StatusReport() {
346 }
~StatusReport()347 virtual ~StatusReport() {
348 }
349 virtual void updateStatus( int status, int maxStatus, const char *message = NULL ) = 0;
350 };
351
352 /// Encapsulates most of the game's constants, and a few utility functions.
353
354 class Constants {
355 private:
356 static int maxMissionId;
357 public:
358
getNextMissionId()359 static inline int getNextMissionId() {
360 return maxMissionId++;
361 }
362
363 static std::string scourgeLocaleName;
364
365 // equip locations
366 static const int EQUIP_LOCATION_HEAD = 1;
367 static const int EQUIP_LOCATION_NECK = 2;
368 static const int EQUIP_LOCATION_BACK = 4;
369 static const int EQUIP_LOCATION_CHEST = 8;
370 static const int EQUIP_LOCATION_LEFT_HAND = 16;
371 static const int EQUIP_LOCATION_RIGHT_HAND = 32;
372 static const int EQUIP_LOCATION_BELT = 64;
373 static const int EQUIP_LOCATION_LEGS = 128;
374 static const int EQUIP_LOCATION_FEET = 256;
375 static const int EQUIP_LOCATION_RING1 = 512;
376 static const int EQUIP_LOCATION_RING2 = 1024;
377 static const int EQUIP_LOCATION_RING3 = 2048;
378 static const int EQUIP_LOCATION_RING4 = 4096;
379 static const int EQUIP_LOCATION_WEAPON_RANGED = 8192;
380 static const int EQUIP_LOCATION_GLOVE = 16384;
381 static const int EQUIP_LOCATION_COUNT = 15;
382
383 static std::map<int, int> EQUIP_LOCATION_LOOKUP;
384
385 static int getLocationIndex( int locationValue );
386
387 static const char *equipLocationTags[];
388
389 static const int MAP_GRID_TILE_WIDTH = 6;
390 static const int MAP_GRID_TILE_HEIGHT = 5;
391 static const int MAP_GRID_TILE_PIXEL_WIDTH = 256;
392 static const int MAP_GRID_TILE_PIXEL_HEIGHT = 256;
393
394 // creature movement
395 enum motion {
396 MOTION_MOVE_TOWARDS = 0,
397 MOTION_MOVE_AWAY, // flee
398 MOTION_CLEAR_PATH, //rapidly make way
399 MOTION_LOITER, //wander slowly
400 MOTION_STAND //FREEZE!
401 };
402
403 enum {
404 SEX_MALE = 0,
405 SEX_FEMALE
406 };
407
408 // This stores the speed of the animation between each key frame for md2 models
409 // A higher value means a *faster* animation and NOT a *smoother* animation.
410 // The smoothing of the animation is only determined by fps.
411 // So this value should not be modified. Maybe later there will be an
412 // animation_speed for each creature, to give the feeling some are faster than others ?
413 #define ANIMATION_SPEED 5.0f
414
415 #define DEFAULT_SERVER_PORT 6543
416
417 // The map's dimensions
418 // Warning: if this ever changes, be sure to look at Map::createTripletKey().
419 // it assumes that MAP_WIDTH >= MAP_HEIGHT and that MAP_WIDTH^3 < 2^32.
420 #define MAP_WIDTH 600
421 #define MAP_DEPTH 600
422
423 // How big is the on-screen view. Should be calculated.
424 #define MAP_VIEW_HEIGHT 16
425
426 // How big is 1 map chunk
427 #define MAP_UNIT 16
428 #define MAP_UNIT_OFFSET 2
429 #define MAP_WALL_HEIGHT 12
430
431 // Number of chunks on the map
432 #define MAP_CHUNKS_X MAP_WIDTH / MAP_UNIT
433 #define MAP_CHUNKS_Y MAP_DEPTH / MAP_UNIT
434
435 // How far from the edge to start drawing in map
436 #define MAP_OFFSET 80
437
438 // cave chunk size
439 #define CAVE_CHUNK_SIZE 8
440
441 #define OUTDOOR_FLOOR_TEX_SIZE 4
442
443 // outdoor floor tile
444 #define OUTDOORS_STEP 4
445
446 // Number of tiles on an outdoor map
447 #define MAP_TILES_X MAP_WIDTH / OUTDOORS_STEP
448 #define MAP_TILES_Y MAP_DEPTH / OUTDOORS_STEP
449
450 // The max value of a skill under normal circumstances.
451 #define MAX_SKILL 100
452
453 // Directions (a bitfield so they can be combined)
454 static const Uint16 MOVE_UP = 1;
455 static const Uint16 MOVE_DOWN = 2;
456 static const Uint16 MOVE_LEFT = 4;
457 static const Uint16 MOVE_RIGHT = 8;
458 // Short cuts - useful when working in 8 directions
459 static const Uint16 MOVE_UP_RIGHT = MOVE_UP | MOVE_RIGHT;
460 static const Uint16 MOVE_UP_LEFT = MOVE_UP | MOVE_LEFT;
461 static const Uint16 MOVE_DOWN_RIGHT = MOVE_DOWN | MOVE_RIGHT;
462 static const Uint16 MOVE_DOWN_LEFT = MOVE_DOWN | MOVE_LEFT;
463
464 enum { NORTH = 0, EAST, SOUTH, WEST };
465
466 // messages
467 enum {
468 WELCOME = 0,
469 ITEM_OUT_OF_REACH,
470 DOOR_BLOCKED,
471 SINGLE_MODE,
472 GROUP_MODE,
473 TURN_MODE,
474 REAL_TIME_MODE,
475 CLOSE_LABEL,
476 DROP_ITEM_LABEL,
477 OPEN_CONTAINER_LABEL,
478 EXPLAIN_DRAG_AND_DROP,
479 PLAY_MISSION_LABEL,
480 EXIT_MISSION_LABEL,
481 TELEPORT_TO_BASE_LABEL,
482 OK_LABEL,
483 CANCEL_LABEL,
484 YES_LABEL,
485 NO_LABEL,
486 LEVEL_UP_ERROR,
487 OUT_OF_POINTS_ERROR,
488 NO_SKILL_ERROR,
489 SCOURGE_DIALOG,
490 USE_GATE_LABEL,
491 DEAD_CHARACTER_ERROR,
492 HP_LABEL,
493 AC_LABEL,
494 SPELL_FAILED_MESSAGE,
495 ITEM_ACL_VIOLATION,
496 JOIN_SERVER_ERROR,
497 CLIENT_CANT_CONNECT_ERROR,
498 DOOR_OPENED_CLOSE,
499 DOOR_OPENED,
500 DOOR_OPENED_FAR,
501 DOOR_LOCKED,
502 TELEPORTER_OFFLINE,
503 INFO_GUI_TITLE,
504 DELETE_OLD_SAVED_GAME,
505 ITEM_LEVEL_VIOLATION,
506 CHANGE_KEY,
507 WAITING_FOR_KEY,
508 CONVERSATION_GUI_TITLE,
509 TRADE_DIALOG_TITLE,
510 TRAIN_DIALOG_TITLE,
511 HEAL_DIALOG_TITLE,
512 DONATE_DIALOG_TITLE,
513 UNMET_CAPABILITY_PREREQ_ERROR,
514 CANNOT_USE_AUTO_CAPABILITY_ERROR,
515 ITEM_TWO_HANDED_VIOLATION,
516 TRAINING_AVAILABLE,
517 SKILL_POINTS_AVAILABLE,
518 LOCKED_DOOR_OPENS_MAGICALLY,
519 CAUSE_OF_DEATH,
520 UNCURSE_DIALOG_TITLE,
521 RECHARGE_DIALOG_TITLE,
522 IDENTIFY_DIALOG_TITLE,
523 // last one
524 MESSAGE_COUNT
525 };
526 static char *messages[][100];
527 static int messageCount[];
528
529 static const char *localhost;
530 static const char *adminUserName;
531
532 // other things potions can act on:
533 enum {
534 HP = 0,
535 MP,
536 AC,
537
538 POTION_SKILL_COUNT
539 };
540
541 static const char *POTION_SKILL_NAMES[];
542 // return -1 on failure, or (-2 - i) on success
543 static int getPotionSkillByName( char const* p );
544
545 // Some threshold values for potions.
546 #define LOW_HP 0.25f
547 #define LOW_MP 0.25f
548 #define HIGH_AC 10
549
550 enum {
551 LESSER_MAGIC_ITEM = 0,
552 GREATER_MAGIC_ITEM,
553 CHAMPION_MAGIC_ITEM,
554 DIVINE_MAGIC_ITEM,
555 MAGIC_ITEM_LEVEL_COUNT
556 };
557
558 static const char *MAGIC_ITEM_NAMES[];
559 static const Color *MAGIC_ITEM_COLOR[];
560 static const Color *SPECIAL_ITEM_COLOR;
561
562 // special effect names
563 enum {
564 EFFECT_FLAMES = 0,
565 EFFECT_GLOW,
566 EFFECT_TELEPORT,
567 EFFECT_GREEN,
568 EFFECT_EXPLOSION,
569 EFFECT_SWIRL,
570 EFFECT_CAST_SPELL,
571 EFFECT_RING,
572 EFFECT_RIPPLE,
573 EFFECT_DUST,
574 EFFECT_HAIL,
575 EFFECT_TOWER,
576 EFFECT_BLAST,
577 EFFECT_SMOKE,
578 EFFECT_FIRE,
579
580 // must be last
581 EFFECT_COUNT
582 };
583 static const int DAMAGE_DURATION = 500;
584
585 static const char *EFFECT_NAMES[];
getEffectByName(char const * s)586 inline static int getEffectByName( char const* s ) {
587 for ( int i = 0; i < EFFECT_COUNT; i++ )
588 if ( !strcmp( s, EFFECT_NAMES[i] ) )
589 return i;
590 return EFFECT_FLAMES;
591 }
592
593 // Magic school base alignments
594 #define ALIGNMENT_CHAOTIC 0.0f
595 #define ALIGNMENT_NEUTRAL 0.5f
596 #define ALIGNMENT_LAWFUL 1.0f
597
598 // glColor for texts
599 enum {
600 RED_COLOR = 0,
601 BLUE_COLOR,
602 YELLOW_COLOR,
603 DEFAULT_COLOR // must be last for textColor[][]
604 };
605 //static float textColor[][4];
606
607 static bool multitexture;
608
609 enum {
610 CURSOR_NORMAL = 0,
611 CURSOR_CROSSHAIR,
612 CURSOR_ATTACK,
613 CURSOR_TALK,
614 CURSOR_USE,
615 CURSOR_FORBIDDEN,
616 CURSOR_RANGED,
617 CURSOR_MOVE,
618
619 CURSOR_COUNT // must be the last one
620 };
621
622 static const char *cursorTextureName[];
623
624 enum {
625 SCOURGE_DEFAULT_FONT = 0,
626 SCOURGE_UI_FONT,
627 SCOURGE_MONO_FONT,
628 SCOURGE_LARGE_FONT
629 };
630
631 enum {
632 NO_SHADOWS = 0,
633 OBJECT_SHADOWS,
634 ALL_SHADOWS
635 };
636
637 enum {
638 LOGLEVEL_MINIMAL = 0,
639 LOGLEVEL_PARTIAL,
640 LOGLEVEL_VERBOSE,
641 LOGLEVEL_FULL
642 };
643
644 enum { // Message types as they show up in the log window
645 MSGTYPE_NORMAL = 0, // Normal text: Descriptions etc.
646 MSGTYPE_MISSION, // Mission related and other key text
647 MSGTYPE_PLAYERDAMAGE, // Player has taken damage
648 MSGTYPE_NPCDAMAGE, // NPC/monster has taken damage
649 MSGTYPE_PLAYERMAGIC, // Player uses magic
650 MSGTYPE_NPCMAGIC, // NPC/monster uses magic
651 MSGTYPE_PLAYERITEM, // Player uses an item
652 MSGTYPE_NPCITEM, // NPC/monster uses an item
653 MSGTYPE_PLAYERBATTLE, // Player's battle actions
654 MSGTYPE_NPCBATTLE, // NPCs'/monsters' battle actions
655 MSGTYPE_PLAYERDEATH, // A player character has died
656 MSGTYPE_NPCDEATH, // An NPC or monster has died
657 MSGTYPE_FAILURE, // The player has failed at something
658 MSGTYPE_STATS, // Player's stats have changed: State mods, leveled up etc.
659 MSGTYPE_SYSTEM, // System and debug messages
660 MSGTYPE_SKILL // Skill related messages
661 };
662
663 // Weather modifiers
664 #define WEATHER_CLEAR 0x00
665 #define WEATHER_RAIN 0x01
666 #define WEATHER_THUNDER 0x02
667 #define WEATHER_FOG 0x04
668 #define MAX_WEATHER 0x08
669
670 // Creature actions
671 enum {
672 ACTION_NO_ACTION = -1,
673 ACTION_EAT_DRINK = 0,
674 ACTION_CAST_SPELL,
675 ACTION_SPECIAL,
676
677 // this must be the last one
678 ACTION_COUNT
679 };
680
681 // sound types
682 enum {
683 SOUND_TYPE_COMMAND = 0,
684 SOUND_TYPE_HIT,
685 SOUND_TYPE_SELECT,
686 SOUND_TYPE_ATTACK,
687
688 // must be the last one
689 SOUND_TYPE_COUNT
690 };
691
692 // reserved sound channels
693 enum {
694 OBJECT_CHANNEL = 0,
695 AMBIENT_CHANNEL,
696 FOOTSTEP_CHANNEL,
697 RAIN_CHANNEL
698 };
699
700 // npc types
701 enum {
702 NPC_TYPE_COMMONER = 0,
703 NPC_TYPE_MERCHANT,
704 NPC_TYPE_HEALER,
705 NPC_TYPE_SAGE,
706 NPC_TYPE_TRAINER,
707
708 // must be the last one
709 NPC_TYPE_COUNT
710 };
711
712 // Maximum variance when trading, based on leadership skill.
713 #define MAX_DISCOUNT 0.25f
714
715 // engine actions
716 enum {
717 ENGINE_ACTION_SCROLL_SOUTH = 0,
718 ENGINE_ACTION_SCROLL_NORTH,
719 ENGINE_ACTION_SCROLL_EAST,
720 ENGINE_ACTION_SCROLL_WEST,
721 ENGINE_ACTION_PLAYER0,
722 ENGINE_ACTION_PLAYER1,
723 ENGINE_ACTION_PLAYER2,
724 ENGINE_ACTION_PLAYER3,
725 ENGINE_ACTION_GROUP_MODE,
726 ENGINE_ACTION_BACKPACK,
727 ENGINE_ACTION_OPTIONS,
728 ENGINE_ACTION_FORMATION,
729 ENGINE_ACTION_MINIMAP,
730 ENGINE_ACTION_ZOOM_IN,
731 ENGINE_ACTION_ZOOM_OUT,
732 ENGINE_ACTION_ALWAYS_CENTER,
733 ENGINE_ACTION_INCREASE_SPEED,
734 ENGINE_ACTION_DECREASE_SPEED,
735 ENGINE_ACTION_NEXT_ROUND,
736 ENGINE_ACTION_FLOATING_UI,
737 ENGINE_ACTION_BOTTOM_UI,
738 ENGINE_ACTION_BACKPACK_UI,
739 ENGINE_ACTION_COMBAT_MODE,
740 ENGINE_ACTION_NEXT_WEAPON,
741 ENGINE_ACTION_QUICKSPELL1,
742 ENGINE_ACTION_QUICKSPELL2,
743 ENGINE_ACTION_QUICKSPELL3,
744 ENGINE_ACTION_QUICKSPELL4,
745 ENGINE_ACTION_QUICKSPELL5,
746 ENGINE_ACTION_QUICKSPELL6,
747 ENGINE_ACTION_QUICKSPELL7,
748 ENGINE_ACTION_QUICKSPELL8,
749 ENGINE_ACTION_QUICKSPELL9,
750 ENGINE_ACTION_QUICKSPELL10,
751 ENGINE_ACTION_QUICKSPELL11,
752 ENGINE_ACTION_QUICKSPELL12,
753 ENGINE_ACTION_QUICK_SAVE,
754 ENGINE_ACTION_QUICK_LOAD,
755 ENGINE_ACTION_AUTO_LOAD
756 };
757
758 static const char *npcTypeName[];
759 static const char *npcTypeDisplayName[];
760
761 // the speed when hand fighting is used instead of a weapon
762 static const int HAND_WEAPON_SPEED = 5;
763
764 Constants();
765 ~Constants();
766
767 static char *getMessage( int index );
768
769 // shortest distance between two rectangles
770 static float distance( float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2 );
771
772 static void checkTexture( char *message, int w, int h );
773
774 // read until EOL into line. Exclude EOL from LINE.
775 // returns the next char after the EOL.
776 static int readLine( char *line, FILE *fp );
777
778 /// Converts degrees to radians.
779
toRadians(float angle)780 inline static float toRadians( float angle ) {
781 // 2.13.3(1) The type of a floating literal is double unless explicitly specified by a suffix.
782 // explicit float conversion to silence warning
783 return static_cast<float>( 3.14159 * ( angle / 180.0f ) );
784 }
785
786 /// Converts radians to degrees.
787
toAngle(float rad)788 inline static float toAngle( float rad ) {
789 return static_cast<float>( ( 180.0f * rad ) / 3.14159 );
790 }
791
792 static void getQuadrantAndAngle( float nx, float ny, int *q, float *angle );
793
794 static int initRootDir( int argc, char *argv[] );
795
796 static int findLocaleDir();
797 static bool checkFile( const std::string& dir, const std::string& file );
798
799 static void generateTrigTables();
800 static float sinFromAngle( int angle );
801 static float cosFromAngle( int angle );
802 static float windFromAngle( float angle );
803
804 private:
805 // used to run scourge with local resources
806 static std::string findLocalResources( const std::string& appPath );
807 };
808
809 std::string GetDataPath( const std::string& file );
810
811 /// A 3D point with texture coordinates and color.
812 /* -=K=-: Used only by Map ... migrated there
813 class CVectorTex {
814 public:
815 float x, y, z, u, v, r, g, b, a;
816 GLuint tex;
817 };*/
818
819 /// A 3D point with texture coordinates.
820 /* -=K=-: Unused
821 class CVector5 {
822 public:
823 float x, y, z, u, v;
824 };*/
825
826 /// This is our 3D point class. This will be used to store the vertices of our model.
827 class CVector3 {
828 public:
829 float x, y, z;
830
831 /**
832 * This computes the magnitude of a normal.
833 * (magnitude = sqrt(x^2 + y^2 + z^2)
834 */
835 double magnitude() const;
836 void normalize();
837
838 /**
839 * @return This returns the cross product between 2 vectors
840 */
841 CVector3 cross( const CVector3& vVector1 );
842
843 CVector3 operator+( const CVector3& vVector1 ) const;
844 void operator+=( const CVector3& vVector1 );
845
846 CVector3 operator-( const CVector3& vPoint1 ) const;
847
848 CVector3 operator/( const float scalar ) const;
849 void operator/=( const float scalar );
850
851 bool operator==( const CVector3& compare ) const;
852 void operator=( const CVector3& copy );
853
854 CVector3();
855 CVector3( float x, float y, float z );
856 CVector3( const CVector3& copy );
857 };
858
859 /// This is our 2D point class. This will be used to store the UV coordinates.
860 class CVector2 {
861 public:
862 float x, y;
863 };
864
865
866 // This file includes all of the model structures that are needed to load
867 // in a .Md2 file. When it comes to skeletal animation, we need to add quite
868 // a bit more variables to these structures. Not all of the data will be used
869 // because Quake2 models don't have such a need. I decided to keep the structures
870 // the same as the rest of the model loaders on our site so that we could eventually
871 // use a base class in the future for a library.
872 //
873
874 typedef unsigned char BYTE;
875 #define MAX_TEXTURES 100 // The maximum amount of textures to load
876
877 // -=K=-: to avoid using mallocs lets keep Texture data in vectors
878 typedef std::vector<GLubyte> TextureData;
879
880 /// A triangle face for use in arrays.
881
882 /// This is our face structure. This is is used for indexing into the vertex
883 /// and texture coordinate arrays. From this information we know which vertices
884 /// from our vertex array go to which face, along with the correct texture coordinates.
885 struct tFace {
886 int vertIndex[3]; // indicies for the verts that make up this triangle
887 int coordIndex[3]; // indicies for the tex coords to texture this face
888 };
889
890 /// A material (for character models)
891
892 /// This holds the information for a material. It may be a texture map of a color.
893 /// Some of these are not used, but I left them because you will want to eventually
894 /// read in the UV tile ratio and the UV tile offset for some models.
895 struct tMaterialInfo {
896 char strName[255]; // The texture name
897 std::string strFile; // The texture file name (If this is set it's a texture map)
898 BYTE color[3]; // The color of the object (R, G, B)
899 int texureId; // the texture ID
900 float uTile; // u tiling of texture (Currently not used)
901 float vTile; // v tiling of texture (Currently not used)
902 float uOffset; // u offset of texture (Currently not used)
903 float vOffset; // v offset of texture (Currently not used)
904 } ;
905
906 /// An inanimate 3D object.
907
908 /// This holds all the information for our model/scene.
909 /// You should eventually turn into a robust class that
910 /// has loading/drawing/querying functions like:
911 /// LoadModel(...); DrawObject(...); DrawModel(...); DestroyModel(...);
912 struct t3DObject {
913 int numOfVerts; // The number of verts in the model
914 int numOfFaces; // The number of faces in the model
915 int numTexVertex; // The number of texture coordinates
916 int numGlCommands; // The number of glCommands
917 int materialID; // The texture ID to use, which is the index into our texture array
918 bool bHasTexture; // This is TRUE if there is a texture map for this object
919 char strName[255]; // The name of the object
920 CVector3 *pVerts; // The object's vertices
921 CVector3 *pNormals; // The object's normals
922 float *shadingColorDelta; // 1 per normal
923 CVector2 *pTexVerts; // The texture's UV coordinates
924 tFace *pFaces; // The faces information of the object
925 };
926
927 /// A character model animation.
928
929 /// This holds our information for each animation of the Quake model.
930 /// A STL vector list of this structure is created in our t3DModel structure below.
931 struct tAnimationInfo {
932 char strName[255]; // This stores the name of the animation (Jump, Pain, etc..)
933 int startFrame; // This stores the first frame number for this animation
934 int endFrame; // This stores the last frame number for this animation
935 int loopingFrames; // This stores the looping frames for this animation (not used)
936 int framesPerSecond; // This stores the frames per second that this animation runs
937 };
938
939 typedef float vect3d[3];
940
941 /// A 3D character model.
942
943 /// We added 4 new variables to our model structure. These will help us handle
944 /// the current animation. As of now, the current animation will continue to loop
945 /// from it's start from to it's end frame until we right click and change animations.
946 struct t3DModel {
947 int numOfObjects; // The number of objects in the model
948 int numOfMaterials; // The number of materials for the model
949 int numOfAnimations; // The number of animations in this model
950 //int currentAnim; // The current index into pAnimations list
951 //int currentFrame; // The current frame of the current animation
952 //int nextFrame; // The next frame of animation to interpolate too
953 //float t; // The ratio of 0.0f to 1.0f between each key frame
954 //float lastTime; // This stores the last time that was stored
955
956 int numOfTags; // This stores the number of tags in the model
957 std::vector<t3DModel*> pLinks; // This stores a list of pointers that are linked to this model
958 struct tMd3Tag *pTags; // This stores all the tags for the model animations
959 float movex; // Needed to draw the model
960 float movey;
961 float movez;
962 std::vector<tAnimationInfo> pAnimations; // The list of animations
963 std::map<std::string, int> pAnimationMap; // name->index into pAnimations.
964 std::vector<tMaterialInfo> pMaterials; // The list of material information (Textures and colors)
965 std::vector<t3DObject> pObject; // The object list for our model (frames)
966 vect3d *vertices; // All vertices for every frame of the model
967 int numVertices; // The number of vertices (constant for each frame)
968 int *pGlCommands; // The glCommands used to draw the model faster
969 };
970
971 char *getAn( const char *name );
972
973 typedef unsigned char byte;
974
975 extern void ComputeNormals( t3DModel *pModel );
976 extern void CreateTexture( GLuint textureArray[], char *strFileName, int textureID );
977 extern void swap( unsigned char & a, unsigned char & b );
978 extern void findNormal( CVector3 *p1, CVector3 *p2, CVector3 *p3, CVector3 *normal );
979
980 // just easy way to get rid of malloc/free/strdup
981 // comment these out if you really need one of them
982 #define malloc please_avoid_malloc_in_cpp
983 #define calloc please_avoid_calloc_in_cpp
984 #define free please_avoid_free_in_cpp
985 #undef strdup
986 #define strdup please_avoid_strdup_in_cpp
987 #endif
988