summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2017-11-21 17:35:32 +0100
committernsensfel <SpamShield0@noot-noot.org>2017-11-21 17:35:32 +0100
commitf633e4d5320806f13b4cffa8dbef0f59a08ae90f (patch)
tree00759914fa79b18577e0cc0368403db4ee60d8f4
parenteea0d1d6d519bba540c261787a6223536abf237b (diff)
Server/client disagreement on tile crossing cost.
-rw-r--r--src/battlemap.erl50
-rw-r--r--src/battlemap/cross.erl62
-rw-r--r--src/battlemap_instance.erl2
-rw-r--r--src/battlemap_shim.erl2
-rw-r--r--src/character.erl11
-rw-r--r--src/tile.erl7
-rw-r--r--www/handler/battlemap/character_turn.yaws14
-rw-r--r--www/handler/battlemap/load_state.yaws4
8 files changed, 91 insertions, 61 deletions
diff --git a/src/battlemap.erl b/src/battlemap.erl
index 0b742d9..d8940e9 100644
--- a/src/battlemap.erl
+++ b/src/battlemap.erl
@@ -1,53 +1,5 @@
-module(battlemap).
--export
-(
- [
- cross/4
- ]
-).
-include("timed_cache_data.hrl").
-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),
- OtherCharsLocs =
- lists:map
- (
- fun character_instance:get_location/1,
- OtherChars
- ),
- {ok, calc_new_loc(X, Y, Path, 99, Battlemap, OtherCharsLocs)}.
+-include("battlemap/cross.erl").
diff --git a/src/battlemap/cross.erl b/src/battlemap/cross.erl
new file mode 100644
index 0000000..add9c27
--- /dev/null
+++ b/src/battlemap/cross.erl
@@ -0,0 +1,62 @@
+-export([cross/5]).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+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, _CharInstsLocs) ->
+ io:format("~nPoints remaining: ~p ~n", [Points]),
+ true = (Points >= 0),
+ {X, Y};
+calc_new_loc (X, Y, [Step|Path], Points, Map, CharInstsLocs) ->
+ io:format("~nStep - Points remaining: ~p ~n", [Points]),
+ {NX, NY} = next_loc(X, Y, Step),
+ TileCost =
+ tile:get_cost
+ (
+ array:get
+ (
+ loc_to_index(NX, NY, Map),
+ Map#battlemap.content
+ )
+ ),
+ io:format("~nStep cost: ~p ~n", [TileCost]),
+ NPoints =
+ (
+ Points
+ -
+ TileCost
+ ),
+ false = lists:member({NX, NY}, CharInstsLocs),
+ calc_new_loc(NX, NY, Path, NPoints, Map, CharInstsLocs).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+cross (Battlemap, {X, Y}, Points, Path, CharInsts) ->
+ calc_new_loc
+ (
+ X,
+ Y,
+ Path,
+ Points,
+ Battlemap,
+ lists:map
+ (
+ fun character_instance:get_location/1,
+ CharInsts
+ )
+ ).
diff --git a/src/battlemap_instance.erl b/src/battlemap_instance.erl
index ef573eb..b18fa4e 100644
--- a/src/battlemap_instance.erl
+++ b/src/battlemap_instance.erl
@@ -18,7 +18,7 @@ get_char_instances (BattlemapInstance) ->
).
get_char_instance (BattlemapInstance, CharInstID) ->
- {ok, dict:fetch(CharInstID, BattlemapInstance#battlemap_instance.chars)}.
+ dict:fetch(CharInstID, BattlemapInstance#battlemap_instance.chars).
set_char_instance (BattlemapInstance, CharInstID, CharInst) ->
BattlemapInstance#battlemap_instance
diff --git a/src/battlemap_shim.erl b/src/battlemap_shim.erl
index baabf62..845bb8e 100644
--- a/src/battlemap_shim.erl
+++ b/src/battlemap_shim.erl
@@ -16,7 +16,7 @@ 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(32) of
+ case rand:uniform(64) of
N when (N >= 16) ->
generate(Prev, [Prev|Result], (X - 1), Y, BaseWidth);
diff --git a/src/character.erl b/src/character.erl
new file mode 100644
index 0000000..f596570
--- /dev/null
+++ b/src/character.erl
@@ -0,0 +1,11 @@
+-module(character).
+-export
+(
+ [
+ get_movement_points/1
+ ]
+).
+
+-include("timed_cache_data.hrl").
+
+get_movement_points (Char) -> Char#character.mov_pts.
diff --git a/src/tile.erl b/src/tile.erl
index 2e9f562..cb5811b 100644
--- a/src/tile.erl
+++ b/src/tile.erl
@@ -8,5 +8,8 @@
).
cost_when_oob () -> 255.
-get_cost(N) when (N =< 200) -> N;
-get_cost(_N) -> cost_when_oob().
+get_cost (N) ->
+ if
+ (N =< 200) -> (N + 1);
+ true -> cost_when_oob()
+ end.
diff --git a/www/handler/battlemap/character_turn.yaws b/www/handler/battlemap/character_turn.yaws
index 495f451..3506e13 100644
--- a/www/handler/battlemap/character_turn.yaws
+++ b/www/handler/battlemap/character_turn.yaws
@@ -13,7 +13,7 @@
}
).
--include("/tmp/timed_cache_data.hrl").
+-include("/my/src/tacticians-server/src/timed_cache_data.hrl").
parse_input (Req) ->
JSONReqMap = jiffy:decode(Req, [return_maps]),
@@ -32,25 +32,27 @@ handle (Req) ->
%%%% Parse
Input = parse_input(Req),
%%%% Fetch
- Battlemap = timed_cache:fetch(battlemap_db, Input#input.battlemap_id),
- BattlemapInstance =
+ Battlemap = timed_cache:fetch(battlemap_db, Input#input.battlemap_id),
+ BattlemapInstance =
timed_cache:fetch
(
battlemap_instance_db,
<<"0">>
),
- {ok, CharInst} =
+ Character = timed_cache:fetch(character_db, Input#input.char_id),
+ CharInst =
battlemap_instance:get_char_instance
(
BattlemapInstance,
Input#input.char_id
),
%%%% Calc
- {ok, {X, Y}} =
+ {X, Y} =
battlemap:cross
(
Battlemap,
- CharInst,
+ character_instance:get_location(CharInst),
+ character:get_movement_points(Character),
Input#input.path,
battlemap_instance:get_char_instances(BattlemapInstance)
),
diff --git a/www/handler/battlemap/load_state.yaws b/www/handler/battlemap/load_state.yaws
index d68c6a4..5c37764 100644
--- a/www/handler/battlemap/load_state.yaws
+++ b/www/handler/battlemap/load_state.yaws
@@ -1,7 +1,7 @@
<erl>
-record(input, {session_token, player_id, battlemap_id, instance_id}).
--include("/tmp/timed_cache_data.hrl").
+-include("/my/src/tacticians-server/src/timed_cache_data.hrl").
parse_input (Req) ->
JSONReqMap = jiffy:decode(Req, [return_maps]),
@@ -20,7 +20,7 @@ generate_set_map (Battlemap) ->
[
{<<"width">>, Battlemap#battlemap.width},
{<<"height">>, Battlemap#battlemap.height},
- {<<"content">>, array:to_list(Battlemap#battlemap.content)}
+ {<<"content">>, array:sparse_to_list(Battlemap#battlemap.content)}
]
}
).