ShapeInfo.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2007 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "ShapeInfo.h"
00022 #include "CoreApp.h"
00023 
00024 bool ShapeInfo::getTypeFlag(int typeflag)
00025 {
00026         if (GAME_IS_U8)
00027                 return getTypeFlagU8(typeflag);
00028         else if (GAME_IS_CRUSADER)
00029                 return getTypeFlagCrusader(typeflag);
00030         CANT_HAPPEN_MSG("Invalid game type");
00031         return false;
00032 }
00033 
00034 bool ShapeInfo::getTypeFlagU8(int typeflag)
00035 {
00036         // This is not nice. The Typeflags in U8 were stored in an 8 byte array
00037         // and they could access them with a number from 0 to 63
00038         // Problem: We don't store them in an 8 byte array so we can't access 
00039         // with a number from 0 to 63
00040 
00041         // So what we do is split the flag up into the bits
00042 
00043         if (typeflag <= 11)                     // flags                Byte 0, 1:0-3   Bits  0-11
00044         {
00045                 return (flags >> typeflag) & 1;
00046         }
00047         else if (typeflag <= 15)        // family               Byte 1:4-7              Bits 11-15
00048         {
00049                 return (family >> (typeflag-12)) & 1;
00050         }
00051         else if (typeflag <= 19)        // equiptype    Byte 2:0-3              Bits 16-19
00052         {
00053                 return (equiptype >> (typeflag-16)) & 1;
00054         }
00055         else if (typeflag <= 23)        // x                    Byte 2:4-7              Bits 20-23
00056         {
00057                 return (x >> (typeflag-20)) & 1;
00058         }
00059         else if (typeflag <= 27)        // y                    Byte 3:0-3              Bits 24-27
00060         {
00061                 return (y >> (typeflag-24)) & 1;
00062         }
00063         else if (typeflag <= 31)        // z                    Byte 3:4-7              Bits 28-31
00064         {
00065                 return (z >> (typeflag-28)) & 1;
00066         }
00067         else if (typeflag <= 35)        // animtype             Byte 4:0-3              Bits 32-35
00068         {
00069                 return (animtype >> (typeflag-32)) & 1;
00070         }
00071         else if (typeflag <= 39)        // animdata             Byte 4:4-7              Bits 36-49
00072         {
00073                 return (animdata >> (typeflag-36)) & 1;
00074         }
00075         else if (typeflag <= 43)        // unknown              Byte 5:0-3              Bits 40-43
00076         {
00077                 return (unknown >> (typeflag-40)) & 1;
00078         }
00079         else if (typeflag <= 47)        // flags                Byte 5:4-7              Bits 44-47
00080         {
00081                 return (flags >> (12+typeflag-44)) & 1;
00082         }
00083         else if (typeflag <= 55)        // weight               Byte 6                  Bits 48-55
00084         {
00085                 return (weight >> (typeflag-48)) & 1;
00086         }
00087         else if (typeflag <= 63)        // volume               Byte 7                  Bits 56-63
00088         {
00089                 return (volume >> (typeflag-56)) & 1;
00090         }
00091 
00092         return false;
00093 }
00094 
00095 bool ShapeInfo::getTypeFlagCrusader(int typeflag)
00096 {
00097         if (typeflag <= 11)                     // flags                Byte 0, 1:0-3   Bits  0-11
00098         {
00099                 return (flags >> typeflag) & 1;
00100         }
00101         else if (typeflag <= 16)        // family               Byte 1:4-7,2:0  Bits 12-16
00102         {
00103                 return (family >> (typeflag-12)) & 1;
00104         }
00105         else if (typeflag <= 20)        // unknown              Byte 2:0-3              Bits 17-20
00106         {
00107                 perr << "Warning: unknown typeflag requested." << std::endl;
00108         }
00109         else if (typeflag <= 26)        // x                    Byte 2:4-7,3:0-1        Bits 21-26
00110         {
00111                 return (x >> (typeflag-21)) & 1;
00112         }
00113         else if (typeflag <= 31)        // y                    Byte 3:2-6              Bits 27-31
00114         {
00115                 return (y >> (typeflag-27)) & 1;
00116         }
00117         else if (typeflag <= 36)        // z                    Byte 3:7,4:0-3  Bits 32-36
00118         {
00119                 return (z >> (typeflag-32)) & 1;
00120         }
00121         else if (typeflag <= 47)
00122         {
00123                 perr << "Warning: unknown typeflag requested." << std::endl;
00124         }
00125         else if (typeflag <= 55)        // flags                Byte 6: 0-7             Bits 48-55
00126         {
00127                 return (flags >> (12+typeflag-55)) & 1;
00128         }
00129         else if (typeflag <= 71)
00130         {
00131                 perr << "Warning: unknown typeflag requested." << std::endl;
00132         }
00133 
00134         return false;
00135 }
00136 

Generated on Fri Jul 27 22:27:36 2007 for pentagram by  doxygen 1.4.7