summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--data/tile/global.m4.conf14
-rw-r--r--data/tile/grassland.m4d5
-rw-r--r--src/battle/struct/btl_tile.erl9
-rw-r--r--src/battle/struct/btl_tile.erl.m490
5 files changed, 120 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 7a42688..9837720 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ BIN_DIR ?= ${CURDIR}/ebin
INCLUDE_DIR ?= ${CURDIR}/include
WWW_DIR ?= ${CURDIR}/www
LOG_DIR ?= ${CURDIR}/log
+DATA_DIR ?= ${CURDIR}/data
## Local only?
#ERL_NAME_VS_SNAME ?= -name
@@ -72,6 +73,7 @@ M4_EXEC = $(M4) $(M4_OPTS)
################################################################################
MAKEFILE_TO_M4 = \
+ --define=__MAKEFILE_DATA_DIR=$(DATA_DIR) \
--define=__MAKEFILE_BIN_DIR=$(BIN_DIR) \
--define=__MAKEFILE_LOG_DIR=$(LOG_DIR) \
--define=__MAKEFILE_WWW_DIR=$(WWW_DIR) \
@@ -124,8 +126,8 @@ debug_run:
--src --plt $(DIALYZER_PLT_FILE)
endif
-$(PREPROCESSED_FILES): %: $(PREPROCESSOR_CONFIG_FILES) %.m4
- $(M4_EXEC) -P $(MAKEFILE_TO_M4) $^> $@
+$(PREPROCESSED_FILES): %: %.m4 .PHONY
+ $(M4_EXEC) -P $(MAKEFILE_TO_M4) $(PREPROCESSOR_CONFIG_FILES) $< > $@
$(OPTIONAL_DIRS): %:
mkdir -p $@
@@ -133,3 +135,6 @@ $(OPTIONAL_DIRS): %:
.SECONDEXPANSION:
$(ERL_BIN_FILES): $(BIN_DIR)/%.beam: $$(shell find $(SRC_DIR) -name "%.erl")
$(ERLC_EXEC) -o $(BIN_DIR) $<
+
+.PHONY:
+
diff --git a/data/tile/global.m4.conf b/data/tile/global.m4.conf
new file mode 100644
index 0000000..686e4f9
--- /dev/null
+++ b/data/tile/global.m4.conf
@@ -0,0 +1,14 @@
+m4_define(`__TILE_CHOOSE_STYLE', `m4_define(`__TILE_CLASS',m4_defn(`$1'))m4_undefine(`$1')')m4_dnl
+m4_define(`__TILE_COST_WHEN_OCCUPIED', 201)m4_dnl
+m4_define(`__TILE_COST_WHEN_OOB', 255)m4_dnl
+m4_define(`__TILE_CLASS_ERLANG_STYLE',`from_id (`$1') ->
+ #tile
+ {
+ id = $1,
+ name = <<"[__TILE_CATEGORY_NAME] $2">>,
+ cost = $3,
+ class_range_min = $4,
+ class_range_max = $5
+ };')m4_dnl
+m4_define(`__TILE_CATEGORY',`m4_define(`__TILE_CATEGORY_NAME', `$1')')m4_dnl
+m4_define(`__TILE_CLASS_USE_ERLANG_STYLE',`__TILE_CHOOSE_STYLE(`__TILE_CLASS_ERLANG_STYLE')')m4_dnl
diff --git a/data/tile/grassland.m4d b/data/tile/grassland.m4d
new file mode 100644
index 0000000..7d4c943
--- /dev/null
+++ b/data/tile/grassland.m4d
@@ -0,0 +1,5 @@
+__TILE_CATEGORY(`Grassland')m4_dnl
+__TILE_CLASS(0, `Grass', 6, 0, 0)
+__TILE_CLASS(1, `Mushroom Infestation', 12, 1, 1)
+__TILE_CLASS(2, `Tree Remains', 24, 2, 2)
+__TILE_CLASS(3, `Clear Water', __TILE_COST_WHEN_OCCUPIED, 3, 17)
diff --git a/src/battle/struct/btl_tile.erl b/src/battle/struct/btl_tile.erl
index 16e671b..2ac3832 100644
--- a/src/battle/struct/btl_tile.erl
+++ b/src/battle/struct/btl_tile.erl
@@ -94,17 +94,16 @@ from_id (3) ->
{
id = 3,
name = <<"[Grassland] Clear Water">>,
- cost = cost_when_occupied(),
+ cost = 201,
class_range_min = 3,
class_range_max = 17
- }.
+ };
+from_id(_) ->
+ from_id(0).
-spec cost_when_oob () -> non_neg_integer().
cost_when_oob () -> 255.
--spec cost_when_occupied () -> non_neg_integer().
-cost_when_occupied () -> 201.
-
-spec get_id (type()) -> non_neg_integer().
get_id (Tile) -> Tile#tile.id.
diff --git a/src/battle/struct/btl_tile.erl.m4 b/src/battle/struct/btl_tile.erl.m4
new file mode 100644
index 0000000..8c884ca
--- /dev/null
+++ b/src/battle/struct/btl_tile.erl.m4
@@ -0,0 +1,90 @@
+-module(btl_tile).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ tile,
+ {
+ id :: id(),
+ name :: binary(),
+ cost :: non_neg_integer(),
+ class_range_min :: non_neg_integer(),
+ class_range_max :: non_neg_integer()
+ }
+).
+
+-opaque id() :: non_neg_integer().
+-opaque class_id() :: non_neg_integer().
+-opaque type() :: #tile{}.
+
+-export_type([type/0, class_id/0, id/0]).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export
+(
+ [
+ get_id/1,
+ get_name/1,
+ get_cost/1,
+ get_range_minimum/1,
+ get_range_maximum/1,
+ from_id/1,
+ cost_when_oob/0
+ ]
+).
+
+-export
+(
+ [
+ class_id_to_type_id/1,
+ class_id_from_int/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+-spec class_id_to_type_id (class_id()) -> id().
+class_id_to_type_id (ClassID) ->
+ case ClassID of
+ 0 -> 0;
+ 1 -> 1;
+ 2 -> 2;
+ N when ((N >= 3) and (N =< 17)) -> 3
+ end.
+
+-spec from_id (id()) -> type().
+m4_include(__MAKEFILE_DATA_DIR/tile/global.m4.conf)m4_dnl
+__TILE_CLASS_USE_ERLANG_STYLE
+m4_include(__MAKEFILE_DATA_DIR/tile/grassland.m4d)m4_dnl
+from_id(_) ->
+ from_id(0).
+
+-spec cost_when_oob () -> non_neg_integer().
+cost_when_oob () -> __TILE_COST_WHEN_OOB.
+
+-spec get_id (type()) -> non_neg_integer().
+get_id (Tile) -> Tile#tile.id.
+
+-spec get_cost (type()) -> non_neg_integer().
+get_cost (Tile) -> Tile#tile.cost.
+
+-spec get_name (type()) -> binary().
+get_name (Tile) -> Tile#tile.name.
+
+-spec get_range_minimum (type()) -> non_neg_integer().
+get_range_minimum (Tile) -> Tile#tile.class_range_min.
+
+-spec get_range_maximum (type()) -> non_neg_integer().
+get_range_maximum (Tile) -> Tile#tile.class_range_max.
+
+-spec class_id_from_int (non_neg_integer()) -> id().
+class_id_from_int (I) -> I.