| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/struct')
| -rw-r--r-- | src/struct/attributes.erl | 19 | ||||
| -rw-r--r-- | src/struct/battlemap.erl | 31 | ||||
| -rw-r--r-- | src/struct/battlemap_instance.erl | 42 | ||||
| -rw-r--r-- | src/struct/character.erl | 27 | ||||
| -rw-r--r-- | src/struct/character_instance.erl | 35 | ||||
| -rw-r--r-- | src/struct/statistics.erl | 2 | ||||
| -rw-r--r-- | src/struct/tile.erl | 41 | ||||
| -rw-r--r-- | src/struct/weapon.erl | 27 | 
8 files changed, 216 insertions, 8 deletions
| diff --git a/src/struct/attributes.erl b/src/struct/attributes.erl index 022cad2..bb68032 100644 --- a/src/struct/attributes.erl +++ b/src/struct/attributes.erl @@ -39,6 +39,14 @@     ]  ). +%%%% Accessors +-export +( +   [ +      random/0 +   ] +). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -66,3 +74,14 @@ set_speed (Val, Att) ->     Att#attributes{ speed = Val }.  set_strength (Val, Att) ->     Att#attributes{ strength = Val }. + +random () -> +   #attributes +   { +      constitution = roll:percentage(), +      dexterity = roll:percentage(), +      intelligence = roll:percentage(), +      mind = roll:percentage(), +      speed = roll:percentage(), +      strength = roll:percentage() +   }. diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl index b0eb5fb..b999436 100644 --- a/src/struct/battlemap.erl +++ b/src/struct/battlemap.erl @@ -27,9 +27,28 @@        get_tile_ids/1     ]  ). + +-export +( +   [ +      random/3 +   ] +). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +generate_random_tile_ids (_PreviousTileID, Result, _X, 0, _Width) -> +   Result; +generate_random_tile_ids (PreviousTileID, Result, 0, Y, Width) -> +   generate_random_tile_ids(PreviousTileID, Result, Width, (Y - 1), Width); +generate_random_tile_ids (PreviousTileID, Result, X, Y, Width) -> +   NewTile = +      case roll:percentage() of +         N when (N >= 10) -> PreviousTileID; +         _ -> tile:random_id() +      end, +   generate_random_tile_ids(NewTile, [NewTile|Result], (X - 1), Y, Width).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -39,3 +58,15 @@ get_id (Battlemap) -> Battlemap#battlemap.id.  get_width (Battlemap) -> Battlemap#battlemap.width.  get_height (Battlemap) -> Battlemap#battlemap.height.  get_tile_ids (Battlemap) -> Battlemap#battlemap.tile_ids. + +random (ID, Width, Height) -> +   InitialTile = tile:random_id(), +   TileIDs = generate_random_tile_ids(InitialTile, [], Width, Height, Width), + +   #battlemap +   { +      id = ID, +      width = Width, +      height = Height, +      tile_ids = TileIDs +   }. diff --git a/src/struct/battlemap_instance.erl b/src/struct/battlemap_instance.erl index 9a57d09..d031ccd 100644 --- a/src/struct/battlemap_instance.erl +++ b/src/struct/battlemap_instance.erl @@ -38,6 +38,13 @@     ]  ). +-export +( +   [ +      random/4 +   ] +). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -92,3 +99,38 @@ set_last_turns_effects (Effects, BattlemapInstance) ->     {        last_turns_effects = Effects     }. + +random (ID, PlayersAsList, Battlemap, Characters) -> +   BattlemapWidth = battlemap:get_width(Battlemap), +   BattlemapHeight = battlemap:get_height(Battlemap), +   CharacterInstancesAsList = +      lists:mapfoldl +      ( +         fun (Character, ForbiddenLocations) -> +            NewCharacterInstance = +               character_instance:random +               ( +                  Character, +                  BattlemapWidth, +                  BattlemapHeight, +                  ForbiddenLocations +               ), +            NewCharacterInstanceLocation = +               character_instance:get_location(NewCharacterInstance), +            { +               NewCharacterInstance, +               [NewCharacterInstanceLocation|ForbiddenLocations] +            } +         end, +         Characters +      ), + +   #battlemap_instance +   { +      id = ID, +      battlemap = Battlemap, +      character_instances = array:from_list(CharacterInstancesAsList), +      players = array:from_list(PlayersAsList), +      current_player_turn = player_turn:new(0, 0), +      last_turns_effects = [] +   }. diff --git a/src/struct/character.erl b/src/struct/character.erl index 0459214..90e449c 100644 --- a/src/struct/character.erl +++ b/src/struct/character.erl @@ -41,6 +41,13 @@     ]  ). +-export +( +   [ +      random/2 +   ] +). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -71,3 +78,23 @@ set_statistics (Stats, Char) ->     {        statistics = Stats     }. + +random (ID, OwnerID) -> +   WeaponIDs = {weapon:random_id(), weapon:random_id()}, +   Attributes = attributes:random(), +   Statistics = statistics:new(Attributes, WeaponIDs), +   IDAsListString = integer_to_list(ID), +   IDAsBinaryString = list_to_binary(IDAsListString), + +   #character +   { +      id = ID, +      owner_id = OwnerID, +      name = list_to_binary("Char" ++ IDAsListString), +      icon = IDAsBinaryString, +      portrait = IDAsBinaryString, +      attributes = Attributes, +      weapon_ids = WeaponIDs, +      glyphs = [], +      statistics = Statistics +   }. 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) +   ). diff --git a/src/struct/statistics.erl b/src/struct/statistics.erl index f5a4650..f8797bb 100644 --- a/src/struct/statistics.erl +++ b/src/struct/statistics.erl @@ -110,7 +110,7 @@ new (BaseAttributes, WeaponIDs) ->     {ActiveWeaponID, _} = WeaponIDs,     ActiveWeapon = weapon:from_id(ActiveWeaponID),     {MinDamage, MaxDamage} = weapon:get_damages(ActiveWeapon), -   Attributes = weapon:apply_to_attributes(ActiveWeapon, BaseAttributes), +   Attributes = weapon:apply_to_attributes(BaseAttributes, ActiveWeapon),     Constitution = attributes:get_constitution(Attributes),     Dexterity = attributes:get_dexterity(Attributes),     Intelligence = attributes:get_intelligence(Attributes), diff --git a/src/struct/tile.erl b/src/struct/tile.erl new file mode 100644 index 0000000..05da3ec --- /dev/null +++ b/src/struct/tile.erl @@ -0,0 +1,41 @@ +-module(tile). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( +   [ +      get_cost/1, +      cost_when_oob/0 +   ] +). + +-export +( +   [ +      random_id/0 +   ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +cost_when_oob () -> 255. + +get_cost (N) -> +   if +      (N =< 200) -> (N + 8); +      true -> cost_when_oob() +   end. + +random_id () -> +   roll:between(0, 15). diff --git a/src/struct/weapon.erl b/src/struct/weapon.erl index add445a..ca74ada 100644 --- a/src/struct/weapon.erl +++ b/src/struct/weapon.erl @@ -23,7 +23,8 @@  -export  (     [ -      get_id/1 +      get_id/1, +      random_id/0     ]  ). @@ -32,7 +33,8 @@     [        from_id/1,        get_ranges/1, -      get_damages/1 +      get_damages/1, +      apply_to_attributes/2     ]  ). @@ -285,3 +287,24 @@ from_id (24) ->        damage_type = pierce,        damage_mod = heavy     }. + +random_id () -> +   roll:between(0, 24). + +apply_to_attributes (Attributes, Weapon) -> +   Dexterity = attributes:get_dexterity(Attributes), +   Speed = attributes:get_dexterity(Attributes), +   RangeModifier = Weapon#weapon.range_mod, +   DamageModifier = Weapon#weapon.damage_mod, +   WithRangeModifier = +      case RangeModifier of +         long -> +            attributes:set_dexterity(max(0, (Dexterity - 20)), Attributes); +         _ -> Attributes +      end, +   case DamageModifier of +      heavy -> +         attributes:set_speed(max(0, (Speed - 20)), WithRangeModifier); +      _ -> WithRangeModifier +   end. + | 


