WpnOvlayDat.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2005 The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (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 "WpnOvlayDat.h"
00022 
00023 #include "IDataSource.h"
00024 #include "WeaponOverlay.h"
00025 #include "RawArchive.h"
00026 #include "GameData.h"
00027 #include "MainShapeArchive.h"
00028 #include "AnimAction.h"
00029 
00030 WpnOvlayDat::WpnOvlayDat()
00031 {
00032 
00033 }
00034 
00035 
00036 WpnOvlayDat::~WpnOvlayDat()
00037 {
00038         for (unsigned int i = 0; i < overlay.size(); i++)
00039                 delete overlay[i];
00040         overlay.clear();
00041 }
00042 
00043 const AnimWeaponOverlay* WpnOvlayDat::getAnimOverlay(uint32 action) const
00044 {
00045         if (action >= overlay.size()) return 0;
00046         return overlay[action];
00047 }
00048 
00049 const WeaponOverlayFrame* WpnOvlayDat::getOverlayFrame(uint32 action, int type,
00050                                                                                                            int direction,
00051                                                                                                            int frame) const
00052 {
00053         if (action >= overlay.size()) return 0;
00054         if (!overlay[action]) return 0;
00055         return overlay[action]->getFrame(type, direction, frame);
00056 }
00057 
00058 
00059 void WpnOvlayDat::load(RawArchive *overlaydat)
00060 {
00061         WeaponOverlayFrame f;
00062 
00063         MainShapeArchive* msf = GameData::get_instance()->getMainShapes();
00064         assert(msf);
00065 
00066         overlay.resize(overlaydat->getCount());
00067 
00068         for (unsigned int action = 0; action < overlay.size(); action++)
00069         {
00070                 IDataSource* ds = overlaydat->get_datasource(action);
00071                 overlay[action] = 0;
00072 
00073                 if (ds && ds->getSize()) {
00074                         // get Avatar's animation
00075                         AnimAction* anim = msf->getAnim(1, action);
00076                         if (!anim) {
00077                                 perr << "Skipping wpnovlay action " << action << " because animation doesn't exist." << std::endl;
00078                                 continue;
00079                         }
00080 
00081                         AnimWeaponOverlay* awo = new AnimWeaponOverlay;
00082                         overlay[action] = awo;
00083 
00084                         unsigned int animlength = anim->size;
00085                         unsigned int dircount = anim->dircount;
00086 
00087                         unsigned int typecount = ds->getSize() / (4*dircount*animlength);
00088                         awo->overlay.resize(typecount);
00089 
00090                         for (unsigned int type = 0; type < typecount; type++) {
00091                                 awo->overlay[type].dircount = dircount;
00092                                 awo->overlay[type].frames =
00093                                         new std::vector<WeaponOverlayFrame>[dircount];
00094                                 for (unsigned int dir = 0; dir < dircount; dir++) {
00095                                         awo->overlay[type].frames[dir].resize(animlength);
00096                                         for (unsigned int frame = 0; frame < animlength; frame++) {
00097                                                 unsigned int offset = type*8*animlength
00098                                                         + dir*animlength + frame;
00099                                                 ds->seek(4 * offset);
00100                                                 f.xoff = ds->readXS(1);
00101                                                 f.yoff = ds->readXS(1);
00102                                                 f.frame = ds->read2();
00103 
00104                                                 awo->overlay[type].frames[dir][frame] = f;      
00105                                         }
00106                                 }
00107                         }
00108                 }
00109 
00110 
00111                 delete ds;
00112         }
00113 
00114 }

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