summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2013-03-25 11:19:10 +0100
committerBardur Arantsson <bardur@scientician.net>2013-09-27 14:46:41 +0200
commit07abe10e701b6e6d5acbfc79db665e29bceeb0ab (patch)
tree54c11d55fa4c0fdffa27a221f71e3f36e8a7bb1e
parent63bb0520dcdb6177533fe3b412fd72ee1ce6d711 (diff)
Split "dice" out
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/dice.c94
-rw-r--r--src/dice.h13
-rw-r--r--src/dice_fwd.h12
-rw-r--r--src/externs.h6
-rw-r--r--src/spell_type.c1
-rw-r--r--src/spells4.c93
-rw-r--r--src/types.h11
-rw-r--r--src/types_fwd.h1
9 files changed, 121 insertions, 112 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cf0b88b2..74d71c68 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,7 +24,7 @@ SET(SRCS
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
- help.c hiscore.c range.c
+ help.c hiscore.c range.c dice.c
generate.c gen_maze.c gen_evol.c wild.c levels.c store.c bldg.c
cmovie.c
wizard2.c init2.c birth.c wizard1.c init1.c main.c
diff --git a/src/dice.c b/src/dice.c
new file mode 100644
index 00000000..ea9b7533
--- /dev/null
+++ b/src/dice.c
@@ -0,0 +1,94 @@
+#include "dice.h"
+
+void dice_init(dice_type *dice, long base, long num, long sides)
+{
+ assert(dice != NULL);
+
+ dice->base = base;
+ dice->num = num;
+ dice->sides = sides;
+}
+
+bool_ dice_parse(dice_type *dice, cptr s)
+{
+ long base, num, sides;
+
+ if (sscanf(s, "%ld+%ldd%ld", &base, &num, &sides) == 3)
+ {
+ dice_init(dice, base, num, sides);
+ return TRUE;
+ }
+
+ if (sscanf(s, "%ld+d%ld", &base, &sides) == 2)
+ {
+ dice_init(dice, base, 1, sides);
+ return TRUE;
+ }
+
+ if (sscanf(s, "d%ld", &sides) == 1)
+ {
+ dice_init(dice, 0, 1, sides);
+ return TRUE;
+ }
+
+ if (sscanf(s, "%ldd%ld", &num, &sides) == 2)
+ {
+ dice_init(dice, 0, num, sides);
+ return TRUE;
+ }
+
+ if (sscanf(s, "%ld", &base) == 1)
+ {
+ dice_init(dice, base, 0, 0);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void dice_parse_checked(dice_type *dice, cptr s)
+{
+ bool_ result = dice_parse(dice, s);
+ if (!result)
+ {
+ abort();
+ }
+}
+
+long dice_roll(dice_type *dice)
+{
+ assert(dice != NULL);
+ return dice->base + damroll(dice->num, dice->sides);
+}
+
+void dice_print(dice_type *dice, char *output)
+{
+ char buf[16];
+
+ output[0] = '\0';
+
+ if (dice->base > 0)
+ {
+ sprintf(buf, "%ld", dice->base);
+ strcat(output, buf);
+ }
+
+ if ((dice->num > 0) || (dice->sides > 0))
+ {
+ if (dice->base > 0)
+ {
+ strcat(output, "+");
+ }
+
+ if (dice->num > 1)
+ {
+ sprintf(buf, "%ld", dice->num);
+ strcat(output, buf);
+ }
+
+ strcat(output, "d");
+
+ sprintf(buf, "%ld", dice->sides);
+ strcat(output, buf);
+ }
+}
diff --git a/src/dice.h b/src/dice.h
new file mode 100644
index 00000000..3253f348
--- /dev/null
+++ b/src/dice.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "dice_fwd.h"
+
+/**
+ * Dice
+ */
+struct dice_type
+{
+ long base; /* Base value to which roll is added. */
+ long num; /* Number of dice */
+ long sides; /* Sides per dice */
+};
diff --git a/src/dice_fwd.h b/src/dice_fwd.h
new file mode 100644
index 00000000..ffc8fbfa
--- /dev/null
+++ b/src/dice_fwd.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "angband.h"
+
+typedef struct dice_type dice_type;
+struct dice_type;
+
+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);
+long dice_roll(dice_type *dice);
+void dice_print(dice_type *dice, char *buf);
diff --git a/src/externs.h b/src/externs.h
index f139a1e1..cf8702bd 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1920,12 +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 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);
-long dice_roll(dice_type *dice);
-void dice_print(dice_type *dice, char *buf);
-
/* spells5.c */
void school_spells_init();
spell_type *spell_at(s32b index);
diff --git a/src/spell_type.c b/src/spell_type.c
index f0f8ee93..ab219be5 100644
--- a/src/spell_type.c
+++ b/src/spell_type.c
@@ -2,6 +2,7 @@
#include "string_list.h"
#include "range.h"
#include "device_allocation.h"
+#include "dice.h"
#include "angband.h"
diff --git a/src/spells4.c b/src/spells4.c
index f01930ec..5a099483 100644
--- a/src/spells4.c
+++ b/src/spells4.c
@@ -629,96 +629,3 @@ void lua_cast_school_spell(s32b s, bool_ no_cost)
p_ptr->redraw |= PR_MANA;
p_ptr->window |= PW_PLAYER;
}
-
-void dice_init(dice_type *dice, long base, long num, long sides)
-{
- assert(dice != NULL);
-
- dice->base = base;
- dice->num = num;
- dice->sides = sides;
-}
-
-bool_ dice_parse(dice_type *dice, cptr s)
-{
- long base, num, sides;
-
- if (sscanf(s, "%ld+%ldd%ld", &base, &num, &sides) == 3)
- {
- dice_init(dice, base, num, sides);
- return TRUE;
- }
-
- if (sscanf(s, "%ld+d%ld", &base, &sides) == 2)
- {
- dice_init(dice, base, 1, sides);
- return TRUE;
- }
-
- if (sscanf(s, "d%ld", &sides) == 1)
- {
- dice_init(dice, 0, 1, sides);
- return TRUE;
- }
-
- if (sscanf(s, "%ldd%ld", &num, &sides) == 2)
- {
- dice_init(dice, 0, num, sides);
- return TRUE;
- }
-
- if (sscanf(s, "%ld", &base) == 1)
- {
- dice_init(dice, base, 0, 0);
- return TRUE;
- }
-
- return FALSE;
-}
-
-void dice_parse_checked(dice_type *dice, cptr s)
-{
- bool_ result = dice_parse(dice, s);
- if (!result)
- {
- abort();
- }
-}
-
-long dice_roll(dice_type *dice)
-{
- assert(dice != NULL);
- return dice->base + damroll(dice->num, dice->sides);
-}
-
-void dice_print(dice_type *dice, char *output)
-{
- char buf[16];
-
- output[0] = '\0';
-
- if (dice->base > 0)
- {
- sprintf(buf, "%ld", dice->base);
- strcat(output, buf);
- }
-
- if ((dice->num > 0) || (dice->sides > 0))
- {
- if (dice->base > 0)
- {
- strcat(output, "+");
- }
-
- if (dice->num > 1)
- {
- sprintf(buf, "%ld", dice->num);
- strcat(output, buf);
- }
-
- strcat(output, "d");
-
- sprintf(buf, "%ld", dice->sides);
- strcat(output, buf);
- }
-}
diff --git a/src/types.h b/src/types.h
index 5d336815..92aa428b 100644
--- a/src/types.h
+++ b/src/types.h
@@ -2469,17 +2469,6 @@ struct cli_comm
};
/*
- * Dice
- */
-typedef struct dice_type dice_type;
-struct dice_type
-{
- long base; /* Base value to which roll is added. */
- long num; /* Number of dice */
- long sides; /* Sides per dice */
-};
-
-/*
* Skills !
*/
typedef struct skill_type skill_type;
diff --git a/src/types_fwd.h b/src/types_fwd.h
index 4c7084f9..d5b2ec7d 100644
--- a/src/types_fwd.h
+++ b/src/types_fwd.h
@@ -81,7 +81,6 @@ struct hooks_chain;
struct hist_type;
struct set_type;
struct cli_comm;
-struct dice_type;
struct skill_type;
struct school_idx;
struct spell_type;