summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-26 13:52:29 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-26 13:52:29 +0100
commitfd4d031ab5b31763d376c663cc049f62ee389243 (patch)
treecd09a29bb888acf772fa1aee59fe95e8bd75fe4e /src/battlemap
parent66ec11ce5d2e227846d6e6b2899cda851a70fc04 (diff)
Got it to run, at last.
Diffstat (limited to 'src/battlemap')
-rw-r--r--src/battlemap/movement.erl68
-rw-r--r--src/battlemap/roll.erl30
2 files changed, 98 insertions, 0 deletions
diff --git a/src/battlemap/movement.erl b/src/battlemap/movement.erl
new file mode 100644
index 0000000..7fc5db1
--- /dev/null
+++ b/src/battlemap/movement.erl
@@ -0,0 +1,68 @@
+-module(movement).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+-export
+(
+ [
+ cross/4,
+ steps_between/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+location_after_step (Step, X, Y) ->
+ case Step of
+ <<"L">> -> {(X - 1), Y};
+ <<"R">> -> {(X + 1), Y};
+ <<"U">> -> {X, (Y - 1)};
+ <<"D">> -> {X, (Y + 1)}
+ end.
+
+location_to_array_index (ArrayWidth, X, Y) ->
+ if
+ (X < 0) -> -1;
+ (Y < 0) -> -1;
+ (X >= ArrayWidth) -> error;
+ true -> ((Y * ArrayWidth) + X)
+ end.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+cross (_Battlemap, _ForbiddenLocations, [], Cost, X, Y) ->
+ {{X, Y}, Cost};
+cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, X, Y) ->
+ BattlemapTiles = battlemap:get_tiles(Battlemap),
+
+ {NextX, NextY} = location_after_step(Step, X, Y),
+ NextTileIX =
+ location_to_array_index(array:size(BattlemapTiles), NextX, NextY),
+ NextTile = array:get(array:get(NextTileIX, BattlemapTiles)),
+ NextCost = (Cost + tile:get_cost(NextTile)),
+ IsForbidden =
+ array:foldl
+ (
+ fun (_IX, Location, Prev) ->
+ (Prev or ({NextX, NextY} == Location))
+ end,
+ ForbiddenLocations
+ ),
+
+ IsForbidden = false,
+
+ cross(Battlemap, ForbiddenLocations, NextSteps, NextCost, NextX, NextY).
+
+cross (Battlemap, ForbiddenLocations, Path, {X, Y}) ->
+ cross(Battlemap, ForbiddenLocations, Path, 0, X, Y).
+
+steps_between ({OX, OY}, {DX, DY}) ->
+ (abs(DY - OY) + abs(DX - OX)).
diff --git a/src/battlemap/roll.erl b/src/battlemap/roll.erl
new file mode 100644
index 0000000..803a6de
--- /dev/null
+++ b/src/battlemap/roll.erl
@@ -0,0 +1,30 @@
+-module(roll).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export
+(
+ [
+ percentage/0,
+ between/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+between (Min, Max) ->
+ Diff = (Max - Min),
+ (Min + (rand:uniform(Diff + 1) - 1)).
+
+percentage () ->
+ between(0, 100).