shapeinf.h

Go to the documentation of this file.
00001 
00007 #ifndef INCL_SHAPEINF
00008 #define INCL_SHAPEINF 1
00009 
00010 /*
00011 Copyright (C) 1998  Jeffrey S. Freedman
00012 
00013 This program is free software; you can redistribute it and/or
00014 modify it under the terms of the GNU General Public License
00015 as published by the Free Software Foundation; either version 2
00016 of the License, or (at your option) any later version.
00017 
00018 This program is distributed in the hope that it will be useful,
00019 but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00026 */
00027 
00028 class Monster_info;
00029 
00030 #include <iosfwd>
00031 
00032 /*
00033  *  Specific information about weapons from 'weapons.dat':
00034  *  MAYBE:  Move this and ammo. to separate source file(s).
00035  */
00036 class Weapon_info
00037   {
00038   char damage;      // Damage points (positive).
00039 public:
00040   enum Powers     // Special weapon powers.
00041     {     // Guesses from printout:
00042     sleep = 1,
00043     charm = 2,
00044     curse = 4,
00045     poison = 8,
00046     paralyze = 16,
00047     magebane = 32   // Takes away mana.
00048     };
00049   enum Damage_type    // Type of damage.  These also are the
00050           //   bit #'s in Monster_info's 
00051           //   immune and vulerable fields.
00052     {
00053     normal_damage = 0,
00054     fire_damage = 1,
00055     magic_damage = 2,
00056     poison_damage = 3 // Not sure about rest.
00057     };
00058   enum Actor_frames   // Actor frames to show when using:
00059     {
00060     raise = 1,
00061     reach = 2
00062     };
00063 private:
00064   unsigned char powers;   // Poison, sleep, charm. flags.
00065   unsigned char damage_type;  // See Damage_type above.
00066   unsigned char actor_frames; // Frames for NPC when using (from
00067           //   Actor_frames above).  Low 2 bits
00068           //   are for 'strike', next 2 are for
00069           //   shooting/throwing.
00070   short ammo;     // Shape # of ammo. consumed, or
00071           //   -1 = ?? (swords, also sling).
00072           //   -2 = ?? wands?
00073           //   -3 = throw weapon itself.
00074   short projectile;   // Projectile shape, or 0.
00075   bool m_explodes;    // Projectile explodes on impact.
00076   bool m_returns;     // Boomerang, magic axe.
00077   bool m_no_blocking;   // Can move through walls.
00078   short usecode;      // Usecode function, or 0.
00079   unsigned char uses;   // 0 = hand-hand, 1,2 = throwable,
00080           //   3 = missile-firing.
00081   unsigned char range;    // Distance weapon can be used.
00082   short sfx, hitsfx;    // Sound when using/hit, or -1.
00083 public:
00084   friend class Shape_info;
00085   Weapon_info() {  }
00086   int read(std::istream& mfile, bool bg); // Read in from file.
00087           // Write out.
00088   void write(int shapenum, std::ostream& mfile, bool bg);
00089   int get_damage() const
00090     { return damage; }
00091   int get_damage_type() const
00092     { return damage_type; }
00093   void set_damage(int dmg, int dmgtype)
00094     { damage = dmg; damage_type = dmgtype; }
00095   unsigned char get_powers() const
00096     { return powers; }
00097   void set_powers(unsigned char p)
00098     { powers = p; }
00099   unsigned char get_actor_frames(bool projectile) const
00100     { return !projectile ? (actor_frames&3) : (actor_frames>>2); }
00101   void set_actor_frames(unsigned char f)
00102     { actor_frames = f; }
00103   int get_ammo_consumed()
00104     { return ammo > 0 ? ammo : 0; }
00105   void set_ammo(int a)      // Raw value, for map-editor.
00106     { ammo = a; }
00107   bool uses_charges()
00108     { return ammo == -2; }
00109   bool is_thrown() const
00110     { return uses == 1 || uses == 2 || m_returns; }
00111   bool returns() const
00112     { return m_returns; }
00113   void set_returns(bool tf)
00114     { m_returns = tf; }
00115   bool explodes() const
00116     { return m_explodes; }
00117   void set_explodes(bool tf)
00118     { m_explodes = tf; }
00119   bool no_blocking() const
00120     { return m_no_blocking; }
00121   void set_no_blocking(bool tf)
00122     { m_no_blocking = tf; }
00123   unsigned char get_uses() const
00124     { return uses; }
00125   void set_uses(unsigned char u)
00126     { uses = u; }
00127   int get_range()     // Raw # (for map-editor).
00128     { return range; }
00129   void set_range(int r)
00130     { range = r; }
00131   int get_striking_range()  // Guessing about div. by 2.
00132     { return uses < 3 ? range/2 : 0; }
00133   int get_projectile_range()  // +++Guess for thrown weapons.
00134     { return uses == 3 ? range : is_thrown() ? 20 : 0; }
00135   int get_projectile()
00136     { return projectile; }
00137   void set_projectile(int p)
00138     { projectile = p; }
00139   int get_usecode()
00140     { return usecode; }
00141   void set_usecode(int u)
00142     { usecode = u; }
00143   int get_sfx()     // Return sound-effects #, or -1.
00144     { return sfx; }
00145   int get_hitsfx()
00146     { return hitsfx; }
00147   void set_sfxs(int s, int hits)
00148     { sfx = s; hitsfx = hits; }
00149   };
00150 
00151 /*
00152  *  Info. from 'ammo.dat':
00153  */
00154 class Ammo_info
00155   {
00156   int family_shape;   // I.e., burst-arrow's is 'arrow'.
00157   unsigned short type2;   // ?? A shape.
00158   unsigned char damage;   // Extra damage points.
00159   unsigned char powers;   // Same as for weapons.
00160   unsigned char damage_type;  // Same as for weapons.
00161   bool m_no_blocking;   // Can move through walls.
00162 public:
00163   friend class Shapes_vga_file;
00164   Ammo_info()
00165     {  }
00166   int read(std::istream& mfile);  // Read in from file.
00167           // Write out.
00168   void write(int shapenum, std::ostream& mfile);
00169   int get_family_shape()
00170     { return family_shape; }
00171   void set_family_shape(int f)
00172     { family_shape = f; }
00173   int get_damage()
00174     { return damage; }
00175   int get_damage_type() const
00176     { return damage_type; }
00177   void set_damage(int dmg, int dtype)
00178     { damage = dmg; damage_type = dtype; }
00179   unsigned char get_powers() const
00180     { return powers; }
00181   void set_powers(unsigned char p)
00182     { powers = p; }
00183   bool no_blocking() const
00184     { return m_no_blocking; }
00185   void set_no_blocking(bool tf)
00186     { m_no_blocking = tf; }
00187   };
00188 
00189 /*
00190  *  Armor:
00191  */
00192 class Armor_info
00193   {
00194   unsigned char prot;   // Protection value.
00195   unsigned char immune;   // Weapon_info::damage_type bits.
00196 public:
00197   friend class Shape_info;
00198   Armor_info() {  }
00199   int read(std::istream& mfile);  // Read in from file.
00200           // Write out.
00201   void write(int shapenum, std::ostream& mfile);
00202   unsigned char get_prot() const
00203     { return prot; }
00204   void set_prot(unsigned char p)
00205     { prot = p; }
00206   unsigned char get_immune() const
00207     { return immune; }
00208   void set_immune(unsigned char i)
00209     { immune = i; }
00210   };
00211 
00212 /*
00213  *  This class contains information only about shapes from "shapes.vga".
00214  */
00215 class Shape_info
00216   {
00217   unsigned char tfa[3];   // From "tfa.dat".+++++Keep for
00218           //   debugging, for now.
00219           // 3D dimensions in tiles:
00220   unsigned char dims[3];    //   (x, y, z)
00221   unsigned char weight, volume; // From "wgtvol.dat".
00222   unsigned char shpdims[2]; // From "shpdims.dat".
00223   unsigned char ready_type; // From "ready.dat":  where item can
00224           //   be worn.
00225   bool occludes_flag;   // Flagged in 'occlude.dat'.  Roof.
00226   unsigned char *weapon_offsets;  // From "wihh.dat": pixel offsets
00227           //   for drawing weapon in hand
00228   Armor_info *armor;    // From armor.dat.
00229   Weapon_info *weapon;    // From weapon.dat, if a weapon.
00230   Ammo_info *ammo;    // From ammo.dat, if ammo.
00231   Monster_info *monstinf;   // From monster.dat.
00232   void set_tfa_data()   // Set fields from tfa.
00233     {
00234     dims[0] = 1 + (tfa[2]&7);
00235     dims[1] = 1 + ((tfa[2]>>3)&7);
00236     dims[2] = (tfa[0] >> 5);
00237     }
00238           // Set/clear tfa bit.
00239   void set_tfa(int i, int bit, bool tf)
00240     { tfa[i] = tf ? (tfa[i]|(1<<bit)) : (tfa[i]&~(1<<bit)); }
00241   // This private copy constructor and assignment operator are never
00242   // defined so copying will cause a link error (intentional)
00243   Shape_info(const Shape_info & other);
00244   const Shape_info & operator = (const Shape_info & other);
00245 public:
00246   friend class Shapes_vga_file; // Class that reads in data.
00247   Shape_info() : weight(0), volume(0),
00248     ready_type(255), occludes_flag(false), weapon_offsets(0), 
00249     armor(0), weapon(0), ammo(0), monstinf(0)
00250     {
00251     tfa[0] = tfa[1] = tfa[2] = shpdims[0] = shpdims[1] = 0;
00252     dims[0] = dims[1] = dims[2] = 0;
00253     }
00254   virtual ~Shape_info();
00255   int get_weight()    // Get weight, volume.
00256     { return weight; }
00257   int get_volume()
00258     { return volume; }
00259   void set_weight_volume(int w, int v)
00260     { weight = w; volume = v; }
00261   int get_armor()     // Get armor protection.
00262     { return armor ? armor->prot : 0; }
00263   Weapon_info *get_weapon_info()
00264     { return weapon; }
00265   Weapon_info *set_weapon_info(bool tf);
00266   Ammo_info *get_ammo_info()
00267     { return ammo; }
00268   Ammo_info *set_ammo_info(bool tf);
00269   Armor_info *get_armor_info()
00270     { return armor; }
00271   Armor_info *set_armor_info(bool tf);
00272   Monster_info *get_monster_info()
00273     { return monstinf; }
00274   Monster_info *set_monster_info(bool tf);
00275           // Get tile dims., flipped for
00276           //   reflected (bit 5) frames.
00277   int get_3d_xtiles(unsigned int framenum = 0)
00278     { return dims[(framenum >> 5)&1]; }
00279   int get_3d_ytiles(unsigned int framenum = 0)
00280     { return dims[1 ^ ((framenum >> 5)&1)]; }
00281   int get_3d_height()   // Height (in lifts?).
00282     { return dims[2]; }
00283   void set_3d(int xt, int yt, int zt);
00284   unsigned char get_tfa(int i)  // For debugging:
00285     { return tfa[i]; }
00286   int has_sfx()     // Has a sound effect (guessing).
00287     { return (tfa[0] & (1<<0)) != 0; }
00288   void set_sfx(bool tf)
00289     { set_tfa(0, 0, tf); }
00290   int has_strange_movement()  // Slimes, sea monsters.
00291     { return (tfa[0] & (1<<1)) != 0; }
00292   void set_strange_movement(bool tf)
00293     { set_tfa(0, 1, tf); }
00294   int is_animated()
00295     { return (tfa[0] & (1<<2)) != 0; }
00296   void set_animated(bool tf)
00297     { set_tfa(0, 2, tf); }
00298   int is_solid()      // Guessing.  Means can't walk through.
00299     { return (tfa[0] & (1<<3)) != 0; }
00300   void set_solid(bool tf)
00301     { set_tfa(0, 3, tf); }
00302   int is_water()      // Guessing.
00303     { return (tfa[0] & (1<<4)) != 0; }
00304   void set_water(bool tf)
00305     { set_tfa(0, 4, tf); }
00306   int is_poisonous()    // Swamps.  Applies to tiles.
00307     { return (tfa[1] & (1<<4)) != 0; }
00308   int is_field()      // Applies to Game_objects??
00309     { return (tfa[1] & (1<<4)) != 0; }
00310   void set_field(bool tf)
00311     { set_tfa(1, 4, tf); }
00312   int is_door()
00313     { return (tfa[1] & (1<<5)) != 0; }
00314   void set_door(bool tf)
00315     { set_tfa(1, 5, tf); }
00316   int is_barge_part()
00317     { return (tfa[1] & (1<<6)) != 0; }
00318   void set_barge_part(bool tf)
00319     { set_tfa(1, 6, tf); }
00320   int is_transparent()    // ??
00321     { return (tfa[1] & (1<<7)) != 0; }
00322   void set_transparent(bool tf)
00323     { set_tfa(1, 7, tf); }
00324   int is_light_source()
00325     { return (tfa[2] & (1<<6)) != 0; }
00326   void set_light_source(bool tf)
00327     { set_tfa(2, 6, tf); }
00328   int has_translucency()
00329     { return (tfa[2] & (1<<7)) != 0; }
00330   void set_translucency(bool tf)
00331     { set_tfa(2, 7, tf); }
00332   int is_xobstacle()    // Obstacle in x-dir.???
00333     { return (shpdims[1] & 1) != 0; }
00334   int is_yobstacle()    // Obstacle in y-dir.???
00335     { return (shpdims[0] & 1) != 0; }
00336   void set_obstacle(bool x, bool y)
00337     {
00338     shpdims[1] = x ? (shpdims[1]|1) : (shpdims[1]&~1);
00339     shpdims[0] = y ? (shpdims[0]|1) : (shpdims[0]&~1);
00340     }
00341   /*
00342    *  TFA[1][b0-b3] seems to indicate object types:
00343    */
00344   enum Shape_class {
00345     unusable = 0,   // Trees.
00346     quality = 2,
00347     quantity = 3,   // Can have more than 1:  coins, arrs.
00348     has_hp = 4,     // Breakable items (if hp != 0, that is)
00349     quality_flags = 5,  // Item quality is set of flags:
00350           // Bit 3 = okay-to-take.
00351     container = 6,
00352     hatchable = 7,    // Eggs, traps, moongates.
00353     spellbook = 8,
00354     barge = 9,
00355     virtue_stone = 11,
00356     monster = 12,   // Non-human's.
00357     human = 13,   // Human NPC's.
00358     building = 14   // Roof, window, mountain.
00359     };
00360   Shape_class get_shape_class()
00361     { return (Shape_class) (tfa[1]&15); }
00362   void set_shape_class(Shape_class c)
00363     { tfa[1] = (tfa[1]&~15)|(int) c; }
00364   bool is_npc()
00365     {
00366     Shape_class c = get_shape_class();
00367     return c == human || c == monster;
00368     }
00369   bool has_quantity()
00370     { return get_shape_class() == quantity; }
00371   bool has_quality_flags()  // Might be more...
00372     { return get_shape_class() == quality_flags; }
00373   bool has_quality()
00374     {
00375 #if 0
00376     static bool qual[16] =  // Ugly, but quick.
00377     //      quality
00378           { false,  false,  true, false,  false,  false,
00379     //  ctainer egg       virtue stone
00380       true, true, false,  false,  false,  true,
00381     //  monst human
00382       true, true, false,  false };
00383 #endif
00384     Shape_class c = get_shape_class();
00385     return (c == 2 || c == 6 || c == 7 || c == 11 || c == 12 || c == 13);
00386     //    return qual[(int) c];
00387     }
00388   bool occludes() const
00389     { return occludes_flag; }
00390   void set_occludes(bool tf)
00391     { occludes_flag = tf; }
00392   unsigned char get_ready_type()
00393     { return ready_type; }
00394   void set_ready_type(unsigned char t)
00395     { ready_type = t; }
00396   // Sets x to 255 if there is no weapon offset
00397   void get_weapon_offset(int frame, unsigned char& x, unsigned char& y)
00398     {
00399     if(!weapon_offsets)
00400       x = 255;
00401     else
00402       {
00403       // x could be 255 (see read_info())
00404       x = weapon_offsets[frame * 2];
00405       y = weapon_offsets[frame * 2 + 1];
00406       }
00407     }
00408   void set_weapon_offset(int frame, unsigned char x, unsigned char y);
00409   };
00410 
00411 #endif

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