summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2017-11-21 13:19:14 +0100
committernsensfel <SpamShield0@noot-noot.org>2017-11-21 13:19:14 +0100
commiteea0d1d6d519bba540c261787a6223536abf237b (patch)
tree49a59c2cd41526343becca8687e21b4f0248a6d2
parente21132add7ab02cb39d41ea3cf839244e5d2cfb2 (diff)
Adds some server-side checks for char movements.
-rw-r--r--src/battlemap.erl49
-rw-r--r--src/battlemap_shim.erl4
-rw-r--r--src/tile.erl12
3 files changed, 53 insertions, 12 deletions
diff --git a/src/battlemap.erl b/src/battlemap.erl
index 209a4ab..0b742d9 100644
--- a/src/battlemap.erl
+++ b/src/battlemap.erl
@@ -8,17 +8,46 @@
-include("timed_cache_data.hrl").
-calc_new_loc (X, Y, [], _Points, _Map, _OtherChars) ->
- {X, Y};
-calc_new_loc (X, Y, [Step|Path], Points, Map, OtherChars) ->
- case Step of
- <<"U">> -> calc_new_loc(X, (Y - 1), Path, Points, Map, OtherChars);
- <<"D">> -> calc_new_loc(X, (Y + 1), Path, Points, Map, OtherChars);
- <<"L">> -> calc_new_loc((X - 1), Y, Path, Points, Map, OtherChars);
- <<"R">> -> calc_new_loc((X + 1), Y, Path, Points, Map, OtherChars);
- _ -> calc_new_loc(X, Y, Path, Points, Map, OtherChars)
+next_loc (X, Y, <<"L">>) -> {(X - 1), Y};
+next_loc (X, Y, <<"R">>) -> {(X + 1), Y};
+next_loc (X, Y, <<"U">>) -> {X, (Y - 1)};
+next_loc (X, Y, <<"D">>) -> {X, (Y + 1)}.
+
+loc_to_index(X, Y, Map) ->
+ if
+ (X < 0) -> error;
+ (Y < 0) -> error;
+ (X >= Map#battlemap.width) -> error;
+ true -> ((Y * Map#battlemap.width) + X)
end.
+calc_new_loc (X, Y, [], Points, _Map, _OtherCharsLocs) ->
+ true = (Points >= 0),
+ {X, Y};
+calc_new_loc (X, Y, [Step|Path], Points, Map, OtherCharsLocs) ->
+ {NX, NY} = next_loc(X, Y, Step),
+ NPoints =
+ (
+ Points
+ -
+ tile:get_cost
+ (
+ array:get
+ (
+ loc_to_index(X, Y, Map),
+ Map#battlemap.content
+ )
+ )
+ ),
+ false = lists:member({NX, NY}, OtherCharsLocs),
+ calc_new_loc(NX, NY, Path, NPoints, Map, OtherCharsLocs).
+
cross (Battlemap, CharInst, Path, OtherChars) ->
{X, Y} = character_instance:get_location(CharInst),
- {ok, calc_new_loc(X, Y, Path, 99, Battlemap, OtherChars)}.
+ OtherCharsLocs =
+ lists:map
+ (
+ fun character_instance:get_location/1,
+ OtherChars
+ ),
+ {ok, calc_new_loc(X, Y, Path, 99, Battlemap, OtherCharsLocs)}.
diff --git a/src/battlemap_shim.erl b/src/battlemap_shim.erl
index b805a9b..baabf62 100644
--- a/src/battlemap_shim.erl
+++ b/src/battlemap_shim.erl
@@ -16,8 +16,8 @@ generate(_Prev, Result, _X, 0, _BaseWidth) ->
generate(Prev, Result, 0, Y, BaseWidth) ->
generate(Prev, Result, BaseWidth, (Y - 1), BaseWidth);
generate(Prev, Result, X, Y, BaseWidth) ->
- case rand:uniform(6) of
- N when (N > 3) ->
+ case rand:uniform(32) of
+ N when (N >= 16) ->
generate(Prev, [Prev|Result], (X - 1), Y, BaseWidth);
N ->
diff --git a/src/tile.erl b/src/tile.erl
new file mode 100644
index 0000000..2e9f562
--- /dev/null
+++ b/src/tile.erl
@@ -0,0 +1,12 @@
+-module(tile).
+-export
+(
+ [
+ get_cost/1,
+ cost_when_oob/0
+ ]
+).
+cost_when_oob () -> 255.
+
+get_cost(N) when (N =< 200) -> N;
+get_cost(_N) -> cost_when_oob().