summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-23 11:35:45 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-23 11:35:45 +0100
commitacf9e9f1eb880ffb8ab918c40724eda566aefcc7 (patch)
treeefa3dd6c88d7970632fbe44f322d03b983b02768 /src/struct
parent43e38e5fc54fd58e8230b2b5198b6d8cb625803c (diff)
Starting a big refactoring...
Diffstat (limited to 'src/struct')
-rw-r--r--src/struct/armor.erl51
-rw-r--r--src/struct/attributes.erl68
-rw-r--r--src/struct/battlemap.erl60
-rw-r--r--src/struct/battlemap_instance.erl94
-rw-r--r--src/struct/character.erl54
-rw-r--r--src/struct/character_instance.erl126
-rw-r--r--src/struct/glyph.erl45
-rw-r--r--src/struct/player_turn.erl51
-rw-r--r--src/struct/statistics.erl157
-rw-r--r--src/struct/weapon.erl287
10 files changed, 993 insertions, 0 deletions
diff --git a/src/struct/armor.erl b/src/struct/armor.erl
new file mode 100644
index 0000000..89df653
--- /dev/null
+++ b/src/struct/armor.erl
@@ -0,0 +1,51 @@
+-module(armor).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ armor,
+ {
+ id,
+ name,
+ icon,
+ type,
+ prof_max,
+ pos_stat_mods,
+ neg_stat_mods
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1,
+ get_name/1,
+ get_icon/1,
+ get_type/1,
+ get_max_prof/1,
+ get_pos_stat_mods/1,
+ get_neg_stat_mods/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (Ar) -> Ar#armor.id.
+get_name (Ar) -> Ar#armor.name.
+get_icon (Ar) -> Ar#armor.icon.
+get_type (Ar) -> Ar#armor.type.
+get_max_prof (Ar) -> Ar#armor.prof_max.
+get_pos_stat_mods (Ar) -> Ar#armor.pos_stat_mods.
+get_neg_stat_mods (Ar) -> Ar#armor.neg_stat_mods.
diff --git a/src/struct/attributes.erl b/src/struct/attributes.erl
new file mode 100644
index 0000000..b4395cb
--- /dev/null
+++ b/src/struct/attributes.erl
@@ -0,0 +1,68 @@
+-module(attributes).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ attributes,
+ {
+ constitution,
+ dexterity,
+ intelligence,
+ mind,
+ speed,
+ strength
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_constitution/1,
+ get_dexterity/1,
+ get_intelligence/1,
+ get_mind/1,
+ get_speed/1,
+ get_strength/1,
+
+ set_constitution/2,
+ set_dexterity/2,
+ set_intelligence/2,
+ set_mind/2,
+ set_speed/2,
+ set_strength/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_constitution (Att) -> Att#attributes.constitution.
+get_dexterity (Att) -> Att#attributes.dexterity.
+get_intelligence (Att) -> Att#attributes.intelligence.
+get_mind (Att) -> Att#attributes.mind.
+get_speed (Att) -> Att#attributes.speed.
+get_strength (Att) -> Att#attributes.strength.
+
+set_constitution (Att, Val) ->
+ Att#attributes{ constitution = Val }.
+set_dexterity (Att, Val) ->
+ Att#attributes{ dexterity = Val }.
+set_intelligence (Att, Val) ->
+ Att#attributes{ intelligence = Val }.
+set_mind (Att, Val) ->
+ Att#attributes{ mind = Val }.
+set_speed (Att, Val) ->
+ Att#attributes{ speed = Val }.
+set_strength (Att, Val) ->
+ Att#attributes{ strength = Val }.
diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl
new file mode 100644
index 0000000..f55aadb
--- /dev/null
+++ b/src/struct/battlemap.erl
@@ -0,0 +1,60 @@
+-module(battlemap).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ battlemap,
+ {
+ id,
+ width,
+ height,
+ content,
+ instances
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1,
+ get_width/1,
+ get_height/1,
+ list_tiles/1,
+ get_instances/1
+ ]
+).
+
+%%%% Utils
+-export
+(
+ [
+ cross/5,
+ dist/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (Battlemap) -> Battlemap#battlemap.id.
+get_width (Battlemap) -> Battlemap#battlemap.width.
+get_height (Battlemap) -> Battlemap#battlemap.height.
+list_tiles (Battlemap) -> array:sparse_to_list(Battlemap#battlemap.content).
+get_instances (Battlemap) -> Battlemap#battlemap.instances.
+
+%%%% Utils
+-include("battlemap/cross_5.erl").
+
+dist ({OX, OY}, {DX, DY}) ->
+ (abs(OX - DX) + abs(OY - DY)).
diff --git a/src/struct/battlemap_instance.erl b/src/struct/battlemap_instance.erl
new file mode 100644
index 0000000..c219a07
--- /dev/null
+++ b/src/struct/battlemap_instance.erl
@@ -0,0 +1,94 @@
+-module(battlemap_instance).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ battlemap_instance,
+ {
+ id,
+ battlemap,
+ character_instances,
+ players,
+ current_player_turn,
+ last_player_turn
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1,
+ get_battlemap/1,
+ get_character_instances/1,
+ get_players/1,
+ get_current_player_turn/1,
+ get_last_player_turn/1,
+
+ set_battlemap/2,
+ set_character_instances/2,
+ set_players/2,
+ set_current_player_turn/2,
+ set_last_player_turn/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (BattlemapInstance) -> BattlemapInstance#battlemap_instance.id.
+
+get_battlemap (BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance.battlemap.
+
+get_character_instances (BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance.character_instances.
+
+get_players (BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance.players.
+
+get_current_player_turn (BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance.current_player_turn.
+
+get_last_player_turn (BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance.last_player_turn.
+
+set_battlemap (Battlemap, BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance
+ {
+ battlemap = Battlemap
+ }.
+
+set_character_instances (CharacterInstances, BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance
+ {
+ character_instances = CharacterInstances
+ }.
+
+set_players (Players, BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance
+ {
+ players = Players
+ }.
+
+set_current_player_turn (PlayerTurn, BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance
+ {
+ current_player_turn = PlayerTurn
+ }.
+
+set_last_player_turn (PlayerTurn, BattlemapInstance) ->
+ BattlemapInstance#battlemap_instance
+ {
+ last_player_turn = PlayerTurn
+ }.
diff --git a/src/struct/character.erl b/src/struct/character.erl
new file mode 100644
index 0000000..03906e3
--- /dev/null
+++ b/src/struct/character.erl
@@ -0,0 +1,54 @@
+-module(character).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ character,
+ {
+ id,
+ name,
+ icon,
+ portrait,
+ attributes,
+ weapons,
+ glyphs,
+ armors
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1,
+ get_name/1,
+ get_icon/1,
+ get_portrait/1,
+ get_attributes/1,
+ get_weapons/1,
+ get_armors/1,
+ get_glyphs/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (Char) -> Char#character.id.
+get_name (Char) -> Char#character.name.
+get_icon (Char) -> Char#character.icon.
+get_portrait (Char) -> Char#character.portrait.
+get_attributes (Char) -> Char#character.attributes.
+get_weapons (Char) -> Char#character.weapons.
+get_armors (Char) -> Char#character.armors.
+get_glyphs (Char) -> Char#character.glyphs.
diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl
new file mode 100644
index 0000000..63045a7
--- /dev/null
+++ b/src/struct/character_instance.erl
@@ -0,0 +1,126 @@
+-module(character_instance).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ character_instance,
+ {
+ x,
+ y,
+ health,
+ team,
+ active_wp,
+ stats
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_location/1,
+ get_current_health/1,
+ get_owner/1,
+ get_active_weapon/2,
+ get_statistics/1,
+ set_location/3,
+ mod_health/3
+ ]
+).
+
+%%%% Utils
+-export
+(
+ [
+ new_instance_of/3,
+ switch_weapon/2,
+ is_dead/1 % is_alive is reserved.
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+get_new_weapon(CharInst, Char) ->
+ case CharInst#character_instance.active_wp of
+ 0 ->
+ {_, Weapon} = character:get_weapons(Char),
+ {1, Weapon};
+
+ 1 ->
+ {Weapon, _} = character:get_weapons(Char),
+ {0, Weapon}
+ end.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_location (CharInst) ->
+ {CharInst#character_instance.x, CharInst#character_instance.y}.
+
+get_current_health (CharInst) -> CharInst#character_instance.health.
+
+get_owner (CharInst) -> CharInst#character_instance.team.
+
+get_active_weapon (CharInst, Char) ->
+ case CharInst#character_instance.active_wp of
+ 0 ->
+ {_, Weapon} = character:get_weapons(Char),
+ Weapon;
+
+ 1 ->
+ {Weapon, _} = character:get_weapons(Char),
+ Weapon
+ end.
+
+get_statistics (CharInst) -> CharInst#character_instance.stats.
+
+set_location (CharInst, X, Y) ->
+ CharInst#character_instance
+ {
+ x = X,
+ y = Y
+ }.
+
+mod_health (CharInst, MaxHealth, HealthMod) ->
+ NewHealth = (CharInst#character_instance.health + HealthMod),
+ if
+ (NewHealth < 0) ->
+ CharInst#character_instance{ health = 0 };
+
+ (NewHealth > MaxHealth) ->
+ CharInst#character_instance{ health = MaxHealth };
+
+ true ->
+ CharInst#character_instance{ health = NewHealth }
+ end.
+
+%%%% Utils
+new_instance_of (Char, Owner, {X, Y}) ->
+ {Weapon, _} = character:get_weapons(Char),
+ Stats = statistics:calc_for(character:get_attributes(Char), Weapon),
+ #character_instance
+ {
+ x = X,
+ y = Y,
+ health = statistics:get_health(Stats),
+ team = Owner,
+ stats = Stats,
+ active_wp = 0
+ }.
+
+switch_weapon (CharInst, Char) ->
+ {NewWpIndex, Weapon} = get_new_weapon(CharInst, Char),
+ CharInst#character_instance
+ {
+ active_wp = NewWpIndex,
+ stats = statistics:calc_for(character:get_attributes(Char), Weapon)
+ }.
+
+is_dead (CharInst) -> (CharInst#character_instance.health == 0).
diff --git a/src/struct/glyph.erl b/src/struct/glyph.erl
new file mode 100644
index 0000000..18d8455
--- /dev/null
+++ b/src/struct/glyph.erl
@@ -0,0 +1,45 @@
+-module(glyph).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ glyph,
+ {
+ id,
+ name,
+ icon,
+ pos_attrib_mods,
+ neg_attrib_mods
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1,
+ get_name/1,
+ get_icon/1,
+ get_pos_attrib_mods/1,
+ get_neg_attrib_mods/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (Gh) -> Gh#glyph.id.
+get_name (Gh) -> Gh#glyph.name.
+get_icon (Gh) -> Gh#glyph.icon.
+get_pos_attrib_mods (Gh) -> Gh#glyph.pos_attrib_mods.
+get_neg_attrib_mods (Gh) -> Gh#glyph.neg_attrib_mods.
diff --git a/src/struct/player_turn.erl b/src/struct/player_turn.erl
new file mode 100644
index 0000000..b973135
--- /dev/null
+++ b/src/struct/player_turn.erl
@@ -0,0 +1,51 @@
+-module(player_turn).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ player_turn,
+ {
+ number,
+ player_id
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export
+(
+ [
+ new/2
+ ]
+).
+
+%%%% Accessors
+-export
+(
+ [
+ get_number/1,
+ get_player_id/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+new (Number, PlayerID) ->
+ #player_turn
+ {
+ number = Number,
+ player_id = PlayerID
+ }.
+
+get_number (PlayerTurn) -> PlayerTurn#player_turn.number.
+
+get_player_id (PlayerTurn) -> PlayerTurn#player_turn.player_id.
diff --git a/src/struct/statistics.erl b/src/struct/statistics.erl
new file mode 100644
index 0000000..0668fea
--- /dev/null
+++ b/src/struct/statistics.erl
@@ -0,0 +1,157 @@
+-module(statistics).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ statistics,
+ {
+ movement_points,
+ health,
+ dodges,
+ parries,
+ damage_min,
+ damage_max,
+ accuracy,
+ double_hits,
+ critical_hits
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_movement_points/1,
+ get_health/1,
+ get_dodges/1,
+ get_parries/1,
+ get_damage_min/1,
+ get_damage_max/1,
+ get_accuracy/1,
+ get_double_hits/1,
+ get_critical_hits/1
+ ]
+).
+
+-export
+(
+ [
+ calc_for/2
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ceil (F) ->
+ I = trunc(F),
+ case (F > I) of
+ true -> (I + 1);
+ _ -> I
+ end.
+
+float_to_int (F) -> trunc(ceil(F)).
+min_max (Min, Max, V) -> min(Max, max(Min, V)).
+
+average ([]) -> 0;
+average (L) -> lists:sum(L) / length(L).
+
+% V | 010 | 030 | 050 | 070 | 100 |
+% F | 004 | 023 | 058 | 104 | 200 |
+gentle_squared_growth (V) -> float_to_int(math:pow(V, 1.8) / 20).
+
+% V | 010 | 030 | 050 | 070 | 100 |
+% F | 001 | 005 | 018 | 041 | 100 |
+sudden_squared_growth (V) -> float_to_int(math:pow(V, 2.5) / 1000).
+
+% V | 010 | 030 | 050 | 070 | 100 |
+% F | 002 | 006 | 016 | 049 | 256 |
+sudden_exp_growth (V) -> float_to_int(math:pow(4, V / 25)).
+
+% V | 010 | 030 | 050 | 070 | 100 |
+% F | 040 | 066 | 079 | 088 | 099 |
+% Seems too generous, values for attributes below 50 should dip faster and
+% lower.
+already_high_slow_growth (V) -> float_to_int(30 * math:log((V + 5)/4)).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_movement_points (Stats) -> Stats#statistics.movement_points.
+get_health (Stats) -> Stats#statistics.health.
+get_dodges (Stats) -> Stats#statistics.dodges.
+get_parries (Stats) -> Stats#statistics.parries.
+get_damage_min (Stats) -> Stats#statistics.damage_min.
+get_damage_max (Stats) -> Stats#statistics.damage_max.
+get_accuracy (Stats) -> Stats#statistics.accuracy.
+get_double_hits (Stats) -> Stats#statistics.double_hits.
+get_critical_hits (Stats) -> Stats#statistics.critical_hits.
+
+calc_for (Att, _Wp) ->
+ #statistics
+ {
+ movement_points = gentle_squared_growth(attributes:get_speed(Att)),
+ health = gentle_squared_growth(attributes:get_constitution(Att)),
+ dodges =
+ min_max
+ (
+ 0,
+ 100,
+ sudden_exp_growth
+ (
+ average
+ (
+ [
+ attributes:get_dexterity(Att),
+ attributes:get_mind(Att),
+ attributes:get_speed(Att)
+ ]
+ )
+ )
+ ),
+ parries =
+ min_max
+ (
+ 0,
+ 75,
+ sudden_exp_growth
+ (
+ average
+ (
+ [
+ attributes:get_dexterity(Att),
+ attributes:get_speed(Att),
+ attributes:get_strength(Att)
+ ]
+ )
+ )
+ ),
+ damage_min = 0,
+ damage_max = 100,
+ accuracy =
+ % Hitting should involve this stat (not with this formula though), but
+ % also the target's dodge stat, with three possible results:
+ % - Missed
+ % - Grazed (Halved damage)
+ % - Hit
+ % Stat = (target.dodge - char.accuracy)
+ % Roll = RAND(0, 100)
+ % if (Roll >= (Stat * 2)): Hit
+ % else if (Roll >= Stat): Grazed
+ % else: Missed.
+ min_max
+ (
+ 0,
+ 100,
+ sudden_squared_growth(attributes:get_dexterity(Att))
+ ),
+ double_hits =
+ min_max(0, 100, sudden_squared_growth(attributes:get_speed(Att))),
+ critical_hits =
+ min_max(0, 100, sudden_squared_growth(attributes:get_intelligence(Att)))
+ }.
diff --git a/src/struct/weapon.erl b/src/struct/weapon.erl
new file mode 100644
index 0000000..add445a
--- /dev/null
+++ b/src/struct/weapon.erl
@@ -0,0 +1,287 @@
+-module(weapon).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-record
+(
+ weapon,
+ {
+ id,
+ name,
+ range_type,
+ range_mod,
+ damage_type,
+ damage_mod
+ }
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+-export
+(
+ [
+ get_id/1
+ ]
+).
+
+-export
+(
+ [
+ from_id/1,
+ get_ranges/1,
+ get_damages/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ranges_of_type (ranged, long) -> {2, 6};
+ranges_of_type (ranged, short) -> {1, 4};
+ranges_of_type (melee, long) -> {0, 2};
+ranges_of_type (melee, short) -> {0, 1}.
+
+damages_of_type (ranged, heavy) -> {10, 25};
+damages_of_type (ranged, light) -> {5, 20};
+damages_of_type (melee, heavy) -> {20, 35};
+damages_of_type (melee, light) -> {15, 30}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
+get_id (Wp) -> Wp#weapon.id.
+
+get_ranges (Wp) ->
+ ranges_of_type(Wp#weapon.range_type, Wp#weapon.range_mod).
+get_damages (Wp) ->
+ damages_of_type(Wp#weapon.range_type, Wp#weapon.damage_mod).
+
+from_id (0) ->
+ #weapon{
+ id = 0,
+ name = "None",
+ range_type = melee,
+ range_mod = short,
+ damage_type = blunt,
+ damage_mod = light
+ };
+from_id (1) ->
+ #weapon{
+ id = 1,
+ name = "Dagger",
+ range_type = melee,
+ range_mod = short,
+ damage_type = slash,
+ damage_mod = light
+ };
+from_id (2) ->
+ #weapon{
+ id = 2,
+ name = "Sword",
+ range_type = melee,
+ range_mod = short,
+ damage_type = slash,
+ damage_mod = heavy
+ };
+from_id (3) ->
+ #weapon{
+ id = 3,
+ name = "Claymore",
+ range_type = melee,
+ range_mod = long,
+ damage_type = slash,
+ damage_mod = light
+ };
+from_id (4) ->
+ #weapon{
+ id = 4,
+ name = "Bardiche",
+ range_type = melee,
+ range_mod = long,
+ damage_type = slash,
+ damage_mod = heavy
+ };
+from_id (5) ->
+ #weapon{
+ id = 5,
+ name = "Stiletto",
+ range_type = melee,
+ range_mod = short,
+ damage_type = pierce,
+ damage_mod = light
+ };
+from_id (6) ->
+ #weapon{
+ id = 6,
+ name = "Pickaxe",
+ range_type = melee,
+ range_mod = short,
+ damage_type = pierce,
+ damage_mod = heavy
+ };
+from_id (7) ->
+ #weapon{
+ id = 7,
+ name = "Rapier",
+ range_type = melee,
+ range_mod = long,
+ damage_type = pierce,
+ damage_mod = light
+ };
+from_id (8) ->
+ #weapon{
+ id = 8,
+ name = "Pike",
+ range_type = melee,
+ range_mod = long,
+ damage_type = pierce,
+ damage_mod = heavy
+ };
+from_id (9) ->
+ #weapon{
+ id = 9,
+ name = "Club",
+ range_type = melee,
+ range_mod = short,
+ damage_type = blunt,
+ damage_mod = light
+ };
+from_id (10) ->
+ #weapon{
+ id = 10,
+ name = "Mace",
+ range_type = melee,
+ range_mod = short,
+ damage_type = blunt,
+ damage_mod = heavy
+ };
+from_id (11) ->
+ #weapon{
+ id = 11,
+ name = "Staff",
+ range_type = melee,
+ range_mod = long,
+ damage_type = blunt,
+ damage_mod = light
+ };
+from_id (12) ->
+ #weapon{
+ id = 12,
+ name = "War Hammer",
+ range_type = melee,
+ range_mod = long,
+ damage_type = blunt,
+ damage_mod = heavy
+ };
+from_id (13) ->
+ #weapon{
+ id = 13,
+ name = "Short Bow (Broadhead)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = slash,
+ damage_mod = light
+ };
+from_id (14) ->
+ #weapon{
+ id = 14,
+ name = "Short Bow (Blunt)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = blunt,
+ damage_mod = light
+ };
+from_id (15) ->
+ #weapon{
+ id = 15,
+ name = "Short Bow (Bodkin Point)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = pierce,
+ damage_mod = light
+ };
+from_id (16) ->
+ #weapon{
+ id = 16,
+ name = "Long Bow (Broadhead)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = slash,
+ damage_mod = light
+ };
+from_id (17) ->
+ #weapon{
+ id = 17,
+ name = "Long Bow (Blunt)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = blunt,
+ damage_mod = light
+ };
+from_id (18) ->
+ #weapon{
+ id = 18,
+ name = "Long Bow (Bodkin Point)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = pierce,
+ damage_mod = light
+ };
+from_id (19) ->
+ #weapon{
+ id = 19,
+ name = "Crossbow (Broadhead)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = slash,
+ damage_mod = heavy
+ };
+from_id (20) ->
+ #weapon{
+ id = 20,
+ name = "Crossbow (Blunt)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = blunt,
+ damage_mod = heavy
+ };
+from_id (21) ->
+ #weapon{
+ id = 21,
+ name = "Crossbow (Bodkin Point)",
+ range_type = ranged,
+ range_mod = short,
+ damage_type = pierce,
+ damage_mod = heavy
+ };
+from_id (22) ->
+ #weapon{
+ id = 22,
+ name = "Arbalest (Broadhead)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = slash,
+ damage_mod = heavy
+ };
+from_id (23) ->
+ #weapon{
+ id = 23,
+ name = "Arbalest (Blunt)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = blunt,
+ damage_mod = heavy
+ };
+from_id (24) ->
+ #weapon{
+ id = 24,
+ name = "Arbalest (Bodkin Point)",
+ range_type = ranged,
+ range_mod = long,
+ damage_type = pierce,
+ damage_mod = heavy
+ }.