| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-28 17:14:02 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-28 17:14:02 +0100 | 
| commit | f539b7072c357339328d9bfd54f1f1ed51828586 (patch) | |
| tree | b6205dd79c78090831e812aceac177d2a9f35d28 /src/type/battlemap | |
| parent | 80358376b9300a0d73cb8b62dfa9fdd65240ca66 (diff) | |
Trying to tidy up this mess.
Diffstat (limited to 'src/type/battlemap')
| -rw-r--r-- | src/type/battlemap/cross.erl | 60 | 
1 files changed, 60 insertions, 0 deletions
diff --git a/src/type/battlemap/cross.erl b/src/type/battlemap/cross.erl new file mode 100644 index 0000000..aa1645e --- /dev/null +++ b/src/type/battlemap/cross.erl @@ -0,0 +1,60 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% 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 +      ) +   ).  | 


