[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Adonthell-commits] CVS: adonthell/src inventory.cc,1.4,1.5 item_base.c
From: |
Kai Sterker <address@hidden> |
Subject: |
[Adonthell-commits] CVS: adonthell/src inventory.cc,1.4,1.5 item_base.cc,1.6,1.7 item_base.h,1.6,1.7 item_storage.cc,1.1,1.2 py_adonthell.i,1.37,1.38 slot.cc,1.2,1.3 slot.h,1.2,1.3 |
Date: |
Wed, 12 Feb 2003 10:59:01 -0500 |
Update of /cvsroot/adonthell/adonthell/src
In directory subversions:/tmp/cvs-serv8445
Modified Files:
inventory.cc item_base.cc item_base.h item_storage.cc
py_adonthell.i slot.cc slot.h
Log Message:
FIXED bugs in inventory code
Index: inventory.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/inventory.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** inventory.cc 11 Feb 2003 21:00:35 -0000 1.4
--- inventory.cc 12 Feb 2003 15:58:55 -0000 1.5
***************
*** 46,50 ****
void inventory::grow (const u_int16 & count)
{
! for (u_int16 i = 0; i == count; i++)
Slots.push_back (new slot (this));
}
--- 46,50 ----
void inventory::grow (const u_int16 & count)
{
! for (u_int16 i = 0; i < count; i++)
Slots.push_back (new slot (this));
}
***************
*** 96,100 ****
{
for (i = Slots.begin (); i != Slots.end (); i++)
! if ((*i)->count () != 0 && item->equals ((*i)->get_item ()))
{
remaining = (*i)->add (item, remaining);
--- 96,100 ----
{
for (i = Slots.begin (); i != Slots.end (); i++)
! if ((*i)->count () > 0 && (*i)->accepts (item))
{
remaining = (*i)->add (item, remaining);
Index: item_base.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** item_base.cc 11 Feb 2003 19:59:26 -0000 1.6
--- item_base.cc 12 Feb 2003 15:58:55 -0000 1.7
***************
*** 38,47 ****
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 ();
}
--- 38,50 ----
item_base::~item_base ()
{
! if (Mutable)
! {
! // 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 ();
}
Index: item_base.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** item_base.h 11 Feb 2003 19:59:26 -0000 1.6
--- item_base.h 12 Feb 2003 15:58:55 -0000 1.7
***************
*** 92,95 ****
--- 92,103 ----
*/
bool use (character_base *character);
+
+ /**
+ * Combine this item with another item. Returns the result of the
+ * combination, or NULL if the combination fails.
+ * @param item the item to combine with this one
+ * @return item resulting from combination, or \c NULL if combination
fails.
+ */
+ // item_base *combine (item_base * item);
//@}
Index: item_storage.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_storage.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** item_storage.cc 11 Feb 2003 19:59:26 -0000 1.1
--- item_storage.cc 12 Feb 2003 15:58:55 -0000 1.2
***************
*** 33,43 ****
std::hash_map<std::string, item_base*>::iterator i;
for (i = Items.begin (); i != Items.end (); i++)
- {
- // just a precaution
(*i).second->set_slot (NULL);
! delete (*i).second;
! }
!
Items.clear ();
}
--- 33,40 ----
std::hash_map<std::string, item_base*>::iterator i;
+ // just a precaution
for (i = Items.begin (); i != Items.end (); i++)
(*i).second->set_slot (NULL);
!
Items.clear ();
}
Index: py_adonthell.i
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_adonthell.i,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** py_adonthell.i 11 Feb 2003 19:59:26 -0000 1.37
--- py_adonthell.i 12 Feb 2003 15:58:55 -0000 1.38
***************
*** 17,20 ****
--- 17,21 ----
#include "character_base.h"
#include "item_storage.h"
+ #include "inventory.h"
#include "quest.h"
#include "drawing_area.h"
***************
*** 150,153 ****
--- 151,155 ----
%include "item_base.h"
%include "item_storage.h"
+ %include "inventory.h"
%include "drawing_area.h"
%include "quest.h"
Index: slot.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/slot.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** slot.cc 11 Feb 2003 19:59:26 -0000 1.2
--- slot.cc 12 Feb 2003 15:58:55 -0000 1.3
***************
*** 37,41 ****
{
// if the slot contains item(s), delete them
! if (Item && Item->is_mutable ())
{
Item->set_slot (NULL);
--- 37,41 ----
{
// if the slot contains item(s), delete them
! if (Item && Item->is_mutable ())
{
Item->set_slot (NULL);
***************
*** 44,47 ****
--- 44,62 ----
}
+ // retrieve item(s) in slot
+ item_base *slot::get_item ()
+ {
+ // temporarily assign slot to immutable items
+ if (Item && !Item->is_mutable ()) Item->set_slot (this);
+ return Item;
+ }
+
+ // check whether slot accepts given item
+ bool slot::accepts (item_base *item)
+ {
+ if (!Item) return true;
+ else return Item->equals (item);
+ }
+
// add item(s) to slot
u_int32 slot::add (item_base *item, const u_int32 & count)
***************
*** 56,59 ****
--- 71,77 ----
else
{
+ // items from same slot?
+ if (this == item->get_slot ()) return 0;
+
// item stackable?
if (Count >= Item->max_stack ()) return count;
Index: slot.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/slot.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** slot.h 11 Feb 2003 19:59:26 -0000 1.2
--- slot.h 12 Feb 2003 15:58:55 -0000 1.3
***************
*** 58,68 ****
//@{
/**
! * Retrieve pointer to the item kept in this %slot.
* @return item in this %slot, or \c NULL in case it is empty.
*/
! item_base *get_item ()
! {
! return Item;
! }
/**
--- 58,75 ----
//@{
/**
! * Retrieve pointer to the item kept in this %slot. In case of an
! * immutable item, it will also adjust item_base::Slot.
* @return item in this %slot, or \c NULL in case it is empty.
*/
! item_base *get_item ();
!
! /**
! * Checks whether the given item is allowed to go into this %slot.
! * This is the case when the %slot is empty, or if the items
! * already in the %slot (roughly) equal the given item.
! * @param item Item to test against.
! * @return \b true if the item may go into the %slot, \b falso otherwise
! */
! bool accepts (item_base *item);
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Adonthell-commits] CVS: adonthell/src inventory.cc,1.4,1.5 item_base.cc,1.6,1.7 item_base.h,1.6,1.7 item_storage.cc,1.1,1.2 py_adonthell.i,1.37,1.38 slot.cc,1.2,1.3 slot.h,1.2,1.3,
Kai Sterker <address@hidden> <=
- Prev by Date:
[Adonthell-commits] CVS: adonthell/src inventory.cc,1.3,1.4 inventory.h,1.8,1.9
- Next by Date:
[Adonthell-commits] CVS: adonthell/src label.cc,1.8,NONE label.h,1.5,NONE
- Previous by thread:
[Adonthell-commits] CVS: adonthell/src inventory.cc,1.3,1.4 inventory.h,1.8,1.9
- Next by thread:
[Adonthell-commits] CVS: adonthell/src label.cc,1.8,NONE label.h,1.5,NONE
- Index(es):