adonthell-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-commits] CVS: adonthell/src slot.cc,NONE,1.1 slot.h,NONE,1.1


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src slot.cc,NONE,1.1 slot.h,NONE,1.1 Makefile.am,1.99,1.100 event.cc,1.22,1.23 event.h,1.32,1.33 event_list.cc,1.7,1.8 event_list.h,1.6,1.7 item_base.cc,1.4,1.5 item_base.h,1.4,1.5 py_adonthell.i,1.35,1.36
Date: Mon, 10 Feb 2003 15:01:16 -0500

Update of /cvsroot/adonthell/adonthell/src
In directory subversions:/tmp/cvs-serv16876

Modified Files:
        Makefile.am event.cc event.h event_list.cc event_list.h 
        item_base.cc item_base.h py_adonthell.i 
Added Files:
        slot.cc slot.h 
Log Message:
ADDED Id to events (not loaded/saved yet)
ADDED First pieces of inventory implementation (slot class)


***** Error reading new file: [Errno 2] No such file or directory: 'slot.cc'
***** Error reading new file: [Errno 2] No such file or directory: 'slot.h'
Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Makefile.am,v
retrieving revision 1.99
retrieving revision 1.100
diff -C2 -r1.99 -r1.100
*** Makefile.am 16 Jan 2003 11:22:45 -0000      1.99
--- Makefile.am 10 Feb 2003 20:01:13 -0000      1.100
***************
*** 24,28 ****
  inventory.h item_base.h landmap.h map_event.h map_event_handler.h mapsquare.h 
\
  mapsquare_walkable.h nls.h mapcharacter.h mapobject.h mapview.h path.h \
! pnm.h prefs.h python_class.h py_object.h quest.h screen.h surface.h storage.h 
\
  types.h text_bubble.h time_event.h time_event_handler.h win_background.h \
  win_base.h win_border.h win_container.h str_hash.h win_font.h win_image.h \
--- 24,28 ----
  inventory.h item_base.h landmap.h map_event.h map_event_handler.h mapsquare.h 
\
  mapsquare_walkable.h nls.h mapcharacter.h mapobject.h mapview.h path.h \
! pnm.h prefs.h python_class.h py_object.h quest.h screen.h slot.h surface.h 
storage.h \
  types.h text_bubble.h time_event.h time_event_handler.h win_background.h \
  win_base.h win_border.h win_container.h str_hash.h win_font.h win_image.h \
***************
*** 38,42 ****
  map_event_handler.cc mapsquare_walkable.cc mapcharacter.cc mapsquare.cc \
  mapobject.cc mapview.cc nls.cc path.cc pnm.cc prefs.cc py_callback.cc \
! python_class.cc py_adonthell_wrap.cc py_object.cc quest.cc screen.cc \
  surface.cc storage.cc text_bubble.cc time_event.cc time_event_handler.cc \
  win_background.cc win_base.cc win_border.cc win_container.cc win_font.cc \
--- 38,42 ----
  map_event_handler.cc mapsquare_walkable.cc mapcharacter.cc mapsquare.cc \
  mapobject.cc mapview.cc nls.cc path.cc pnm.cc prefs.cc py_callback.cc \
! python_class.cc py_adonthell_wrap.cc py_object.cc quest.cc screen.cc slot.cc \
  surface.cc storage.cc text_bubble.cc time_event.cc time_event_handler.cc \
  win_background.cc win_base.cc win_border.cc win_container.cc win_font.cc \

Index: event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.cc,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** event.cc    20 Jan 2003 20:18:43 -0000      1.22
--- event.cc    10 Feb 2003 20:01:13 -0000      1.23
***************
*** 34,37 ****
--- 34,38 ----
      Args = NULL;
      List = NULL;
+     Id = "";
  }
  
***************
*** 137,140 ****
--- 138,142 ----
  {
      Type >> file;
+     // Id >> file;
      Repeat >> file;
      Paused >> file;
***************
*** 174,177 ****
--- 176,180 ----
      // Note that »Type« is already read by event_list::load to
      // determine what event subclass to instanciate
+     // Id << file;
      Repeat << file;
      Paused << file;

Index: event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -r1.32 -r1.33
*** event.h     20 Jan 2003 20:18:43 -0000      1.32
--- event.h     10 Feb 2003 20:01:13 -0000      1.33
***************
*** 90,96 ****
      
      /**
       * Get the event's type.
       *
!      * @return type of the event
       */
      u_int8 type () const
--- 90,100 ----
      
      /**
+      * @name Member access
+      */
+     //@{
+     /**
       * Get the event's type.
       *
!      * @return type of the %event
       */
      u_int8 type () const
***************
*** 100,103 ****
--- 104,128 ----
  
      /**
+      * Get the event's id.
+      *
+      * @return id of the %event.
+      */
+     const string & id () const
+     {
+         return Id;
+     }
+     
+     /**
+      * Assign an id to the %event, so it may be retrieved from an
+      * event_list later on, without having a pointer to it.
+      *
+      * @param id a string to identify the %event.
+      */
+     void set_id (const string & id)
+     {
+         Id = id;
+     }
+     
+     /**
       * Test whether the %event is registered with the %event handler.
       *
***************
*** 148,152 ****
          Repeat = count;
      }
! 
      /**
       * @name Event Handling
--- 173,178 ----
          Repeat = count;
      }
!     //@}
!     
      /**
       * @name Event Handling
***************
*** 228,232 ****
      /**
       * Check whether the %event is temporarily disabled or not.
!      * @return \b true if it is paused, \b false otherwise.                   
                                    
       */
      bool is_paused () const
--- 254,258 ----
      /**
       * Check whether the %event is temporarily disabled or not.
!      * @return \b true if it is paused, \b false otherwise.                   
  
       */
      bool is_paused () const
***************
*** 281,284 ****
--- 307,315 ----
      u_int8 Type;
  
+     /**
+      * (Optional) Id of the event
+      */
+     string Id;
+     
      /**
       * What happens if the event occurs - see enum above.

Index: event_list.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_list.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** event_list.cc       24 Jan 2003 22:15:43 -0000      1.7
--- event_list.cc       10 Feb 2003 20:01:13 -0000      1.8
***************
*** 80,83 ****
--- 80,94 ----
  }
  
+ // retrieve event by its id
+ event *event_list::get_event (const string & id)
+ {
+     vector<event*>::iterator i;
+ 
+     for (i = Events.begin (); i != Events.end (); i++)
+          if ((*i)->id () == id) return *i;
+     
+     return NULL;   
+ }
+ 
  // disable all events in the list
  void event_list::pause ()

Index: event_list.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_list.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** event_list.h        27 Jan 2003 19:54:29 -0000      1.6
--- event_list.h        10 Feb 2003 20:01:13 -0000      1.7
***************
*** 29,32 ****
--- 29,34 ----
  #include "event.h"
  
+ using std::string;
+ 
  #ifndef SWIG
  /**
***************
*** 66,69 ****
--- 68,75 ----
      void clear ();
  
+     /**
+      * @name List Operations
+      */
+     //@{
      /** 
       * Adds an %event to this list. The %event will be
***************
*** 84,87 ****
--- 90,105 ----
      
      /**
+      * Try to retrieve the %event with given id from the list.
+      *
+      * @return a pointer to the %event, or \b NULL if it's not in the list.
+      */
+     event *get_event (const string & id);
+     //@}
+     
+     /**
+      * @name Pausing / Resuming execution
+      */
+     //@{
+     /**
       * Disable any events associated with this %event_list. This will
       * effectively stop all actions of the %object the %event_list
***************
*** 97,105 ****
  
      /**
!      * Check whether this %event list is paused.
!      * @return \b true if it is paused, \b false otherwise.
       */
!     bool is_paused () { return Paused; }
! 
  #ifndef SWIG    
      /**
--- 115,127 ----
  
      /**
!      * Check whether the %event list is temporarily disabled or not.
!      * @return \b true if it is paused, \b false otherwise.                   
  
       */
!     bool is_paused () const
!     {
!         return Paused;
!     }
!     //@}
!     
  #ifndef SWIG    
      /**
***************
*** 116,120 ****
      static void register_event (u_int8 type, new_event e);
  #endif // SWIG
!     
      /** 
       * Save the %event_list to a file.
--- 138,146 ----
      static void register_event (u_int8 type, new_event e);
  #endif // SWIG
! 
!     /**
!      * @name Loading / Saving
!      */
!     //@{
      /** 
       * Save the %event_list to a file.
***************
*** 136,139 ****
--- 162,166 ----
       */
      bool get_state (igzstream& in);
+     //@}
  
  #ifndef SWIG

Index: item_base.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** item_base.cc        18 Jan 2003 23:22:59 -0000      1.4
--- item_base.cc        10 Feb 2003 20:01:13 -0000      1.5
***************
*** 25,33 ****
  #include <algorithm>
  #include "item_base.h"
  
  // ctor
  item_base::item_base (const std::string & item) : py_object ()
  {
!     std::cout << "Item instance of '" << item << "' created" << std::endl;
  
      get_state (item);    
--- 25,34 ----
  #include <algorithm>
  #include "item_base.h"
+ #include "character_base.h"
  
  // ctor
  item_base::item_base (const std::string & item) : py_object ()
  {
!     Slot = NULL;
  
      get_state (item);    
***************
*** 37,41 ****
  item_base::~item_base ()
  {
!     std::cout << "Item instance deleted" << endl;
      
      py_object::clear ();
--- 38,46 ----
  item_base::~item_base ()
  {
!     // if the item is still inside an inventory, remove it
!     if (Slot) Slot->remove (this);
!     
!     // if we have a stack of items, delete the whole stack
!     if (Next) delete Next;
      
      py_object::clear ();
***************
*** 45,50 ****
  bool item_base::use (character_base *character)
  {
-     std::cout << "Item '" << name () << "' used" << std::endl;
-     
      // can't be used
      if (!has_attribute ("use")) return false;
--- 50,53 ----
***************
*** 90,96 ****
      if (!Instance) return false;
      
      // save the template this item uses
      class_name () >> file;
!     
      // pass file
      PyObject *args = PyTuple_New (1);
--- 93,103 ----
      if (!Instance) return false;
      
+     // save the attributes
+     Mutable >> file;
+     MaxStack >> file;
+         
      // save the template this item uses
      class_name () >> file;
! 
      // pass file
      PyObject *args = PyTuple_New (1);
***************
*** 101,104 ****
--- 108,119 ----
      Py_DECREF (args);    
      
+     // recursively save stack
+     if (this->Next)
+     {
+         true >> file;
+         Next->put_state (file);
+     }
+     else false >> file;
+     
      return true;
  }
***************
*** 124,131 ****
--- 139,151 ----
  {
      std::string tmpl;
+     bool more;
      
      // clean up, if neccessary
      if (Instance) clear ();
      
+     // get attributes
+     Mutable << file;
+     MaxStack << file;
+     
      // get template to use for item
      tmpl << file;
***************
*** 142,145 ****
--- 162,178 ----
      Py_DECREF (args);
      
+     // add reference to item_base
+     set_attribute ("this", python::pass_instance (this, "item_base"));
+     
+     // recursively get stack
+     more << file;
+     
+     if (more)
+     {
+         Next = new item_base (true);
+         Next->get_state (file);
+     }
+     else Next = NULL;
+     
      return true;  
  }
***************
*** 161,162 ****
--- 194,224 ----
  }
  */
+ 
+ // add item(s) to this stack
+ void item_base::stack (item_base *item)
+ {
+     item_base *bottom = this;
+     
+     // add given stack on top of our own stack
+     while (bottom->Next) bottom = bottom->Next;
+     bottom->Next = item;
+ }
+ 
+ // remove item(s) from this stack
+ item_base *item_base::split (u_int32 count)
+ {
+     // in case of count = 0, this is a noop
+     if (count == 0) return this;
+     
+     item_base *remaining, *stack = this;
+     
+     // retrieve the topmost items
+     while (--count) stack = stack->Next;
+     remaining = stack->Next;
+     
+     // split this stack
+     stack->Next = NULL;
+     set_slot (NULL);
+     
+     return remaining;    
+ }

Index: item_base.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** item_base.h 20 Jan 2003 00:15:41 -0000      1.4
--- item_base.h 10 Feb 2003 20:01:13 -0000      1.5
***************
*** 25,36 ****
  #define ITEM_BASE_H
  
- #include "character_base.h"
  #include "py_object.h"
  #include "fileops.h"
  
  using std::string;
  
  /**
!  * It is a wrapper for item_base.py, which is the actual item superclass.
   * For flexibility, items are implemented on python side. But since they
   * are often used on C++ side, this class provides methods to the most
--- 25,38 ----
  #define ITEM_BASE_H
  
  #include "py_object.h"
  #include "fileops.h"
+ #include "slot.h"
  
  using std::string;
  
+ class character_base;
+ 
  /**
!  * It is a wrapper for item.py, which is the actual item superclass.
   * For flexibility, items are implemented on python side. But since they
   * are often used on C++ side, this class provides methods to the most
***************
*** 42,45 ****
--- 44,52 ----
   * attributes. If required, they can be accessed via methods provided by
   * the py_object class.
+  *
+  * There are two 'classes' of items. Of immutable items, only one %object
+  * will be instanciated when loading a saved %game. All copies of such an
+  * item are actually references to the one object. Mutable items however 
+  * will be instanciated as often as copies of that item exist.
   */
  class item_base : public py_object 
***************
*** 48,54 ****
  
      /**
!      * Default constructor. Creates an empty item.
       */
!     item_base () : py_object () {};
  #ifndef SWIG    
      /**
--- 55,72 ----
  
      /**
!      * Default constructor. Creates an empty item. For safety reasons
!      * the item's 'class' has to set at construction time. It cannot
!      * be changed ever after.
!      * @param is_mutable whether the item may change its state or not.
!      * @see is_mutable ()
       */
!     item_base (bool is_mutable) : py_object () 
!     {
!         Mutable = is_mutable;
!         MaxStack = 1;
!         Next = NULL;
!         Slot = NULL;
!     }
!     
  #ifndef SWIG    
      /**
***************
*** 57,66 ****
       */
      item_base (const string & item);
! #endif    
      /**
       * Destructor.
       */
      ~item_base ();
!     
      /**
       * @name Item Actions
--- 75,85 ----
       */
      item_base (const string & item);
! #endif
!         
      /**
       * Destructor.
       */
      ~item_base ();
!      
      /**
       * @name Item Actions
***************
*** 169,172 ****
--- 188,245 ----
          set_attribute_int ("MaxCharge", max_charge); 
      }
+ 
+     /**
+      * Check whether the item is mutable or immutable. Mutable
+      * items are those that may change their attributes during
+      * livetime. Therefore they need to be treated different
+      * from items that do never change as long as they live.
+      * @return \b true if the item is mutable, \b false otherwise.
+      */
+     bool is_mutable () const
+     {
+         return Mutable;
+     }
+     
+     /**
+      * If the item is kept in an inventory, it will be assigned
+      * to a certain slot. For mutable items, the assignment will be
+      * pertinent. For immutable items however, it will be only temporary
+      * and only valid for the item that is currently manipulated. In
+      * reality, no difference should be notable though.
+      * @return slot holding the item or \c NULL, if it isn't kept in
+      *      an inventory.
+      */
+     slot *get_slot () const
+     {
+         return Slot;
+     }
+     
+     /**
+      * Set the slot this (stack of) item(s) is kept in.
+      * @param s the slot to assign to the item(s).
+      */
+     void set_slot (slot *s)
+     {
+         Slot = s;
+         if (Next != NULL) Next->set_slot (s);
+     }
+     
+     /** 
+      * Check how many items of this kind may be stacked in one slot.
+      * @return maximum size of a stack of this kind of item.
+      */    
+     u_int32 max_stack () const
+     {
+         return MaxStack;
+     }
+     
+     /** 
+      * Set how many items of this kind may be stacked in one slot.
+      * @param max_stack maximum size of a stack of this kind of item.
+      */    
+     void set_max_stack (u_int32 max_stack)
+     {
+         MaxStack = max_stack;
+     }
      //@}
      
***************
*** 223,226 ****
--- 296,351 ----
      bool put_state (ogzstream & file) const;
      //@}
+ 
+ protected:
+ #ifndef SWIG
+     /**
+      * The number of items that can be stacked
+      */
+     u_int32 MaxStack;
+             
+     /**
+      * The slot this item is kept in.
+      */
+     slot *Slot;
+ 
+     /**
+      * Whether the item is mutable or immutable
+      */
+     bool Mutable;
+     
+     /**
+      * If we're dealing with a stack of mutable items, Next will point
+      * to the next item in the stack.
+      */
+     item_base *Next;
+     
+     /**
+      * @name Item Stack handling
+      */
+     //@{
+     friend u_int32 slot::add (item_base * item, const u_int32 & count = 1);
+     friend bool slot::remove (item_base * item, const u_int32 & count = 1);
+ 
+     /**
+      * Add an item (or stack of items) to this item's stack. We assume
+      * that checks for item equality and number of items on the stack
+      * have been made already. That's why this method is only available 
+      * to friends of %item_base. In fact, it should only be used by
+      * slot::add_item and slot::remove_item.
+      * @param stack Item (stack) to be added to this item. It will be the
+      *      new top of stack.
+      */
+     void stack (item_base *stack);
+     
+     /**
+      * Retrieve number items from this stack. This method will return
+      * the topmost item(s) of the stack. Like item_base::stack, this
+      * method is only available to the slot class.
+      * @param number Number of items to retrieve from the stack.
+      * @return the item(s) remaining in this stack.
+      */
+     item_base *split (u_int32 number = 1);
+     //@}
+ #endif SWIG
  };
  

Index: py_adonthell.i
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_adonthell.i,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** py_adonthell.i      20 Jan 2003 00:15:41 -0000      1.35
--- py_adonthell.i      10 Feb 2003 20:01:13 -0000      1.36
***************
*** 16,19 ****
--- 16,20 ----
  #include "audio.h"
  #include "character_base.h"
+ #include "slot.h"
  #include "item_base.h"
  #include "quest.h"
***************
*** 146,149 ****
--- 147,151 ----
  %include "audio.h"
  %include "character_base.h"
+ %include "slot.h"
  %include "py_object.h"
  %include "item_base.h"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]