contain.h

Go to the documentation of this file.
00001 /*
00002  *  contain.h - Container objects.
00003  *
00004  *  Copyright (C) 1998-1999  Jeffrey S. Freedman
00005  *  Copyright (C) 2000-2001  The Exult Team
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef INCL_CONTAIN
00023 #define INCL_CONTAIN  1
00024 
00025 #include "iregobjs.h"
00026 
00027 /*
00028  *  A container object:
00029  */
00030 class Container_game_object : public Ireg_game_object
00031   {
00032   int volume_used;    // Amount of volume occupied.
00033   char resistance;  // Resistance to attack.
00034 protected:
00035   Object_list objects;    // ->first object.
00036   int get_max_volume() const  // Max. we'll hold.  (Guessing).
00037     { int v = get_volume(); return v; }
00038 public:
00039   Container_game_object(int shapenum, int framenum, unsigned int tilex, 
00040         unsigned int tiley, unsigned int lft,
00041         char res = 0)
00042     : Ireg_game_object(shapenum, framenum, tilex, tiley, lft),
00043       volume_used(0), resistance(res), objects(0)
00044     {  }
00045   Container_game_object() : volume_used(0), resistance(0),
00046     objects(0) {  }
00047   virtual ~Container_game_object();
00048   Object_list& get_objects()
00049     { return objects; }
00050           // For when an obj's quantity changes:
00051   void modify_volume_used(int delta)
00052     { volume_used += delta; }
00053           // Room for this object?
00054   int has_room(Game_object *obj) const
00055     { return get_max_volume() <= 0 || 
00056       obj->get_volume() + volume_used <= get_max_volume(); }
00057           // Remove an object.
00058   virtual void remove(Game_object *obj);
00059           // Add an object.
00060   virtual bool add(Game_object *obj, bool dont_check = false,
00061               bool combine = false);
00062           // Change member shape.
00063   virtual void change_member_shape(Game_object *obj, int newshape);
00064           // Find object's spot.
00065   virtual int find_readied(Game_object *obj)
00066     { return -1; }
00067   virtual Game_object *get_readied(int index) const
00068     { return 0; }
00069   virtual void call_readied_usecode(int index,
00070           Game_object *obj, int eventid)
00071     {  }
00072           // Add/remove quantities of objs.
00073   virtual int add_quantity(int delta, int shapenum, 
00074       int qual = c_any_qual,
00075       int framenum = c_any_framenum, int dontcreate = 0);
00076   virtual int create_quantity(int delta, int shapenum, int qual,
00077           int framenum, bool temporary = false);
00078   virtual int remove_quantity(int delta, int shapenum, int qual,
00079                 int framenum);
00080   virtual Game_object *find_item(int shapenum, int qual, int framenum);
00081           // Run usecode function.
00082   virtual void activate(int event = 1);
00083   virtual int get_weight();
00084           // Drop another onto this.
00085   virtual int drop(Game_object *obj);
00086           // Count contained objs.
00087   virtual int count_objects(int shapenum, int qual = c_any_qual,
00088             int framenum = c_any_framenum);
00089           // Get contained objs.
00090   virtual int get_objects(Game_object_vector& vec, int shapenum, 
00091           int qual, int framenum);
00092   virtual void set_flag_recursively(int flag);
00093           // Write out to IREG file.
00094   virtual void write_ireg(DataSource* out);
00095         // Get size of IREG. Returns -1 if can't write to buffer
00096   virtual int get_ireg_size();
00097           // Write contents in IREG format.
00098   virtual void write_contents(DataSource* out);
00099 
00100   virtual int get_obj_hp() const { return resistance; }
00101   virtual void set_obj_hp(int hp) { resistance = (char)hp; }
00102 
00103   bool extract_contents();
00104 
00105   virtual void delete_contents();
00106   
00107   virtual void remove_this(int nodel = 0);
00108 
00109   virtual Container_game_object *as_container() { return this; }
00110 
00111   };
00112 
00113 #endif

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