|
From: <lor...@us...> - 2008-11-22 01:19:47
|
Revision: 44
http://deraciel.svn.sourceforge.net/deraciel/?rev=44&view=rev
Author: lordhoto
Date: 2008-11-22 01:19:43 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
- Formatting
- Added stubs for proper object name support
Modified Paths:
--------------
trunk/char.h
trunk/inventory.c
trunk/inventory.h
trunk/obj_types.c
trunk/obj_types.h
trunk/object.c
trunk/object.h
Modified: trunk/char.h
===================================================================
--- trunk/char.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/char.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -5,7 +5,8 @@
#include "inventory.h"
-enum stats {
+enum
+{
STAT_STRENGTH,
STAT_DEXTERITY,
STAT_WISDOM,
@@ -15,7 +16,8 @@
STAT_MAX_STATS
};
-struct char_struct {
+struct char_struct
+{
char name[32];
uint8_t stats[STAT_MAX_STATS];
Modified: trunk/inventory.c
===================================================================
--- trunk/inventory.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/inventory.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -1,16 +1,16 @@
#include "inventory.h"
-void invt_init(struct invt_struct *inventory) {
- obj_init(OBJ_DESC_COINS, &inventory->coins);
-
- for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
- obj_init(OBJ_DESC_INVALID, inventory->objects + i);
+void invt_init(struct invt_struct *inventory)
+{
+ memset(inventory, 0, sizeof(struct invt_struct));
+
+ inventory->coins = obj_init(OBJ_DESC_COINS);
}
void invt_uninit(struct invt_struct *inventory) {
- obj_uninit(&inventory->coins);
+ obj_uninit(inventory->coins);
for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
- obj_uninit(inventory->objects + i);
+ obj_uninit(inventory->objects[i]);
}
Modified: trunk/inventory.h
===================================================================
--- trunk/inventory.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/inventory.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -5,10 +5,11 @@
#define MAX_INVENTORY_OBJECTS 26
-struct invt_struct {
- struct obj_struct coins;
+struct invt_struct
+{
+ struct obj_struct *coins;
- struct obj_struct objects[MAX_INVENTORY_OBJECTS];
+ struct obj_struct *objects[MAX_INVENTORY_OBJECTS];
};
void invt_init(struct invt_struct *inventory);
Modified: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/obj_types.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -1,20 +1,24 @@
#include "obj_types.h"
+#include "object.h"
// Gold piles always contain 0 coins by default
static const uint32_t coins_default_value = 0;
#define DEFINE_OBJ(ID, d, s) { ID, false, d, s }
-static struct obj_desc_struct obj_descs[] = {
+static struct obj_desc_struct obj_descs[] =
+{
DEFINE_OBJ(OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value)),
DEFINE_OBJ(OBJ_DESC_INVALID, NULL, 0)
};
-const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id) {
+const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id)
+{
if (id == OBJ_DESC_INVALID)
return NULL;
- for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i) {
+ for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i)
+ {
if (obj_descs[i].id == id)
return obj_descs + i;
}
@@ -22,20 +26,26 @@
return NULL;
}
-bool obj_desc_is_identified(obj_descriptor_id id) {
+bool obj_desc_is_identified(obj_descriptor_id id)
+{
const struct obj_desc_struct *desc = obj_desc_find(id);
if (desc)
return desc->is_identified;
return false;
}
-void obj_desc_mark_identified(obj_descriptor_id id) {
+void obj_desc_mark_identified(obj_descriptor_id id)
+{
struct obj_desc_struct *desc = (struct obj_desc_struct *)obj_desc_find(id);
if (desc)
+ {
desc->is_identified = true;
+ obj_update_names(id);
+ }
}
-const char *obj_desc_get_name(obj_descriptor_id id) {
+const char *obj_desc_get_name(obj_descriptor_id id)
+{
// TODO
return "";
}
Modified: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/obj_types.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -13,7 +13,8 @@
/**
* Different object types we have
*/
-enum {
+enum
+{
/**
* Object type for coins.
*
@@ -22,7 +23,8 @@
OBJ_DESC_COINS
};
-struct obj_desc_struct {
+struct obj_desc_struct
+{
obj_descriptor_id id;
bool is_identified;
Modified: trunk/object.c
===================================================================
--- trunk/object.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/object.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -3,7 +3,12 @@
#include <string.h>
-void obj_init(obj_descriptor_id id, struct obj_struct *obj) {
+struct obj_struct *obj_init(obj_descriptor_id id)
+{
+ struct obj_struct *obj;
+ mem_alloc(struct obj_struct, obj);
+ // TODO: need to put obj into a global object list
+
obj->id = id;
strncpy(obj->name, obj_desc_get_name(id), sizeof(obj->name));
@@ -12,18 +17,28 @@
memset(obj->user_name, 0, sizeof(obj->user_name));
const struct obj_desc_struct *obj_desc = obj_desc_find(id);
- if (obj_desc) {
+ if (obj_desc)
+ {
mem_alloc_size(obj_desc->default_data_size, void, obj->user_data);
memcpy(obj->user_data, obj_desc->default_data, obj_desc->default_data_size);
- } else {
+ }
+ else
+ {
obj->user_data = NULL;
}
+
+ return obj;
}
-void obj_uninit(struct obj_struct *obj) {
- obj->id = OBJ_DESC_INVALID;
- memset(obj->name, 0, sizeof(obj->name));
-
+void obj_uninit(struct obj_struct *obj)
+{
mem_dealloc(obj->user_data);
+ // TODO: remove obj from global object list
+ mem_dealloc(obj);
}
+void obj_update_names(obj_descriptor_id id)
+{
+ // TODO: implemt via global object list
+}
+
Modified: trunk/object.h
===================================================================
--- trunk/object.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/object.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -7,7 +7,8 @@
#define OBJ_NAME_LENGTH 64
-struct obj_struct {
+struct obj_struct
+{
obj_descriptor_id id;
char name[OBJ_NAME_LENGTH];
char user_name[OBJ_NAME_LENGTH];
@@ -15,9 +16,14 @@
void *user_data;
};
-void obj_init(obj_descriptor_id id, struct obj_struct *obj);
+struct obj_struct *obj_init(obj_descriptor_id id);
void obj_uninit(struct obj_struct *obj);
+// id == OBJ_DESC_INVALID would update all object names
+// TODO: define if all unidentified objects would get
+// new random names then too
+void obj_update_names(obj_descriptor_id id);
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|