shapeinf.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 1998  Jeffrey S. Freedman
00009 Copyright (C) 1999-2002 The Exult Team
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00024 */
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 
00030 #include "shapeinf.h"
00031 #include "monstinf.h"
00032 
00033 #include "utils.h"
00034 #include <iomanip>  /* Debugging */
00035 using std::cout;
00036 using std::endl;
00037 
00038 /*
00039  *  Read in a weapon-info entry from 'weapons.dat'.
00040  *
00041  *  Output: Shape # this entry describes.
00042  */
00043 
00044 int Weapon_info::read
00045   (
00046   std::istream& in,     // Read from here.
00047   bool bg
00048   )
00049   {
00050   uint8 buf[21];      // Entry length.
00051   in.read((char *) buf, sizeof(buf));
00052   uint8 *ptr = buf;
00053   int shapenum = Read2(ptr);  // Bytes 0-1.
00054   ammo = Read2(ptr);    // This is ammo family, or a neg. #.
00055           // Shape to strike with, or projectile
00056           //   shape if shoot/throw.
00057   projectile = Read2(ptr);
00058 #if 0
00059     extern char **item_names;
00060     cout << dec << "Weapon " //  << item_names[shapenum]
00061       << '(' << shapenum << ')' << endl;
00062 #endif
00063           // +++++Wonder what strike < 0 means.
00064   if (projectile == shapenum || projectile < 0)
00065     projectile = 0;   // Means no projectile thrown.
00066   damage = *ptr++;
00067   unsigned char flags0 = *ptr++;
00068   m_explodes = (flags0>>1)&1;
00069   m_no_blocking = (flags0>>2)&1;
00070   damage_type = (flags0>>4)&15;
00071   range = *ptr++;
00072   uses = (range>>1)&3;    // Throwable, etc.:
00073   range = range>>3;
00074   unsigned char flags1 = *ptr++;
00075   m_returns = (flags1&1);
00076 #if 0
00077   unsigned char unk1 = *ptr++;  // Figured it out now... I think.
00078   cout << "Unk1 = " << hex << "0x" << setfill('0') << setw(2) <<(int)unk1
00079               << endl;
00080 #endif
00081   actor_frames = (*ptr++)&15;
00082   powers = *ptr++;
00083   *ptr++;       // Skip (0).
00084   usecode = Read2(ptr);
00085           // BG:  Subtract 1 from each sfx.
00086   int sfx_delta = bg ? -1 : 0;
00087   sfx = Read2(ptr) + sfx_delta;
00088   hitsfx = Read2(ptr) + sfx_delta;
00089   if (hitsfx == 123 && !bg) // SerpentIsle:  Does not sound right.
00090     hitsfx = 61;    // Sounds more like a weapon.
00091   return shapenum;
00092   }
00093 
00094 /*
00095  *  Read in an ammo-info entry from 'ammo.dat'.
00096  *
00097  *  Output: Shape # this entry describes.
00098  */
00099 
00100 int Ammo_info::read
00101   (
00102   std::istream& in    // Read from here.
00103   )
00104   {
00105   uint8 buf[13];      // Entry length.
00106   in.read((char *) buf, sizeof(buf));
00107   uint8 *ptr = buf;
00108   int shapenum = Read2(ptr);  // Bytes 0-1.
00109   family_shape = Read2(ptr);
00110   type2 = Read2(ptr);   // ???
00111   damage = *ptr++;
00112   ptr += 2;     // 2 unknown.
00113   unsigned char flags0 = *ptr++;
00114   m_no_blocking = (flags0>>3)&1;
00115   damage_type = (flags0>>4)&15;
00116   powers = *ptr++;
00117           // Last 2 unknown.
00118   return shapenum;
00119   }
00120 
00121 /*
00122  *  Read in an armor-info entry from 'armor.dat'.
00123  *
00124  *  Output: Shape # this entry describes.
00125  */
00126 
00127 int Armor_info::read
00128   (
00129   std::istream& in    // Read from here.
00130   )
00131   {
00132   uint8 buf[10];      // Entry length.
00133   in.read((char *) buf, sizeof(buf));
00134   uint8 *ptr = buf;
00135   int shapenum = Read2(ptr);  // Bytes 0-1.
00136   prot = *ptr++;      // Protection value.
00137   ptr++;        // Unknown.
00138   immune = *ptr++;    // Immunity flags.
00139           // Last 5 are unknown/unused.
00140   return shapenum;
00141   }
00142 
00143 /*
00144  *  Clean up.
00145  */
00146 
00147 Shape_info::~Shape_info()
00148   {
00149   delete weapon;
00150   delete ammo;
00151   delete armor;
00152   if(weapon_offsets)
00153     delete [] weapon_offsets;
00154   delete monstinf;
00155   }
00156 
00157 /*
00158  *  Create/delete 'info' for weapons, ammo, etc.
00159  *
00160  *  Output: Possibly updated ->info .
00161  */
00162 
00163 Weapon_info *Shape_info::set_weapon_info(bool tf)
00164   {
00165   if (!tf)
00166     {
00167     delete weapon;
00168     weapon = 0;
00169     }
00170   else
00171     {
00172     if (!weapon)
00173       weapon = new Weapon_info();
00174     }
00175   return weapon;
00176   }
00177 Ammo_info *Shape_info::set_ammo_info(bool tf)
00178   {
00179   if (!tf)
00180     {
00181     delete ammo;
00182     ammo = 0;
00183     }
00184   else
00185     {
00186     if (!ammo)
00187       ammo = new Ammo_info();
00188     }
00189   return ammo;
00190   }
00191 Armor_info *Shape_info::set_armor_info(bool tf)
00192   {
00193   if (!tf)
00194     {
00195     delete armor;
00196     armor = 0;
00197     }
00198   else
00199     {
00200     if (!armor)
00201       armor = new Armor_info();
00202     }
00203   return armor;
00204   }
00205 Monster_info *Shape_info::set_monster_info(bool tf)
00206   {
00207   if (!tf)
00208     {
00209     delete monstinf;
00210     monstinf = 0;
00211     }
00212   else
00213     {
00214     if (!monstinf)
00215       monstinf = new Monster_info();
00216     }
00217   return monstinf;
00218   }
00219 
00220 /*
00221  *  Set 3D dimensions.
00222  */
00223 
00224 void Shape_info::set_3d
00225   (
00226   int xt, int yt, int zt    // In tiles.
00227   )
00228   {
00229   xt = (xt - 1) & 7;    // Force legal values.
00230   yt = (yt - 1) & 7;
00231   zt &= 7;
00232   tfa[2] = (tfa[2]&~63)|xt|(yt<<3);
00233   tfa[0] = (tfa[0]&~(7<<5))|(zt<<5);
00234   dims[0] = xt + 1;
00235   dims[1] = yt + 1;
00236   dims[2] = zt;
00237   }
00238 
00239 /*
00240  *  Set weapon offsets for given frame.
00241  */
00242 
00243 void Shape_info::set_weapon_offset
00244   (
00245   int frame,      // 0-31.
00246   unsigned char x, unsigned char y// 255 means "dont' draw".
00247   )
00248   {
00249   if (frame < 0 || frame > 31)
00250     return;
00251   if (x == 255 && y == 255)
00252     {
00253     if (weapon_offsets) // +++Could delete if all 255's now.
00254       weapon_offsets[frame*2] =
00255       weapon_offsets[frame*2 + 1] = 255;
00256     return;
00257     }
00258   if (!weapon_offsets)
00259     {
00260     weapon_offsets = new unsigned char[64];
00261     std::memset(weapon_offsets, 255, sizeof(weapon_offsets));
00262     }
00263   weapon_offsets[frame*2] = x;
00264   weapon_offsets[frame*2 + 1] = y;
00265   }

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