00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SHAPEPALETTE_H
00019 #define SHAPEPALETTE_H
00020
00021 #include <string>
00022 #include <vector>
00023 #include <map>
00024 #include "constants.h"
00025 #include "shape.h"
00026 #include "glshape.h"
00027 #include "gltorch.h"
00028 #include "glteleporter.h"
00029 #include "gllocator.h"
00030 #include "md2shape.h"
00031 #include "3dsshape.h"
00032 #include "Md2.h"
00033 #include "rpg/monster.h"
00034
00035 using namespace std;
00036
00041 class GLShape;
00042 class GLTorch;
00043 class Session;
00044 class ShapePalette;
00045
00046
00047 typedef struct _ShapeValues {
00048 char textureGroupIndex[100];
00049 int width, height, depth;
00050 char name[100];
00051 int descriptionIndex;
00052 long color;
00053 int skipSide, stencil, blocksLight;
00054 int torch;
00055 char m3ds_name[100];
00056 float m3ds_scale;
00057 int teleporter;
00058 float xrot, yrot, zrot;
00059 } ShapeValues;
00060
00061 typedef struct _Md2ModelInfo {
00062 t3DModel *model;
00063 char name[100];
00064 char filename[100];
00065 float scale;
00066 } Md2ModelInfo;
00067
00068 typedef struct _CharacterModelInfo {
00069 char model_name[100];
00070 char skin_name[300];
00071 float scale;
00072 } CharacterModelInfo;
00073
00074 #define MAX_TEXTURE_COUNT 10
00075 class WallTheme {
00076 public:
00077
00078
00079 enum {
00080 THEME_REF_WALL,
00081 THEME_REF_CORNER,
00082 THEME_REF_DOOR_EW,
00083 THEME_REF_DOOR_NS,
00084 THEME_REF_PASSAGE_FLOOR,
00085 THEME_REF_ROOM_FLOOR,
00086 THEME_REF_HEADBOARD,
00087
00088
00089 THEME_REF_COUNT
00090 };
00091 static char themeRefName[THEME_REF_COUNT][40];
00092 static const int MULTI_TEX_COUNT = 2;
00093
00094 private:
00095 static const int NAME_LENGTH = 40;
00096 char *name;
00097 char textures[THEME_REF_COUNT][MAX_TEXTURE_COUNT][NAME_LENGTH];
00098 GLuint textureGroup[THEME_REF_COUNT][MAX_TEXTURE_COUNT];
00099 int faceCount[THEME_REF_COUNT];
00100 map<string,GLuint> loadedTextures;
00101 map<string,int> themeRefMap;
00102 GLfloat r[MULTI_TEX_COUNT], g[MULTI_TEX_COUNT], b[MULTI_TEX_COUNT], intensity[MULTI_TEX_COUNT];
00103 bool smooth[MULTI_TEX_COUNT];
00104 ShapePalette *shapePal;
00105
00106 public:
00107 WallTheme( char *name, ShapePalette *shapePal );
00108 ~WallTheme();
00109
00110 inline void setFaceCount( int themeRef, int value ) { faceCount[ themeRef ] = value; }
00111 int getFaceCount( string themeRefName );
00112
00113 inline void addTextureName(int themeRef, int face, const char *name) {
00114 if( themeRef < 0 || themeRef > THEME_REF_COUNT ) {
00115 cerr << "*** Error: theme ref is out of bounds: theme=" << getName() << endl;
00116 } else {
00117 strncpy( textures[themeRef][face], name, NAME_LENGTH - 1 );
00118 textures[themeRef][face][NAME_LENGTH - 1] = '\0';
00119
00120
00121
00122
00123
00124
00125 }
00126 }
00127 inline void setMultiTexRed( int index, GLfloat value ) { r[index] = value; }
00128 inline void setMultiTexGreen( int index, GLfloat value ) { g[index] = value; }
00129 inline void setMultiTexBlue( int index, GLfloat value ) { b[index] = value; }
00130 inline void setMultiTexInt( int index, GLfloat value ) { intensity[index] = value; }
00131 inline void setMultiTexSmooth( int index, bool value ) { smooth[index] = value; }
00132
00133 inline GLfloat getMultiTexRed( int index ) { return r[index]; }
00134 inline GLfloat getMultiTexGreen( int index ) { return g[index]; }
00135 inline GLfloat getMultiTexBlue( int index ) { return b[index]; }
00136 inline GLfloat getMultiTexInt( int index ) { return intensity[index]; }
00137 inline bool getMultiTexSmooth( int index ) { return smooth[index]; }
00138
00139 GLuint *getTextureGroup( string themeRefName );
00140 inline char *getName() { return name; }
00141 void load();
00142 void unload();
00143
00144 protected:
00145 void loadTextureGroup( int ref, int face, char *texture );
00146 void debug();
00147 };
00148
00149
00150 #define MAX_SYSTEM_TEXTURE_COUNT 1000
00151
00152 class ShapePalette {
00153 private:
00154 GLShape *shapes[256];
00155 map<string, GLShape *> shapeMap;
00156 int shapeCount;
00157 GLuint gui_texture, gui_wood_texture, paper_doll_texture, gui_texture2, ripple_texture;
00158 map<int, GLuint> statModIcons;
00159
00160 typedef struct _Texture {
00161 GLuint id;
00162 char filename[80];
00163 } Texture;
00164
00165 Texture textures[ MAX_SYSTEM_TEXTURE_COUNT ];
00166 int texture_count;
00167 GLShape *shapeNameArray[256];
00168
00169
00170 GLuint textureGroup[100][3];
00171 int textureGroupCount;
00172
00173 GLuint md2_tex[6];
00174
00175
00176 const static Sint16 unitSide = MAP_UNIT;
00177 const static Sint16 unitOffset = MAP_UNIT_OFFSET;
00178 const static Sint16 wallHeight = MAP_WALL_HEIGHT;
00179
00180
00181 vector<vector<string>*> descriptions;
00182
00183
00184 vector<ShapeValues*> shapeValueVector;
00185
00186
00187 map<string, Md2ModelInfo*> old_creature_models;
00188 map<string, GLuint> creature_skins;
00189 map<GLuint, int> loaded_skins;
00190 map<string, Md2ModelInfo*> creature_models;
00191 map<Md2ModelInfo*, int> loaded_models;
00192 vector<CharacterModelInfo*> character_models;
00193
00194 static ShapePalette *instance;
00195
00196
00197 CLoadMD2 g_LoadMd2;
00198 t3DModel * LoadMd2Model(char *file_name);
00199 void UnloadMd2Model( t3DModel *model );
00200
00201 Session *session;
00202 WallTheme *themes[100];
00203 int themeCount;
00204 WallTheme *currentTheme;
00205 vector<GLShape*> themeShapes;
00206 vector<string> themeShapeRef;
00207
00208 vector<GLuint> portraitTextures;
00209 GLuint deathPortraitTexture;
00210
00211 char aboutText[3000];
00212
00213 public:
00214 ShapePalette(Session *session);
00215 ~ShapePalette();
00216
00217 inline char *getAboutText() { return aboutText; }
00218
00219 void initialize();
00220 GLuint loadSystemTexture( char *line );
00221
00222 void loadNpcPortraits();
00223
00224 inline int getCharacterModelInfoCount() { return character_models.size(); }
00225 inline CharacterModelInfo *getCharacterModelInfo( int index ) { return character_models[ index ]; }
00226
00227 void loadTheme( WallTheme *theme );
00228 void loadTheme( const char *name );
00229 void loadRandomTheme();
00230
00231 GLuint formationTexIndex;
00232 inline GLuint getTexture(int index) { return textures[index].id; }
00233
00234 inline GLuint getStatModIcon(int statModIndex) { if(statModIcons.find(statModIndex) == statModIcons.end()) return (GLuint)0; else return statModIcons[statModIndex]; }
00235
00236
00237 inline static ShapePalette *getInstance() { return instance; }
00238
00239
00240 SDL_Surface *tiles, *spells;
00241 GLubyte *tilesImage[20][20], *spellsImage[20][20];
00242 GLuint tilesTex[20][20], spellsTex[20][20];
00243 SDL_Surface *cursor, *crosshair, *attackCursor, *talkCursor, *paperDoll;
00244 GLubyte *cursorImage, *crosshairImage, *attackImage, *talkImage, *paperDollImage;
00245 GLuint cursor_texture, crosshair_texture, attack_texture, talk_texture;
00246
00247 SDL_Surface *logo;
00248 GLubyte *logoImage;
00249 GLuint logo_texture;
00250
00251 SDL_Surface *chain;
00252 GLubyte *chainImage;
00253 GLuint chain_texture;
00254
00255 SDL_Surface *scourge;
00256 GLubyte *scourgeImage;
00257
00258 GLuint cloud, candle, torchback, highlight;
00259
00260 GLuint border, border2, gargoyle;
00261
00262 inline GLShape *getShape(int index) { return shapes[index]; }
00263
00264 inline Sint16 getUnitSide() { return unitSide; }
00265 inline Sint16 getUnitOffset() { return unitOffset; }
00266 inline Sint16 getWallHeight() { return wallHeight; }
00267
00268 inline GLuint getRippleTexture() { return ripple_texture; }
00269 inline GLuint getGuiTexture() { return gui_texture; }
00270 inline GLuint getGuiTexture2() { return gui_texture2; }
00271 inline GLuint getGuiWoodTexture() { return gui_wood_texture; }
00272 inline GLuint getPaperDollTexture() { return paper_doll_texture; }
00273 inline GLuint getBorderTexture() { return border; }
00274 inline GLuint getBorder2Texture() { return border2; }
00275 inline GLuint getGargoyleTexture() { return gargoyle; }
00276 inline GLuint getHighlightTexture() { return highlight; }
00277
00278 inline int getPortraitCount() { return portraitTextures.size(); }
00279 inline GLuint getPortraitTexture( int index ) { return portraitTextures[ index ]; }
00280 inline GLuint getDeathPortraitTexture() { return deathPortraitTexture; }
00281
00282 GLuint findTextureByName(const char *filename);
00283 GLShape *findShapeByName(const char *name, bool variation=false);
00284 int findShapeIndexByName(const char *name);
00285
00286
00287 GLShape *getCreatureShape(char *model_name, char *skin_name, float scale=0.0f,
00288 Monster *monster=NULL);
00289 void decrementSkinRefCount(char *model_name, char *skin_name,
00290 Monster *monster=NULL);
00291
00292 char *getRandomDescription(int descriptionGroup);
00293
00294 GLuint loadGLTextures(char *fileName);
00295
00296 protected:
00297 GLuint loadGLTextureBGRA(SDL_Surface *surface, GLubyte *image, int gl_scale=GL_NEAREST);
00298 GLuint loadGLTextureBGRA(int w, int h, GLubyte *image, int gl_scale=GL_NEAREST);
00299 void setupAlphaBlendedBMP(char *filename, SDL_Surface **surface, GLubyte **image, int red=0, int green=0, int blue=0);
00300 void setupAlphaBlendedBMPGrid(char *filename, SDL_Surface **surface, GLubyte *tilesImage[20][20], int imageWidth, int imageHeight, int tileWidth, int tileHeight, int red=0, int green=0, int blue=0, int nred=-1, int ngreen=-1, int nblue=-1);
00301 void swap(unsigned char & a, unsigned char & b);
00302 };
00303
00304 #endif