00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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>
00035 using std::cout;
00036 using std::endl;
00037
00038
00039
00040
00041
00042
00043
00044 int Weapon_info::read
00045 (
00046 std::istream& in,
00047 bool bg
00048 )
00049 {
00050 uint8 buf[21];
00051 in.read((char *) buf, sizeof(buf));
00052 uint8 *ptr = buf;
00053 int shapenum = Read2(ptr);
00054 ammo = Read2(ptr);
00055
00056
00057 projectile = Read2(ptr);
00058 #if 0
00059 extern char **item_names;
00060 cout << dec << "Weapon "
00061 << '(' << shapenum << ')' << endl;
00062 #endif
00063
00064 if (projectile == shapenum || projectile < 0)
00065 projectile = 0;
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;
00073 range = range>>3;
00074 unsigned char flags1 = *ptr++;
00075 m_returns = (flags1&1);
00076 #if 0
00077 unsigned char unk1 = *ptr++;
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++;
00084 usecode = Read2(ptr);
00085
00086 int sfx_delta = bg ? -1 : 0;
00087 sfx = Read2(ptr) + sfx_delta;
00088 hitsfx = Read2(ptr) + sfx_delta;
00089 if (hitsfx == 123 && !bg)
00090 hitsfx = 61;
00091 return shapenum;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 int Ammo_info::read
00101 (
00102 std::istream& in
00103 )
00104 {
00105 uint8 buf[13];
00106 in.read((char *) buf, sizeof(buf));
00107 uint8 *ptr = buf;
00108 int shapenum = Read2(ptr);
00109 family_shape = Read2(ptr);
00110 type2 = Read2(ptr);
00111 damage = *ptr++;
00112 ptr += 2;
00113 unsigned char flags0 = *ptr++;
00114 m_no_blocking = (flags0>>3)&1;
00115 damage_type = (flags0>>4)&15;
00116 powers = *ptr++;
00117
00118 return shapenum;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 int Armor_info::read
00128 (
00129 std::istream& in
00130 )
00131 {
00132 uint8 buf[10];
00133 in.read((char *) buf, sizeof(buf));
00134 uint8 *ptr = buf;
00135 int shapenum = Read2(ptr);
00136 prot = *ptr++;
00137 ptr++;
00138 immune = *ptr++;
00139
00140 return shapenum;
00141 }
00142
00143
00144
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
00159
00160
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
00222
00223
00224 void Shape_info::set_3d
00225 (
00226 int xt, int yt, int zt
00227 )
00228 {
00229 xt = (xt - 1) & 7;
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
00241
00242
00243 void Shape_info::set_weapon_offset
00244 (
00245 int frame,
00246 unsigned char x, unsigned char y
00247 )
00248 {
00249 if (frame < 0 || frame > 31)
00250 return;
00251 if (x == 255 && y == 255)
00252 {
00253 if (weapon_offsets)
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 }