summaryrefslogtreecommitdiff
path: root/src/shim
diff options
context:
space:
mode:
Diffstat (limited to 'src/shim')
-rw-r--r--src/shim/attributes_shim.erl47
-rw-r--r--src/shim/battlemap_instance_shim.erl55
-rw-r--r--src/shim/battlemap_shim.erl64
-rw-r--r--src/shim/character_shim.erl57
-rw-r--r--src/shim/database_shim.erl104
-rw-r--r--src/shim/weapon_shim.erl24
6 files changed, 55 insertions, 296 deletions
diff --git a/src/shim/attributes_shim.erl b/src/shim/attributes_shim.erl
deleted file mode 100644
index b80ee6d..0000000
--- a/src/shim/attributes_shim.erl
+++ /dev/null
@@ -1,47 +0,0 @@
--module(attributes_shim).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--record
-(
- attributes,
- {
- constitution,
- dexterity,
- intelligence,
- mind,
- speed,
- strength
- }
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% Accessors
--export
-(
- [
- rand/0
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-random_attribute (Min, Max) -> (rand:uniform(Max - Min) - 1) + Min.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-rand () ->
- #attributes
- {
- constitution = random_attribute(10, 100),
- dexterity = random_attribute(10, 100),
- intelligence = random_attribute(10, 100),
- mind = random_attribute(10, 100),
- speed = random_attribute(10, 100),
- strength = random_attribute(10, 100)
- }.
diff --git a/src/shim/battlemap_instance_shim.erl b/src/shim/battlemap_instance_shim.erl
deleted file mode 100644
index 94ae7ce..0000000
--- a/src/shim/battlemap_instance_shim.erl
+++ /dev/null
@@ -1,55 +0,0 @@
--module(battlemap_instance_shim).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--record
-(
- battlemap_instance,
- {
- id,
- chars,
- curr_player,
- players,
- rem_chars,
- last_turn
- }
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- generate_random/2
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-generate_random (CharInsts, Players) ->
- #battlemap_instance
- {
- id = <<"0">>,
- chars = dict:from_list(CharInsts),
- curr_player = 0,
- players = array:from_list(Players),
- rem_chars =
- lists:filtermap
- (
- fun ({K, V}) ->
- case character_instance:get_owner(V) of
- 0 -> {true, K};
- _ -> false
- end
- end,
- CharInsts
- ),
- last_turn = []
- }.
diff --git a/src/shim/battlemap_shim.erl b/src/shim/battlemap_shim.erl
deleted file mode 100644
index b19a653..0000000
--- a/src/shim/battlemap_shim.erl
+++ /dev/null
@@ -1,64 +0,0 @@
--module(battlemap_shim).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--record
-(
- battlemap,
- {
- id,
- width,
- height,
- content,
- instances
- }
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- generate_random/0
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-generate(_Prev, Result, _X, 0, _BaseWidth) ->
- Result;
-generate(Prev, Result, 0, Y, BaseWidth) ->
- generate(Prev, Result, BaseWidth, (Y - 1), BaseWidth);
-generate(Prev, Result, X, Y, BaseWidth) ->
- case rand:uniform(100) of
- N when (N >= 10) ->
- generate(Prev, [Prev|Result], (X - 1), Y, BaseWidth);
-
- N ->
- NewTileType = (N - 1),
- generate
- (
- NewTileType,
- [NewTileType|Result],
- (X - 1),
- Y,
- BaseWidth
- )
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-generate_random () ->
- Width = (rand:uniform(48) + 16),
- Height = (rand:uniform(48) + 16),
- #battlemap
- {
- id = <<"0">>,
- width = Width,
- height = Height,
- content = array:from_list(generate(0, [], Width, Height, Width))
- }.
diff --git a/src/shim/character_shim.erl b/src/shim/character_shim.erl
deleted file mode 100644
index 35a0753..0000000
--- a/src/shim/character_shim.erl
+++ /dev/null
@@ -1,57 +0,0 @@
--module(character_shim).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--record
-(
- character,
- {
- id,
- name,
- icon,
- portrait,
- attributes,
- weapons,
- glyphs,
- armors
- }
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- generate_random/1
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-generate_char (N) ->
- IDAsString = list_to_binary(integer_to_list(N)),
- #character
- {
- id = IDAsString, % ID
- name = IDAsString, % Name
- icon = IDAsString, % Icon
- portrait = IDAsString, % Portrait
- attributes = attributes_shim:rand(),
- weapons = {weapon_shim:rand(), weapon_shim:rand()},
- glyphs = [],
- armors = []
- }.
-
-generate (0, Result) ->
- Result;
-generate (N, Prev) ->
- generate((N - 1), [generate_char(N - 1)|Prev]).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-generate_random (N) ->
- generate(N, []).
diff --git a/src/shim/database_shim.erl b/src/shim/database_shim.erl
index d55d848..1589d14 100644
--- a/src/shim/database_shim.erl
+++ b/src/shim/database_shim.erl
@@ -12,8 +12,7 @@
[
generate_db/1,
fetch/2,
- commit/4,
- assert_session_is_valid/2
+ commit/4
]
).
@@ -38,24 +37,47 @@ add_to_db (ID, Val) ->
io:format("~nadd to db_shim: ~p.~n", [{ID, Val}]),
ets:insert(db_shim, {ID, Val}).
-generate_char_instances (Battlemap, Characters) ->
- lists:map
+generate_random_characters
+(
+ 0,
+ 0,
+ _CharactersPerPlayer,
+ _TotalCharacterCount,
+ Result
+) ->
+ Result;
+generate_random_characters
+(
+ MaxPlayerID,
+ 0,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Result
+) ->
+ generate_random_characters
(
- fun (Char) ->
- {
- character:get_id(Char),
- character_instance:new_instance_of
- (
- Char,
- (rand:uniform(2) - 1), % team,
- {
- rand:uniform(battlemap:get_width(Battlemap) - 1), % X
- rand:uniform(battlemap:get_height(Battlemap) - 1) % Y
- }
- )
- }
- end,
- Characters
+ (MaxPlayerID - 1),
+ CharactersPerPlayer,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Result
+ );
+generate_random_characters
+(
+ MaxPlayerID,
+ PlayerCharacterCount,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Result
+) ->
+ NewCharacter = character:random(TotalCharacterCount, MaxPlayerID),
+ generate_random_characters
+ (
+ MaxPlayerID,
+ (PlayerCharacterCount - 1),
+ CharactersPerPlayer,
+ (TotalCharacterCount + 1),
+ [NewCharacter|Result]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -67,29 +89,21 @@ generate_db (Heir) ->
receive
ok -> ok
end,
- Players = [<<"0">>, <<"1">>],
- Battlemap = battlemap_shim:generate_random(),
- Characters = character_shim:generate_random(rand:uniform(12) + 4),
- CharacterInsts = generate_char_instances(Battlemap, Characters),
+ BattlemapWidth = roll:between(16, 64),
+ BattlemapHeight = roll:between(16, 64),
+ Battlemap = battlemap:random(0, BattlemapWidth, BattlemapHeight),
+ Characters = generate_random_characters(1, 7, 8, 0, []),
+ PlayersAsList = [<<"0">>, <<"1">>],
BattlemapInstance =
- battlemap_instance_shim:generate_random
+ battlemap_instance_shim:random
(
- CharacterInsts,
- Players
+ <<"0">>,
+ PlayersAsList,
+ Battlemap,
+ Characters
),
- add_to_db({battlemap_db, battlemap:get_id(Battlemap)}, Battlemap),
- lists:map
- (
- fun (Char) ->
- add_to_db({character_db, character:get_id(Char)}, Char)
- end,
- Characters
- ),
- add_to_db
- (
- {battlemap_instance_db, battlemap_instance:get_id(BattlemapInstance)},
- BattlemapInstance
- ).
+
+ add_to_db({battlemap_instance_db, <<"0">>}, BattlemapInstance).
fetch (DB, ObjectID) ->
io:format("~ndb_shim lookup: ~p.~n", [{DB, ObjectID}]),
@@ -98,13 +112,5 @@ fetch (DB, ObjectID) ->
[] -> nothing
end.
-commit (DB, Owner, ObjectID, Value) ->
- add_to_db({DB, ObjectID}, Value),
- timed_cache:invalidate(DB, Owner, ObjectID).
-
-assert_session_is_valid (_PlayerID, _SessionToken) ->
- % Ask PlayerID's login server if SessionToken is correct.
- % If so, update last login time to prevent relogin within
- % (database_timeout * 2).
- % If not, crash.
- ok.
+commit (DB, _Owner, ObjectID, Value) ->
+ add_to_db({DB, ObjectID}, Value).
diff --git a/src/shim/weapon_shim.erl b/src/shim/weapon_shim.erl
deleted file mode 100644
index e0364f0..0000000
--- a/src/shim/weapon_shim.erl
+++ /dev/null
@@ -1,24 +0,0 @@
--module(weapon_shim).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- rand/0
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-rand() -> (rand:uniform(25) - 1).