[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.101,1.102 inventor
From: |
Kai Sterker <address@hidden> |
Subject: |
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.101,1.102 inventory.cc,1.7,1.8 inventory.h,1.11,1.12 item_base.cc,1.9,1.10 item_base.h,1.12,1.13 py_adonthell.i,1.38,1.39 py_object.cc,1.16,1.17 py_object.h,1.13,1.14 slot.cc,1.4,1.5 slot.h,1.4,1.5 |
Date: |
Sun, 18 May 2003 17:54:23 -0400 |
Update of /cvsroot/adonthell/adonthell/src
In directory subversions:/tmp/cvs-serv12102
Modified Files:
Makefile.am inventory.cc inventory.h item_base.cc item_base.h
py_adonthell.i py_object.cc py_object.h slot.cc slot.h
Log Message:
ADDED initial manager class for keeping track of character stats and the like
FIXED bug in output typemap (did that introduce memleaks?)
Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Makefile.am,v
retrieving revision 1.101
retrieving revision 1.102
diff -C2 -r1.101 -r1.102
*** Makefile.am 11 Feb 2003 19:59:26 -0000 1.101
--- Makefile.am 18 May 2003 21:54:20 -0000 1.102
***************
*** 22,26 ****
drawing_area.h event.h event_handler.h event_handler_base.h event_list.h \
fileops.h game.h gamedate.h gametime.h gettext.h getopt.h image.h input.h \
! inventory.h item_base.h item_storage.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 \
--- 22,26 ----
drawing_area.h event.h event_handler.h event_handler_base.h event_list.h \
fileops.h game.h gamedate.h gametime.h gettext.h getopt.h image.h input.h \
! inventory.h item_base.h item_storage.h landmap.h manager.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 \
***************
*** 35,39 ****
drawable.cc drawing_area.cc event.cc event_handler.cc event_list.cc \
fileops.cc game.cc gamedata.cc gamedate.cc gametime.cc image.cc input.cc \
! inventory.cc item_base.cc item_storage.cc label.cc label_input.cc landmap.cc
lex.prefs.cc map_event.cc \
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 \
--- 35,40 ----
drawable.cc drawing_area.cc event.cc event_handler.cc event_list.cc \
fileops.cc game.cc gamedata.cc gamedate.cc gametime.cc image.cc input.cc \
! inventory.cc item_base.cc item_storage.cc label.cc label_input.cc landmap.cc \
! lex.prefs.cc manager.cc map_event.cc \
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 \
Index: inventory.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/inventory.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** inventory.cc 5 May 2003 18:52:48 -0000 1.7
--- inventory.cc 18 May 2003 21:54:20 -0000 1.8
***************
*** 25,33 ****
// ctor
! inventory::inventory (const u_int16 & size, const bool & limited)
{
QueryType = 0;
QueryKey = "";
Limited = limited;
grow (size);
}
--- 25,34 ----
// ctor
! inventory::inventory (const u_int16 & size, const bool & limited,
character_base *owner)
{
QueryType = 0;
QueryKey = "";
Limited = limited;
+ Owner = owner;
grow (size);
}
***************
*** 53,59 ****
// add named slot to inventory
! void inventory::add_slot (const std::string & id)
{
! Slots.push_back (new slot (this, id));
}
--- 54,60 ----
// add named slot to inventory
! void inventory::add_slot (const std::string & id, const bool & equipment)
{
! Slots.push_back (new slot (this, id, equipment));
}
Index: inventory.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/inventory.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** inventory.h 5 May 2003 18:52:48 -0000 1.11
--- inventory.h 18 May 2003 21:54:20 -0000 1.12
***************
*** 27,30 ****
--- 27,32 ----
#include "slot.h"
+ class character_base;
+
/**
* Whenever items need to be stored by an object -- be it %character,
***************
*** 43,47 ****
* @param limited Whether %inventory has fixed size or not.
*/
! inventory (const u_int16 & size = 0, const bool & limited = true);
/**
--- 45,50 ----
* @param limited Whether %inventory has fixed size or not.
*/
! inventory (const u_int16 & size = 0, const bool & limited = true,
! character_base *owner = NULL);
/**
***************
*** 66,71 ****
* The size of the %inventory will grow by one.
* @param id Id of the %slot to add.
*/
! void add_slot (const string & id);
/**
--- 69,75 ----
* The size of the %inventory will grow by one.
* @param id Id of the %slot to add.
+ * @param equipment Whether the slot is suitable for equipping items
*/
! void add_slot (const string & id, const bool & equipment = false);
/**
***************
*** 192,195 ****
--- 196,208 ----
//@}
+ /**
+ * Retrieve the %character to whom this inventory belongs.
+ * @return Owner of the inventory, or \c NULL if nobody owns it.
+ */
+ character_base *owner () const
+ {
+ return Owner;
+ }
+
private:
#ifndef SWIG
***************
*** 219,222 ****
--- 232,240 ----
*/
u_int8 QueryType;
+
+ /**
+ * Character to whom this inventory is assigned.
+ */
+ character_base *Owner;
#endif // SWIG
};
Index: item_base.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** item_base.cc 5 May 2003 18:52:48 -0000 1.9
--- item_base.cc 18 May 2003 21:54:20 -0000 1.10
***************
*** 56,64 ****
}
! // apply item effects
! void item_base::equip (character_base *character)
{
! // no effect
! if (!has_attribute ("equip")) return;
// pass character
--- 56,66 ----
}
! // can the given character equip this item?
! bool item_base::can_equip (character_base *character)
{
! // no
! if (!has_attribute ("equipped")) return false;
!
! int result = 0;
// pass character
***************
*** 67,91 ****
// call method
! call_method ("equip", args);
// cleanzp
Py_DECREF (args);
}
! // remove item effects
! void item_base::unequip (character_base *character)
{
// no effect
! if (!has_attribute ("unequip")) return;
! // pass character
! PyObject *args = PyTuple_New (1);
! PyTuple_SetItem (args, 0, python::pass_instance (character,
"character_base"));
// call method
! call_method ("unequip", args);
! // cleanzp
! Py_DECREF (args);
}
--- 69,110 ----
// call method
! PyObject *retval = call_method_ret ("can_equip", args);
+ // if we have valid retval retrieve it
+ if (PyInt_Check (retval)) result = PyInt_AS_LONG (retval);
+
// cleanzp
+ Py_XDECREF (retval);
Py_DECREF (args);
+
+ return (result != 0);
}
! // tell item it has been equipped
! void item_base::equipped (slot *target)
{
// no effect
! if (!has_attribute ("equipped")) return;
! if (!Mutable) Slot = target;
!
! // call method
! call_method ("equipped");
!
! if (!Mutable) Slot = NULL;
! }
!
! // tell item it has been removed
! void item_base::unequipped (slot *target)
! {
! // no effect
! if (!has_attribute ("unequipped")) return;
!
! if (!Mutable) Slot = target;
// call method
! call_method ("unequipped");
! if (!Mutable) Slot = NULL;
}
***************
*** 246,249 ****
--- 265,293 ----
return true;
}
+
+ // return list of categories this item belongs to
+ std::vector<string> item_base::categories () const
+ {
+ std::vector<string> categories;
+ PyObject *list = get_attribute ("Categories");
+ PyObject *str;
+
+ if (!PySequence_Check (list)) return categories;
+
+ // get all category strings
+ for (int i = 0; i < PySequence_Size (list); i++)
+ {
+ str = PySequence_GetItem (list, i);
+ if (PyString_Check (str))
+ categories.push_back (PyString_AsString (str));
+ Py_XDECREF (str);
+ }
+
+ // cleanup
+ Py_DECREF (list);
+
+ return categories;
+ }
+
/*
Index: item_base.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** item_base.h 6 May 2003 08:38:07 -0000 1.12
--- item_base.h 18 May 2003 21:54:20 -0000 1.13
***************
*** 25,28 ****
--- 25,29 ----
#define ITEM_BASE_H
+ #include <vector>
#include "py_object.h"
#include "slot.h"
***************
*** 107,122 ****
//@{
/**
! * This method is invoked when the given character equips this item.
! * It can be used to apply item effects to the character if desired.
! * @param character The character equipping this item.
*/
! void equip (character_base *character);
/**
! * This method is invoked when the given character unequips this item.
! * It can be used to remove item effects from the character if neccessary.
! * @param character The character equipping this item.
*/
! void unequip (character_base *character);
/**
--- 108,130 ----
//@{
/**
! * This method is invoked when the item is equipped by a character. It can
! * be used to trigger special events.
! * @param target the slot to which the items where added
*/
! void equipped (slot *target);
/**
! * This method is invoked when this item is unequipped by a character.
! * It can be used to trigger special events.
! * @param target the slot from which the items where removed
*/
! void unequipped (slot *target);
!
! /**
! * Check whether this item can be equipped by the given character.
! * @param character The character that wants to equip this item.
! * @return \b true if the character can equip the item, \b false
otherwise.
! */
! bool can_equip (character_base *character);
/**
***************
*** 194,198 ****
return (result != 0);
}
!
/**
* Get the charge the item has left.
--- 202,212 ----
return (result != 0);
}
!
! /**
! * Retrieve a list of categories this item belongs to.
! * @return List of item categories.
! */
! std::vector<string> categories () const;
!
/**
* Get the charge the item has left.
Index: py_adonthell.i
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_adonthell.i,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -r1.38 -r1.39
*** py_adonthell.i 12 Feb 2003 15:58:55 -0000 1.38
--- py_adonthell.i 18 May 2003 21:54:20 -0000 1.39
***************
*** 18,21 ****
--- 18,22 ----
#include "item_storage.h"
#include "inventory.h"
+ #include "manager.h"
#include "quest.h"
#include "drawing_area.h"
***************
*** 95,98 ****
--- 96,100 ----
}
%typemap(python,in) const string & = string &;
+ %typemap(python,in) const std::string & = string &;
%typemap(python,out) string
***************
*** 105,109 ****
{
$result = PyString_FromString((const char *)$1->c_str());
! delete $1;
}
%typemap(python,out) const string & = string &;
--- 107,111 ----
{
$result = PyString_FromString((const char *)$1->c_str());
! // delete $1;
}
%typemap(python,out) const string & = string &;
***************
*** 117,120 ****
--- 119,123 ----
}
%typemap (python, freearg) const string & = string &;
+ %typemap (python, freearg) const std::string & = string &;
%typemap (python,in) PyObject *pyfunc
***************
*** 133,136 ****
--- 136,143 ----
}
+ %include "typemaps.i"
+ %apply unsigned int *INOUT { unsigned int *count };
+
+
%include "types.h"
%include "fileops.h"
***************
*** 152,155 ****
--- 159,163 ----
%include "item_storage.h"
%include "inventory.h"
+ %include "manager.h"
%include "drawing_area.h"
%include "quest.h"
Index: py_object.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_object.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** py_object.cc 20 Jan 2003 20:18:43 -0000 1.16
--- py_object.cc 18 May 2003 21:54:20 -0000 1.17
***************
*** 137,141 ****
// Get an attribute of the instance
! PyObject *py_object::get_attribute (const string &name)
{
if (Instance)
--- 137,141 ----
// Get an attribute of the instance
! PyObject *py_object::get_attribute (const string &name) const
{
if (Instance)
Index: py_object.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_object.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** py_object.h 23 Feb 2003 23:14:34 -0000 1.13
--- py_object.h 18 May 2003 21:54:20 -0000 1.14
***************
*** 144,148 ****
* @return New reference to the attribute or NULL on error
*/
! PyObject* get_attribute (const string & name);
/**
--- 144,148 ----
* @return New reference to the attribute or NULL on error
*/
! PyObject* get_attribute (const string & name) const;
/**
Index: slot.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/slot.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** slot.cc 17 Feb 2003 19:31:21 -0000 1.4
--- slot.cc 18 May 2003 21:54:20 -0000 1.5
***************
*** 25,29 ****
// ctor
! slot::slot (inventory *owner, const std::string & id)
{
Owner = owner;
--- 25,29 ----
// ctor
! slot::slot (inventory *owner, const std::string & id, const bool & equipment)
{
Owner = owner;
***************
*** 31,34 ****
--- 31,36 ----
Count = 0;
Item = NULL;
+ Negated = false;
+ Equipment = equipment;
}
***************
*** 162,165 ****
--- 164,169 ----
Id >> file;
Count >> file;
+ Negated >> file;
+ Equipment >> file;
// save the item(s) in the slot
***************
*** 184,188 ****
Id << file;
Count << file;
!
// get item(s) if any
if (Count > 0)
--- 188,194 ----
Id << file;
Count << file;
! Negated << file;
! Equipment << file;
!
// get item(s) if any
if (Count > 0)
Index: slot.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/slot.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** slot.h 23 Feb 2003 23:14:34 -0000 1.4
--- slot.h 18 May 2003 21:54:20 -0000 1.5
***************
*** 39,47 ****
/**
* Create a new %slot with an optional id. The id can be used to
! * retrieve certain slots from the %inventory.
* @param owner The %inventory the %slot belongs to
* @param id The slot's id
*/
! slot (inventory *owner, const string & id = "");
/**
--- 39,51 ----
/**
* Create a new %slot with an optional id. The id can be used to
! * retrieve certain slots from the %inventory. The equipment flag
! * determines whether this %slot will be able to contain equipped items,
! * i.e. those worn or held by a %character. The manager::equip () method
! * will only accept slots with the equipment flag set to true.
* @param owner The %inventory the %slot belongs to
* @param id The slot's id
+ * @param equipment \b true to allow equipping items in that slot
*/
! slot (inventory *owner, const string & id = "", const bool & equipment =
false);
/**
***************
*** 56,60 ****
/**
* 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.
*/
--- 60,65 ----
/**
* Retrieve pointer to the item kept in this %slot. In case of an
! * immutable item, it will also adjust item_base::Slot. To check
! * whether a slot is empty, use the count() method below; it's faster.
* @return item in this %slot, or \c NULL in case it is empty.
*/
***************
*** 104,108 ****
/**
! * Retrieve the number of items in this %slot.
* @return number of items this %slot contains.
*/
--- 109,115 ----
/**
! * Retrieve the number of items in this %slot. This is the preferred
! * method to check whether a slot is empty or not, as it has much less
! * overhead than get_item() above.
* @return number of items this %slot contains.
*/
***************
*** 114,117 ****
--- 121,133 ----
/**
+ * Return the inventory this slot belongs to.
+ * @return inventory this slot belongs to.
+ */
+ inventory *owner () const
+ {
+ return Owner;
+ }
+
+ /**
* Attribute access
*/
***************
*** 134,137 ****
--- 150,186 ----
Id = id;
}
+
+ /**
+ * Is that slot 'disabled'?
+ * @return \b true if that is the case, \b false otherwise.
+ */
+ bool is_negated () const
+ {
+ return Negated;
+ }
+
+ /**
+ * Disable or enable this slot. It's up to users of the slot to
+ * make use of this flag.
+ * @param negated \b false to enable, \b true to disable the slot.
+ */
+ void set_negated (const bool & negated)
+ {
+ Negated = negated;
+ }
+
+ /**
+ * Is this slot meant for equipped items?
+ * @return \b true if that is the case, \b false otherwise.
+ */
+ bool is_equipment () const
+ {
+ return Equipment;
+ }
+
+ void set_equipment (const bool & equipment)
+ {
+ Equipment = equipment;
+ }
//@}
***************
*** 177,180 ****
--- 226,239 ----
*/
u_int32 Count;
+
+ /**
+ * Whether the slot is disabled.
+ */
+ bool Negated;
+
+ /**
+ * Whether this slot is for equipping items.
+ */
+ bool Equipment;
#endif // SWIG
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Adonthell-commits] CVS: adonthell/src Makefile.am,1.101,1.102 inventory.cc,1.7,1.8 inventory.h,1.11,1.12 item_base.cc,1.9,1.10 item_base.h,1.12,1.13 py_adonthell.i,1.38,1.39 py_object.cc,1.16,1.17 py_object.h,1.13,1.14 slot.cc,1.4,1.5 slot.h,1.4,1.5,
Kai Sterker <address@hidden> <=
- Prev by Date:
[Adonthell-commits] CVS: adonthell/src item_base.h,1.11,1.12
- Next by Date:
[Adonthell-commits] CVS: adonthell/src manager.cc,NONE,1.1 manager.h,NONE,1.1
- Previous by thread:
[Adonthell-commits] CVS: adonthell/src item_base.h,1.11,1.12
- Next by thread:
[Adonthell-commits] CVS: adonthell/src manager.cc,NONE,1.1 manager.h,NONE,1.1
- Index(es):