| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-21 17:35:32 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-21 17:35:32 +0100 | 
| commit | f633e4d5320806f13b4cffa8dbef0f59a08ae90f (patch) | |
| tree | 00759914fa79b18577e0cc0368403db4ee60d8f4 /src | |
| parent | eea0d1d6d519bba540c261787a6223536abf237b (diff) | |
Server/client disagreement on tile crossing cost.
Diffstat (limited to 'src')
| -rw-r--r-- | src/battlemap.erl | 50 | ||||
| -rw-r--r-- | src/battlemap/cross.erl | 62 | ||||
| -rw-r--r-- | src/battlemap_instance.erl | 2 | ||||
| -rw-r--r-- | src/battlemap_shim.erl | 2 | ||||
| -rw-r--r-- | src/character.erl | 11 | ||||
| -rw-r--r-- | src/tile.erl | 7 | 
6 files changed, 81 insertions, 53 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. | 


