00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00039
00040
00041 void Shapes_vga_file::write_info
00042 (
00043 bool bg
00044 )
00045 {
00046 int i, cnt;
00047 bool have_patch_path = is_system_path_defined("<PATCH>");
00048 assert(have_patch_path);
00049
00050
00051
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
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
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++;
00081 ready.put(cnt);
00082 for (i = 0; i < num_shapes; i++)
00083 if (info[i].ready_type != 255)
00084 {
00085 Write2(ready, i);
00086 ready.put(info[i].ready_type);
00087 for (int j = 0; j < 6; j++)
00088 ready.put(0);
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
00128 ofstream wihh;
00129 U7open(wihh, PATCH_WIHH);
00130 cnt = 0;
00131 for (i = 0; i < num_shapes; i++)
00132 if (info[i].weapon_offsets == 0)
00133 Write2(wihh, 0);
00134 else
00135 Write2(wihh, 2*1024 + 64*(cnt++));
00136 for (i = 0; i < num_shapes; i++)
00137 if (info[i].weapon_offsets)
00138
00139 wihh.write((char *)(info[i].weapon_offsets), 64);
00140 wihh.close();
00141 ofstream mfile;
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);
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
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);
00172 U7open(occ, PATCH_OCCLUDE);
00173 unsigned char occbits[128];
00174
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;
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
00192
00193
00194 void Weapon_info::write
00195 (
00196 int shapenum,
00197 std::ostream& out,
00198 bool bg
00199 )
00200 {
00201 uint8 buf[21];
00202 uint8 *ptr = buf;
00203 Write2(ptr, shapenum);
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
00218 int sfx_delta = bg ? -1 : 0;
00219 Write2(ptr, sfx - sfx_delta);
00220 Write2(ptr, hitsfx + sfx_delta);
00221
00222 Write2(ptr, 0);
00223 out.write((char *) buf, sizeof(buf));
00224 }
00225
00226
00227
00228
00229
00230 void Ammo_info::write
00231 (
00232 int shapenum,
00233 std::ostream& out
00234 )
00235 {
00236 uint8 buf[13];
00237 uint8 *ptr = buf;
00238 Write2(ptr, shapenum);
00239 Write2(ptr, family_shape);
00240 Write2(ptr, type2);
00241 *ptr++ = damage;
00242 Write2(ptr, 0);
00243 *ptr++ = damage_type<<4;
00244 *ptr++ = powers;
00245 Write2(ptr, 0);
00246 out.write((char *) buf, sizeof(buf));
00247 }
00248
00249
00250
00251
00252
00253 void Armor_info::write
00254 (
00255 int shapenum,
00256 std::ostream& out
00257 )
00258 {
00259 uint8 buf[10];
00260 uint8 *ptr = buf;
00261 Write2(ptr, shapenum);
00262 *ptr++ = prot;
00263 *ptr++ = 0;
00264 *ptr++ = immune;
00265 Write4(ptr, 0);
00266 *ptr = 0;
00267 out.write((char *) buf, sizeof(buf));
00268 }
00269
00270
00271
00272
00273
00274 void Monster_info::write
00275 (
00276 int shapenum,
00277 std::ostream& out
00278 )
00279 {
00280 uint8 buf[25];
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;
00290 *ptr++ = (weapon << 4) | reach;
00291 *ptr++ = flags;
00292 *ptr++ = vulnerable;
00293 *ptr++ = immune;
00294 *ptr++ = (m_cant_yell ? (1<<5) : 0) |
00295 (m_cant_bleed ? (1<<6) : 0);
00296 *ptr++ = 0;
00297 *ptr++ = equip_offset;
00298 out.write((char *) buf, sizeof(buf));
00299 }
00300