| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/struct/character_instance.erl')
| -rw-r--r-- | src/struct/character_instance.erl | 35 | 
1 files changed, 30 insertions, 5 deletions
| 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) +   ). | 


