u7drag.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #  include <config.h>
00027 #endif
00028 
00029 
00030 #include "u7drag.h"
00031 #include "utils.h"
00032 
00033 /*
00034  *  Store in char array.
00035  *
00036  *  Output: Length of what's stored.
00037  */
00038 
00039 int Store_u7_shapeid
00040   (
00041   unsigned char *data,    // At least 4 bytes.
00042   int file,       // 0-255.
00043   int shape,      // 0-0xffff.
00044   int frame     // 0-255.
00045   )
00046   {
00047   unsigned char *ptr = data;
00048   *ptr++ = file;
00049   Write2(ptr, shape);
00050   *ptr++ = frame;
00051   return (ptr - data);
00052   }
00053 
00054 /*
00055  *  Retrieve shapeid.
00056  */
00057 
00058 void Get_u7_shapeid
00059   (
00060   unsigned char *data,    // At least 4 bytes.
00061   int& file,      // 0-255.
00062   int& shape,     // 0-0xffff.
00063   int& frame      // 0-255.
00064   )
00065   {
00066   unsigned char *ptr = data;
00067   file = *ptr++;
00068   shape = Read2(ptr);
00069   frame = *ptr;
00070   }
00071 
00072 /*
00073  *  Store in char array.
00074  *
00075  *  Output: Length of what's stored.
00076  */
00077 
00078 int Store_u7_chunkid
00079   (
00080   unsigned char *data,    // At least 4 bytes.
00081   int cnum      // Chunk #.
00082   )
00083   {
00084   unsigned char *ptr = data;
00085   Write2(ptr, cnum);
00086   return (ptr - data);
00087   }
00088 
00089 /*
00090  *  Retrieve cnum#.
00091  */
00092 
00093 void Get_u7_chunkid
00094   (
00095   unsigned char *data,    // At least 4 bytes.
00096   int& cnum     // 0-0xffff returned.
00097   )
00098   {
00099   unsigned char *ptr = data;
00100   cnum = Read2(ptr);
00101   }
00102 
00103 /*
00104  *  Store combo.
00105  *
00106  *  Output: Length of data stored.
00107  */
00108 
00109 int Store_u7_comboid
00110   (
00111   unsigned char *data, 
00112   int xtiles, int ytiles,   // Footprint in tiles.
00113   int tiles_right,    // Tiles to right of hot-spot.
00114   int tiles_below,    // Tiles below hot-spot.
00115   int cnt,      // # members.
00116   U7_combo_data *ents   // The members, with locs. relative to
00117           //   hot-spot.
00118   )
00119   {
00120   unsigned char *ptr = data;
00121   Write2(ptr, xtiles);
00122   Write2(ptr, ytiles);
00123   Write2(ptr, tiles_right);
00124   Write2(ptr, tiles_below);
00125   Write2(ptr, cnt);
00126   for (int i = 0; i < cnt; i++)
00127     {
00128     Write2(ptr, ents[i].tx);
00129     Write2(ptr, ents[i].ty);
00130     Write2(ptr, ents[i].tz);
00131     Write2(ptr, ents[i].shape);
00132     *ptr++ = (unsigned char) ents[i].frame;
00133     }
00134   return (ptr - data);
00135   }
00136 
00137 /*
00138  *  Retrieve a combo.
00139  *
00140  *  Output: cnt = #elements.
00141  *    ents = ALLOCATED array of shapes with offsets rel. to hot-spot.
00142  */
00143 
00144 void Get_u7_comboid
00145   (
00146   unsigned char *data, 
00147   int& xtiles, int& ytiles, // Footprint in tiles.
00148   int& tiles_right,   // Tiles to right of hot-spot.
00149   int& tiles_below,   // Tiles below hot-spot.
00150   int& cnt, 
00151   U7_combo_data *& ents
00152   )
00153   {
00154   unsigned char *ptr = data;
00155   xtiles = Read2(ptr);
00156   ytiles = Read2(ptr);
00157   tiles_right = Read2(ptr);
00158   tiles_below = Read2(ptr);
00159   cnt = Read2(ptr);
00160   ents = new U7_combo_data[cnt];
00161   for (int i = 0; i < cnt; i++)
00162     {     // Tiles can be negative!
00163     ents[i].tx = (int) (short) Read2(ptr);
00164     ents[i].ty = (int) (short) Read2(ptr);
00165     ents[i].tz = (int) (short) Read2(ptr);
00166     ents[i].shape = Read2(ptr);
00167     ents[i].frame = *ptr++;
00168     }
00169   }

Generated on Mon Jul 9 14:42:50 2007 for ExultEngine by  doxygen 1.5.1