diff options
author | Bardur Arantsson <bardur@scientician.net> | 2013-03-25 10:59:33 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2013-09-27 14:46:41 +0200 |
commit | 63bb0520dcdb6177533fe3b412fd72ee1ce6d711 (patch) | |
tree | f5b8cba5d209522cf9d33ea347a43d57678d22ef /src | |
parent | d1bc64bd22673bc72bafd7e200cbbea6eacb06c1 (diff) |
Split out data types
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/device_allocation.c | 26 | ||||
-rw-r--r-- | src/device_allocation.h | 31 | ||||
-rw-r--r-- | src/device_allocation_fwd.h | 17 | ||||
-rw-r--r-- | src/externs.h | 6 | ||||
-rw-r--r-- | src/lua_bind.c | 1 | ||||
-rw-r--r-- | src/object2.c | 2 | ||||
-rw-r--r-- | src/range.c | 2 | ||||
-rw-r--r-- | src/range.h | 15 | ||||
-rw-r--r-- | src/range_fwd.h | 4 | ||||
-rw-r--r-- | src/spell_type.c | 3 | ||||
-rw-r--r-- | src/spell_type.h | 4 | ||||
-rw-r--r-- | src/spells4.c | 25 | ||||
-rw-r--r-- | src/spells5.c | 2 | ||||
-rw-r--r-- | src/string_list.c | 2 | ||||
-rw-r--r-- | src/string_list.h | 22 | ||||
-rw-r--r-- | src/types.h | 47 | ||||
-rw-r--r-- | src/types_fwd.h | 2 |
18 files changed, 129 insertions, 84 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fcddce9d..cf0b88b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ SET(SRCS monster1.c monster2.c monster3.c xtra1.c xtra2.c skills.c powers.c gods.c spells1.c spells2.c spells3.c spells4.c spells5.c spells6.c - spell_type.c + spell_type.c device_allocation.c corrupt.c joke.c mimic.c status.c files.c notes.c loadsave.c string_list.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c diff --git a/src/device_allocation.c b/src/device_allocation.c new file mode 100644 index 00000000..e64f0401 --- /dev/null +++ b/src/device_allocation.c @@ -0,0 +1,26 @@ +#include "device_allocation.h" + +int compare_device_allocation(device_allocation *a, device_allocation *b) +{ + return SGLIB_NUMERIC_COMPARATOR(a->tval, b->tval); +} + +SGLIB_DEFINE_LIST_FUNCTIONS(device_allocation, compare_device_allocation, next); + +void device_allocation_init(device_allocation *device_allocation, byte tval) +{ + assert(device_allocation != NULL); + + device_allocation->tval = tval; + device_allocation->rarity = 0; + range_init(&device_allocation->base_level, 0, 0); + range_init(&device_allocation->max_level, 0, 0); + device_allocation->next = NULL; +} + +device_allocation *device_allocation_new(byte tval) +{ + device_allocation *d = malloc(sizeof(device_allocation)); + device_allocation_init(d, tval); + return d; +} diff --git a/src/device_allocation.h b/src/device_allocation.h new file mode 100644 index 00000000..e620270f --- /dev/null +++ b/src/device_allocation.h @@ -0,0 +1,31 @@ +#pragma once + +#include "device_allocation_fwd.h" +#include "range.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Device allocation for skill + */ +struct device_allocation +{ + byte tval; + s32b rarity; + range_type base_level; + range_type max_level; + /* Next device allocation in the list */ + device_allocation *next; +}; + +int compare_device_allocation(device_allocation *a, device_allocation *b); +SGLIB_DEFINE_LIST_PROTOTYPES(device_allocation, compare_device_allocation, next); + +void device_allocation_init(struct device_allocation *device_allocation, byte tval); +struct device_allocation *device_allocation_new(byte tval); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/device_allocation_fwd.h b/src/device_allocation_fwd.h new file mode 100644 index 00000000..7bc0e0b0 --- /dev/null +++ b/src/device_allocation_fwd.h @@ -0,0 +1,17 @@ +#pragma once + +#include "angband.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct device_allocation device_allocation; +struct device_allocation; + +void device_allocation_init(struct device_allocation *device_allocation, byte tval); +struct device_allocation *device_allocation_new(byte tval); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/externs.h b/src/externs.h index 11bdc3f3..f139a1e1 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1920,9 +1920,6 @@ int spell_x(int sval, int pval, int i); bool_ school_book_contains_spell(int sval, s32b spell_idx); void lua_cast_school_spell(s32b spell_idx, bool_ no_cost); -void device_allocation_init(device_allocation *device_allocation, byte tval); -device_allocation *device_allocation_new(byte tval); - void dice_init(dice_type *dice, long base, long num, long sides); bool_ dice_parse(dice_type *dice, cptr s); void dice_parse_checked(dice_type *dice, cptr s); @@ -1943,9 +1940,6 @@ school_type *school_at(int index); void mana_school_calc_mana(int *msp); -/* range.c */ -extern void range_init(range_type *range, s32b min, s32b max); - /* randart.c */ extern int get_activation_power(void); extern void build_prob(cptr learn); diff --git a/src/lua_bind.c b/src/lua_bind.c index a15e9eb8..a3e2b0bb 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -15,6 +15,7 @@ #include <assert.h> #include "spell_type.h" +#include "range.h" /* * Monsters diff --git a/src/object2.c b/src/object2.c index b82691ea..cf688c15 100644 --- a/src/object2.c +++ b/src/object2.c @@ -13,6 +13,8 @@ #include "angband.h" #include "spell_type.h" +#include "device_allocation.h" + /* * Calculate the player's total inventory weight. diff --git a/src/range.c b/src/range.c index 647f0576..0cb21469 100644 --- a/src/range.c +++ b/src/range.c @@ -1,4 +1,4 @@ -#include <angband.h> +#include "range.h" void range_init(range_type *range, s32b min, s32b max) { diff --git a/src/range.h b/src/range.h new file mode 100644 index 00000000..0d840c18 --- /dev/null +++ b/src/range.h @@ -0,0 +1,15 @@ +#pragma once + +#include "range_fwd.h" +#include "angband.h" + +/* + * Range + */ +struct range_type +{ + s32b min; + s32b max; +}; + +void range_init(range_type *range, s32b min, s32b max); diff --git a/src/range_fwd.h b/src/range_fwd.h new file mode 100644 index 00000000..b5eef3fa --- /dev/null +++ b/src/range_fwd.h @@ -0,0 +1,4 @@ +#pragma once + +typedef struct range_type range_type; +struct range_type; diff --git a/src/spell_type.c b/src/spell_type.c index b8bec0cd..f0f8ee93 100644 --- a/src/spell_type.c +++ b/src/spell_type.c @@ -1,4 +1,7 @@ #include "spell_type.h" +#include "string_list.h" +#include "range.h" +#include "device_allocation.h" #include "angband.h" diff --git a/src/spell_type.h b/src/spell_type.h index eef6ce44..7f985bca 100644 --- a/src/spell_type.h +++ b/src/spell_type.h @@ -4,6 +4,8 @@ #include "h-type.h" #include "types_fwd.h" +#include "device_allocation_fwd.h" +#include "range_fwd.h" #ifdef __cplusplus extern "C" { @@ -64,7 +66,7 @@ void spell_type_describe(spell_type *spell, cptr line); void spell_type_add_school(spell_type *spell, s32b school_idx); void spell_type_set_device_charges(spell_type *spell, cptr charges_s); -void spell_type_add_device_allocation(spell_type *spell, struct device_allocation *a); +void spell_type_add_device_allocation(spell_type *spell, device_allocation *a); spell_type *spell_type_new(cptr name); diff --git a/src/spells4.c b/src/spells4.c index c977742d..f01930ec 100644 --- a/src/spells4.c +++ b/src/spells4.c @@ -630,31 +630,6 @@ void lua_cast_school_spell(s32b s, bool_ no_cost) p_ptr->window |= PW_PLAYER; } -void device_allocation_init(device_allocation *device_allocation, byte tval) -{ - assert(device_allocation != NULL); - - device_allocation->tval = tval; - device_allocation->rarity = 0; - range_init(&device_allocation->base_level, 0, 0); - range_init(&device_allocation->max_level, 0, 0); - device_allocation->next = NULL; -} - -device_allocation *device_allocation_new(byte tval) -{ - device_allocation *d = malloc(sizeof(device_allocation)); - device_allocation_init(d, tval); - return d; -} - -int compare_device_allocation(device_allocation *a, device_allocation *b) -{ - return SGLIB_NUMERIC_COMPARATOR(a->tval, b->tval); -} - -SGLIB_DEFINE_LIST_FUNCTIONS(device_allocation, compare_device_allocation, next); - void dice_init(dice_type *dice, long base, long num, long sides) { assert(dice != NULL); diff --git a/src/spells5.c b/src/spells5.c index 7ad0d3b9..72eddb76 100644 --- a/src/spells5.c +++ b/src/spells5.c @@ -3,6 +3,8 @@ #include <assert.h> #include "spell_type.h" +#include "device_allocation.h" + static spell_type *spell_new(s32b *index, cptr id, cptr name) { diff --git a/src/string_list.c b/src/string_list.c index 8a63cc3c..2d658e1c 100644 --- a/src/string_list.c +++ b/src/string_list.c @@ -1,4 +1,4 @@ -#include "angband.h" +#include "string_list.h" int compare_string_list(string_list *a, string_list *b) { diff --git a/src/string_list.h b/src/string_list.h new file mode 100644 index 00000000..bd88602f --- /dev/null +++ b/src/string_list.h @@ -0,0 +1,22 @@ +#pragma once + +#include "sglib.h" +#include "angband.h" + +/* + * String list. + */ +typedef struct string_list string_list; +struct string_list { + /* The string list owns the string */ + cptr s; + /* Next */ + string_list *next; +}; + +int compare_string_list(string_list *a, string_list *b); +SGLIB_DEFINE_LIST_PROTOTYPES(string_list, compare_string, next); + +void string_list_init(string_list *sl, cptr s); /* Initialize element; copies string */ +void string_list_destroy(string_list *sl); /* Destroy element */ +void string_list_append(string_list **slist, cptr s); /* Append string */ diff --git a/src/types.h b/src/types.h index 2e871a40..5d336815 100644 --- a/src/types.h +++ b/src/types.h @@ -48,25 +48,6 @@ */ -/* - * String list. - */ -typedef struct string_list string_list; -struct string_list { - /* The string list owns the string */ - cptr s; - /* Next */ - string_list *next; -}; - -int compare_string_list(string_list *a, string_list *b); -SGLIB_DEFINE_LIST_PROTOTYPES(string_list, compare_string, next); - -void string_list_init(string_list *sl, cptr s); /* Initialize element; copies string */ -void string_list_destroy(string_list *sl); /* Destroy element */ -void string_list_append(string_list **slist, cptr s); /* Append string */ - - /* * Template file header information (see "init.c"). 16 bytes. @@ -2488,16 +2469,6 @@ struct cli_comm }; /* - * Range - */ -typedef struct range_type range_type; -struct range_type -{ - s32b min; - s32b max; -}; - -/* * Dice */ typedef struct dice_type dice_type; @@ -2509,24 +2480,6 @@ struct dice_type }; /* - * Device allocation for skill - */ -typedef struct device_allocation device_allocation; -struct device_allocation -{ - byte tval; - s32b rarity; - range_type base_level; - range_type max_level; - /* Next device allocation in the list */ - device_allocation *next; -}; - -int compare_device_allocation(device_allocation *a, device_allocation *b); -SGLIB_DEFINE_LIST_PROTOTYPES(device_allocation, compare_device_allocation, next); - - -/* * Skills ! */ typedef struct skill_type skill_type; diff --git a/src/types_fwd.h b/src/types_fwd.h index 581609e9..4c7084f9 100644 --- a/src/types_fwd.h +++ b/src/types_fwd.h @@ -81,9 +81,7 @@ struct hooks_chain; struct hist_type; struct set_type; struct cli_comm; -struct range_type; struct dice_type; -struct device_allocation; struct skill_type; struct school_idx; struct spell_type; |