📄 constants.cpp
字号:
/*************************************************************************** constants.cpp - description ------------------- begin : Sun Oct 12 2003 copyright : (C) 2003 by Gabor Torok email : cctorok@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "constants.h" // assign the data dirchar rootDir[300] = DATA_DIR;char configDir[300] = CONFIG_DIR;int get_config_dir_name( char *buff, int len ){#if defined( WIN32 ) if ( strlen( CONFIG_DIR ) +1 > len ) { return 1; } strcpy( buff, CONFIG_DIR ); return 0;#else struct passwd *pwent; pwent = getpwuid( getuid() ); if ( pwent == NULL ) { perror( "getpwuid" ); return 1; } if ( strlen( pwent->pw_dir ) + strlen( CONFIG_DIR) + 2 > len ) { return 1; } sprintf( buff, "%s/%s", pwent->pw_dir, CONFIG_DIR ); return 0;#endif /* defined( WIN32 ) */}int get_config_file_name( char *buff, int len ){ if (get_config_dir_name( buff, len ) != 0) { return 1; } if ( strlen( buff ) + strlen( CONFIG_FILE ) +2 > len ) { return 1; }#if defined( WIN32 ) strcat( buff, "\\" );#else strcat( buff, "/" );#endif /* defined( WIN32 ) */ strcat( buff, CONFIG_FILE); return 0;}//sprintf(s, "Welcome to Scourge version %7.2f", SCOURGE_VERSION);char *Constants::messages[][80] = { { "Infamy awaits in the dungeons of Scourge!", "Another day, another sewer! Welcome to Scourge!", "Happy hunting; welcome to Scourge!" }, { "That item is out of your reach", "You can't touch that", "You have to be closer to get that", "You are too far to reach it" }, { "The door is blocked", "Something is blocking that door", "You can't use that door; something is in the way" }, { "You are now in single-step mode" }, { "You are now in group mode" }, { "Paused: you have entered turn-based mode" }, { "Un-paused: you are in real-time mode" }, { "Close" }, { "Drop Item" }, { "Open Item" }, { "Drag items to/from the list" }, { "Play Mission" }, { "Do you really want to exit this mission?" }, { "Exit mission and teleport back to base?" }, { "OK" }, { "Cancel" }, { "Yes" }, { "No" }, { "Select a character who is alive and has leveled up." }, { "No skill points available." }, { "Select a skill first." }, { "S.C.O.U.R.G.E. dialog" }, { "Use gate to enter another level?" }, { "A dead character cannot perform this action." }, { "hp:" }, { "ac:" }, { "Your magic fizzles and dies.", "Only the roaches are impressed by your mumbled words.", "The silence is broken only by some crickets nearby.", "Bazzoomm! A small cloud of smoke rises to the ceiling." }, { "Your character cannot equip that item." }};int Constants::messageCount[] = { 3, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1};// opengl extension routinesPFNGLACTIVETEXTUREARBPROC glSDLActiveTextureARB = NULL;PFNGLMULTITEXCOORD2FARBPROC glSDLMultiTexCoord2fARB = NULL;PFNGLMULTITEXCOORD2IARBPROC glSDLMultiTexCoord2iARB = NULL;const char *Constants::SKILL_NAMES[] = { "SWORD_WEAPON", "AXE_WEAPON", "BOW_WEAPON", "HAND_TO_HAND_COMBAT", "SPEED", "COORDINATION", "POWER", "IQ", "LEADERSHIP", "LUCK", "PIETY", "LORE", "SHIELD_DEFEND", "ARMOR_DEFEND", "WEAPON_DEFEND", "HAND_DEFEND", "NATURE_MAGIC", "AWARENESS_MAGIC", "LIFE_AND_DEATH_MAGIC", "HISTORY_MAGIC", "DECEIT_MAGIC", "CONFRONTATION_MAGIC", "OPEN_LOCK", "FIND_TRAP", "MOVE_UNDETECTED", "SKILL_0", "SKILL_1", "SKILL_2", "SKILL_3", "SKILL_4", "SKILL_5", "SKILL_6", "SKILL_7", "SKILL_8", "SKILL_9"};const char *Constants::POTION_SKILL_NAMES[] = { "HP", "MP", "AC" };const char *Constants::STATE_NAMES[] = { "blessed", "empowered", "enraged", "ac_protected", "magic_protected", "drunk", "poisoned", "cursed", "possessed", "blinded", "charmed", "changed", "overloaded", "dead", "leveled"}; const char *Constants::EFFECT_NAMES[] = { "EFFECT_FLAMES", "EFFECT_GLOW", " EFFECT_TELEPORT", "EFFECT_GREEN", "EFFECT_EXPLOSION", "EFFECT_SWIRL", "EFFECT_CAST_SPELL", "EFFECT_RING"};/*float Constants::textColor[][4]={{0.8f, 0.2f, 0.0f, 0.0f}, {0.0f, 0.2f, 0.0f, 0.0f} };*/bool Constants::multitexture = true; Constants::Constants(){}Constants::~Constants(){}char *Constants::getMessage(int index) { int n = (int)((float)messageCount[index] * rand() / RAND_MAX); return messages[index][n];}int Constants::getSkillByName(char *p) { if(!p || !strlen(p)) return -1; for(int i = 0; i < SKILL_COUNT; i++) { if(!strcmp(p, SKILL_NAMES[i])) return i; } return -1;}// return -1 on failure, or (-2 - i) on successint Constants::getPotionSkillByName(char *p) { if(!p || !strlen(p)) return -1; for(int i = 0; i < POTION_SKILL_COUNT; i++) { if(!strcmp(p, POTION_SKILL_NAMES[i])) return (-2 - i); } return -1;}/* Read until the EOL (or EOF whichever comes first) Put line chars into 'line', excluding EOL chars. Return first char after EOL. */int Constants::readLine(char *line, FILE *fp) { bool reachedEOL = false; int lc = 0; int n; while((n = fgetc(fp)) != EOF) { bool isEOLchar = (n == '\n' || n == '\r'); if(reachedEOL) { if(!isEOLchar) { line[lc++] = '\0'; return n; } } else { if(!isEOLchar) line[lc++] = n; else reachedEOL = true; } } line[lc++] = '\0'; return EOF;}// *Note* //// Below are some math functions for calculating vertex normals. We want vertex normals// because it makes the lighting look really smooth and life like. You probably already// have these functions in the rest of your engine, so you can delete these and call// your own. I wanted to add them so I could show how to calculate vertex normals.////////////////////////////// Math Functions ////////////////////////////////*// This computes the magnitude of a normal. (magnitude = sqrt(x^2 + y^2 + z^2)#define Mag(Normal) (sqrt(Normal.x*Normal.x + Normal.y*Normal.y + Normal.z*Normal.z))// This calculates a vector between 2 points and returns the resultCVector3 Vector(CVector3 vPoint1, CVector3 vPoint2){ CVector3 vVector; // The variable to hold the resultant vector vVector.x = vPoint1.x - vPoint2.x; // Subtract point1 and point2 x's vVector.y = vPoint1.y - vPoint2.y; // Subtract point1 and point2 y's vVector.z = vPoint1.z - vPoint2.z; // Subtract point1 and point2 z's return vVector; // Return the resultant vector}// This adds 2 vectors together and returns the resultCVector3 AddVector(CVector3 vVector1, CVector3 vVector2){ CVector3 vResult; // The variable to hold the resultant vector vResult.x = vVector2.x + vVector1.x; // Add Vector1 and Vector2 x's vResult.y = vVector2.y + vVector1.y; // Add Vector1 and Vector2 y's vResult.z = vVector2.z + vVector1.z; // Add Vector1 and Vector2 z's return vResult; // Return the resultant vector}// This divides a vector by a single number (scalar) and returns the resultCVector3 DivideVectorByScaler(CVector3 vVector1, float Scaler){ CVector3 vResult; // The variable to hold the resultant vector vResult.x = vVector1.x / Scaler; // Divide Vector1's x value by the scaler vResult.y = vVector1.y / Scaler; // Divide Vector1's y value by the scaler vResult.z = vVector1.z / Scaler; // Divide Vector1's z value by the scaler return vResult; // Return the resultant vector}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -