From fd4d031ab5b31763d376c663cc049f62ee389243 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 26 Feb 2018 13:52:29 +0100 Subject: Got it to run, at last. --- src/struct/character_instance.erl | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/struct/character_instance.erl') diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl index c530424..e736a4c 100644 --- a/src/struct/character_instance.erl +++ b/src/struct/character_instance.erl @@ -20,7 +20,8 @@ -export ( [ - new/2 + new/2, + random/4 ] ). @@ -43,6 +44,23 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> + X = roll:between(0, (BattlemapWidth - 1)), + Y = roll:between(0, (BattlemapHeight - 1)), + + IsForbidden = lists:member({X, Y}, ForbiddenLocations), + + case IsForbidden of + true -> + find_random_location + ( + BattlemapWidth, + BattlemapHeight, + ForbiddenLocations + ); + + _ -> {X, Y} + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -83,12 +101,19 @@ set_is_active (Active, CharInst) -> }. %%%% Utils -new (Char, Location) -> - Stats = character:get_statistics(Char), +new (Character, Location) -> + CharacterStatistics = character:get_statistics(Character), #character_instance { - character = Char, + character = Character, location = Location, - current_health = statistics:get_health(Stats), + current_health = statistics:get_health(CharacterStatistics), active = false }. + +random (Character, BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> + new + ( + Character, + find_random_location(BattlemapWidth, BattlemapHeight, ForbiddenLocations) + ). -- cgit v1.2.3-70-g09d2