shapewrite.cc

Go to the documentation of this file.
00001 /*
00002  *  shapewrite.cc - Write out the shape 'info' files.
00003  *
00004  *  Note:  Currently only used by ExultStudio.
00005  *
00006  *  Copyright (C) 2002  The Exult Team
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #  include <config.h>
00025 #endif
00026 
00027 #include "shapevga.h"
00028 #include "shapeinf.h"
00029 #include "monstinf.h"
00030 #include "utils.h"
00031 #include "exceptions.h"
00032 
00033 using std::ifstream;
00034 using std::ios;
00035 using std::ofstream;
00036 
00037 /*
00038  *  Write out data files about shapes.
00039  */
00040 
00041 void Shapes_vga_file::write_info
00042   (
00043   bool bg       // True if BlackGate.
00044   )
00045   {
00046   int i, cnt;
00047   bool have_patch_path = is_system_path_defined("<PATCH>");
00048   assert(have_patch_path);
00049 
00050   // ShapeDims
00051   // Starts at 0x96'th shape.
00052   ofstream shpdims;
00053   U7open(shpdims, PATCH_SHPDIMS);
00054   for (i = 0x96; i < num_shapes; i++)
00055     {
00056     shpdims.put((char&) info[i].shpdims[0]);
00057     shpdims.put((char&) info[i].shpdims[1]);
00058     }
00059 
00060   // WGTVOL
00061   ofstream wgtvol;
00062   U7open(wgtvol, PATCH_WGTVOL);
00063   for (i = 0; i < num_shapes; i++)
00064     {
00065     wgtvol.put((char&) info[i].weight);
00066     wgtvol.put((char&) info[i].volume);
00067     }
00068 
00069   // TFA
00070   ofstream tfa;
00071   U7open(tfa, PATCH_TFA);
00072   for (i = 0; i < num_shapes; i++)
00073     tfa.write((char*)&info[i].tfa[0], 3);
00074 
00075   ofstream ready;
00076   U7open(ready, PATCH_READY);
00077   cnt = 0;
00078   for (i = 0; i < num_shapes; i++)
00079     if (info[i].ready_type != 255)
00080       cnt++;  //++++Got to init ready_type to 255!!!!!
00081   ready.put(cnt);
00082   for (i = 0; i < num_shapes; i++)
00083     if (info[i].ready_type != 255)
00084       {
00085       Write2(ready, i); // Shape #.
00086       ready.put(info[i].ready_type);
00087       for (int j = 0; j < 6; j++)
00088         ready.put(0); // 6 0's.
00089       }
00090   ready.close();
00091 
00092   ofstream armor;
00093   U7open(armor, PATCH_ARMOR);
00094   cnt = 0;
00095   for (i = 0; i < num_shapes; i++)
00096     if (info[i].armor != 0)
00097       cnt++;
00098   armor.put(cnt);
00099   for (i = 0; i < num_shapes; i++)
00100     if (info[i].armor != 0)
00101       info[i].armor->write(i, armor);
00102   armor.close();
00103   ofstream weapon;
00104   U7open(weapon, PATCH_WEAPONS);
00105   cnt = 0;
00106   for (i = 0; i < num_shapes; i++)
00107     if (info[i].weapon)
00108       cnt++;
00109   weapon.put(cnt);
00110   for (i = 0; i < num_shapes; i++)
00111     if (info[i].weapon)
00112       info[i].weapon->write(i, weapon, bg);
00113   weapon.close(); 
00114 
00115   ofstream ammo;
00116   U7open(ammo, PATCH_AMMO);
00117   cnt = 0;
00118   for (i = 0; i < num_shapes; i++)
00119     if (info[i].ammo)
00120       cnt++;
00121   ammo.put(cnt);
00122   for (i = 0; i < num_shapes; i++)
00123     if (info[i].ammo)
00124       info[i].ammo->write(i, ammo);
00125   ammo.close();
00126 
00127   // Write data about drawing the weapon in an actor's hand
00128   ofstream wihh;
00129   U7open(wihh, PATCH_WIHH);
00130   cnt = 0;      // Keep track of actual entries.
00131   for (i = 0; i < num_shapes; i++)
00132     if (info[i].weapon_offsets == 0)
00133       Write2(wihh, 0);// None for this shape.
00134     else      // Write where it will go.
00135       Write2(wihh, 2*1024 + 64*(cnt++));
00136   for (i = 0; i < num_shapes; i++)
00137     if (info[i].weapon_offsets)
00138         // There are two bytes per frame: 64 total
00139       wihh.write((char *)(info[i].weapon_offsets), 64);
00140   wihh.close();
00141   ofstream mfile;     // Now get monster info.
00142   U7open(mfile, PATCH_MONSTERS);
00143   cnt = 0;
00144   for (i = 0; i < num_shapes; i++)
00145     if (info[i].monstinf)
00146       cnt++;
00147   mfile.put(cnt);
00148   for (i = 0; i < num_shapes; i++)
00149     if (info[i].monstinf)
00150       info[i].monstinf->write(i, mfile);
00151   mfile.close();
00152 
00153   U7open(mfile, PATCH_EQUIP); // Write 'equip.dat'.
00154   cnt = Monster_info::get_equip_cnt();
00155   mfile.put(cnt);
00156   for (i = 0; i < cnt; i++)
00157     {
00158     Equip_record& rec = Monster_info::get_equip(i);
00159           // 10 elements/record.
00160     for (int e = 0; e < 10; e++)
00161       {
00162       Equip_element& elem = rec.get(e);
00163       Write2(mfile, elem.get_shapenum());
00164       mfile.put(elem.get_probability());
00165       mfile.put(elem.get_quantity());
00166       Write2(mfile, 0);
00167       }
00168     }
00169   mfile.close();
00170 
00171   ofstream(occ);      // Write occlude.dat.
00172   U7open(occ, PATCH_OCCLUDE);
00173   unsigned char occbits[128]; // 1024 bit flags.
00174           // +++++This could be rewritten better!
00175   memset(&occbits[0], 0, sizeof(occbits));
00176   for (i = 0; i < sizeof(occbits); i++)
00177     {
00178     unsigned char bits = 0;
00179     int shnum = i*8;  // Check each bit.
00180     for (int b = 0; b < 8; b++)
00181       if (shnum + b >= num_shapes)
00182         break;
00183       else if (info[shnum + b].occludes_flag)
00184         bits |= (1<<b);
00185     occbits[i] = bits;  
00186     }
00187   occ.write((char *)occbits, sizeof(occbits));
00188   }
00189 
00190 /*
00191  *  Write out a weapon-info entry to 'weapons.dat'.
00192  */
00193 
00194 void Weapon_info::write
00195   (
00196   int shapenum,
00197   std::ostream& out,    // Write to here.
00198   bool bg
00199   )
00200   {
00201   uint8 buf[21];      // Entry length.
00202   uint8 *ptr = buf;
00203   Write2(ptr, shapenum);    // Bytes 0-1.
00204   Write2(ptr, ammo);
00205   Write2(ptr, projectile);
00206   *ptr++ = damage;
00207   unsigned char flags0 = (damage_type<<4) |
00208         ((m_explodes ? 1 : 0)<<1);
00209   *ptr++ = flags0;
00210   *ptr++ = (range<<3) | (uses<<1);
00211   unsigned char flags1 = m_returns ? 1 : 0;
00212   *ptr++ = flags1;
00213   *ptr++ = actor_frames;
00214   *ptr++ = powers;
00215   *ptr++ = 0;     // ??
00216   Write2(ptr, usecode);
00217           // BG:  Subtracted 1 from each sfx.
00218   int sfx_delta = bg ? -1 : 0;
00219   Write2(ptr, sfx - sfx_delta);
00220   Write2(ptr, hitsfx + sfx_delta);
00221           // Last 2 bytes unknown/unused.
00222   Write2(ptr, 0);
00223   out.write((char *) buf, sizeof(buf));
00224   }
00225 
00226 /*
00227  *  Write out an ammo-info entry to 'ammo.dat'.
00228  */
00229 
00230 void Ammo_info::write
00231   (
00232   int shapenum,
00233   std::ostream& out   // Write to here.
00234   )
00235   {
00236   uint8 buf[13];      // Entry length.
00237   uint8 *ptr = buf;
00238   Write2(ptr, shapenum);
00239   Write2(ptr, family_shape);
00240   Write2(ptr, type2);
00241   *ptr++ = damage;
00242   Write2(ptr, 0);     // Unknown.
00243   *ptr++ = damage_type<<4;
00244   *ptr++ = powers;
00245   Write2(ptr, 0);     // Unknown.
00246   out.write((char *) buf, sizeof(buf));
00247   }
00248 
00249 /*
00250  *  Write out an armor-info entry to 'armor.dat'.
00251  */
00252 
00253 void Armor_info::write
00254   (
00255   int shapenum,
00256   std::ostream& out   // Write to here.
00257   )
00258   {
00259   uint8 buf[10];      // Entry length.
00260   uint8 *ptr = buf;
00261   Write2(ptr, shapenum);
00262   *ptr++ = prot;      // Protection value.
00263   *ptr++ = 0;     // Unknown.
00264   *ptr++ = immune;    // Immunity flags.
00265         Write4(ptr, 0);     // Last 5 are unknown/unused.
00266   *ptr = 0;
00267   out.write((char *) buf, sizeof(buf));
00268   }
00269 
00270 /*
00271  *  Write out monster info. to 'monsters.dat'.
00272  */
00273 
00274 void Monster_info::write
00275   (
00276   int shapenum,
00277   std::ostream& out
00278   )
00279   {
00280   uint8 buf[25];    // Entry length.
00281   memset(&buf[0], 0, sizeof(buf));
00282   uint8 *ptr = buf;
00283   Write2(ptr, shapenum);
00284   *ptr++ = strength << 2;
00285   *ptr++ = dexterity << 2;
00286   *ptr++ = (intelligence << 2) | (m_poison_safe ? 1 : 0);
00287   *ptr++ = (combat << 2) | alignment;
00288   *ptr++ = (armor << 4) | (m_splits ? 1 : 0) | (m_cant_die ? 2 : 0);
00289   *ptr++ = 0;     // Unknown.
00290   *ptr++ = (weapon << 4) | reach;
00291   *ptr++ = flags;     // Byte 9.
00292   *ptr++ = vulnerable;
00293   *ptr++ = immune;
00294   *ptr++ = (m_cant_yell ? (1<<5) : 0) |
00295      (m_cant_bleed ? (1<<6) : 0);
00296   *ptr++ = 0;     // Unknown.
00297   *ptr++ = equip_offset;
00298   out.write((char *) buf, sizeof(buf));
00299   }
00300 

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