|
From: <lor...@us...> - 2008-11-22 00:39:42
|
Revision: 40
http://deraciel.svn.sourceforge.net/deraciel/?rev=40&view=rev
Author: lordhoto
Date: 2008-11-22 00:39:38 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added primiliary object, inventory and character structs.
Modified Paths:
--------------
trunk/INSTALL
trunk/util.h
Added 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/INSTALL
===================================================================
--- trunk/INSTALL 2008-11-21 23:10:39 UTC (rev 39)
+++ trunk/INSTALL 2008-11-22 00:39:38 UTC (rev 40)
@@ -1,7 +1,7 @@
Compile
=======
-clear && gcc -std=c99 -o main main.c text_window.c random.c -lncurses -lform
+clear && gcc -std=c99 -o main *.c -lncurses -lform
Run
Added: trunk/char.h
===================================================================
--- trunk/char.h (rev 0)
+++ trunk/char.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,30 @@
+#ifndef DERACIEL_CHAR_H
+#define DERACIEL_CHAR_H
+
+#include <stdint.h>
+
+#include "inventory.h"
+
+enum stats {
+ STAT_STRENGTH,
+ STAT_DEXTERITY,
+ STAT_WISDOM,
+ STAT_WILLPOWER,
+ STAT_CONSTITUTION,
+ STAT_CHARISMA,
+ STAT_MAX_STATS
+};
+
+struct char_struct {
+ char name[32];
+
+ uint8_t stats[STAT_MAX_STATS];
+
+ uint32_t experience;
+ uint8_t level;
+
+ struct invt_struct inventory;
+};
+
+#endif
+
Property changes on: trunk/char.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/inventory.c
===================================================================
--- trunk/inventory.c (rev 0)
+++ trunk/inventory.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +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_uninit(struct invt_struct *inventory) {
+ obj_uninit(&inventory->coins);
+
+ for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
+ obj_uninit(inventory->objects + i);
+}
+
Property changes on: trunk/inventory.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/inventory.h
===================================================================
--- trunk/inventory.h (rev 0)
+++ trunk/inventory.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,18 @@
+#ifndef DERACIEL_INVENTORY_H
+#define DERACIEL_INVENTORY_H
+
+#include "object.h"
+
+#define MAX_INVENTORY_OBJECTS 26
+
+struct invt_struct {
+ struct obj_struct coins;
+
+ struct obj_struct objects[MAX_INVENTORY_OBJECTS];
+};
+
+void invt_init(struct invt_struct *inventory);
+
+void invt_uninit(struct invt_struct *inventory);
+
+#endif
Property changes on: trunk/inventory.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c (rev 0)
+++ trunk/obj_types.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,22 @@
+#include "obj_types.h"
+
+// Gold piles always contain 0 coins by default
+static const uint32_t coins_default_value = 0;
+
+static const struct obj_desc_struct obj_descs[] = {
+ { OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value) },
+ { OBJ_DESC_INVALID, NULL, 0 }
+};
+
+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) {
+ if (obj_descs[i].id == id)
+ return obj_descs + i;
+ }
+
+ return NULL;
+}
+
Property changes on: trunk/obj_types.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h (rev 0)
+++ trunk/obj_types.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,33 @@
+#ifndef DERACIEL_OBJ_TYPES_H
+#define DERACIEL_OBJ_TYPES_H
+
+#include <stdint.h>
+#include <string.h>
+
+typedef uint32_t obj_descriptor_id;
+
+#define OBJ_DESC_INVALID ((obj_descriptor_id)-1)
+
+/*
+ * Different object types we have
+ */
+enum {
+ /*
+ * Object type for coins.
+ *
+ * [default_data] = uint32_t
+ */
+ OBJ_DESC_COINS
+};
+
+struct obj_desc_struct {
+ obj_descriptor_id id;
+
+ const void *default_data;
+ size_t default_data_size;
+};
+
+const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id);
+
+#endif
+
Property changes on: trunk/obj_types.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/object.c
===================================================================
--- trunk/object.c (rev 0)
+++ trunk/object.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,25 @@
+#include "object.h"
+#include "util.h"
+
+#include <string.h>
+
+void obj_init(obj_descriptor_id id, struct obj_struct *obj) {
+ obj->id = id;
+ memset(obj->name, 0, sizeof(obj->name));
+
+ const struct obj_desc_struct *obj_desc = obj_desc_find(id);
+ 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 {
+ obj->user_data = NULL;
+ }
+}
+
+void obj_uninit(struct obj_struct *obj) {
+ obj->id = OBJ_DESC_INVALID;
+ memset(obj->name, 0, sizeof(obj->name));
+
+ mem_dealloc(obj->user_data);
+}
+
Property changes on: trunk/object.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/object.h
===================================================================
--- trunk/object.h (rev 0)
+++ trunk/object.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,21 @@
+#ifndef DERACIEL_OBJECT_H
+#define DERACIEL_OBJECT_H
+
+#include "obj_types.h"
+
+#include <stdint.h>
+
+#define OBJ_NAME_LENGTH 64
+
+struct obj_struct {
+ obj_descriptor_id id;
+ char name[OBJ_NAME_LENGTH];
+
+ void *user_data;
+};
+
+void obj_init(obj_descriptor_id id, struct obj_struct *obj);
+
+void obj_uninit(struct obj_struct *obj);
+
+#endif
Property changes on: trunk/object.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: trunk/util.h
===================================================================
--- trunk/util.h 2008-11-21 23:10:39 UTC (rev 39)
+++ trunk/util.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -13,6 +13,15 @@
} \
} while (0)
+#define mem_alloc_size(size, type, var) \
+ do { \
+ var = (type*)malloc(size); \
+ if (!var) { \
+ fprintf(stderr, "Couldn't allocate memory for var %s of size %d in file %s line %d\n", #var, (int)size, __FILE__, __LINE__); \
+ exit(-1); \
+ } \
+ } while (0)
+
#define mem_dealloc(var) free(var)
#endif // !DERACIEL_UTIL_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|