project_files/frontlib/model/weapon.h
changeset 7230 240620f46dd7
parent 7224 5143861c83bd
child 7271 5608ac657362
--- a/project_files/frontlib/model/weapon.h	Tue Jun 12 21:10:11 2012 +0200
+++ b/project_files/frontlib/model/weapon.h	Fri Jun 15 19:57:25 2012 +0200
@@ -10,6 +10,7 @@
  * For the other setting, 9 is invalid.
  */
 typedef struct {
+	int _referenceCount;
 	char loadout[WEAPONS_COUNT+1];
 	char crateprob[WEAPONS_COUNT+1];
 	char crateammo[WEAPONS_COUNT+1];
@@ -17,6 +18,12 @@
 	char *name;
 } flib_weaponset;
 
+typedef struct {
+	int _referenceCount;
+	int weaponsetCount;
+	flib_weaponset **weaponsets;
+} flib_weaponsetlist;
+
 /**
  * Returns a new weapon set, or NULL on error.
  * name must not be NULL.
@@ -27,15 +34,57 @@
 flib_weaponset *flib_weaponset_create(const char *name);
 
 /**
- * Loads a weapon set, returns NULL on error.
+ * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
+ * Returns the parameter.
+ */
+flib_weaponset *flib_weaponset_retain(flib_weaponset *weaponset);
+
+/**
+ * Decrease the reference count of the object and free it if this was the last reference.
  */
-flib_weaponset *flib_weaponset_from_ini(const char *filename);
+void flib_weaponset_release(flib_weaponset *weaponset);
+
+/**
+ * Load a list of weaponsets from the ini file.
+ * Returns NULL on error.
+ */
+flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename);
+
+/**
+ * Store the list of weaponsets to an ini file.
+ * Returns NULL on error.
+ */
+int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *weaponsets);
 
 /**
- * Write the weapon set to an ini file. Attempts to
- * retain extra ini settings that were already present.
+ * Create an empty weaponset list. Returns NULL on error.
+ */
+flib_weaponsetlist *flib_weaponsetlist_create();
+
+/**
+ * Insert a new weaponset into the list at position pos, moving all higher weaponsets to make place.
+ * pos must be at least 0 (insert at the start) and at most list->weaponsetCount (insert at the end).
+ * The weaponset is retained automatically.
+ * Returns 0 on success.
  */
-int flib_weaponset_to_ini(const char *filename, const flib_weaponset *set);
-void flib_weaponset_destroy(flib_weaponset *set);
+int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *weaponset, int pos);
+
+/**
+ * Delete a weaponset from the list at position pos, moving down all higher weaponsets.
+ * The weaponset is released automatically.
+ * Returns 0 on success.
+ */
+int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos);
+
+/**
+ * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
+ * Returns the parameter.
+ */
+flib_weaponsetlist *flib_weaponsetlist_retain(flib_weaponsetlist *list);
+
+/**
+ * Decrease the reference count of the object and free it if this was the last reference.
+ */
+void flib_weaponsetlist_release(flib_weaponsetlist *list);
 
 #endif