| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | Makefile | 13 | ||||
| -rw-r--r-- | src/battlemap.erl | 8 | ||||
| -rw-r--r-- | src/character.erl | 16 | ||||
| -rw-r--r-- | src/data/tile.erl (renamed from src/tile.erl) | 0 | ||||
| -rw-r--r-- | src/io/database_shim.erl (renamed from src/database_shim.erl) | 59 | ||||
| -rw-r--r-- | src/io/timed_cache.erl (renamed from src/timed_cache.erl) | 0 | ||||
| -rw-r--r-- | src/io/timed_caches_manager.erl (renamed from src/timed_caches_manager.erl) | 0 | ||||
| -rw-r--r-- | src/query/character_turn.erl (renamed from www/handler/battlemap/character_turn.yaws) | 7 | ||||
| -rw-r--r-- | src/query/load_state.erl (renamed from www/handler/battlemap/load_state.yaws) | 36 | ||||
| -rw-r--r-- | src/timed_cache_data.hrl | 9 | ||||
| -rw-r--r-- | src/type/battlemap.erl | 38 | ||||
| -rw-r--r-- | src/type/battlemap/cross.erl (renamed from src/battlemap/cross.erl) | 2 | ||||
| -rw-r--r-- | src/type/battlemap_instance.erl (renamed from src/battlemap_instance.erl) | 21 | ||||
| -rw-r--r-- | src/type/battlemap_instance_shim.erl | 40 | ||||
| -rw-r--r-- | src/type/battlemap_shim.erl (renamed from src/battlemap_shim.erl) | 17 | ||||
| -rw-r--r-- | src/type/character.erl | 34 | ||||
| -rw-r--r-- | src/type/character_instance.erl (renamed from src/character_instance.erl) | 48 | ||||
| -rw-r--r-- | src/type/character_shim.erl (renamed from src/character_shim.erl) | 19 | 
18 files changed, 253 insertions, 114 deletions
| @@ -3,7 +3,7 @@ SRC_DIR ?= src  BIN_DIR ?= ebin  CONF_DIR ?= conf -YAWS_CONF = $(CONF_DIR)/yaws.conf +YAWS_CONF ?= $(CONF_DIR)/yaws.conf  ## Binaries  YAWS ?= yaws @@ -11,9 +11,18 @@ ERLC ?= erlc  ################################################################################  SRC_FILES = $(wildcard $(SRC_DIR)/*.erl) -MODULES = $(patsubst $(SRC_DIR)/%.erl,%,$(SRC_FILES)) +MODULES = $(patsubst %.erl,%,$(SRC_FILES)) +SUB_DIRS = $(filter-out $(MODULES),$(sort $(dir $(wildcard $(SRC_DIR)/*/))))  BIN_FILES = $(patsubst $(SRC_DIR)/%.erl,$(BIN_DIR)/%.beam,$(SRC_FILES)) + +export  ################################################################################ +all: +	for subdir in $(SUB_DIRS) ; do \ +		echo "Building dir $$subdir" ; \ +		$(MAKE) build SRC_DIR=$$subdir || exit 1;\ +	done +  build: $(BIN_DIR) $(BIN_FILES)  run: $(BIN_FILES) diff --git a/src/battlemap.erl b/src/battlemap.erl deleted file mode 100644 index ba89733..0000000 --- a/src/battlemap.erl +++ /dev/null @@ -1,8 +0,0 @@ --module(battlemap). --export([dist/2]). --include("timed_cache_data.hrl"). - --include("battlemap/cross.erl"). - -dist ({OX, OY}, {DX, DY}) -> -   (abs(OX - DX) + abs(OY + DY)). diff --git a/src/character.erl b/src/character.erl deleted file mode 100644 index 4da1684..0000000 --- a/src/character.erl +++ /dev/null @@ -1,16 +0,0 @@ --module(character). --export -( -   [ -      get_movement_points/1, -      get_attack_range/1, -      get_max_health/1 -   ] -). - --include("timed_cache_data.hrl"). - -get_movement_points (Char) -> Char#character.mov_pts. -get_attack_range (Char) -> Char#character.atk_rg. - -get_max_health (Char) -> Char#character.health. diff --git a/src/tile.erl b/src/data/tile.erl index cb5811b..cb5811b 100644 --- a/src/tile.erl +++ b/src/data/tile.erl diff --git a/src/database_shim.erl b/src/io/database_shim.erl index c840009..243051b 100644 --- a/src/database_shim.erl +++ b/src/io/database_shim.erl @@ -8,8 +8,6 @@     ]  ). --include("timed_cache_data.hrl"). -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -36,40 +34,21 @@ generate_char_instances (Battlemap, Characters) ->     (        fun (Char) ->           { -            Char#character.id, -            #character_instance -            { -               x = rand:uniform(Battlemap#battlemap.width - 1), -               y = rand:uniform(Battlemap#battlemap.height - 1), -               team = (rand:uniform(2) - 1), -               health = Char#character.health -            } +            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_heigth(Battlemap) - 1)  % Y +               } +            )           }        end,        Characters     ). -generate_map_instance (CharInts) -> -   #battlemap_instance -   { -      id = <<"0">>, -      chars = dict:from_list(CharInts), -      curr_player = 0, -      players = array:from_list([<<"0">>, <<"1">>]), -      rem_chars = -         lists:filtermap -         ( -            fun ({K, V}) -> -               case character_instance:get_owner(V) of -                  0 -> {true, K}; -                  _ -> false -               end -            end, -            CharInts -         ), -      last_turn = [] -   }. -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -79,21 +58,27 @@ generate_db (Heir) ->     receive        ok -> ok     end, -   Battlemap = battlemap_shim:generate(), -   Characters = character_shim:generate(rand:uniform(12) + 4), +   Players = [<<"0">>, <<"1">>], +   Battlemap = battlemap_shim:generate_random(), +   Characters = character_shim:generate_random(rand:uniform(12) + 4),     CharacterInsts = generate_char_instances(Battlemap, Characters), -   BattlemapInstance = generate_map_instance(CharacterInsts), -   add_to_db({battlemap_db, Battlemap#battlemap.id}, Battlemap), +   BattlemapInstance = +      battlemap_instance_shim:generate_random +      ( +         CharacterInsts, +         Players +      ), +   add_to_db({battlemap_db, battlemap:get_id(Battlemap)}, Battlemap),     lists:map     (        fun (Char) -> -         add_to_db({character_db, Char#character.id}, Char) +         add_to_db({character_db, character:get_id(Char)}, Char)        end,        Characters     ),     add_to_db     ( -      {battlemap_instance_db, BattlemapInstance#battlemap_instance.id}, +      {battlemap_instance_db, battlemap_instance:get_id(BattlemapInstance)},        BattlemapInstance     ). diff --git a/src/timed_cache.erl b/src/io/timed_cache.erl index c86caab..c86caab 100644 --- a/src/timed_cache.erl +++ b/src/io/timed_cache.erl diff --git a/src/timed_caches_manager.erl b/src/io/timed_caches_manager.erl index ad66fbb..ad66fbb 100644 --- a/src/timed_caches_manager.erl +++ b/src/io/timed_caches_manager.erl diff --git a/www/handler/battlemap/character_turn.yaws b/src/query/character_turn.erl index 2b3f818..cf55585 100644 --- a/www/handler/battlemap/character_turn.yaws +++ b/src/query/character_turn.erl @@ -1,4 +1,4 @@ -<erl> +-module(character_turn).  -record  (     input, @@ -26,9 +26,7 @@        target_char_inst     }  ). - - --include("/my/src/tacticians-server/src/timed_cache_data.hrl"). +-export([out/1]).  parse_input (Req) ->     JSONReqMap = jiffy:decode(Req, [return_maps]), @@ -179,4 +177,3 @@ out(A) ->        "application/json; charset=UTF-8",        handle(A#arg.clidata)     }. -</erl> diff --git a/www/handler/battlemap/load_state.yaws b/src/query/load_state.erl index e04fd96..f2818bd 100644 --- a/www/handler/battlemap/load_state.yaws +++ b/src/query/load_state.erl @@ -1,7 +1,6 @@ -<erl> +-module(load_state).  -record(input, {session_token, player_id, battlemap_id, instance_id}). - --include("/my/src/tacticians-server/src/timed_cache_data.hrl"). +-export([out/1]).  parse_input (Req) ->     JSONReqMap = jiffy:decode(Req, [return_maps]), @@ -18,34 +17,36 @@ generate_set_map (Battlemap) ->     (        {           [ -            {<<"width">>, Battlemap#battlemap.width}, -            {<<"height">>, Battlemap#battlemap.height}, -            {<<"content">>, array:sparse_to_list(Battlemap#battlemap.content)} +            {<<"width">>, battlemap:get_width(Battlemap)}, +            {<<"height">>, battlemap:get_height(Battlemap)}, +            {<<"content">>, battlemap:list_tiles(Battlemap)}           ]        }     ).  generate_add_char (Char, CharInstance, BattlemapInstance, PlayerID) -> +   {X, Y} = character_instance:get_location(CharInstance), +   CharID = character:get_id(Char),     jiffy:encode     (        {           [ -            {<<"id">>, Char#character.id}, -            {<<"name">>, Char#character.name}, -            {<<"icon">>, Char#character.icon}, -            {<<"portrait">>, Char#character.portrait}, -            {<<"loc_x">>, CharInstance#character_instance.x}, -            {<<"loc_y">>, CharInstance#character_instance.y}, -            {<<"team">>, CharInstance#character_instance.team}, -            {<<"mov_pts">>, Char#character.mov_pts}, -            {<<"atk_rg">>, Char#character.atk_rg}, +            {<<"id">>, character:get_id(Char)}, +            {<<"name">>, character:get_name(Char)}, +            {<<"icon">>, character:get_icon(Char)}, +            {<<"portrait">>, character:get_portrait(Char)}, +            {<<"loc_x">>, X}, +            {<<"loc_y">>, Y}, +            {<<"team">>, character_instance:get_owner(CharInstance)}, +            {<<"mov_pts">>, character:get_movement_points(Char)}, +            {<<"atk_rg">>, character:get_attack_range(Char)},              {                 <<"enabled">>,                 battlemap_instance:can_play_char_instance                 (                    BattlemapInstance,                    PlayerID, -                  Char#character.id +                  CharID                 )              }           ] @@ -101,7 +102,7 @@ handle (Req) ->                 CharInst              }           end, -         dict:to_list(BattlemapInstance#battlemap_instance.chars) +         battlemap_instance:list_characters(BattlemapInstance)        ),     %%%% Calc     %%%% Commit @@ -120,4 +121,3 @@ out(A) ->        "application/json; charset=UTF-8",        handle(A#arg.clidata)     }. -</erl> diff --git a/src/timed_cache_data.hrl b/src/timed_cache_data.hrl deleted file mode 100644 index 89e0f41..0000000 --- a/src/timed_cache_data.hrl +++ /dev/null @@ -1,9 +0,0 @@ -%% TODO: add types. --record(battlemap, {id, width, height, content, instances}). --record(battlemap_instance, {id, chars, curr_player, players, rem_chars, last_turn}). --record(character, {id, name, icon, portrait, health, mov_pts, atk_rg}). --record(character_turn, {id, path, target}). --record(player, {id, battlemaps, characters}). - -%% Not stored in its own timed cache. --record(character_instance, {x, y, health, team}). diff --git a/src/type/battlemap.erl b/src/type/battlemap.erl new file mode 100644 index 0000000..cce1a76 --- /dev/null +++ b/src/type/battlemap.erl @@ -0,0 +1,38 @@ +-module(battlemap). +-record +( +   battlemap, +   { +      id, +      width, +      height, +      content, +      instances +   } +). +-export +( +   [ +      get_id/1, +      get_width/1, +      get_height/1, +      list_tiles/1, +      get_instances/1 +   ] +). +-export +( +   [dist/2] +). +-export([cross/5]). + +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. + +-include("battlemap/cross.erl"). + +dist ({OX, OY}, {DX, DY}) -> +   (abs(OX - DX) + abs(OY + DY)). diff --git a/src/battlemap/cross.erl b/src/type/battlemap/cross.erl index add9c27..aa1645e 100644 --- a/src/battlemap/cross.erl +++ b/src/type/battlemap/cross.erl @@ -1,5 +1,3 @@ --export([cross/5]). -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/battlemap_instance.erl b/src/type/battlemap_instance.erl index afe6e32..26ca5b1 100644 --- a/src/battlemap_instance.erl +++ b/src/type/battlemap_instance.erl @@ -1,4 +1,22 @@  -module(battlemap_instance). +-record +( +   battlemap_instance, +   { +      id, +      chars, +      curr_player, +      players, +      rem_chars, +      last_turn +   } +). +-export +( +   [ +      list_characters/1 +   ] +).  -export  (     [ @@ -10,7 +28,8 @@     ]  ). --include("timed_cache_data.hrl"). +list_characters (BattlemapInstance) -> +   dict:to_list(BattlemapInstance#battlemap_instance.chars).  get_char_instances (BattlemapInstance) ->     lists:map diff --git a/src/type/battlemap_instance_shim.erl b/src/type/battlemap_instance_shim.erl new file mode 100644 index 0000000..80a1007 --- /dev/null +++ b/src/type/battlemap_instance_shim.erl @@ -0,0 +1,40 @@ +-module(battlemap_instance_shim). +-record +( +   battlemap_instance, +   { +      id, +      chars, +      curr_player, +      players, +      rem_chars, +      last_turn +   } +). +-export +( +   [ +      generate_random/2 +   ] +). + +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/battlemap_shim.erl b/src/type/battlemap_shim.erl index f4042d2..1fb035e 100644 --- a/src/battlemap_shim.erl +++ b/src/type/battlemap_shim.erl @@ -1,13 +1,22 @@  -module(battlemap_shim). +-record +( +   battlemap, +   { +      id, +      width, +      height, +      content, +      instances +   } +).  -export  (     [ -      generate/0 +      generate_random/0     ]  ). --include("timed_cache_data.hrl"). -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -35,7 +44,7 @@ generate(Prev, Result, X, Y, BaseWidth) ->  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -generate () -> +generate_random () ->     Width = (rand:uniform(48) + 16),     Height = (rand:uniform(48) + 16),     #battlemap diff --git a/src/type/character.erl b/src/type/character.erl new file mode 100644 index 0000000..e5b6d9f --- /dev/null +++ b/src/type/character.erl @@ -0,0 +1,34 @@ +-module(character). +-record +( +   character, +   { +      id, +      name, +      icon, +      portrait, +      health, +      mov_pts, +      atk_rg +   } +). +-export +( +   [ +      get_id/1, +      get_name/1, +      get_icon/1, +      get_portrait/1, +      get_max_health/1, +      get_movement_points/1, +      get_attack_range/1 +   ] +). + +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_max_health (Char) -> Char#character.health. +get_movement_points (Char) -> Char#character.mov_pts. +get_attack_range (Char) -> Char#character.atk_rg. diff --git a/src/character_instance.erl b/src/type/character_instance.erl index e1cf7fe..5432c99 100644 --- a/src/character_instance.erl +++ b/src/type/character_instance.erl @@ -1,16 +1,52 @@  -module(character_instance). +-record +( +   character_instance, +   { +      x, +      y, +      health, +      team +   } +).  -export  (     [ -      set_location/3, -      mod_health/3, -      is_dead/1, % is_alive is reserved.        get_location/1, +      get_current_health/1,        get_owner/1     ]  ). +-export +( +   [ +      new_instance_of/3 +   ] +). +-export +( +   [ +      set_location/3, +      mod_health/3, +      is_dead/1 % is_alive is reserved. +   ] +). + +get_location (CharInst) -> +   {CharInst#character_instance.x, CharInst#character_instance.y}. + +get_current_health (CharInst) -> CharInst#character_instance.health. --include("timed_cache_data.hrl"). +get_owner (CharInst) -> CharInst#character_instance.team. + +new_instance_of (Char, Owner, {X, Y}) -> +   #character_instance +   { +      x = X, +      y = Y, +      health = character:get_max_health(Char), +      team = Owner +   }.  set_location (CharInst, X, Y) ->     CharInst#character_instance @@ -34,7 +70,3 @@ mod_health (CharInst, MaxHealth, HealthMod) ->  is_dead (CharInst) -> (CharInst#character_instance.health == 0). -get_location (CharInst) -> -   {CharInst#character_instance.x, CharInst#character_instance.y}. - -get_owner (CharInst) -> CharInst#character_instance.team. diff --git a/src/character_shim.erl b/src/type/character_shim.erl index 47d9cac..0ad357d 100644 --- a/src/character_shim.erl +++ b/src/type/character_shim.erl @@ -1,13 +1,24 @@  -module(character_shim). +-record +( +   character, +   { +      id, +      name, +      icon, +      portrait, +      health, +      mov_pts, +      atk_rg +   } +).  -export  (     [ -      generate/1 +      generate_random/1     ]  ). --include("timed_cache_data.hrl"). -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -32,5 +43,5 @@ generate (N, Prev) ->  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -generate (N) -> +generate_random (N) ->     generate(N, []). | 


